Compare commits
8 Commits
2d38a8d50d
...
amused
Author | SHA1 | Date | |
---|---|---|---|
429429fad3 | |||
e42bd55e46 | |||
84bb66cd82 | |||
fbb9607587 | |||
8d107203ce | |||
812232094f | |||
6956d0f4b9 | |||
5b7e60d840 |
49
config.def.h
49
config.def.h
@ -1,28 +1,31 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int gappx = 5; /* gaps between windows */
|
||||
static const unsigned int borderpx = 0; /* border pixel of windows */
|
||||
static const unsigned int gappx = 10; /* gaps between windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
static const int horizpadbar = 2; /* horizontal padding for statusbar */
|
||||
static const int vertpadbar = 0; /* vertical padding for statusbar */
|
||||
static const char *fonts[] = { "monospace:size=10" };
|
||||
static const char dmenufont[] = "monospace:size=10";
|
||||
static const char col_gray1[] = "#222222";
|
||||
static const char col_gray2[] = "#444444";
|
||||
static const char col_gray3[] = "#bbbbbb";
|
||||
static const int horizpadbar = 0; /* horizontal padding for statusbar */
|
||||
static const int vertpadbar = 5; /* vertical padding for statusbar */
|
||||
static const int vertpad = 10; /* vertical padding of bar */
|
||||
static const int sidepad = 10; /* horizontal padding of bar */
|
||||
static const char *fonts[] = { "monospace:size=12", "remixicon:size=14" };
|
||||
static const char dmenufont[] = "monospace:size=12";
|
||||
static const char col_gray1[] = "#597445";
|
||||
static const char col_gray2[] = "#658147";
|
||||
static const char col_gray3[] = "#e7f0dc";
|
||||
static const char col_gray4[] = "#eeeeee";
|
||||
static const char col_cyan[] = "#005577";
|
||||
static const char col_cyan[] = "#c6b652";
|
||||
static const char *colors[][3] = {
|
||||
/* fg bg border */
|
||||
[SchemeNorm] = { col_gray3, col_gray1, col_gray2 },
|
||||
[SchemeSel] = { col_gray4, col_cyan, col_cyan },
|
||||
[SchemeSel] = { col_cyan, col_gray1, col_gray1 },
|
||||
};
|
||||
|
||||
/* tagging */
|
||||
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
|
||||
static const char *tag_with_window = "";
|
||||
static const char *tags[] = { "", "", "", "", "", "", "", "", "" };
|
||||
|
||||
static const Rule rules[] = {
|
||||
/* xprop(1):
|
||||
@ -42,13 +45,13 @@ static const int lockfullscreen = 1; /* 1 will force focus on the fullscreen win
|
||||
|
||||
static const Layout layouts[] = {
|
||||
/* symbol arrange function */
|
||||
{ "[]=", tile }, /* first entry is default */
|
||||
{ "><>", NULL }, /* no layout function means floating behavior */
|
||||
{ "[M]", monocle },
|
||||
{ "", tile }, /* first entry is default */
|
||||
{ "", NULL }, /* no layout function means floating behavior */
|
||||
{ "", monocle },
|
||||
};
|
||||
|
||||
/* key definitions */
|
||||
#define MODKEY Mod1Mask
|
||||
#define MODKEY Mod4Mask
|
||||
#define TAGKEYS(KEY,TAG) \
|
||||
{ MODKEY, KEY, view, {.ui = 1 << TAG} }, \
|
||||
{ MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \
|
||||
@ -58,6 +61,8 @@ static const Layout layouts[] = {
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
#define STATUSBAR "dwmblocks"
|
||||
|
||||
/* commands */
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
||||
@ -65,18 +70,18 @@ static const char *termcmd[] = { "st", NULL };
|
||||
|
||||
static const Key keys[] = {
|
||||
/* modifier key function argument */
|
||||
{ MODKEY, XK_p, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY, XK_d, spawn, {.v = dmenucmd } },
|
||||
{ MODKEY|ShiftMask, XK_Return, spawn, {.v = termcmd } },
|
||||
{ MODKEY, XK_b, togglebar, {0} },
|
||||
{ MODKEY, XK_j, focusstack, {.i = +1 } },
|
||||
{ MODKEY, XK_k, focusstack, {.i = -1 } },
|
||||
{ MODKEY, XK_i, incnmaster, {.i = +1 } },
|
||||
{ MODKEY, XK_d, incnmaster, {.i = -1 } },
|
||||
{ MODKEY, XK_u, incnmaster, {.i = -1 } },
|
||||
{ MODKEY, XK_h, setmfact, {.f = -0.05} },
|
||||
{ MODKEY, XK_l, setmfact, {.f = +0.05} },
|
||||
{ MODKEY, XK_Return, zoom, {0} },
|
||||
{ MODKEY, XK_Tab, view, {0} },
|
||||
{ MODKEY|ShiftMask, XK_c, killclient, {0} },
|
||||
{ MODKEY|ShiftMask, XK_q, killclient, {0} },
|
||||
{ MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
|
||||
{ MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
|
||||
{ MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
|
||||
@ -100,7 +105,7 @@ static const Key keys[] = {
|
||||
TAGKEYS( XK_7, 6)
|
||||
TAGKEYS( XK_8, 7)
|
||||
TAGKEYS( XK_9, 8)
|
||||
{ MODKEY|ShiftMask, XK_q, quit, {0} },
|
||||
{ MODKEY|ShiftMask, XK_l, quit, {0} },
|
||||
};
|
||||
|
||||
/* button definitions */
|
||||
@ -110,7 +115,9 @@ static const Button buttons[] = {
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
{ ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
{ ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} },
|
||||
{ ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} },
|
||||
{ ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
|
133
dwm.c
133
dwm.c
@ -172,6 +172,7 @@ static void focusstack(const Arg *arg);
|
||||
static Atom getatomprop(Client *c, Atom prop);
|
||||
static int getrootptr(int *x, int *y);
|
||||
static long getstate(Window w);
|
||||
static pid_t getstatusbarpid();
|
||||
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||
static void grabbuttons(Client *c, int focused);
|
||||
static void grabkeys(void);
|
||||
@ -206,6 +207,7 @@ static void setmfact(const Arg *arg);
|
||||
static void setup(void);
|
||||
static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
static void sigstatusbar(const Arg *arg);
|
||||
static void spawn(const Arg *arg);
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
@ -238,10 +240,15 @@ static void zoom(const Arg *arg);
|
||||
/* variables */
|
||||
static const char broken[] = "broken";
|
||||
static char stext[256];
|
||||
static int statusw;
|
||||
static int statussig;
|
||||
static pid_t statuspid = -1;
|
||||
static int screen;
|
||||
static int sw, sh; /* X display screen geometry width, height */
|
||||
static int bh; /* bar height */
|
||||
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 unsigned int numlockmask = 0;
|
||||
static void (*handler[LASTEvent]) (XEvent *) = {
|
||||
@ -424,6 +431,7 @@ buttonpress(XEvent *e)
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
char *text, *s, ch;
|
||||
|
||||
click = ClkRootWin;
|
||||
/* focus monitor if necessary */
|
||||
@ -442,9 +450,27 @@ buttonpress(XEvent *e)
|
||||
arg.ui = 1 << i;
|
||||
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
|
||||
click = ClkLtSymbol;
|
||||
else if (ev->x > selmon->ww - (int)TEXTW(stext))
|
||||
else if (ev->x > selmon->ww - statusw) {
|
||||
x = selmon->ww - statusw;
|
||||
click = ClkStatusText;
|
||||
statussig = 0;
|
||||
for (text = s = stext; *s && x <= ev->x; s++) {
|
||||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
x += TEXTW(text) - lrpad;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
if (x >= ev->x)
|
||||
break;
|
||||
/* reset on matching signal raw byte */
|
||||
if (ch == statussig)
|
||||
statussig = 0;
|
||||
else
|
||||
statussig = ch;
|
||||
}
|
||||
}
|
||||
} else
|
||||
click = ClkWinTitle;
|
||||
} else if ((c = wintoclient(ev->window))) {
|
||||
focus(c);
|
||||
@ -571,7 +597,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);
|
||||
@ -711,9 +737,26 @@ drawbar(Monitor *m)
|
||||
|
||||
/* draw status first so it can be overdrawn by tags later */
|
||||
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||
char *text, *s, ch;
|
||||
drw_setscheme(drw, scheme[SchemeNorm]);
|
||||
tw = TEXTW(stext);
|
||||
drw_text(drw, m->ww - tw, 0, tw, bh, lrpad / 2, stext, 0);
|
||||
drw_text(drw, m->ww - tw - 2 * sp, 0, tw, bh, lrpad / 2, stext, 0);
|
||||
|
||||
x = 0;
|
||||
for (text = s = stext; *s; s++) {
|
||||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
tw = TEXTW(text) - lrpad;
|
||||
drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
|
||||
x += tw;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
}
|
||||
}
|
||||
tw = TEXTW(text) - lrpad + 2;
|
||||
drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
|
||||
tw = statusw;
|
||||
}
|
||||
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
@ -725,11 +768,11 @@ drawbar(Monitor *m)
|
||||
for (i = 0; i < LENGTH(tags); i++) {
|
||||
w = TEXTW(tags[i]);
|
||||
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_text(drw, x, 0, w, bh, lrpad / 2, tag_with_window, urg & 1 << i);
|
||||
else
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i);
|
||||
x += w;
|
||||
}
|
||||
w = TEXTW(m->ltsymbol);
|
||||
@ -739,12 +782,12 @@ drawbar(Monitor *m)
|
||||
if ((w = m->ww - tw - x) > bh) {
|
||||
if (m->sel) {
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 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);
|
||||
@ -879,6 +922,30 @@ getatomprop(Client *c, Atom prop)
|
||||
return atom;
|
||||
}
|
||||
|
||||
pid_t
|
||||
getstatusbarpid()
|
||||
{
|
||||
char buf[32], *str = buf, *c;
|
||||
FILE *fp;
|
||||
|
||||
if (statuspid > 0) {
|
||||
snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
|
||||
if ((fp = fopen(buf, "r"))) {
|
||||
fgets(buf, sizeof(buf), fp);
|
||||
while ((c = strchr(str, '/')))
|
||||
str = c + 1;
|
||||
fclose(fp);
|
||||
if (!strcmp(str, STATUSBAR))
|
||||
return statuspid;
|
||||
}
|
||||
}
|
||||
if (!(fp = popen("pidof -s "STATUSBAR, "r")))
|
||||
return -1;
|
||||
fgets(buf, sizeof(buf), fp);
|
||||
pclose(fp);
|
||||
return strtol(buf, NULL, 10);
|
||||
}
|
||||
|
||||
int
|
||||
getrootptr(int *x, int *y)
|
||||
{
|
||||
@ -1575,7 +1642,10 @@ setup(void)
|
||||
die("no fonts could be loaded.");
|
||||
lrpad = drw->fonts->h + horizpadbar;
|
||||
bh = drw->fonts->h + vertpadbar;
|
||||
sp = sidepad;
|
||||
vp = (topbar == 1) ? vertpad : - vertpad;
|
||||
updategeom();
|
||||
|
||||
/* init atoms */
|
||||
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
@ -1656,6 +1726,20 @@ showhide(Client *c)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
sigstatusbar(const Arg *arg)
|
||||
{
|
||||
union sigval sv;
|
||||
|
||||
if (!statussig)
|
||||
return;
|
||||
sv.sival_int = arg->i;
|
||||
if ((statuspid = getstatusbarpid()) <= 0)
|
||||
return;
|
||||
|
||||
sigqueue(statuspid, SIGRTMIN+statussig, sv);
|
||||
}
|
||||
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
@ -1729,7 +1813,7 @@ 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);
|
||||
}
|
||||
|
||||
@ -1840,7 +1924,7 @@ updatebars(void)
|
||||
for (m = mons; m; m = m->next) {
|
||||
if (m->barwin)
|
||||
continue;
|
||||
m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
|
||||
m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen),
|
||||
CopyFromParent, DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
|
||||
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||||
@ -1855,11 +1939,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
|
||||
@ -2017,8 +2101,25 @@ updatesizehints(Client *c)
|
||||
void
|
||||
updatestatus(void)
|
||||
{
|
||||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||||
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) {
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
statusw = TEXTW(stext) - lrpad + 2;
|
||||
} else {
|
||||
char *text, *s, ch;
|
||||
|
||||
statusw = 0;
|
||||
for (text = s = stext; *s; s++) {
|
||||
if ((unsigned char)(*s) < ' ') {
|
||||
ch = *s;
|
||||
*s = '\0';
|
||||
statusw += TEXTW(text) - lrpad;
|
||||
*s = ch;
|
||||
text = s + 1;
|
||||
}
|
||||
}
|
||||
statusw += TEXTW(text) - lrpad + 2;
|
||||
|
||||
}
|
||||
drawbar(selmon);
|
||||
}
|
||||
|
||||
|
118
patches/dwm-barpadding-20211020-a786211.diff
Normal file
118
patches/dwm-barpadding-20211020-a786211.diff
Normal file
@ -0,0 +1,118 @@
|
||||
From a3cfb215f7f647d83d67e33df8f33a73e43bd65f Mon Sep 17 00:00:00 2001
|
||||
From: Bakkeby <bakkeby@gmail.com>
|
||||
Date: Wed, 20 Oct 2021 09:14:07 +0200
|
||||
Subject: [PATCH] barpadding: adds space between the statusbar and the edge of
|
||||
the screen
|
||||
|
||||
---
|
||||
config.def.h | 2 ++
|
||||
dwm.c | 25 +++++++++++++++----------
|
||||
2 files changed, 17 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index a2ac963..f0b739f 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -5,6 +5,8 @@ static const unsigned int borderpx = 1; /* border pixel of windows */
|
||||
static const unsigned int snap = 32; /* snap pixel */
|
||||
static const int showbar = 1; /* 0 means no bar */
|
||||
static const int topbar = 1; /* 0 means bottom bar */
|
||||
+static const int vertpad = 10; /* vertical padding of bar */
|
||||
+static const int sidepad = 10; /* horizontal padding of bar */
|
||||
static const char *fonts[] = { "monospace:size=10" };
|
||||
static const char dmenufont[] = "monospace:size=10";
|
||||
static const char col_gray1[] = "#222222";
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 5e4d494..df6d0d7 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -242,6 +242,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 unsigned int numlockmask = 0;
|
||||
static void (*handler[LASTEvent]) (XEvent *) = {
|
||||
@@ -568,7 +570,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);
|
||||
@@ -706,7 +708,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) {
|
||||
@@ -732,12 +734,12 @@ drawbar(Monitor *m)
|
||||
if ((w = m->ww - tw - x) > bh) {
|
||||
if (m->sel) {
|
||||
drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]);
|
||||
- drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 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);
|
||||
@@ -1547,7 +1549,10 @@ setup(void)
|
||||
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 */
|
||||
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
|
||||
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
|
||||
@@ -1704,7 +1709,7 @@ 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);
|
||||
}
|
||||
|
||||
@@ -1814,7 +1819,7 @@ updatebars(void)
|
||||
for (m = mons; m; m = m->next) {
|
||||
if (m->barwin)
|
||||
continue;
|
||||
- m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen),
|
||||
+ m->barwin = XCreateWindow(dpy, root, m->wx + sp, m->by + vp, m->ww - 2 * sp, bh, 0, DefaultDepth(dpy, screen),
|
||||
CopyFromParent, DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect|CWBackPixmap|CWEventMask, &wa);
|
||||
XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor);
|
||||
@@ -1829,11 +1834,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
|
||||
--
|
||||
2.33.0
|
||||
|
220
patches/dwm-statuscmd-20241009-8933ebc.diff
Normal file
220
patches/dwm-statuscmd-20241009-8933ebc.diff
Normal file
@ -0,0 +1,220 @@
|
||||
From ca2a2e6386a746ebfc3480787e5d99da11e7abee Mon Sep 17 00:00:00 2001
|
||||
From: Justinas Grigas <dev@jstnas.com>
|
||||
Date: Wed, 9 Oct 2024 01:00:20 +0100
|
||||
Subject: [PATCH] [dwm][statuscmd] better click regions
|
||||
|
||||
The main improvement of this patch over the previous version 20210405 is that
|
||||
the click region now ends on a matching signal raw byte.
|
||||
|
||||
The matching byte is optional, and without it dwm will behave as before.
|
||||
|
||||
To take advantage of this feature, scripts need to be modified to print the raw
|
||||
byte at the end as well.
|
||||
|
||||
In addition, this patch cleanly applies onto master branch.
|
||||
---
|
||||
config.def.h | 6 ++-
|
||||
dwm.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++---
|
||||
2 files changed, 104 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 9efa774..d008275 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -55,6 +55,8 @@ static const Layout layouts[] = {
|
||||
/* helper for spawning shell commands in the pre dwm-5.0 fashion */
|
||||
#define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } }
|
||||
|
||||
+#define STATUSBAR "dwmblocks"
|
||||
+
|
||||
/* commands */
|
||||
static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */
|
||||
static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
|
||||
@@ -104,7 +106,9 @@ static const Button buttons[] = {
|
||||
{ ClkLtSymbol, 0, Button1, setlayout, {0} },
|
||||
{ ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} },
|
||||
{ ClkWinTitle, 0, Button2, zoom, {0} },
|
||||
- { ClkStatusText, 0, Button2, spawn, {.v = termcmd } },
|
||||
+ { ClkStatusText, 0, Button1, sigstatusbar, {.i = 1} },
|
||||
+ { ClkStatusText, 0, Button2, sigstatusbar, {.i = 2} },
|
||||
+ { ClkStatusText, 0, Button3, sigstatusbar, {.i = 3} },
|
||||
{ ClkClientWin, MODKEY, Button1, movemouse, {0} },
|
||||
{ ClkClientWin, MODKEY, Button2, togglefloating, {0} },
|
||||
{ ClkClientWin, MODKEY, Button3, resizemouse, {0} },
|
||||
diff --git a/dwm.c b/dwm.c
|
||||
index 1443802..94ee0c7 100644
|
||||
--- a/dwm.c
|
||||
+++ b/dwm.c
|
||||
@@ -171,6 +171,7 @@ static void focusstack(const Arg *arg);
|
||||
static Atom getatomprop(Client *c, Atom prop);
|
||||
static int getrootptr(int *x, int *y);
|
||||
static long getstate(Window w);
|
||||
+static pid_t getstatusbarpid();
|
||||
static int gettextprop(Window w, Atom atom, char *text, unsigned int size);
|
||||
static void grabbuttons(Client *c, int focused);
|
||||
static void grabkeys(void);
|
||||
@@ -204,6 +205,7 @@ static void setmfact(const Arg *arg);
|
||||
static void setup(void);
|
||||
static void seturgent(Client *c, int urg);
|
||||
static void showhide(Client *c);
|
||||
+static void sigstatusbar(const Arg *arg);
|
||||
static void spawn(const Arg *arg);
|
||||
static void tag(const Arg *arg);
|
||||
static void tagmon(const Arg *arg);
|
||||
@@ -236,6 +238,9 @@ static void zoom(const Arg *arg);
|
||||
/* variables */
|
||||
static const char broken[] = "broken";
|
||||
static char stext[256];
|
||||
+static int statusw;
|
||||
+static int statussig;
|
||||
+static pid_t statuspid = -1;
|
||||
static int screen;
|
||||
static int sw, sh; /* X display screen geometry width, height */
|
||||
static int bh; /* bar height */
|
||||
@@ -422,6 +427,7 @@ buttonpress(XEvent *e)
|
||||
Client *c;
|
||||
Monitor *m;
|
||||
XButtonPressedEvent *ev = &e->xbutton;
|
||||
+ char *text, *s, ch;
|
||||
|
||||
click = ClkRootWin;
|
||||
/* focus monitor if necessary */
|
||||
@@ -440,9 +446,27 @@ buttonpress(XEvent *e)
|
||||
arg.ui = 1 << i;
|
||||
} else if (ev->x < x + TEXTW(selmon->ltsymbol))
|
||||
click = ClkLtSymbol;
|
||||
- else if (ev->x > selmon->ww - (int)TEXTW(stext))
|
||||
+ else if (ev->x > selmon->ww - statusw) {
|
||||
+ x = selmon->ww - statusw;
|
||||
click = ClkStatusText;
|
||||
- else
|
||||
+ statussig = 0;
|
||||
+ for (text = s = stext; *s && x <= ev->x; s++) {
|
||||
+ if ((unsigned char)(*s) < ' ') {
|
||||
+ ch = *s;
|
||||
+ *s = '\0';
|
||||
+ x += TEXTW(text) - lrpad;
|
||||
+ *s = ch;
|
||||
+ text = s + 1;
|
||||
+ if (x >= ev->x)
|
||||
+ break;
|
||||
+ /* reset on matching signal raw byte */
|
||||
+ if (ch == statussig)
|
||||
+ statussig = 0;
|
||||
+ else
|
||||
+ statussig = ch;
|
||||
+ }
|
||||
+ }
|
||||
+ } else
|
||||
click = ClkWinTitle;
|
||||
} else if ((c = wintoclient(ev->window))) {
|
||||
focus(c);
|
||||
@@ -708,9 +732,24 @@ drawbar(Monitor *m)
|
||||
|
||||
/* draw status first so it can be overdrawn by tags later */
|
||||
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||
+ char *text, *s, ch;
|
||||
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);
|
||||
+
|
||||
+ x = 0;
|
||||
+ for (text = s = stext; *s; s++) {
|
||||
+ if ((unsigned char)(*s) < ' ') {
|
||||
+ ch = *s;
|
||||
+ *s = '\0';
|
||||
+ tw = TEXTW(text) - lrpad;
|
||||
+ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
|
||||
+ x += tw;
|
||||
+ *s = ch;
|
||||
+ text = s + 1;
|
||||
+ }
|
||||
+ }
|
||||
+ tw = TEXTW(text) - lrpad + 2;
|
||||
+ drw_text(drw, m->ww - statusw + x, 0, tw, bh, 0, text, 0);
|
||||
+ tw = statusw;
|
||||
}
|
||||
|
||||
for (c = m->clients; c; c = c->next) {
|
||||
@@ -876,6 +915,30 @@ getatomprop(Client *c, Atom prop)
|
||||
return atom;
|
||||
}
|
||||
|
||||
+pid_t
|
||||
+getstatusbarpid()
|
||||
+{
|
||||
+ char buf[32], *str = buf, *c;
|
||||
+ FILE *fp;
|
||||
+
|
||||
+ if (statuspid > 0) {
|
||||
+ snprintf(buf, sizeof(buf), "/proc/%u/cmdline", statuspid);
|
||||
+ if ((fp = fopen(buf, "r"))) {
|
||||
+ fgets(buf, sizeof(buf), fp);
|
||||
+ while ((c = strchr(str, '/')))
|
||||
+ str = c + 1;
|
||||
+ fclose(fp);
|
||||
+ if (!strcmp(str, STATUSBAR))
|
||||
+ return statuspid;
|
||||
+ }
|
||||
+ }
|
||||
+ if (!(fp = popen("pidof -s "STATUSBAR, "r")))
|
||||
+ return -1;
|
||||
+ fgets(buf, sizeof(buf), fp);
|
||||
+ pclose(fp);
|
||||
+ return strtol(buf, NULL, 10);
|
||||
+}
|
||||
+
|
||||
int
|
||||
getrootptr(int *x, int *y)
|
||||
{
|
||||
@@ -1643,6 +1706,20 @@ showhide(Client *c)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+sigstatusbar(const Arg *arg)
|
||||
+{
|
||||
+ union sigval sv;
|
||||
+
|
||||
+ if (!statussig)
|
||||
+ return;
|
||||
+ sv.sival_int = arg->i;
|
||||
+ if ((statuspid = getstatusbarpid()) <= 0)
|
||||
+ return;
|
||||
+
|
||||
+ sigqueue(statuspid, SIGRTMIN+statussig, sv);
|
||||
+}
|
||||
+
|
||||
void
|
||||
spawn(const Arg *arg)
|
||||
{
|
||||
@@ -2004,8 +2081,25 @@ updatesizehints(Client *c)
|
||||
void
|
||||
updatestatus(void)
|
||||
{
|
||||
- if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
|
||||
+ if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) {
|
||||
strcpy(stext, "dwm-"VERSION);
|
||||
+ statusw = TEXTW(stext) - lrpad + 2;
|
||||
+ } else {
|
||||
+ char *text, *s, ch;
|
||||
+
|
||||
+ statusw = 0;
|
||||
+ for (text = s = stext; *s; s++) {
|
||||
+ if ((unsigned char)(*s) < ' ') {
|
||||
+ ch = *s;
|
||||
+ *s = '\0';
|
||||
+ statusw += TEXTW(text) - lrpad;
|
||||
+ *s = ch;
|
||||
+ text = s + 1;
|
||||
+ }
|
||||
+ }
|
||||
+ statusw += TEXTW(text) - lrpad + 2;
|
||||
+
|
||||
+ }
|
||||
drawbar(selmon);
|
||||
}
|
||||
|
||||
--
|
||||
2.46.2
|
||||
|
Reference in New Issue
Block a user