From 9cbc6bfeb9853a5d535b5a629a83101103332063 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Thu, 4 May 2023 00:50:10 -0700 Subject: [PATCH] Save client tags and monitors only on restart --- dwm.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/dwm.c b/dwm.c index a54bdc0..1566830 100644 --- a/dwm.c +++ b/dwm.c @@ -77,7 +77,7 @@ enum { SchemeNorm, SchemeSel, SchemeStatus, SchemeTagsSel, SchemeTagsNorm, Schem enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetSystemTray, NetSystemTrayOP, NetSystemTrayOrientation, NetSystemTrayOrientationHorz, NetWMFullscreen, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ + NetWMWindowTypeDialog, NetClientList, NetClientInfo, NetLast }; /* EWMH atoms */ enum { Manager, Xembed, XembedInfo, XLast }; /* Xembed atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, @@ -220,6 +220,7 @@ static void resizeclient(Client *c, int x, int y, int w, int h); static void resizemouse(const Arg *arg); static void resizerequest(XEvent *e); static void restack(Monitor *m); +static void restart(const Arg *arg); static void run(void); static void scan(void); static int sendevent(Window w, Atom proto, int m, long d0, long d1, long d2, long d3, long d4); @@ -268,7 +269,6 @@ static int xerror(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); -static void restart(const Arg *arg); /* variables */ static const char *exec_name; @@ -1188,6 +1188,26 @@ manage(Window w, XWindowAttributes *wa) updatewindowtype(c); updatesizehints(c); updatewmhints(c); + { + int format; + unsigned long *data, n, extra; + Monitor *m; + Atom atom; + if (XGetWindowProperty(dpy, c->win, netatom[NetClientInfo], 0L, 2L, False, XA_CARDINAL, + &atom, &format, &n, &extra, (unsigned char **)&data) == Success && n == 2) { + c->tags = *data; + for (m = mons; m; m = m->next) { + if (m->num == *(data+1)) { + c->mon = m; + break; + } + } + /* remove the property */ + XDeleteProperty(dpy, c->win, netatom[NetClientInfo]); + } + if (n > 0) + XFree(data); + } XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); grabbuttons(c, 0); if (!c->isfloating) @@ -1562,6 +1582,25 @@ restack(Monitor *m) while (XCheckMaskEvent(dpy, EnterWindowMask, &ev)); } +void +restart(const Arg *arg) +{ + Monitor *m; + Client *c; + + /* tag each client so we can restart with it on the correct tag*/ + for (m = mons; m; m = m->next) { + for (c = m->clients; c; c = c->next) { + long data[] = { (long) c->tags, (long) c->mon->num }; + XChangeProperty(dpy, c->win, netatom[NetClientInfo], XA_CARDINAL, 32, + PropModeReplace, (unsigned char *) data, 2); + } + } + XFlush(dpy); + + execlp(exec_name, exec_name, NULL); +} + void run(void) { @@ -1787,6 +1826,7 @@ setup(void) netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); + netatom[NetClientInfo] = XInternAtom(dpy, "_NET_CLIENT_INFO", False); xatom[Manager] = XInternAtom(dpy, "MANAGER", False); xatom[Xembed] = XInternAtom(dpy, "_XEMBED", False); xatom[XembedInfo] = XInternAtom(dpy, "_XEMBED_INFO", False); @@ -2553,11 +2593,6 @@ zoom(const Arg *arg) pop(c); } -void -restart(const Arg *arg) { - execlp(exec_name, exec_name, NULL); -} - int main(int argc, char *argv[]) {