From 7b0166fdf0db37e0ad7caec8c58899680ecab032 Mon Sep 17 00:00:00 2001 From: Marco Thomas Date: Fri, 26 Mar 2021 12:22:27 +0100 Subject: [PATCH] Cleanup config --- README | 1 - config.h | 14 +- dwm.c | 8 - patches/dwm-activetagindicatorbar-6.2.diff | 17 - ...dwm-actualfullscreen-20191112-cb3f58a.diff | 53 --- patches/dwm-alternativetags-6.2.diff | 93 ---- patches/dwm-attachaside-6.1.diff | 92 ---- .../dwm-fakefullscreen-20170508-ceac8c9.diff | 92 ---- patches/dwm-swallow-20201211-61bb8b2.diff | 412 ------------------ 9 files changed, 7 insertions(+), 775 deletions(-) delete mode 100644 patches/dwm-activetagindicatorbar-6.2.diff delete mode 100644 patches/dwm-actualfullscreen-20191112-cb3f58a.diff delete mode 100644 patches/dwm-alternativetags-6.2.diff delete mode 100644 patches/dwm-attachaside-6.1.diff delete mode 100644 patches/dwm-fakefullscreen-20170508-ceac8c9.diff delete mode 100644 patches/dwm-swallow-20201211-61bb8b2.diff diff --git a/README b/README index ec8116d..e691ad7 100644 --- a/README +++ b/README @@ -5,7 +5,6 @@ dwm is an extremely fast, small, and dynamic window manager for X. Patches ------- + fakefullscreen -+ actualfullscreen + swallow + attachasideandbelow diff --git a/config.h b/config.h index e8e5940..3f80d0e 100644 --- a/config.h +++ b/config.h @@ -28,9 +28,10 @@ static const Rule rules[] = { * WM_CLASS(STRING) = instance, class * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating isterminal noswallow monitor */ + /* class instance title tags mask isfloating isterminal noswallow monitor */ { "Nightly", NULL, NULL, 1 << 2, 0, 0, 0, -1 }, { "Alacritty",NULL, NULL, 0, 0, 1, 0, -1 }, + { "discord", NULL, NULL, 1 << 3, 0, 0, 0, -1 }, }; /* layout(s) */ @@ -69,18 +70,17 @@ static Key keys[] = { { MODKEY, XK_d, spawn, {.v = dmenucmd } }, // open dmenu { MODKEY, XK_Return, spawn, {.v = termcmd } }, // open terminal { MODKEY|ShiftMask, XK_q, killclient, {0} }, // kill window - { MODKEY|ShiftMask, XK_Escape, quit, {0} }, // quit dwm TODO: NOT WORKING + { MODKEY|ShiftMask, XK_l, quit, {0} }, // quit dwm TODO: NOT WORKING { MODKEY|ControlMask, XK_f, spawn, {.v = browser } }, { MODKEY|ControlMask, XK_d, spawn, {.v = discord } }, { MODKEY|ControlMask, XK_p, spawn, {.v = pavu } }, - { MODKEY, XK_space, setlayout, {0} }, // swap layout +// { MODKEY, XK_space, setlayout, {0} }, // swap layout { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, // toggle float per window -// { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, -// { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, -// { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_f, togglefullscr, {0} }, // toggle fullscreen + { MODKEY, XK_t, setlayout, {.v = &layouts[0]} }, // tiling +// { MODKEY, XK_f, setlayout, {.v = &layouts[1]} }, // floatinh + { MODKEY, XK_f, setlayout, {.v = &layouts[2]} }, // monocle { MODKEY, XK_h, setmfact, {.f = -0.05} }, // decrease master size { MODKEY, XK_l, setmfact, {.f = +0.05} }, // increase master size diff --git a/dwm.c b/dwm.c index a7b2908..c3d2991 100644 --- a/dwm.c +++ b/dwm.c @@ -225,7 +225,6 @@ static void tagmon(const Arg *arg); static void tile(Monitor *); static void togglebar(const Arg *arg); static void togglefloating(const Arg *arg); -static void togglefullscr(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c, int setfocus); @@ -1808,13 +1807,6 @@ togglefloating(const Arg *arg) arrange(selmon); } -void -togglefullscr(const Arg *arg) -{ - if(selmon->sel) - setfullscreen(selmon->sel, !selmon->sel->isfullscreen); -} - void toggletag(const Arg *arg) { diff --git a/patches/dwm-activetagindicatorbar-6.2.diff b/patches/dwm-activetagindicatorbar-6.2.diff deleted file mode 100644 index 4450099..0000000 --- a/patches/dwm-activetagindicatorbar-6.2.diff +++ /dev/null @@ -1,17 +0,0 @@ -diff -up dwm-a/dwm.c dwm-b/dwm.c ---- dwm-a/dwm.c 2019-02-02 06:55:28.000000000 -0600 -+++ dwm-b/dwm.c 2019-02-23 21:43:13.359179100 -0600 -@@ -719,9 +719,10 @@ drawbar(Monitor *m) - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); - if (occ & 1 << i) -- drw_rect(drw, x + boxs, boxs, boxw, boxw, -- m == selmon && selmon->sel && selmon->sel->tags & 1 << i, -- urg & 1 << i); -+ drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, -+ m == selmon && selmon->sel && selmon->sel->tags & 1 << i, -+ urg & 1 << i); -+ - x += w; - } - w = blw = TEXTW(m->ltsymbol); diff --git a/patches/dwm-actualfullscreen-20191112-cb3f58a.diff b/patches/dwm-actualfullscreen-20191112-cb3f58a.diff deleted file mode 100644 index 21eea19..0000000 --- a/patches/dwm-actualfullscreen-20191112-cb3f58a.diff +++ /dev/null @@ -1,53 +0,0 @@ -From 3a16816a6f5d38014c2a06ce395873c545c8789a Mon Sep 17 00:00:00 2001 -From: Soenke Lambert -Date: Tue, 12 Nov 2019 10:44:02 +0100 -Subject: [PATCH] Fullscreen current window with [Alt]+[Shift]+[f] - -This actually fullscreens a window, instead of just hiding the statusbar -and applying the monocle layout. ---- - config.def.h | 1 + - dwm.c | 8 ++++++++ - 2 files changed, 9 insertions(+) - -diff --git a/config.def.h b/config.def.h -index 1c0b587..8cd3204 100644 ---- a/config.def.h -+++ b/config.def.h -@@ -78,6 +78,7 @@ static Key keys[] = { - { MODKEY, XK_m, setlayout, {.v = &layouts[2]} }, - { MODKEY, XK_space, setlayout, {0} }, - { MODKEY|ShiftMask, XK_space, togglefloating, {0} }, -+ { MODKEY|ShiftMask, XK_f, togglefullscr, {0} }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, -diff --git a/dwm.c b/dwm.c -index 4465af1..c1b899a 100644 ---- a/dwm.c -+++ b/dwm.c -@@ -211,6 +211,7 @@ static void tagmon(const Arg *arg); - static void tile(Monitor *); - static void togglebar(const Arg *arg); - static void togglefloating(const Arg *arg); -+static void togglefullscr(const Arg *arg); - static void toggletag(const Arg *arg); - static void toggleview(const Arg *arg); - static void unfocus(Client *c, int setfocus); -@@ -1719,6 +1720,13 @@ togglefloating(const Arg *arg) - arrange(selmon); - } - -+void -+togglefullscr(const Arg *arg) -+{ -+ if(selmon->sel) -+ setfullscreen(selmon->sel, !selmon->sel->isfullscreen); -+} -+ - void - toggletag(const Arg *arg) - { --- -2.17.1 - diff --git a/patches/dwm-alternativetags-6.2.diff b/patches/dwm-alternativetags-6.2.diff deleted file mode 100644 index dc6a0cf..0000000 --- a/patches/dwm-alternativetags-6.2.diff +++ /dev/null @@ -1,93 +0,0 @@ -From 25aa44b5998a2aac840a0eecf9d8a479695b2577 Mon Sep 17 00:00:00 2001 -From: Piyush Pangtey -Date: Sat, 13 Apr 2019 00:24:23 +0530 -Subject: [PATCH] alternative tags - -Having icons as tags sure makes dwm look awesome, but having tags number -simplifies tags related operations. This patch introduces alternative -tags which can be switched on the fly for the sole purpose of providing -visual aid. - -Signed-off-by: Piyush Pangtey ---- - config.def.h | 2 ++ - dwm.c | 14 ++++++++++++-- - 2 files changed, 14 insertions(+), 2 deletions(-) - -diff --git a/config.def.h b/config.def.h -index 1c0b587..e6c2565 100644 ---- a/config.def.h -+++ b/config.def.h -@@ -20,6 +20,7 @@ static const char *colors[][3] = { - - /* tagging */ - static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; -+static const char *tagsalt[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; - - static const Rule rules[] = { - /* xprop(1): -@@ -84,6 +85,7 @@ static Key keys[] = { - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, -+ { MODKEY, XK_n, togglealttag, {0} }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) -diff --git a/dwm.c b/dwm.c -index 4465af1..ee292e1 100644 ---- a/dwm.c -+++ b/dwm.c -@@ -130,6 +130,7 @@ struct Monitor { - Monitor *next; - Window barwin; - const Layout *lt[2]; -+ unsigned int alttag; - }; - - typedef struct { -@@ -209,6 +210,7 @@ static void spawn(const Arg *arg); - static void tag(const Arg *arg); - static void tagmon(const Arg *arg); - static void tile(Monitor *); -+static void togglealttag(); - static void togglebar(const Arg *arg); - static void togglefloating(const Arg *arg); - static void toggletag(const Arg *arg); -@@ -695,7 +697,7 @@ dirtomon(int dir) - void - drawbar(Monitor *m) - { -- int x, w, sw = 0; -+ int x, w, wdelta, sw = 0; - int boxs = drw->fonts->h / 9; - int boxw = drw->fonts->h / 6 + 2; - unsigned int i, occ = 0, urg = 0; -@@ -716,8 +718,9 @@ drawbar(Monitor *m) - x = 0; - for (i = 0; i < LENGTH(tags); i++) { - w = TEXTW(tags[i]); -+ wdelta = selmon->alttag ? abs(TEXTW(tags[i]) - TEXTW(tagsalt[i])) / 2 : 0; - drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); -- drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); -+ drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), urg & 1 << i); - if (occ & 1 << i) - drw_rect(drw, x + boxs, boxs, boxw, boxw, - m == selmon && selmon->sel && selmon->sel->tags & 1 << i, -@@ -1696,6 +1699,13 @@ tile(Monitor *m) - } - } - -+void -+togglealttag() -+{ -+ selmon->alttag = !selmon->alttag; -+ drawbar(selmon); -+} -+ - void - togglebar(const Arg *arg) - { --- -2.21.0 - diff --git a/patches/dwm-attachaside-6.1.diff b/patches/dwm-attachaside-6.1.diff deleted file mode 100644 index 176cdb0..0000000 --- a/patches/dwm-attachaside-6.1.diff +++ /dev/null @@ -1,92 +0,0 @@ -diff --git a/dwm.c b/dwm.c -index 0362114..be7e7a6 100644 ---- a/dwm.c -+++ b/dwm.c -@@ -49,7 +49,8 @@ - #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) - #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ - * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) --#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) -+#define ISVISIBLEONTAG(C, T) ((C->tags & T)) -+#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags]) - #define LENGTH(X) (sizeof X / sizeof X[0]) - #define MOUSEMASK (BUTTONMASK|PointerMotionMask) - #define WIDTH(X) ((X)->w + 2 * (X)->bw) -@@ -147,6 +148,7 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac - static void arrange(Monitor *m); - static void arrangemon(Monitor *m); - static void attach(Client *c); -+static void attachaside(Client *c); - static void attachstack(Client *c); - static void buttonpress(XEvent *e); - static void checkotherwm(void); -@@ -184,6 +186,7 @@ static void maprequest(XEvent *e); - static void monocle(Monitor *m); - static void motionnotify(XEvent *e); - static void movemouse(const Arg *arg); -+static Client *nexttagged(Client *c); - static Client *nexttiled(Client *c); - static void pop(Client *); - static void propertynotify(XEvent *e); -@@ -406,6 +409,17 @@ attach(Client *c) - } - - void -+attachaside(Client *c) { -+ Client *at = nexttagged(c); -+ if(!at) { -+ attach(c); -+ return; -+ } -+ c->next = at->next; -+ at->next = c; -+} -+ -+void - attachstack(Client *c) - { - c->snext = c->mon->stack; -@@ -1076,7 +1090,7 @@ manage(Window w, XWindowAttributes *wa) - c->isfloating = c->oldstate = trans != None || c->isfixed; - if (c->isfloating) - XRaiseWindow(dpy, c->win); -- attach(c); -+ attachaside(c); - attachstack(c); - XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, - (unsigned char *) &(c->win), 1); -@@ -1210,6 +1224,16 @@ movemouse(const Arg *arg) - } - - Client * -+nexttagged(Client *c) { -+ Client *walked = c->mon->clients; -+ for(; -+ walked && (walked->isfloating || !ISVISIBLEONTAG(walked, c->tags)); -+ walked = walked->next -+ ); -+ return walked; -+} -+ -+Client * - nexttiled(Client *c) - { - for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); -@@ -1434,7 +1458,7 @@ sendmon(Client *c, Monitor *m) - detachstack(c); - c->mon = m; - c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ -- attach(c); -+ attachaside(c); - attachstack(c); - focus(NULL); - arrange(NULL); -@@ -1891,7 +1915,7 @@ updategeom(void) - m->clients = c->next; - detachstack(c); - c->mon = mons; -- attach(c); -+ attachaside(c); - attachstack(c); - } - if (m == selmon) diff --git a/patches/dwm-fakefullscreen-20170508-ceac8c9.diff b/patches/dwm-fakefullscreen-20170508-ceac8c9.diff deleted file mode 100644 index 0c15db4..0000000 --- a/patches/dwm-fakefullscreen-20170508-ceac8c9.diff +++ /dev/null @@ -1,92 +0,0 @@ -diff --git a/dwm.c b/dwm.c -index a5ce993..42d2049 100644 ---- a/dwm.c -+++ b/dwm.c -@@ -522,7 +522,7 @@ clientmessage(XEvent *e) - if (cme->data.l[1] == netatom[NetWMFullscreen] - || 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))); -+ || cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */)); - } else if (cme->message_type == netatom[NetActiveWindow]) { - if (c != selmon->sel && !c->isurgent) - seturgent(c, 1); -@@ -552,7 +552,6 @@ void - configurenotify(XEvent *e) - { - Monitor *m; -- Client *c; - XConfigureEvent *ev = &e->xconfigure; - int dirty; - -@@ -565,9 +564,6 @@ configurenotify(XEvent *e) - drw_resize(drw, sw, bh); - updatebars(); - for (m = mons; m; m = m->next) { -- for (c = m->clients; c; c = c->next) -- if (c->isfullscreen) -- resizeclient(c, m->mx, m->my, m->mw, m->mh); - XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh); - } - focus(NULL); -@@ -1145,8 +1141,6 @@ movemouse(const Arg *arg) - - if (!(c = selmon->sel)) - return; -- if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ -- return; - restack(selmon); - ocx = c->x; - ocy = c->y; -@@ -1300,8 +1294,6 @@ resizemouse(const Arg *arg) - - if (!(c = selmon->sel)) - return; -- if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ -- return; - restack(selmon); - ocx = c->x; - ocy = c->y; -@@ -1478,24 +1470,10 @@ setfullscreen(Client *c, int fullscreen) - XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, - PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); - c->isfullscreen = 1; -- c->oldstate = c->isfloating; -- c->oldbw = c->bw; -- c->bw = 0; -- c->isfloating = 1; -- resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); -- XRaiseWindow(dpy, c->win); - } else if (!fullscreen && c->isfullscreen){ - XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, - PropModeReplace, (unsigned char*)0, 0); - c->isfullscreen = 0; -- c->isfloating = c->oldstate; -- c->bw = c->oldbw; -- c->x = c->oldx; -- c->y = c->oldy; -- c->w = c->oldw; -- c->h = c->oldh; -- resizeclient(c, c->x, c->y, c->w, c->h); -- arrange(c->mon); - } - } - -@@ -1620,7 +1598,7 @@ showhide(Client *c) - if (ISVISIBLE(c)) { - /* show clients top down */ - XMoveWindow(dpy, c->win, c->x, c->y); -- if ((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen) -+ if (!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) - resize(c, c->x, c->y, c->w, c->h, 0); - showhide(c->snext); - } else { -@@ -1712,8 +1690,6 @@ togglefloating(const Arg *arg) - { - if (!selmon->sel) - return; -- if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ -- return; - selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; - if (selmon->sel->isfloating) - resize(selmon->sel, selmon->sel->x, selmon->sel->y, diff --git a/patches/dwm-swallow-20201211-61bb8b2.diff b/patches/dwm-swallow-20201211-61bb8b2.diff deleted file mode 100644 index 6bc0a1f..0000000 --- a/patches/dwm-swallow-20201211-61bb8b2.diff +++ /dev/null @@ -1,412 +0,0 @@ -From f0cdf40e0a7126838d051eb84d84b91421b771d6 Mon Sep 17 00:00:00 2001 -From: 0x1bi -Date: Fri, 11 Dec 2020 10:16:25 -0500 -Subject: [PATCH] fix swallow for openbsd - ---- - config.def.h | 9 +- - config.mk | 3 +- - dwm.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++-- - 3 files changed, 237 insertions(+), 10 deletions(-) - -diff --git a/config.def.h b/config.def.h -index 1c0b587..fe51476 100644 ---- a/config.def.h -+++ b/config.def.h -@@ -3,6 +3,7 @@ - /* appearance */ - static const unsigned int borderpx = 1; /* border pixel of windows */ - static const unsigned int snap = 32; /* snap pixel */ -+static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ - static const int showbar = 1; /* 0 means no bar */ - static const int topbar = 1; /* 0 means bottom bar */ - static const char *fonts[] = { "monospace:size=10" }; -@@ -26,9 +27,11 @@ static const Rule rules[] = { - * WM_CLASS(STRING) = instance, class - * WM_NAME(STRING) = title - */ -- /* class instance title tags mask isfloating monitor */ -- { "Gimp", NULL, NULL, 0, 1, -1 }, -- { "Firefox", NULL, NULL, 1 << 8, 0, -1 }, -+ /* class instance title tags mask isfloating isterminal noswallow monitor */ -+ { "Gimp", NULL, NULL, 0, 1, 0, 0, -1 }, -+ { "Firefox", NULL, NULL, 1 << 8, 0, 0, -1, -1 }, -+ { "St", NULL, NULL, 0, 0, 1, 0, -1 }, -+ { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ - }; - - /* layout(s) */ -diff --git a/config.mk b/config.mk -index 7084c33..ff9e508 100644 ---- a/config.mk -+++ b/config.mk -@@ -19,10 +19,11 @@ FREETYPELIBS = -lfontconfig -lXft - FREETYPEINC = /usr/include/freetype2 - # OpenBSD (uncomment) - #FREETYPEINC = ${X11INC}/freetype2 -+#KVMLIB = -lkvm - - # includes and libs - INCS = -I${X11INC} -I${FREETYPEINC} --LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -+LIBS = -L${X11LIB} -lX11 ${XINERAMALIBS} ${FREETYPELIBS} -lX11-xcb -lxcb -lxcb-res ${KVMLIB} - - # flags - CPPFLAGS = -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_C_SOURCE=200809L -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} -diff --git a/dwm.c b/dwm.c -index 664c527..0b20086 100644 ---- a/dwm.c -+++ b/dwm.c -@@ -40,6 +40,12 @@ - #include - #endif /* XINERAMA */ - #include -+#include -+#include -+#ifdef __OpenBSD__ -+#include -+#include -+#endif /* __OpenBSD */ - - #include "drw.h" - #include "util.h" -@@ -92,9 +98,11 @@ struct Client { - int basew, baseh, incw, inch, maxw, maxh, minw, minh; - int bw, oldbw; - unsigned int tags; -- int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen; -+ int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow; -+ pid_t pid; - Client *next; - Client *snext; -+ Client *swallowing; - Monitor *mon; - Window win; - }; -@@ -138,6 +146,8 @@ typedef struct { - const char *title; - unsigned int tags; - int isfloating; -+ int isterminal; -+ int noswallow; - int monitor; - } Rule; - -@@ -235,6 +245,12 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee); - static int xerrorstart(Display *dpy, XErrorEvent *ee); - static void zoom(const Arg *arg); - -+static pid_t getparentprocess(pid_t p); -+static int isdescprocess(pid_t p, pid_t c); -+static Client *swallowingclient(Window w); -+static Client *termforwin(const Client *c); -+static pid_t winpid(Window w); -+ - /* variables */ - static const char broken[] = "broken"; - static char stext[256]; -@@ -269,6 +285,8 @@ static Drw *drw; - static Monitor *mons, *selmon; - static Window root, wmcheckwin; - -+static xcb_connection_t *xcon; -+ - /* configuration, allows nested code to access above variables */ - #include "config.h" - -@@ -298,6 +316,8 @@ applyrules(Client *c) - && (!r->class || strstr(class, r->class)) - && (!r->instance || strstr(instance, r->instance))) - { -+ c->isterminal = r->isterminal; -+ c->noswallow = r->noswallow; - c->isfloating = r->isfloating; - c->tags |= r->tags; - for (m = mons; m && m->num != r->monitor; m = m->next); -@@ -414,6 +434,53 @@ attachstack(Client *c) - c->mon->stack = c; - } - -+void -+swallow(Client *p, Client *c) -+{ -+ -+ if (c->noswallow || c->isterminal) -+ return; -+ if (c->noswallow && !swallowfloating && c->isfloating) -+ return; -+ -+ detach(c); -+ detachstack(c); -+ -+ setclientstate(c, WithdrawnState); -+ XUnmapWindow(dpy, p->win); -+ -+ p->swallowing = c; -+ c->mon = p->mon; -+ -+ Window w = p->win; -+ p->win = c->win; -+ c->win = w; -+ updatetitle(p); -+ XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h); -+ arrange(p->mon); -+ configure(p); -+ updateclientlist(); -+} -+ -+void -+unswallow(Client *c) -+{ -+ c->win = c->swallowing->win; -+ -+ free(c->swallowing); -+ c->swallowing = NULL; -+ -+ /* unfullscreen the client */ -+ setfullscreen(c, 0); -+ updatetitle(c); -+ arrange(c->mon); -+ XMapWindow(dpy, c->win); -+ XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); -+ setclientstate(c, NormalState); -+ focus(NULL); -+ arrange(c->mon); -+} -+ - void - buttonpress(XEvent *e) - { -@@ -653,6 +720,9 @@ destroynotify(XEvent *e) - - if ((c = wintoclient(ev->window))) - unmanage(c, 1); -+ -+ else if ((c = swallowingclient(ev->window))) -+ unmanage(c->swallowing, 1); - } - - void -@@ -1018,12 +1088,13 @@ killclient(const Arg *arg) - void - manage(Window w, XWindowAttributes *wa) - { -- Client *c, *t = NULL; -+ Client *c, *t = NULL, *term = NULL; - Window trans = None; - XWindowChanges wc; - - c = ecalloc(1, sizeof(Client)); - c->win = w; -+ c->pid = winpid(w); - /* geometry */ - c->x = c->oldx = wa->x; - c->y = c->oldy = wa->y; -@@ -1038,6 +1109,7 @@ manage(Window w, XWindowAttributes *wa) - } else { - c->mon = selmon; - applyrules(c); -+ term = termforwin(c); - } - - if (c->x + WIDTH(c) > c->mon->mx + c->mon->mw) -@@ -1074,6 +1146,8 @@ manage(Window w, XWindowAttributes *wa) - c->mon->sel = c; - arrange(c->mon); - XMapWindow(dpy, c->win); -+ if (term) -+ swallow(term, c); - focus(NULL); - } - -@@ -1768,6 +1842,20 @@ unmanage(Client *c, int destroyed) - Monitor *m = c->mon; - XWindowChanges wc; - -+ if (c->swallowing) { -+ unswallow(c); -+ return; -+ } -+ -+ Client *s = swallowingclient(c->win); -+ if (s) { -+ free(s->swallowing); -+ s->swallowing = NULL; -+ arrange(m); -+ focus(NULL); -+ return; -+ } -+ - detach(c); - detachstack(c); - if (!destroyed) { -@@ -1782,9 +1870,12 @@ unmanage(Client *c, int destroyed) - XUngrabServer(dpy); - } - free(c); -- focus(NULL); -- updateclientlist(); -- arrange(m); -+ -+ if (!s) { -+ arrange(m); -+ focus(NULL); -+ updateclientlist(); -+ } - } - - void -@@ -2047,6 +2138,136 @@ view(const Arg *arg) - arrange(selmon); - } - -+pid_t -+winpid(Window w) -+{ -+ -+ pid_t result = 0; -+ -+#ifdef __linux__ -+ xcb_res_client_id_spec_t spec = {0}; -+ spec.client = w; -+ spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID; -+ -+ xcb_generic_error_t *e = NULL; -+ xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec); -+ xcb_res_query_client_ids_reply_t *r = xcb_res_query_client_ids_reply(xcon, c, &e); -+ -+ if (!r) -+ return (pid_t)0; -+ -+ xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r); -+ for (; i.rem; xcb_res_client_id_value_next(&i)) { -+ spec = i.data->spec; -+ if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) { -+ uint32_t *t = xcb_res_client_id_value_value(i.data); -+ result = *t; -+ break; -+ } -+ } -+ -+ free(r); -+ -+ if (result == (pid_t)-1) -+ result = 0; -+ -+#endif /* __linux__ */ -+ -+#ifdef __OpenBSD__ -+ Atom type; -+ int format; -+ unsigned long len, bytes; -+ unsigned char *prop; -+ pid_t ret; -+ -+ if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 0), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop) -+ return 0; -+ -+ ret = *(pid_t*)prop; -+ XFree(prop); -+ result = ret; -+ -+#endif /* __OpenBSD__ */ -+ return result; -+} -+ -+pid_t -+getparentprocess(pid_t p) -+{ -+ unsigned int v = 0; -+ -+#ifdef __linux__ -+ FILE *f; -+ char buf[256]; -+ snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); -+ -+ if (!(f = fopen(buf, "r"))) -+ return 0; -+ -+ fscanf(f, "%*u %*s %*c %u", &v); -+ fclose(f); -+#endif /* __linux__*/ -+ -+#ifdef __OpenBSD__ -+ int n; -+ kvm_t *kd; -+ struct kinfo_proc *kp; -+ -+ kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL); -+ if (!kd) -+ return 0; -+ -+ kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n); -+ v = kp->p_ppid; -+#endif /* __OpenBSD__ */ -+ -+ return (pid_t)v; -+} -+ -+int -+isdescprocess(pid_t p, pid_t c) -+{ -+ while (p != c && c != 0) -+ c = getparentprocess(c); -+ -+ return (int)c; -+} -+ -+Client * -+termforwin(const Client *w) -+{ -+ Client *c; -+ Monitor *m; -+ -+ if (!w->pid || w->isterminal) -+ return NULL; -+ -+ for (m = mons; m; m = m->next) { -+ for (c = m->clients; c; c = c->next) { -+ if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid)) -+ return c; -+ } -+ } -+ -+ return NULL; -+} -+ -+Client * -+swallowingclient(Window w) -+{ -+ Client *c; -+ Monitor *m; -+ -+ for (m = mons; m; m = m->next) { -+ for (c = m->clients; c; c = c->next) { -+ if (c->swallowing && c->swallowing->win == w) -+ return c; -+ } -+ } -+ -+ return NULL; -+} -+ - Client * - wintoclient(Window w) - { -@@ -2138,10 +2359,12 @@ main(int argc, char *argv[]) - fputs("warning: no locale support\n", stderr); - if (!(dpy = XOpenDisplay(NULL))) - die("dwm: cannot open display"); -+ if (!(xcon = XGetXCBConnection(dpy))) -+ die("dwm: cannot get xcb connection\n"); - checkotherwm(); - setup(); - #ifdef __OpenBSD__ -- if (pledge("stdio rpath proc exec", NULL) == -1) -+ if (pledge("stdio rpath proc exec ps", NULL) == -1) - die("pledge"); - #endif /* __OpenBSD__ */ - scan(); --- -2.28.0 -