From 303509624424b970d2a4ab36efcb79d53fb318de Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 9 Jul 2022 14:16:07 +0200 Subject: [PATCH] Tag switching --- src/Makefile | 2 +- src/dwm.c | 5 ++++- src/xwrappers.c | 53 ++++++++++++++++++++++++++++++++++++++++++------- src/xwrappers.h | 22 ++++++++++++++++++-- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/src/Makefile b/src/Makefile index a59ccf4..5c4a110 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ include config.mk -SRC = drw.c dwm.c util.c +SRC = drw.c dwm.c util.c xwrappers.c OBJ = ${SRC:.c=.o} all: options dwm dwm-msg diff --git a/src/dwm.c b/src/dwm.c index b8defcd..608d2d6 100644 --- a/src/dwm.c +++ b/src/dwm.c @@ -66,10 +66,13 @@ /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel }; /* color schemes */ +/* enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ +/* enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ + enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ @@ -2187,7 +2190,7 @@ showhide(Client *c) } else { /* hide clients bottom up */ showhide(c->snext); - window_unmap(dpy, c->win, root, 1); + window_umap(dpy, c->win, root, 1); //XMoveWindow(dpy, c->win, WIDTH(c) * -2, c->y); } } diff --git a/src/xwrappers.c b/src/xwrappers.c index 75b1979..b6ee129 100644 --- a/src/xwrappers.c +++ b/src/xwrappers.c @@ -1,10 +1,12 @@ #include #include #include +#include -static Atom atom[LastAtom]; +#include "xwrappers.h" + +static Atom atoms[LastAtom]; static int atoms_intialised = 0; -static int (*xerrorxlib)(Display *, XErrorEvent *); Atom * get_atoms(Display *dpy) @@ -48,10 +50,10 @@ get_atoms(Display *dpy) atoms[Xembed] = XInternAtom(dpy, "_XEMBED", False); atoms[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False); - atoms[MWMClientTags] = XInternAtom(dpy, "_MWM_CLIENT_TAGS", False); - atoms[MWMCurrentTags] = XInternAtom(dpy, "_MWM_CURRENT_TAGS", False); - atoms[MWMClientMonitor] = XInternAtom(dpy, "_MWM_CLIENT_MONITOR", False); - atoms[MWMBorderWidth] = XInternAtom(dpy, "_MWM_BORDER_WIDTH", False); + atoms[WMClientTags] = XInternAtom(dpy, "_MWM_CLIENT_TAGS", False); + atoms[WMCurrentTags] = XInternAtom(dpy, "_MWM_CURRENT_TAGS", False); + atoms[WMClientMonitor] = XInternAtom(dpy, "_MWM_CLIENT_MONITOR", False); + atoms[WMBorderWidth] = XInternAtom(dpy, "_MWM_BORDER_WIDTH", False); atoms[SteamGame] = XInternAtom(dpy, "STEAM_GAME", False); atoms[KDENetWMWindowTypeOverride] = XInternAtom(dpy, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", False); @@ -63,8 +65,45 @@ get_atoms(Display *dpy) return atoms; } +// Function to set a windows state with x void window_set_state(Display *dpy, Window win, long state) { long data[] = {state, None}; - + get_atoms(dpy); + + XChangeProperty(dpy, win, atoms[WMState], atoms[WMState], 32, PropModeReplace, (unsigned char*)data, 2); +} + +void +window_map(Display *dpy, Window win, int deicon) { + if (!win) // if the window does not exist then just panic and escape + return; + + XMapWindow(dpy, win); + if (deicon) + window_set_state(dpy, win, NormalState); + XSetInputFocus(dpy, win, RevertToPointerRoot, CurrentTime); +} + +void +window_umap(Display * dpy, Window win, Window root, int icon) { + static XWindowAttributes ra, ca; + if (!win) + return; + + XGrabServer(dpy); + + XGetWindowAttributes(dpy, root, &ra); + XGetWindowAttributes(dpy, win, &ca); + + XSelectInput(dpy, root, ra.your_event_mask & ~SubstructureNotifyMask); + XSelectInput(dpy, win, ca.your_event_mask & ~SubstructureNotifyMask); + + XUnmapWindow(dpy, win); + if (icon) + window_set_state(dpy, win, IconicState); + + XSelectInput(dpy, root, ra.your_event_mask); + XSelectInput(dpy, win, ca.your_event_mask); + XUngrabServer(dpy); } diff --git a/src/xwrappers.h b/src/xwrappers.h index 62759a2..e8608ff 100644 --- a/src/xwrappers.h +++ b/src/xwrappers.h @@ -2,6 +2,24 @@ #include #include +enum { NetSupported, NetWMDemandsAttention, NetWMName, NetWMState, NetWMCheck, + NetWMActionClose, NetWMActionMinimize, NetWMAction, NetWMMoveResize, + NetWMMaximizedVert, NetWMMaximizedHorz, + NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz, + NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetWMWindowTypeDock, NetWMDesktop, + NetWMWindowTypeDesktop, NetWMWindowTypeDialog, NetClientList, NetClientListStacking, + NetDesktopNames, NetDesktopViewport, NetNumberOfDesktops, + NetCurrentDesktop, /* EWMH atoms */ + + Manager, Xembed, XembedInfo, /* Xembed atoms */ + + SteamGame, WMClientTags, WMCurrentTags, WMClientMonitor, WMBorderWidth, WMLast, + + WMProtocols, WMDelete, WMState, WMTakeFocus, WMChangeState, + WMWindowRole, /* default atoms */ + + KDENetWMWindowTypeOverride, Utf8, Motif, NetLast, LastAtom }; + void window_set_state(Display*, Window, long); -void window_map(Display*, Window win, long state); -void window_umap(Display*, Window win, Window root, int); +void window_map(Display*, Window, int); +void window_umap(Display*, Window, Window, int);