commit dc8cf2cccade6def356b434fa04d0eca29d162b6
parent 9af0350fd7cf753cbaa246a9695045bf8a03daeb
Author: ssnf <ssnf@ssnf.xyz>
Date: Tue, 20 Sep 2022 12:36:30 +0000
bar padding
Diffstat:
M | config.h | | | 6 | ++++-- |
M | dwm.c | | | 126 | +++++++++++++++++++++++++++++++++++++++++-------------------------------------- |
2 files changed, 69 insertions(+), 63 deletions(-)
diff --git a/config.h b/config.h
@@ -7,10 +7,12 @@ static const uint gappoh = 4; /* horiz outer gap between windows and
static const uint gappov = 4; /* vert outer gap between windows and screen edge */
static const int showbar = 1; /* 0 means no bar */
static const int topbar = 1; /* 0 means bottom bar */
-static const char *fonts[] = { "hack:size=12" };
+static const int vertpad = 7; /* vertical padding of bar */
+static const int sidepad = 7; /* horizontal padding of bar */
+static const char* fonts[] = { "hack:size=12" };
static const char col_fg[] = "#454138";
static const char col_bg[] = "#d1cdb7";
-static const char *colors[][3] = {
+static const char* colors[][3] = {
/* fg bg border */
[SchemeNorm] = { col_bg, col_fg, col_fg },
[SchemeSel] = { col_fg, col_bg, col_bg },
diff --git a/dwm.c b/dwm.c
@@ -145,7 +145,7 @@ typedef struct Monitor {
int showbar;
int topbar;
Client* clients;
- Client* selcli;
+ Client* sel;
Client* stack;
struct Monitor* next;
Window barwin;
@@ -272,6 +272,8 @@ static int screen;
static int sw, sh; /* X display screen geometry width, height */
static int bh, blw = 0; /* bar geometry */
static int lrpad; /* sum of left and right padding for text */
+static int vp; /* vertical padding for bar */
+static int sp; /* side padding for bar */
static int (*xerrorxlib)(Display*, XErrorEvent*);
static uint numlockmask = 0;
static void (*handler[LASTEvent])(XEvent*) = {
@@ -494,7 +496,7 @@ buttonpress(XEvent* e)
click = ClkRootWin;
/* focus monitor if necessary */
if ((m = wintomon(ev->window)) && m != selmon) {
- unfocus(selmon->selcli, 1);
+ unfocus(selmon->sel, 1);
selmon = m;
focus(NULL);
}
@@ -594,7 +596,7 @@ clientmessage(XEvent* e)
cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ ||
(cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
} else if (cme->message_type == netatom[NetActiveWindow]) {
- if (c != selmon->selcli && !c->isurgent)
+ if (c != selmon->sel && !c->isurgent)
seturgent(c, 1);
}
}
@@ -638,7 +640,7 @@ configurenotify(XEvent* e)
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);
+ XMoveResizeWindow(dpy, m->barwin, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh);
}
focus(NULL);
arrange(NULL);
@@ -749,9 +751,9 @@ detachstack(Client* c)
;
*tc = c->snext;
- if (c == c->mon->selcli) {
+ if (c == c->mon->sel) {
for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext);
- c->mon->selcli = t;
+ c->mon->sel = t;
}
}
@@ -784,7 +786,7 @@ drawbar(Monitor* m)
if (m == selmon) { /* status is only drawn on selected monitor */
drw_setscheme(drw, scheme[SchemeNorm]);
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
- drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
+ drw_text(drw, m->ww - tw - 2 * sp, 0, tw, bh, 0, stext, 0);
}
for (c = m->clients; c; c = c->next) {
@@ -797,20 +799,20 @@ 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->selcli && selmon->selcli->tags & 1 << i, urg & 1 << i);
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, urg & 1 << i);
x += w;
}
drw_setscheme(drw, scheme[SchemeNorm]);
if ((w = m->ww - tw - x) > bh) {
- if (m->selcli) {
+ if (m->sel) {
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->selcli->name, 0);
- if (m->selcli->isfloating)
- drw_rect(drw, x + boxs, boxs, boxw, boxw, m->selcli->isfixed, 0);
+ drw_text(drw, x, 0, w - 2 * sp, bh, lrpad / 2, m->sel->name, 0);
+ if (m->sel->isfloating)
+ drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
} else {
drw_setscheme(drw, scheme[SchemeNorm]);
- drw_rect(drw, x, 0, w, bh, 1, 1);
+ drw_rect(drw, x, 0, w - 2 * sp, bh, 1, 1);
}
}
drw_map(drw, m->barwin, 0, 0, m->ww, bh);
@@ -837,9 +839,9 @@ enternotify(XEvent* e)
c = wintoclient(ev->window);
m = c ? c->mon : wintomon(ev->window);
if (m != selmon) {
- unfocus(selmon->selcli, 1);
+ unfocus(selmon->sel, 1);
selmon = m;
- } else if (!c || c == selmon->selcli)
+ } else if (!c || c == selmon->sel)
return;
focus(c);
}
@@ -930,8 +932,8 @@ focus(Client* c)
if (!c || !ISVISIBLE(c))
for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext)
;
- if (selmon->selcli && selmon->selcli != c)
- unfocus(selmon->selcli, 0);
+ if (selmon->sel && selmon->sel != c)
+ unfocus(selmon->sel, 0);
if (c) {
if (c->mon != selmon) selmon = c->mon;
if (c->isurgent) seturgent(c, 0);
@@ -944,7 +946,7 @@ focus(Client* c)
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
}
- selmon->selcli = c;
+ selmon->sel = c;
drawbars();
}
@@ -954,8 +956,8 @@ focusin(XEvent* e)
{
XFocusChangeEvent* ev = &e->xfocus;
- if (selmon->selcli && ev->window != selmon->selcli->win)
- setfocus(selmon->selcli);
+ if (selmon->sel && ev->window != selmon->sel->win)
+ setfocus(selmon->sel);
}
void
@@ -967,7 +969,7 @@ focusmon(const Arg* arg)
return;
if ((m = dirtomon(arg->i)) == selmon)
return;
- unfocus(selmon->selcli, 0);
+ unfocus(selmon->sel, 0);
selmon = m;
focus(NULL);
}
@@ -977,18 +979,18 @@ focusstack(const Arg* arg)
{
Client *c = NULL, *i;
- if (!selmon->selcli)
+ if (!selmon->sel)
return;
if (arg->i > sizeof(arg))
return;
if (arg->i > 0) {
- for (c = selmon->selcli->next; c && !ISVISIBLE(c); c = c->next)
+ for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next)
;
if (!c)
for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next)
;
} else {
- for (i = selmon->clients; i != selmon->selcli; i = i->next)
+ for (i = selmon->clients; i != selmon->sel; i = i->next)
if (ISVISIBLE(i)) c = i;
if (!c)
for (; i; i = i->next)
@@ -1135,13 +1137,13 @@ keypress(XEvent* e)
void
killclient(const Arg* arg)
{
- if (!selmon->selcli)
+ if (!selmon->sel)
return;
- if (!sendevent(selmon->selcli, wmatom[WMDelete])) {
+ if (!sendevent(selmon->sel, wmatom[WMDelete])) {
XGrabServer(dpy);
XSetErrorHandler(xerrordummy);
XSetCloseDownMode(dpy, DestroyAll);
- XKillClient(dpy, selmon->selcli->win);
+ XKillClient(dpy, selmon->sel->win);
XSync(dpy, False);
XSetErrorHandler(xerror);
XUngrabServer(dpy);
@@ -1209,8 +1211,8 @@ manage(Window w, XWindowAttributes* wa)
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
setclientstate(c, NormalState);
if (c->mon == selmon)
- unfocus(selmon->selcli, 0);
- c->mon->selcli = c;
+ unfocus(selmon->sel, 0);
+ c->mon->sel = c;
arrange(c->mon);
XMapWindow(dpy, c->win);
if (term)
@@ -1252,7 +1254,7 @@ motionnotify(XEvent* e)
if (ev->window != root)
return;
if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
- unfocus(selmon->selcli, 1);
+ unfocus(selmon->sel, 1);
selmon = m;
focus(NULL);
}
@@ -1268,7 +1270,7 @@ movemouse(const Arg* arg)
XEvent ev;
Time lasttime = 0;
- if (!(c = selmon->selcli))
+ if (!(c = selmon->sel))
return;
if (c->isfullscreen) /* no support moving fullscreen windows by mouse */
return;
@@ -1363,7 +1365,7 @@ propertynotify(XEvent* e)
}
if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
updatetitle(c);
- if (c == c->mon->selcli)
+ if (c == c->mon->sel)
drawbar(c->mon);
}
if (ev->atom == netatom[NetWMWindowType])
@@ -1425,7 +1427,7 @@ resizemouse(const Arg* arg)
XEvent ev;
Time lasttime = 0;
- if (!(c = selmon->selcli))
+ if (!(c = selmon->sel))
return;
if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */
return;
@@ -1482,10 +1484,10 @@ restack(Monitor* m)
XWindowChanges wc;
drawbar(m);
- if (!m->selcli)
+ if (!m->sel)
return;
- if (m->selcli->isfloating || !m->lt[m->sellt]->arrange)
- XRaiseWindow(dpy, m->selcli->win);
+ if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
+ XRaiseWindow(dpy, m->sel->win);
if (m->lt[m->sellt]->arrange) {
wc.stack_mode = Below;
wc.sibling = m->barwin;
@@ -1635,7 +1637,7 @@ setlayout(const Arg* arg)
selmon->sellt ^= 1;
if (arg && arg->v)
selmon->lt[selmon->sellt] = (Layout*)arg->v;
- if (selmon->selcli)
+ if (selmon->sel)
arrange(selmon);
else
drawbar(selmon);
@@ -1677,6 +1679,8 @@ setup()
die("no fonts could be loaded.");
lrpad = drw->fonts->h;
bh = drw->fonts->h + 2;
+ sp = sidepad;
+ vp = (topbar == 1) ? vertpad : - vertpad;
updategeom();
/* init atoms */
@@ -1787,8 +1791,8 @@ spawn(const Arg* arg)
void
tag(const Arg* arg)
{
- if (selmon->selcli && arg->ui & TAGMASK) {
- selmon->selcli->tags = arg->ui & TAGMASK;
+ if (selmon->sel && arg->ui & TAGMASK) {
+ selmon->sel->tags = arg->ui & TAGMASK;
focus(NULL);
arrange(selmon);
}
@@ -1797,9 +1801,9 @@ tag(const Arg* arg)
void
tagmon(const Arg* arg)
{
- if (!selmon->selcli || !mons->next)
+ if (!selmon->sel || !mons->next)
return;
- sendmon(selmon->selcli, dirtomon(arg->i));
+ sendmon(selmon->sel, dirtomon(arg->i));
}
void
@@ -1807,28 +1811,28 @@ togglebar(const Arg* arg)
{
selmon->showbar = !selmon->showbar;
updatebarpos(selmon);
- XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
+ XMoveResizeWindow(dpy, selmon->barwin, selmon->wx + sp, selmon->by + vp, selmon->ww - 2 * sp, bh);
arrange(selmon);
}
void
togglefloating(const Arg* arg)
{
- if (!selmon->selcli)
+ if (!selmon->sel)
return;
- if (selmon->selcli->isfullscreen)
+ if (selmon->sel->isfullscreen)
return; /* no support for fullscreen windows */
- selmon->selcli->isfloating = !selmon->selcli->isfloating || selmon->selcli->isfixed;
- if (selmon->selcli->isfloating)
- resize(selmon->selcli, selmon->selcli->x, selmon->selcli->y, selmon->selcli->w, selmon->selcli->h, 0);
+ 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);
arrange(selmon);
}
void
togglefullscr(const Arg* arg)
{
- if (selmon->selcli)
- setfullscreen(selmon->selcli, !selmon->selcli->isfullscreen);
+ if (selmon->sel)
+ setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
}
void
@@ -1836,11 +1840,11 @@ toggletag(const Arg* arg)
{
uint newtags;
- if (!selmon->selcli)
+ if (!selmon->sel)
return;
- newtags = selmon->selcli->tags ^ (arg->ui & TAGMASK);
+ newtags = selmon->sel->tags ^ (arg->ui & TAGMASK);
if (newtags) {
- selmon->selcli->tags = newtags;
+ selmon->sel->tags = newtags;
focus(NULL);
arrange(selmon);
}
@@ -1942,7 +1946,7 @@ updatebars()
if (m->barwin)
continue;
m->barwin = XCreateWindow(
- dpy, root, m->wx, m->by, m->ww, bh, 0, depth,
+ dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, depth,
InputOutput, visual,
CWOverrideRedirect|CWBackPixel|CWBorderPixel|CWColormap|CWEventMask, &wa
);
@@ -1958,11 +1962,11 @@ updatebarpos(Monitor* m)
m->wy = m->my;
m->wh = m->mh;
if (m->showbar) {
- m->wh -= bh;
- m->by = m->topbar ? m->wy : m->wy + m->wh;
- m->wy = m->topbar ? m->wy + bh : m->wy;
+ m->wh = m->wh - vertpad - bh;
+ m->by = m->topbar ? m->wy : m->wy + m->wh + vertpad;
+ m->wy = m->topbar ? m->wy + bh + vp : m->wy;
} else
- m->by = -bh;
+ m->by = -bh - vp;
}
void
@@ -2152,7 +2156,7 @@ updatewmhints(Client* c)
XWMHints* wmh;
if ((wmh = XGetWMHints(dpy, c->win))) {
- if (c == selmon->selcli && wmh->flags & XUrgencyHint) {
+ if (c == selmon->sel && wmh->flags & XUrgencyHint) {
wmh->flags &= ~XUrgencyHint;
XSetWMHints(dpy, c->win, wmh);
} else
@@ -2170,7 +2174,7 @@ view(const Arg* arg)
{
if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
return;
- selmon->seltags ^= 1; /* toggle selcli tagset */
+ selmon->seltags ^= 1; /* toggle sel tagset */
if (arg->ui & TAGMASK)
selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
focus(NULL);
@@ -2363,9 +2367,9 @@ xinitvisual()
void
zoom(const Arg* arg)
{
- Client* c = selmon->selcli;
+ Client* c = selmon->sel;
- if (!selmon->lt[selmon->sellt]->arrange || (selmon->selcli && selmon->selcli->isfloating))
+ if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating))
return;
if (c == nexttiled(selmon->clients))
if (!c || !(c = nexttiled(c->next)))