aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarrick Lo <warrick.s.z.lo@gmail.com>2021-11-23 21:59:47 -0800
committerWarrick Lo <warrick.s.z.lo@gmail.com>2021-11-23 21:59:47 -0800
commitcdb673245e8633ec95424c7fcab8baca76977d6a (patch)
treec2b24d7df5a695ec0976827a4bae4d00154d3141
parentAdd ability to swap windows around in the stack (diff)
Add EWMH desktop & decoration hints support
-rw-r--r--config.def.h9
-rw-r--r--dwm.c104
2 files changed, 104 insertions, 9 deletions
diff --git a/config.def.h b/config.def.h
index e09d20d..7570fe5 100644
--- a/config.def.h
+++ b/config.def.h
@@ -38,10 +38,11 @@ static const Rule rules[] = {
};
/* layout(s) */
-static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
-static const int nmaster = 1; /* number of clients in master area */
-static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
-static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
+static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */
+static const int nmaster = 1; /* number of clients in master area */
+static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */
+static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen window */
+static const int decorhints = 1; /* 1 means respect decoration hints */
static const Layout layouts[] = {
/* symbol arrange function */
diff --git a/dwm.c b/dwm.c
index fbb7011..84f43de 100644
--- a/dwm.c
+++ b/dwm.c
@@ -56,17 +56,25 @@
#define WIDTH(X) ((X)->w + 2 * (X)->bw)
#define HEIGHT(X) ((X)->h + 2 * (X)->bw)
#define TAGMASK ((1 << LENGTH(tags)) - 1)
+#define TAGSLENGTH (LENGTH(tags))
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#define GAP_TOGGLE 100
#define GAP_RESET 0
+#define MWM_HINTS_FLAGS_FIELD 0
+#define MWM_HINTS_DECORATIONS_FIELD 2
+#define MWM_HINTS_DECORATIONS (1 << 1)
+#define MWM_DECOR_ALL (1 << 0)
+#define MWM_DECOR_BORDER (1 << 1)
+#define MWM_DECOR_TITLE (1 << 3)
+
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { SchemeNorm, SchemeSel }; /* color schemes */
enum { NetSupported, NetWMName, NetWMState, NetWMCheck,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
- NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
+ NetWMWindowTypeDialog, NetClientList, NetDesktopNames, NetDesktopViewport, NetNumberOfDesktops, NetCurrentDesktop, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -208,13 +216,17 @@ static void scan(void);
static int sendevent(Client *c, Atom proto);
static void sendmon(Client *c, Monitor *m);
static void setclientstate(Client *c, long state);
+static void setcurrentdesktop(void);
+static void setdesktopnames(void);
static void setfocus(Client *c);
static void setfullscreen(Client *c, int fullscreen);
static void setgaps(const Arg *arg);
static void setlayout(const Arg *arg);
static void setmfact(const Arg *arg);
+static void setnumdesktops(void);
static void setup(void);
static void seturgent(Client *c, int urg);
+static void setviewport(void);
static void showhide(Client *c);
static void sigchld(int unused);
static void spawn(const Arg *arg);
@@ -228,10 +240,12 @@ static void toggleview(const Arg *arg);
static void unfocus(Client *c, int setfocus);
static void unmanage(Client *c, int destroyed);
static void unmapnotify(XEvent *e);
+static void updatecurrentdesktop(void);
static void updatebarpos(Monitor *m);
static void updatebars(void);
static void updateclientlist(void);
static int updategeom(void);
+static void updatemotifhints(Client *c);
static void updatenumlockmask(void);
static void updatesizehints(Client *c);
static void updatestatus(void);
@@ -271,7 +285,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
[PropertyNotify] = propertynotify,
[UnmapNotify] = unmapnotify
};
-static Atom wmatom[WMLast], netatom[NetLast];
+static Atom wmatom[WMLast], netatom[NetLast], motifatom;
static int running = 1;
static Cur *cursor[CurLast];
static Clr **scheme;
@@ -1145,6 +1159,7 @@ manage(Window w, XWindowAttributes *wa)
updatewindowtype(c);
updatesizehints(c);
updatewmhints(c);
+ updatemotifhints(c);
XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
grabbuttons(c, 0);
if (!c->isfloating)
@@ -1374,8 +1389,8 @@ propertynotify(XEvent *e)
switch(ev->atom) {
default: break;
case XA_WM_TRANSIENT_FOR:
- if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) &&
- (c->isfloating = (wintoclient(trans)) != NULL))
+ if (!c->isfloating && (XGetTransientForHint(dpy, c->win, &trans))
+ && (c->isfloating = (wintoclient(trans)) != NULL))
arrange(c->mon);
break;
case XA_WM_NORMAL_HINTS:
@@ -1393,6 +1408,8 @@ propertynotify(XEvent *e)
}
if (ev->atom == netatom[NetWMWindowType])
updatewindowtype(c);
+ if (ev->atom == motifatom)
+ updatemotifhints(c);
}
}
@@ -1601,6 +1618,17 @@ setclientstate(Client *c, long state)
XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
PropModeReplace, (unsigned char *)data, 2);
}
+void
+setcurrentdesktop(void){
+ long data[] = { 0 };
+ XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
+}
+void
+setdesktopnames(void){
+ XTextProperty text;
+ Xutf8TextListToTextProperty(dpy, (char **)tags, TAGSLENGTH, XUTF8StringStyle, &text);
+ XSetTextProperty(dpy, root, &text, netatom[NetDesktopNames]);
+}
int
sendevent(Client *c, Atom proto)
@@ -1628,6 +1656,12 @@ sendevent(Client *c, Atom proto)
}
void
+setnumdesktops(void){
+ long data[] = { TAGSLENGTH };
+ XChangeProperty(dpy, root, netatom[NetNumberOfDesktops], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
+}
+
+void
setfocus(Client *c)
{
if (!c->neverfocus) {
@@ -1755,6 +1789,11 @@ 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[NetDesktopViewport] = XInternAtom(dpy, "_NET_DESKTOP_VIEWPORT", False);
+ netatom[NetNumberOfDesktops] = XInternAtom(dpy, "_NET_NUMBER_OF_DESKTOPS", False);
+ netatom[NetCurrentDesktop] = XInternAtom(dpy, "_NET_CURRENT_DESKTOP", False);
+ netatom[NetDesktopNames] = XInternAtom(dpy, "_NET_DESKTOP_NAMES", False);
+ motifatom = XInternAtom(dpy, "_MOTIF_WM_HINTS", False);
/* init cursors */
cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr);
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
@@ -1777,6 +1816,10 @@ setup(void)
/* EWMH support per view */
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast);
+ setnumdesktops();
+ setcurrentdesktop();
+ setdesktopnames();
+ setviewport();
XDeleteProperty(dpy, root, netatom[NetClientList]);
/* select events */
wa.cursor = cursor[CurNormal]->cursor;
@@ -1789,7 +1832,6 @@ setup(void)
focus(NULL);
}
-
void
seturgent(Client *c, int urg)
{
@@ -1804,6 +1846,12 @@ seturgent(Client *c, int urg)
}
void
+setviewport(void){
+ long data[] = { 0, 0 };
+ XChangeProperty(dpy, root, netatom[NetDesktopViewport], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 2);
+}
+
+void
showhide(Client *c)
{
if (!c)
@@ -1962,6 +2010,7 @@ toggletag(const Arg *arg)
focus(NULL);
arrange(selmon);
}
+ updatecurrentdesktop();
}
void
@@ -1998,6 +2047,7 @@ toggleview(const Arg *arg)
focus(NULL);
arrange(selmon);
}
+ updatecurrentdesktop();
}
void
@@ -2100,6 +2150,16 @@ updateclientlist()
XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &(c->win), 1);
}
+void
+updatecurrentdesktop(void){
+ long rawdata[] = { selmon->tagset[selmon->seltags] };
+ int i=0;
+ while(*rawdata >> (i+1)){
+ i++;
+ }
+ long data[] = { i };
+ XChangeProperty(dpy, root, netatom[NetCurrentDesktop], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)data, 1);
+}
int
updategeom(void)
@@ -2180,6 +2240,39 @@ updategeom(void)
}
void
+updatemotifhints(Client *c)
+{
+ Atom real;
+ int format;
+ unsigned char *p = NULL;
+ unsigned long n, extra;
+ unsigned long *motif;
+ int width, height;
+
+ if (!decorhints)
+ return;
+
+ if (XGetWindowProperty(dpy, c->win, motifatom, 0L, 5L, False, motifatom,
+ &real, &format, &n, &extra, &p) == Success && p != NULL) {
+ motif = (unsigned long*)p;
+ if (motif[MWM_HINTS_FLAGS_FIELD] & MWM_HINTS_DECORATIONS) {
+ width = WIDTH(c);
+ height = HEIGHT(c);
+
+ if (motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_ALL
+ || motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_BORDER
+ || motif[MWM_HINTS_DECORATIONS_FIELD] & MWM_DECOR_TITLE)
+ c->bw = c->oldbw = borderpx;
+ else
+ c->bw = c->oldbw = 0;
+
+ resize(c, c->x, c->y, width - (2*c->bw), height - (2*c->bw), 0);
+ }
+ XFree(p);
+ }
+}
+
+void
updatenumlockmask(void)
{
unsigned int i, j;
@@ -2322,6 +2415,7 @@ view(const Arg *arg)
focus(NULL);
arrange(selmon);
+ updatecurrentdesktop();
}
Client *