summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorbakkeby <[email protected]>2020-09-10 15:24:51 +0200
committerbakkeby <[email protected]>2020-09-10 15:24:51 +0200
commitd91db5cd653507f67f1c188ce8440783e88518a8 (patch)
treeba8050502d38eecb94d12666bbdb766b39d6f5ba
parent8994f375e8ca8042996d752a385b8d1706526a25 (diff)
downloaddwm-flexipatch-d91db5cd653507f67f1c188ce8440783e88518a8.tar.gz
dwm-flexipatch-d91db5cd653507f67f1c188ce8440783e88518a8.zip
anybar: adding experimental support for having both anybar + dwm bar(s) in play
-rw-r--r--README.md2
-rw-r--r--dwm.c50
-rw-r--r--patch/bar_anybar.c46
-rw-r--r--patches.def.h4
4 files changed, 59 insertions, 43 deletions
diff --git a/README.md b/README.md
index 9ec9a23..1866158 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog:
-2020-09-10 - Added the anybar patch (basic integration, no support for dwm bar(s) + anybar)
+2020-09-10 - Added the anybar patch (with experimental support for dwm bar(s) + anybar)
2020-09-09 - Added the bar border patch
diff --git a/dwm.c b/dwm.c
index cde730b..663312c 100644
--- a/dwm.c
+++ b/dwm.c
@@ -259,6 +259,7 @@ struct Bar {
int idx;
int showbar;
int topbar;
+ int external;
int borderpx;
int borderscheme;
int bx, by, bw, bh; /* bar geometry */
@@ -1087,15 +1088,10 @@ cleanupmon(Monitor *mon)
m->next = mon->next;
}
for (bar = mon->bar; bar; bar = mon->bar) {
- #if BAR_ANYBAR_PATCH
- if (!usealtbar) {
+ if (!bar->external) {
XUnmapWindow(dpy, bar->win);
XDestroyWindow(dpy, bar->win);
}
- #else
- XUnmapWindow(dpy, bar->win);
- XDestroyWindow(dpy, bar->win);
- #endif // BAR_ANYBAR_PATCH
mon->bar = bar->next;
free(bar);
}
@@ -1229,7 +1225,6 @@ configurenotify(XEvent *e)
#endif // !FAKEFULLSCREEN_PATCH
XConfigureEvent *ev = &e->xconfigure;
int dirty;
-
/* TODO: updategeom handling sucks, needs to be simplified */
if (ev->window == root) {
dirty = (sw != ev->width || sh != ev->height);
@@ -1262,9 +1257,11 @@ configurerequest(XEvent *e)
{
Client *c;
Monitor *m;
+ #if BAR_ANYBAR_PATCH
+ Bar *bar;
+ #endif // BAR_ANYBAR_PATCH
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc;
-
if ((c = wintoclient(ev->window))) {
if (ev->value_mask & CWBorderWidth)
c->bw = ev->border_width;
@@ -1316,6 +1313,15 @@ configurerequest(XEvent *e)
} else {
wc.x = ev->x;
wc.y = ev->y;
+ #if BAR_ANYBAR_PATCH
+ m = wintomon(ev->window);
+ for (bar = m->bar; bar; bar = bar->next) {
+ if (bar->win == ev->window) {
+ wc.y = bar->by;
+ wc.x = bar->bx;
+ }
+ }
+ #endif // BAR_ANYBAR_PATCH
wc.width = ev->width;
wc.height = ev->height;
wc.border_width = ev->border_width;
@@ -1412,11 +1418,13 @@ createmon(void)
m->bar = bar;
istopbar = !istopbar;
bar->showbar = 1;
+ bar->external = 0;
#if BAR_BORDER_PATCH
bar->borderpx = borderpx;
#else
bar->borderpx = 0;
#endif // BAR_BORDER_PATCH
+ bar->bh = bh + bar->borderpx * 2;
bar->borderscheme = SchemeNorm;
}
@@ -1576,11 +1584,6 @@ dirtomon(int dir)
void
drawbar(Monitor *m)
{
- #if BAR_ANYBAR_PATCH
- if (usealtbar)
- return;
- #endif // BAR_ANYBAR_PATCH
-
Bar *bar;
for (bar = m->bar; bar; bar = bar->next)
drawbarwin(bar);
@@ -1597,7 +1600,7 @@ drawbars(void)
void
drawbarwin(Bar *bar)
{
- if (!bar->win)
+ if (!bar->win || bar->external)
return;
int r, w, total_drawn = 0;
int rx, lx, rw, lw; // bar size, split between left and right if a center module is added
@@ -3116,10 +3119,6 @@ setup(void)
bh = drw->fonts->h + 2;
#endif // BAR_HEIGHT_PATCH
#endif // BAR_STATUSPADDING_PATCH
- #if BAR_ANYBAR_PATCH
- if (usealtbar)
- bh = 0;
- #endif // BAR_ANYBAR_PATCH
updategeom();
/* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False);
@@ -3781,10 +3780,6 @@ unmapnotify(XEvent *e)
void
updatebars(void)
{
- #if BAR_ANYBAR_PATCH
- if (usealtbar)
- return;
- #endif // BAR_ANYBAR_PATCH
Bar *bar;
Monitor *m;
XSetWindowAttributes wa = {
@@ -3801,6 +3796,8 @@ updatebars(void)
XClassHint ch = {"dwm", "dwm"};
for (m = mons; m; m = m->next) {
for (bar = m->bar; bar; bar = bar->next) {
+ if (bar->external)
+ continue;
if (!bar->win) {
#if BAR_ALPHA_PATCH
bar->win = XCreateWindow(dpy, root, bar->bx, bar->by, bar->bw, bar->bh, 0, depth,
@@ -3847,23 +3844,22 @@ updatebarpos(Monitor *m)
for (bar = m->bar; bar; bar = bar->next) {
bar->bx = m->wx + x_pad;
bar->bw = m->ww - 2 * x_pad;
- bar->bh = bh + bar->borderpx * 2;
}
for (bar = m->bar; bar; bar = bar->next)
if (!m->showbar || !bar->showbar)
- bar->by = -bh - bar->borderpx * 2 - y_pad;
+ bar->by = -bar->bh - y_pad;
if (!m->showbar)
return;
for (bar = m->bar; bar; bar = bar->next) {
if (!bar->showbar)
continue;
if (bar->topbar)
- m->wy = m->wy + bh + bar->borderpx * 2 + y_pad;
- m->wh -= y_pad + bh + bar->borderpx * 2;
+ m->wy = m->wy + bar->bh + y_pad;
+ m->wh -= y_pad + bar->bh;
}
for (bar = m->bar; bar; bar = bar->next)
- bar->by = (bar->topbar ? m->wy - bh - bar->borderpx * 2 : m->wy + m->wh);
+ bar->by = (bar->topbar ? m->wy - bar->bh : m->wy + m->wh);
}
void
diff --git a/patch/bar_anybar.c b/patch/bar_anybar.c
index cc4b714..05b2513 100644
--- a/patch/bar_anybar.c
+++ b/patch/bar_anybar.c
@@ -2,17 +2,32 @@ void
managealtbar(Window win, XWindowAttributes *wa)
{
Monitor *m;
+ Bar *bar;
+ int i;
if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
return;
-
- m->bar->win = win;
- m->bar->by = wa->y;
- bh = m->bar->bh = wa->height;
+ for (i = 0, bar = m->bar; bar && bar->win && bar->next; bar = bar->next, ++i); // find last bar
+ if (!bar) {
+ bar = m->bar = ecalloc(1, sizeof(Bar));
+ bar->topbar = topbar;
+ } else if (bar && bar->win) {
+ bar->next = ecalloc(1, sizeof(Bar));
+ bar->next->topbar = !bar->topbar;
+ bar = bar->next;
+ }
+ bar->external = 1;
+ bar->showbar = 1;
+ bar->mon = m;
+ bar->idx = i;
+ bar->borderpx = 0;
+ bar->win = win;
+ bar->bh = wa->height;
updatebarpos(m);
arrange(m);
XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
- XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
XMapWindow(dpy, win);
+ XMoveResizeWindow(dpy, bar->win, bar->bx, -bar->by, wa->width, bar->bh);
+ arrange(selmon);
XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &win, 1);
}
@@ -27,16 +42,21 @@ spawnbar()
void
unmanagealtbar(Window w)
{
- Monitor *m = wintomon(w);
+ Monitor *m = wintomon(w);
+ Bar *bar;
- if (!m)
- return;
+ if (!m)
+ return;
- m->bar->win = 0;
- m->bar->by = 0;
- m->bar->bh = 0;
- updatebarpos(m);
- arrange(m);
+ for (bar = m->bar; bar && bar->win; bar = bar->next)
+ if (bar->win == w) {
+ bar->win = 0;
+ bar->by = 0;
+ bar->bh = 0;
+ break;
+ }
+ updatebarpos(m);
+ arrange(m);
}
int
diff --git a/patches.def.h b/patches.def.h
index e82d9e6..dac0450 100644
--- a/patches.def.h
+++ b/patches.def.h
@@ -188,8 +188,8 @@
* dwm treats the external bar as it would its own, so all regular dwm commands such as
* togglebar affect the external bar in the same way.
*
- * There is currently no support for anybar + regular dwm bar(s), so if this is to be
- * enabled the recommendation is to disable all bar modules and have { 0 } in the barrules.
+ * NB: Unless you want both anybar + dwm bar(s) then the recommendation is to disable all
+ * bar modules and have { 0 } in the barrules.
*
* https://dwm.suckless.org/patches/anybar/
*/