From 4e0318919dd726f485ea3a495ff0989f69f35630 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 6 Jun 2020 19:56:41 -0700 Subject: hand added swallow patch --- sys/cmd/dwm/client.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) (limited to 'sys/cmd/dwm/client.c') diff --git a/sys/cmd/dwm/client.c b/sys/cmd/dwm/client.c index d2ea972..1401677 100644 --- a/sys/cmd/dwm/client.c +++ b/sys/cmd/dwm/client.c @@ -11,7 +11,8 @@ applyrules(Client *c) /* rule matching */ c->isfloating = 0; - c->tags = 0; + c->tags = 0; + c->noswallow = -1; XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; @@ -22,8 +23,10 @@ applyrules(Client *c) && (!r->class || strstr(class, r->class)) && (!r->instance || strstr(instance, r->instance))) { + c->isterm = r->isterm; + c->noswallow = r->noswallow; c->isfloating = r->isfloating; - c->tags |= r->tags; + c->tags |= r->tags; for (m = mons; m && m->num != r->monitor; m = m->next) ; if (m) @@ -414,6 +417,60 @@ showhide(Client *c) } } +void +swallow(Client *p, Client *c) +{ + Client *s; + + + if (c->noswallow > 0 || c->isterm) + return; + if (c->noswallow < 0 && !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; + + XChangeProperty(dpy, c->win, netatom[NetClientList], XA_WINDOW, 32, PropModeReplace, + (unsigned char *) &(p->win), 1); + + updatetitle(p); + s = scanner ? c : p; + XMoveResizeWindow(dpy, p->win, s->x, s->y, s->w, s->h); + arrange(p->mon); + configure(p); + updateclientlist(); +} + +Client * +termof(Client *w) +{ + Client *c; + Monitor *m; + + if (!w->pid || w->isterm) + return NULL; + + for (m = mons; m; m = m->next) { + for (c = m->clients; c; c = c->next) { + if (c->isterm && !c->swallowing && c->pid && isdescendent(c->pid, w->pid)) + return c; + } + } + + return NULL; +} + void unfocus(Client *c, int setfocus) { @@ -430,11 +487,28 @@ unfocus(Client *c, int setfocus) void unmanage(Client *c, int destroyed) { + Client *s; Monitor *m = c->mon; XWindowChanges wc; + if (c->swallowing) { + unswallow(c); + return; + } + + s = swallowing(c->win); + if (s) { + free(s->swallowing); + s->swallowing = nil; + arrange(m); + focus(nil); + return; + } + + detach(c); detachstack(c); + if (!destroyed) { wc.border_width = c->oldbw; XGrabServer(dpy); /* avoid race conditions */ @@ -450,8 +524,36 @@ unmanage(Client *c, int destroyed) focus(nil); updateclientlist(); arrange(m); + + if (!s) { + // arrange(m); + focus(nil); + updateclientlist(); + } +} + +void +unswallow(Client *c) +{ + c->win = c->swallowing->win; + + free(c->swallowing); + c->swallowing = nil; + + XDeleteProperty(dpy, c->win, netatom[NetClientList]); + + /* 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(nil); + arrange(c->mon); } + void updatesizehints(Client *c) { -- cgit v1.2.1