Add smart borders patch

This commit is contained in:
Alex Selimov 2021-04-09 11:20:47 -04:00
parent 79edc68d93
commit 082c9fa90a
2 changed files with 50 additions and 564 deletions

59
dwm.c
View file

@ -149,7 +149,7 @@ typedef struct {
/* function declarations */
static void applyrules(Client *c);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact);
static void arrange(Monitor *m);
static void arrangemon(Monitor *m);
static void attach(Client *c);
@ -196,8 +196,8 @@ static void pop(Client *);
static void propertynotify(XEvent *e);
static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h);
static void resize(Client *c, int x, int y, int w, int h, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h);
static void resize(Client *c, int x, int y, int w, int h, int bw, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h, int bw);
static void resizemouse(const Arg *arg);
static void restack(Monitor *m);
static void run(void);
@ -332,7 +332,7 @@ applyrules(Client *c)
}
int
applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact)
{
int baseismin;
Monitor *m = c->mon;
@ -345,18 +345,18 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
*x = sw - WIDTH(c);
if (*y > sh)
*y = sh - HEIGHT(c);
if (*x + *w + 2 * c->bw < 0)
if (*x + *w + 2 * *bw < 0)
*x = 0;
if (*y + *h + 2 * c->bw < 0)
if (*y + *h + 2 * *bw < 0)
*y = 0;
} else {
if (*x >= m->wx + m->ww)
*x = m->wx + m->ww - WIDTH(c);
if (*y >= m->wy + m->wh)
*y = m->wy + m->wh - HEIGHT(c);
if (*x + *w + 2 * c->bw <= m->wx)
if (*x + *w + 2 * *bw <= m->wx)
*x = m->wx;
if (*y + *h + 2 * c->bw <= m->wy)
if (*y + *h + 2 * *bw <= m->wy)
*y = m->wy;
}
if (*h < bh)
@ -394,7 +394,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
if (c->maxh)
*h = MIN(*h, c->maxh);
}
return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
return *x != c->x || *y != c->y || *w != c->w || *h != c->h || *bw != c->bw;
}
void
@ -414,9 +414,16 @@ arrange(Monitor *m)
void
arrangemon(Monitor *m)
{
Client *c;
strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
if (m->lt[m->sellt]->arrange)
m->lt[m->sellt]->arrange(m);
else
/* <>< case; rather than providing an arrange function and upsetting other logic that tests for its presence, simply add borders here */
for (c = selmon->clients; c; c = c->next)
if (ISVISIBLE(c) && c->bw == 0)
resize(c, c->x, c->y, c->w - 2*borderpx, c->h - 2*borderpx, borderpx, 0);
}
void
@ -586,7 +593,7 @@ configurenotify(XEvent *e)
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);
resizeclient(c, m->mx, m->my, m->mw, m->mh, 0);
XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
}
focus(NULL);
@ -1161,7 +1168,7 @@ monocle(Monitor *m)
if (n > 0) /* override layout symbol */
snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0);
resize(c, m->wx, m->wy, m->ww, m->wh, 0, 0);
}
void
@ -1229,7 +1236,7 @@ movemouse(const Arg *arg)
&& (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
togglefloating(NULL);
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
resize(c, nx, ny, c->w, c->h, 1);
resize(c, nx, ny, c->w, c->h, c->bw, 1);
break;
}
} while (ev.type != ButtonRelease);
@ -1295,7 +1302,7 @@ moveresize(const Arg *arg) {
XRaiseWindow(dpy, c->win);
Bool xqp = XQueryPointer(dpy, root, &dummy, &dummy, &msx, &msy, &dx, &dy, &dui);
resize(c, nx, ny, nw, nh, True);
resize(c, nx, ny, nw, nh, borderpx, True);
/* move cursor along with the window to avoid problems caused by the sloppy focus */
if (xqp && ox <= msx && (ox + ow) >= msx && oy <= msy && (oy + oh) >= msy)
@ -1381,14 +1388,14 @@ recttomon(int x, int y, int w, int h)
}
void
resize(Client *c, int x, int y, int w, int h, int interact)
resize(Client *c, int x, int y, int w, int h, int bw, int interact)
{
if (applysizehints(c, &x, &y, &w, &h, interact))
resizeclient(c, x, y, w, h);
if (applysizehints(c, &x, &y, &w, &h, &bw, interact))
resizeclient(c, x, y, w, h, bw);
}
void
resizeclient(Client *c, int x, int y, int w, int h)
resizeclient(Client *c, int x, int y, int w, int h, int bw)
{
XWindowChanges wc;
@ -1396,7 +1403,7 @@ resizeclient(Client *c, int x, int y, int w, int h)
c->oldy = c->y; c->y = wc.y = y;
c->oldw = c->w; c->w = wc.width = w;
c->oldh = c->h; c->h = wc.height = h;
wc.border_width = c->bw;
c->oldbw = c->bw; c->bw = wc.border_width = bw;
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c);
XSync(dpy, False);
@ -1445,7 +1452,7 @@ resizemouse(const Arg *arg)
togglefloating(NULL);
}
if (!selmon->lt[selmon->sellt]->arrange || c->isfloating)
resize(c, c->x, c->y, nw, nh, 1);
resize(c, c->x, c->y, nw, nh, c->bw, 1);
break;
}
} while (ev.type != ButtonRelease);
@ -1594,22 +1601,20 @@ setfullscreen(Client *c, int fullscreen)
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);
resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh, 0);
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);
c->bw = c->oldbw;
resizeclient(c, c->x, c->y, c->w, c->h, c->bw);
arrange(c->mon);
}
}
@ -1765,7 +1770,7 @@ showhide(Client *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)
resize(c, c->x, c->y, c->w, c->h, 0);
resize(c, c->x, c->y, c->w, c->h, c->bw, 0);
showhide(c->snext);
} else {
/* hide clients bottom up */
@ -1858,7 +1863,9 @@ togglefloating(const Arg *arg)
selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
if (selmon->sel->isfloating)
resize(selmon->sel, selmon->sel->x, selmon->sel->y,
selmon->sel->w, selmon->sel->h, 0);
selmon->sel->w - 2 * (borderpx - selmon->sel->bw),
selmon->sel->h - 2 * (borderpx - selmon->sel->bw),
borderpx, 0);
arrange(selmon);
}