sites

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

dwm-decorhints-6.2.diff (4371B)


      1 From 3875094925f817e047049635514034a75275d269 Mon Sep 17 00:00:00 2001
      2 From: Jakub Leszczak <szatan@gecc.xyz>
      3 Date: Sat, 18 Apr 2020 19:17:46 +0200
      4 Subject: [PATCH] Respect decoration hints
      5 
      6 Make dwm respect _MOTIF_WM_HINTS property.  Applications use this
      7 property to notify window managers to not draw window decorations.
      8 
      9 Not respecting this property leads to issues with applications that draw
     10 their own borders, like chromium (with "Use system title bar and
     11 borders" turned off) and vlc in fullscreen mode.
     12 ---
     13  config.def.h |  1 +
     14  dwm.c        | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
     15  2 files changed, 47 insertions(+), 1 deletion(-)
     16 
     17 diff --git a/config.def.h b/config.def.h
     18 index 1c0b587..2a32635 100644
     19 --- a/config.def.h
     20 +++ b/config.def.h
     21 @@ -35,6 +35,7 @@ static const Rule rules[] = {
     22  static const float mfact     = 0.55; /* factor of master area size [0.05..0.95] */
     23  static const int nmaster     = 1;    /* number of clients in master area */
     24  static const int resizehints = 1;    /* 1 means respect size hints in tiled resizals */
     25 +static const int decorhints  = 1;    /* 1 means respect decoration hints */
     26  
     27  static const Layout layouts[] = {
     28  	/* symbol     arrange function */
     29 diff --git a/dwm.c b/dwm.c
     30 index 4465af1..95873c7 100644
     31 --- a/dwm.c
     32 +++ b/dwm.c
     33 @@ -57,6 +57,13 @@
     34  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
     35  #define TEXTW(X)                (drw_fontset_getwidth(drw, (X)) + lrpad)
     36  
     37 +#define MWM_HINTS_FLAGS_FIELD       0
     38 +#define MWM_HINTS_DECORATIONS_FIELD 2
     39 +#define MWM_HINTS_DECORATIONS       (1 << 1)
     40 +#define MWM_DECOR_ALL               (1 << 0)
     41 +#define MWM_DECOR_BORDER            (1 << 1)
     42 +#define MWM_DECOR_TITLE             (1 << 3)
     43 +
     44  /* enums */
     45  enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
     46  enum { SchemeNorm, SchemeSel }; /* color schemes */
     47 @@ -220,6 +227,7 @@ static void updatebarpos(Monitor *m);
     48  static void updatebars(void);
     49  static void updateclientlist(void);
     50  static int updategeom(void);
     51 +static void updatemotifhints(Client *c);
     52  static void updatenumlockmask(void);
     53  static void updatesizehints(Client *c);
     54  static void updatestatus(void);
     55 @@ -259,7 +267,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
     56  	[PropertyNotify] = propertynotify,
     57  	[UnmapNotify] = unmapnotify
     58  };
     59 -static Atom wmatom[WMLast], netatom[NetLast];
     60 +static Atom wmatom[WMLast], netatom[NetLast], motifatom;
     61  static int running = 1;
     62  static Cur *cursor[CurLast];
     63  static Clr **scheme;
     64 @@ -1056,6 +1064,7 @@ manage(Window w, XWindowAttributes *wa)
     65  	updatewindowtype(c);
     66  	updatesizehints(c);
     67  	updatewmhints(c);
     68 +	updatemotifhints(c);
     69  	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
     70  	grabbuttons(c, 0);
     71  	if (!c->isfloating)
     72 @@ -1242,6 +1251,8 @@ propertynotify(XEvent *e)
     73  		}
     74  		if (ev->atom == netatom[NetWMWindowType])
     75  			updatewindowtype(c);
     76 +		if (ev->atom == motifatom)
     77 +			updatemotifhints(c);
     78  	}
     79  }
     80  
     81 @@ -1562,6 +1573,7 @@ setup(void)
     82  	netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
     83  	netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
     84  	netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
     85 +	motifatom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
     86  	/* init cursors */
     87  	cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
     88  	cursor[CurResize] = drw_cur_create(drw, XC_sizing);
     89 @@ -1925,6 +1937,39 @@ updategeom(void)
     90  	return dirty;
     91  }
     92  
     93 +void
     94 +updatemotifhints(Client *c)
     95 +{
     96 +	Atom real;
     97 +	int format;
     98 +	unsigned char *p = NULL;
     99 +	unsigned long n, extra;
    100 +	unsigned long *motif;
    101 +	int width, height;
    102 +
    103 +	if (!decorhints)
    104 +		return;
    105 +
    106 +	if (XGetWindowProperty(dpy, c->win, motifatom, 0L, 5L, False, motifatom,
    107 +	                       &real, &format, &n, &extra, &p) == Success && p != NULL) {
    108 +		motif = (unsigned long*)p;
    109 +		if (motif[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
    110 +			width = WIDTH(c);
    111 +			height = HEIGHT(c);
    112 +
    113 +			if (motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_ALL ||
    114 +			    motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_BORDER ||
    115 +			    motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_TITLE)
    116 +				c->bw = c->oldbw = borderpx;
    117 +			else
    118 +				c->bw = c->oldbw = 0;
    119 +
    120 +			resize(c, c->x, c->y, width - (2*c->bw), height - (2*c->bw), 0);
    121 +		}
    122 +		XFree(p);
    123 +	}
    124 +}
    125 +
    126  void
    127  updatenumlockmask(void)
    128  {
    129 -- 
    130 2.26.2
    131