diff --git a/dwm.c b/dwm.c index 268b8c0..3b19265 100644 --- a/dwm.c +++ b/dwm.c @@ -164,6 +164,7 @@ static void configure(Client *c); static void configurenotify(XEvent *e); static void configurerequest(XEvent *e); static Monitor *createmon(void); +static int desiredbw(Client *c); static void destroynotify(XEvent *e); static void detach(Client *c); static void detachstack(Client *c); @@ -435,6 +436,12 @@ void arrangemon(Monitor *m) { strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); + /* layout switches bypass focus(): re-apply the focused window's border + * (e.g. drop it entering monocle, restore it leaving) */ + if (m->sel && !m->sel->isfullscreen && m->sel->bw != desiredbw(m->sel)) { + m->sel->bw = desiredbw(m->sel); + resizeclient(m->sel, m->sel->x, m->sel->y, m->sel->w, m->sel->h); + } if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); } @@ -723,6 +730,15 @@ createmon(void) return m; } +int +desiredbw(Client *c) +{ + /* no border when the layout hides everything else anyway */ + if (!c->isfloating && c->mon->lt[c->mon->sellt]->arrange == monocle) + return 0; + return borderpx; +} + void destroynotify(XEvent *e) { @@ -969,6 +985,17 @@ focus(Client *c) detachstack(c); attachstack(c); grabbuttons(c, 1); + int want = desiredbw(c); + if (!c->isfullscreen && c->bw != want) { + /* give border to the active window; shrink tiled windows so the + * footprint (w + 2*bw) stays what the layout computed */ + int d = 2 * (want - c->bw); + c->bw = want; + if (!c->isfloating && c->mon->lt[c->mon->sellt]->arrange) + resizeclient(c, c->x, c->y, c->w - d, c->h - d); + else + resizeclient(c, c->x, c->y, c->w, c->h); + } if (rainbow_enabled) drawrainbowborder(c); else @@ -2242,6 +2269,16 @@ unfocus(Client *c, int setfocus) if (!c) return; grabbuttons(c, 0); + if (!c->isfullscreen && c->bw) { + /* drop border from inactive windows; grow tiled windows to keep + * the footprint (w + 2*bw) what the layout computed */ + int d = 2 * c->bw; + c->bw = 0; + if (!c->isfloating && c->mon->lt[c->mon->sellt]->arrange) + resizeclient(c, c->x, c->y, c->w + d, c->h + d); + else + resizeclient(c, c->x, c->y, c->w, c->h); + } XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); if (setfocus) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);