sites

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

dwm-sticky-2022-12-05-d47ba0b.diff (5321B)


      1 From d47ba0b8aab26ffb2569c0d05df24fdd61b3f4b0 Mon Sep 17 00:00:00 2001
      2 From: aymey <fabianpaci@gmail.com>
      3 Date: Mon, 5 Dec 2022 22:57:41 +1100
      4 Subject: [PATCH] Sticky windows respect EWMH
      5 
      6 ---
      7  dwm.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
      8  1 file changed, 44 insertions(+), 7 deletions(-)
      9 
     10 diff --git a/dwm.c b/dwm.c
     11 index 253aba7..a9157bf 100644
     12 --- a/dwm.c
     13 +++ b/dwm.c
     14 @@ -49,7 +49,7 @@
     15  #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
     16  #define INTERSECT(x,y,w,h,m)    (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \
     17                                 * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy)))
     18 -#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
     19 +#define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]) || C->issticky)
     20  #define LENGTH(X)               (sizeof X / sizeof X[0])
     21  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
     22  #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
     23 @@ -61,7 +61,7 @@
     24  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     25  enum { SchemeNorm, SchemeSel }; /* color schemes */
     26  enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
     27 -       NetWMFullscreen, NetActiveWindow, NetWMWindowType,
     28 +       NetWMFullscreen, NetWMSticky, NetActiveWindow, NetWMWindowType,
     29         NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
     30  enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
     31  enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
     32 @@ -92,7 +92,7 @@ struct Client {
     33  	int basew, baseh, incw, inch, maxw, maxh, minw, minh, hintsvalid;
     34  	int bw, oldbw;
     35  	unsigned int tags;
     36 -	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
     37 +	int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, issticky;
     38  	Client *next;
     39  	Client *snext;
     40  	Monitor *mon;
     41 @@ -200,6 +200,7 @@ static void sendmon(Client *c, Monitor *m);
     42  static void setclientstate(Client *c, long state);
     43  static void setfocus(Client *c);
     44  static void setfullscreen(Client *c, int fullscreen);
     45 +static void setsticky(Client *c, int sticky);
     46  static void setlayout(const Arg *arg);
     47  static void setmfact(const Arg *arg);
     48  static void setup(void);
     49 @@ -212,6 +213,7 @@ static void tagmon(const Arg *arg);
     50  static void tile(Monitor *m);
     51  static void togglebar(const Arg *arg);
     52  static void togglefloating(const Arg *arg);
     53 +static void togglesticky(const Arg *arg);
     54  static void toggletag(const Arg *arg);
     55  static void toggleview(const Arg *arg);
     56  static void unfocus(Client *c, int setfocus);
     57 @@ -526,6 +528,10 @@ clientmessage(XEvent *e)
     58  		|| cme->data.l[2] == netatom[NetWMFullscreen])
     59  			setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD    */
     60  				|| (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
     61 +
     62 +        if (cme->data.l[1] == netatom[NetWMSticky]
     63 +                || cme->data.l[2] == netatom[NetWMSticky])
     64 +            setsticky(c, (cme->data.l[0] == 1 || (cme->data.l[0] == 2 && !c->issticky)));
     65  	} else if (cme->message_type == netatom[NetActiveWindow]) {
     66  		if (c != selmon->sel && !c->isurgent)
     67  			seturgent(c, 1);
     68 @@ -1498,6 +1504,23 @@ setfullscreen(Client *c, int fullscreen)
     69  	}
     70  }
     71  
     72 +void
     73 +setsticky(Client *c, int sticky)
     74 +{
     75 +
     76 +    if(sticky && !c->issticky) {
     77 +        XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
     78 +                PropModeReplace, (unsigned char *) &netatom[NetWMSticky], 1);
     79 +        c->issticky = 1;
     80 +    } else if(!sticky && c->issticky){
     81 +        XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
     82 +                PropModeReplace, (unsigned char *)0, 0);
     83 +        c->issticky = 0;
     84 +        arrange(c->mon);
     85 +    }
     86 +}
     87 +
     88 +
     89  void
     90  setlayout(const Arg *arg)
     91  {
     92 @@ -1560,6 +1583,7 @@ setup(void)
     93  	netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
     94  	netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False);
     95  	netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
     96 +    netatom[NetWMSticky] = XInternAtom(dpy, "_NET_WM_STATE_STICKY", False);
     97  	netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
     98  	netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
     99  	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
    100 @@ -1719,6 +1743,15 @@ togglefloating(const Arg *arg)
    101  	arrange(selmon);
    102  }
    103  
    104 +void
    105 +togglesticky(const Arg *arg)
    106 +{
    107 +	if (!selmon->sel)
    108 +		return;
    109 +    setsticky(selmon->sel, !selmon->sel->issticky);
    110 +	arrange(selmon);
    111 +}
    112 +
    113  void
    114  toggletag(const Arg *arg)
    115  {
    116 @@ -2009,10 +2042,13 @@ updatewindowtype(Client *c)
    117  	Atom state = getatomprop(c, netatom[NetWMState]);
    118  	Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
    119  
    120 -	if (state == netatom[NetWMFullscreen])
    121 -		setfullscreen(c, 1);
    122 -	if (wtype == netatom[NetWMWindowTypeDialog])
    123 -		c->isfloating = 1;
    124 +    if (state == netatom[NetWMFullscreen])
    125 +        setfullscreen(c, 1);
    126 +    if (state == netatom[NetWMSticky]) {
    127 +        setsticky(c, 1);
    128 +    }
    129 +    if (wtype == netatom[NetWMWindowTypeDialog])
    130 +        c->isfloating = 1;
    131  }
    132  
    133  void
    134 @@ -2147,3 +2183,4 @@ main(int argc, char *argv[])
    135  	XCloseDisplay(dpy);
    136  	return EXIT_SUCCESS;
    137  }
    138 +
    139 -- 
    140 2.38.1
    141