From 425d67b92332deaa50fb712890ff3bf4d3a28c81 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 8 Oct 2020 14:01:47 +0200 Subject: [PATCH 1/3] Make EWMH windows float Move updatewindowtype() functionality into applyrules(), and also make following EWMH windows float: DIALOG, UTILITY, TOOLBAR, SPLASH. Ref. https://lists.suckless.org/hackers/2005/17374.html --- config.def.h | 12 +++++++++--- dwm.c | 28 +++++++++------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/config.def.h b/config.def.h index 1c0b587..221428f 100644 --- a/config.def.h +++ b/config.def.h @@ -21,14 +21,20 @@ static const char *colors[][3] = { /* tagging */ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; +#define WTYPE "_NET_WM_WINDOW_TYPE_" static const Rule rules[] = { /* xprop(1): * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title + * _NET_WM_WINDOW_TYPE(ATOM) = wintype */ - /* class instance title tags mask isfloating monitor */ - { "Gimp", NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, + /* class instance title wintype, tags mask isfloating monitor */ + { NULL, NULL, NULL, WTYPE "DIALOG", 0, 1, -1 }, + { NULL, NULL, NULL, WTYPE "UTILITY", 0, 1, -1 }, + { NULL, NULL, NULL, WTYPE "TOOLBAR", 0, 1, -1 }, + { NULL, NULL, NULL, WTYPE "SPLASH", 0, 1, -1 }, + { "Gimp", NULL, NULL, NULL, 0, 1, -1 }, + { "Firefox", NULL, NULL, NULL, 1 << 8, 0, -1 }, }; /* layout(s) */ diff --git a/dwm.c b/dwm.c index 4465af1..1d4475b 100644 --- a/dwm.c +++ b/dwm.c @@ -62,7 +62,7 @@ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, - NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */ + NetClientList, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ @@ -136,6 +136,7 @@ typedef struct { const char *class; const char *instance; const char *title; + const char *wintype; unsigned int tags; int isfloating; int monitor; @@ -169,6 +170,7 @@ static void focus(Client *c); static void focusin(XEvent *e); static void focusmon(const Arg *arg); static void focusstack(const Arg *arg); +static Atom getatomprop(Client *c, Atom prop); static int getrootptr(int *x, int *y); static long getstate(Window w); static int gettextprop(Window w, Atom atom, char *text, unsigned int size); @@ -224,7 +226,6 @@ static void updatenumlockmask(void); static void updatesizehints(Client *c); static void updatestatus(void); static void updatetitle(Client *c); -static void updatewindowtype(Client *c); static void updatewmhints(Client *c); static void view(const Arg *arg); static Client *wintoclient(Window w); @@ -279,6 +280,7 @@ void applyrules(Client *c) { const char *class, *instance; + Atom wintype; unsigned int i; const Rule *r; Monitor *m; @@ -290,12 +292,14 @@ applyrules(Client *c) XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; + wintype = getatomprop(c, netatom[NetWMWindowType]); for (i = 0; i < LENGTH(rules); i++) { r = &rules[i]; if ((!r->title || strstr(c->name, r->title)) && (!r->class || strstr(class, r->class)) - && (!r->instance || strstr(instance, r->instance))) + && (!r->instance || strstr(instance, r->instance)) + && (!r->wintype || wintype == XInternAtom(dpy, r->wintype, False))) { c->isfloating = r->isfloating; c->tags |= r->tags; @@ -1053,7 +1057,8 @@ manage(Window w, XWindowAttributes *wa) XConfigureWindow(dpy, w, CWBorderWidth, &wc); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); configure(c); /* propagates border_width, if size doesn't change */ - updatewindowtype(c); + if (getatomprop(c, netatom[NetWMState]) == netatom[NetWMFullscreen]) + setfullscreen(c, 1); updatesizehints(c); updatewmhints(c); XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); @@ -1240,8 +1245,6 @@ propertynotify(XEvent *e) if (c == c->mon->sel) drawbar(c->mon); } - if (ev->atom == netatom[NetWMWindowType]) - updatewindowtype(c); } } @@ -1560,7 +1563,6 @@ setup(void) netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); 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); /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); @@ -2001,18 +2003,6 @@ updatetitle(Client *c) strcpy(c->name, broken); } -void -updatewindowtype(Client *c) -{ - Atom state = getatomprop(c, netatom[NetWMState]); - Atom wtype = getatomprop(c, netatom[NetWMWindowType]); - - if (state == netatom[NetWMFullscreen]) - setfullscreen(c, 1); - if (wtype == netatom[NetWMWindowTypeDialog]) - c->isfloating = 1; -} - void updatewmhints(Client *c) { -- 2.19.1 From 6c5cf36e102c66aba4c6cc0cb538ab57ae919369 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 8 Oct 2020 14:18:07 +0200 Subject: [PATCH 2/3] Adding window role rule This patch adds a new rule property based on WM_WINDOW_ROLE(STRING) so that one can differentiate between window roles, e.g. Firefox "browser" vs "Preferences". Ref. https://github.com/bakkeby/patches/wiki/windowrolerule --- config.def.h | 14 +++++++------- dwm.c | 7 ++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/config.def.h b/config.def.h index 221428f..dd003d0 100644 --- a/config.def.h +++ b/config.def.h @@ -28,13 +28,13 @@ static const Rule rules[] = { * WM_NAME(STRING) = title * _NET_WM_WINDOW_TYPE(ATOM) = wintype */ - /* class instance title wintype, tags mask isfloating monitor */ - { NULL, NULL, NULL, WTYPE "DIALOG", 0, 1, -1 }, - { NULL, NULL, NULL, WTYPE "UTILITY", 0, 1, -1 }, - { NULL, NULL, NULL, WTYPE "TOOLBAR", 0, 1, -1 }, - { NULL, NULL, NULL, WTYPE "SPLASH", 0, 1, -1 }, - { "Gimp", NULL, NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, NULL, 1 << 8, 0, -1 }, + /* class role instance title wintype, tags mask isfloating monitor */ + { NULL, NULL, NULL, NULL, WTYPE "DIALOG", 0, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "UTILITY", 0, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "TOOLBAR", 0, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "SPLASH", 0, 1, -1 }, + { "Gimp", NULL, NULL, NULL, NULL, 0, 1, -1 }, + { "Firefox", NULL, NULL, NULL, NULL, 1 << 8, 0, -1 }, }; /* layout(s) */ diff --git a/dwm.c b/dwm.c index 1d4475b..74bf95a 100644 --- a/dwm.c +++ b/dwm.c @@ -63,7 +63,7 @@ enum { SchemeNorm, SchemeSel }; /* color schemes */ enum { NetSupported, NetWMName, NetWMState, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetClientList, NetLast }; /* EWMH atoms */ -enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */ +enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMWindowRole, WMLast }; /* default atoms */ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ @@ -134,6 +134,7 @@ struct Monitor { typedef struct { const char *class; + const char *role; const char *instance; const char *title; const char *wintype; @@ -280,6 +281,7 @@ void applyrules(Client *c) { const char *class, *instance; + char role[64]; Atom wintype; unsigned int i; const Rule *r; @@ -292,12 +294,14 @@ applyrules(Client *c) XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; + gettextprop(c->win, wmatom[WMWindowRole], role, sizeof(role)); wintype = getatomprop(c, netatom[NetWMWindowType]); for (i = 0; i < LENGTH(rules); i++) { r = &rules[i]; if ((!r->title || strstr(c->name, r->title)) && (!r->class || strstr(class, r->class)) + && (!r->role || strstr(role, r->role)) && (!r->instance || strstr(instance, r->instance)) && (!r->wintype || wintype == XInternAtom(dpy, r->wintype, False))) { @@ -1556,6 +1560,7 @@ setup(void) wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False); + wmatom[WMWindowRole] = XInternAtom(dpy, "WM_WINDOW_ROLE", False); netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", False); netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); -- 2.19.1 From b30d7cced69b8c1a50dbc996600ff511e9e34a3a Mon Sep 17 00:00:00 2001 From: bakkeby Date: Thu, 8 Oct 2020 19:38:56 +0200 Subject: [PATCH 3/3] focusedontop: allow the currently focused client to display on top of floating windows, but not on top of transient windows or dialog boxes --- config.def.h | 16 +++++++++------- dwm.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/config.def.h b/config.def.h index dd003d0..7c0c27e 100644 --- a/config.def.h +++ b/config.def.h @@ -5,6 +5,7 @@ static const unsigned int borderpx = 1; /* border pixel of windows */ static const unsigned int snap = 32; /* snap pixel */ static const int showbar = 1; /* 0 means no bar */ static const int topbar = 1; /* 0 means bottom bar */ +static const int focusedontop = 1; /* 1 means focused client is shown on top of floating windows */ static const char *fonts[] = { "monospace:size=10" }; static const char dmenufont[] = "monospace:size=10"; static const char col_gray1[] = "#222222"; @@ -28,13 +29,14 @@ static const Rule rules[] = { * WM_NAME(STRING) = title * _NET_WM_WINDOW_TYPE(ATOM) = wintype */ - /* class role instance title wintype, tags mask isfloating monitor */ - { NULL, NULL, NULL, NULL, WTYPE "DIALOG", 0, 1, -1 }, - { NULL, NULL, NULL, NULL, WTYPE "UTILITY", 0, 1, -1 }, - { NULL, NULL, NULL, NULL, WTYPE "TOOLBAR", 0, 1, -1 }, - { NULL, NULL, NULL, NULL, WTYPE "SPLASH", 0, 1, -1 }, - { "Gimp", NULL, NULL, NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, NULL, NULL, 1 << 8, 0, -1 }, + /* class role instance title wintype, tags mask isfloating alwaysontop monitor */ + { NULL, NULL, NULL, NULL, WTYPE "DIALOG", 0, 1, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "UTILITY", 0, 1, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "TOOLBAR", 0, 1, 1, -1 }, + { NULL, NULL, NULL, NULL, WTYPE "SPLASH", 0, 1, 1, -1 }, + { "Gimp", NULL, NULL, NULL, NULL, 0, 1, 0, -1 }, + { "Firefox", NULL, NULL, NULL, NULL, 1 << 8, 0, 0, -1 }, + { NULL, "pop-up", NULL, NULL, NULL, 0, 1, 1, -1 }, }; /* layout(s) */ diff --git a/dwm.c b/dwm.c index 74bf95a..e8b4a5e 100644 --- a/dwm.c +++ b/dwm.c @@ -60,7 +60,7 @@ /* enums */ enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ enum { SchemeNorm, SchemeSel }; /* color schemes */ -enum { NetSupported, NetWMName, NetWMState, NetWMCheck, +enum { NetSupported, NetWMName, NetWMState, NetWMStateAbove, NetWMCheck, NetWMFullscreen, NetActiveWindow, NetWMWindowType, NetClientList, NetLast }; /* EWMH atoms */ enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMWindowRole, WMLast }; /* default atoms */ @@ -93,6 +93,7 @@ struct Client { int bw, oldbw; unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; + int alwaysontop; Client *next; Client *snext; Monitor *mon; @@ -140,6 +141,7 @@ typedef struct { const char *wintype; unsigned int tags; int isfloating; + int alwaysontop; int monitor; } Rule; @@ -307,6 +309,7 @@ applyrules(Client *c) { c->isfloating = r->isfloating; c->tags |= r->tags; + c->alwaysontop = r->alwaysontop; for (m = mons; m && m->num != r->monitor; m = m->next); if (m) c->mon = m; @@ -530,6 +533,9 @@ clientmessage(XEvent *e) || cme->data.l[2] == netatom[NetWMFullscreen]) setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); + else if (cme->data.l[1] == netatom[NetWMStateAbove] + || cme->data.l[2] == netatom[NetWMStateAbove]) + c->alwaysontop = (cme->data.l[0] || cme->data.l[1]); } else if (cme->message_type == netatom[NetActiveWindow]) { if (c != selmon->sel && !c->isurgent) seturgent(c, 1); @@ -791,6 +797,8 @@ expose(XEvent *e) void focus(Client *c) { + Client *f; + XWindowChanges wc; if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext); if (selmon->sel && selmon->sel != c) @@ -805,6 +813,31 @@ focus(Client *c) grabbuttons(c, 1); XSetWindowBorder(dpy, c->win, scheme[SchemeSel][ColBorder].pixel); setfocus(c); + if (focusedontop && c->mon->lt[c->mon->sellt]->arrange) { + + /* Move all visible tiled clients that are not marked as on top below the bar window */ + wc.stack_mode = Below; + wc.sibling = c->mon->barwin; + for (f = c->mon->stack; f; f = f->snext) + if (f != c && !f->isfloating && ISVISIBLE(f) && !f->alwaysontop) { + XConfigureWindow(dpy, f->win, CWSibling|CWStackMode, &wc); + wc.sibling = f->win; + } + + /* Move the currently focused client above the bar window */ + wc.stack_mode = Above; + wc.sibling = c->mon->barwin; + XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc); + + /* Move all visible floating windows that are not marked as on top below the current window */ + wc.stack_mode = Below; + wc.sibling = c->win; + for (f = c->mon->stack; f; f = f->snext) + if (f != c && f->isfloating && ISVISIBLE(f) && !f->alwaysontop) { + XConfigureWindow(dpy, f->win, CWSibling|CWStackMode, &wc); + wc.sibling = f->win; + } + } } else { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); @@ -859,7 +892,8 @@ focusstack(const Arg *arg) } if (c) { focus(c); - restack(selmon); + if (!focusedontop) + restack(selmon); } } @@ -1042,6 +1076,7 @@ manage(Window w, XWindowAttributes *wa) if (XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) { c->mon = t->mon; c->tags = t->tags; + c->alwaysontop = 1; } else { c->mon = selmon; applyrules(c); @@ -1061,6 +1096,8 @@ manage(Window w, XWindowAttributes *wa) XConfigureWindow(dpy, w, CWBorderWidth, &wc); XSetWindowBorder(dpy, w, scheme[SchemeNorm][ColBorder].pixel); configure(c); /* propagates border_width, if size doesn't change */ + if (getatomprop(c, netatom[NetWMState]) == netatom[NetWMStateAbove]) + c->alwaysontop = 1; if (getatomprop(c, netatom[NetWMState]) == netatom[NetWMFullscreen]) setfullscreen(c, 1); updatesizehints(c); @@ -1082,6 +1119,7 @@ manage(Window w, XWindowAttributes *wa) c->mon->sel = c; arrange(c->mon); XMapWindow(dpy, c->win); + focus(NULL); } @@ -1565,6 +1603,7 @@ setup(void) netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False); + netatom[NetWMStateAbove] = XInternAtom(dpy, "_NET_WM_STATE_ABOVE", False); netatom[NetWMCheck] = XInternAtom(dpy, "_NET_SUPPORTING_WM_CHECK", False); netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False); netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); -- 2.19.1