sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dwm-preserveonrestart-6.3.diff (4090B)


      1 From 713fa8650f5a20006451ebcccf57a4512e83bae8 Mon Sep 17 00:00:00 2001
      2 From: Arda Atci <arda@phytech.io>
      3 Date: Wed, 18 May 2022 17:23:16 +0300
      4 Subject: [PATCH] preserve clients on old tags when renewing dwm
      5 
      6 By default, when dwm is recompiled-restarted all clients will
      7 lose it's current tag and collapse to first tag. This patch preserves
      8 clients on old tags, however note that layout order is not preserved.
      9 
     10 ---
     11  dwm.c | 38 +++++++++++++++++++++++++++++++++++++-
     12  1 file changed, 37 insertions(+), 1 deletion(-)
     13 
     14 diff --git a/dwm.c b/dwm.c
     15 index a96f33c..a12e0bd 100644
     16 --- a/dwm.c
     17 +++ b/dwm.c
     18 @@ -62,7 +62,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     19  enum { SchemeNorm, SchemeSel }; /* color schemes */
     20  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     21         NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     22 -       NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     23 +       NetWMWindowTypeDialog, NetClientList, NetClientInfo, NetLast }; /* EWMH atoms */
     24  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
     25  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
     26         ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
     27 @@ -198,6 +198,7 @@ static void scan(void);
     28  static int sendevent(Client *c, Atom proto);
     29  static void sendmon(Client *c, Monitor *m);
     30  static void setclientstate(Client *c, long state);
     31 +static void setclienttagprop(Client *c);
     32  static void setfocus(Client *c);
     33  static void setfullscreen(Client *c, int fullscreen);
     34  static void setlayout(const Arg *arg);
     35 @@ -1060,6 +1061,26 @@ manage(Window w, XWindowAttributes *wa)
     36  	updatewindowtype(c);
     37  	updatesizehints(c);
     38  	updatewmhints(c);
     39 +	{
     40 +		int format;
     41 +		unsigned long *data, n, extra;
     42 +		Monitor *m;
     43 +		Atom atom;
     44 +		if (XGetWindowProperty(dpy, c->win, netatom[NetClientInfo], 0L, 2L, False, XA_CARDINAL,
     45 +				&atom, &format, &n, &extra, (unsigned char **)&data) == Success && n == 2) {
     46 +			c->tags = *data;
     47 +			for (m = mons; m; m = m->next) {
     48 +				if (m->num == *(data+1)) {
     49 +					c->mon = m;
     50 +					break;
     51 +				}
     52 +			}
     53 +		}
     54 +		if (n > 0)
     55 +			XFree(data);
     56 +	}
     57 +	setclienttagprop(c);
     58 +
     59  	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
     60  	grabbuttons(c, 0);
     61  	if (!c->isfloating)
     62 @@ -1423,6 +1444,7 @@ sendmon(Client *c, Monitor *m)
     63  	c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
     64  	attach(c);
     65  	attachstack(c);
     66 +	setclienttagprop(c);
     67  	focus(NULL);
     68  	arrange(NULL);
     69  }
     70 @@ -1566,6 +1588,7 @@ setup(void)
     71  	netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
     72  	netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
     73  	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
     74 +	netatom[NetClientInfo] = XInternAtom(dpy, "_NET_CLIENT_INFO", False);
     75  	/* init cursors */
     76  	cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
     77  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
     78 @@ -1589,6 +1612,7 @@ setup(void)
     79  	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
     80  		PropModeReplace, (unsigned char *) netatom, NetLast);
     81  	XDeleteProperty(dpy, root, netatom[NetClientList]);
     82 +	XDeleteProperty(dpy, root, netatom[NetClientInfo]);
     83  	/* select events */
     84  	wa.cursor = cursor[CurNormal]->cursor;
     85  	wa.event_mask = SubstructureRedirectMask|SubstructureNotifyMask
     86 @@ -1656,11 +1680,22 @@ spawn(const Arg *arg)
     87  	}
     88  }
     89 
     90 +void
     91 +setclienttagprop(Client *c)
     92 +{
     93 +	long data[] = { (long) c->tags, (long) c->mon->num };
     94 +	XChangeProperty(dpy, c->win, netatom[NetClientInfo], XA_CARDINAL, 32,
     95 +			PropModeReplace, (unsigned char *) data, 2);
     96 +}
     97 +
     98  void
     99  tag(const Arg *arg)
    100  {
    101 +	Client *c;
    102  	if (selmon->sel && arg->ui & TAGMASK) {
    103 +		c = selmon->sel;
    104  		selmon->sel->tags = arg->ui & TAGMASK;
    105 +		setclienttagprop(c);
    106  		focus(NULL);
    107  		arrange(selmon);
    108  	}
    109 @@ -1735,6 +1770,7 @@ toggletag(const Arg *arg)
    110  	newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
    111  	if (newtags) {
    112  		selmon->sel->tags = newtags;
    113 +		setclienttagprop(selmon->sel);
    114  		focus(NULL);
    115  		arrange(selmon);
    116  	}
    117 --
    118 2.36.1