anybar: adding experimental support for having both anybar + dwm bar(s) in play

This commit is contained in:
bakkeby 2020-09-10 15:24:51 +02:00
parent 8994f375e8
commit d91db5cd65
4 changed files with 59 additions and 43 deletions

View File

@ -15,7 +15,7 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog: ### 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 2020-09-09 - Added the bar border patch

50
dwm.c
View File

@ -259,6 +259,7 @@ struct Bar {
int idx; int idx;
int showbar; int showbar;
int topbar; int topbar;
int external;
int borderpx; int borderpx;
int borderscheme; int borderscheme;
int bx, by, bw, bh; /* bar geometry */ int bx, by, bw, bh; /* bar geometry */
@ -1087,15 +1088,10 @@ cleanupmon(Monitor *mon)
m->next = mon->next; m->next = mon->next;
} }
for (bar = mon->bar; bar; bar = mon->bar) { for (bar = mon->bar; bar; bar = mon->bar) {
#if BAR_ANYBAR_PATCH if (!bar->external) {
if (!usealtbar) {
XUnmapWindow(dpy, bar->win); XUnmapWindow(dpy, bar->win);
XDestroyWindow(dpy, bar->win); XDestroyWindow(dpy, bar->win);
} }
#else
XUnmapWindow(dpy, bar->win);
XDestroyWindow(dpy, bar->win);
#endif // BAR_ANYBAR_PATCH
mon->bar = bar->next; mon->bar = bar->next;
free(bar); free(bar);
} }
@ -1229,7 +1225,6 @@ configurenotify(XEvent *e)
#endif // !FAKEFULLSCREEN_PATCH #endif // !FAKEFULLSCREEN_PATCH
XConfigureEvent *ev = &e->xconfigure; XConfigureEvent *ev = &e->xconfigure;
int dirty; int dirty;
/* TODO: updategeom handling sucks, needs to be simplified */ /* TODO: updategeom handling sucks, needs to be simplified */
if (ev->window == root) { if (ev->window == root) {
dirty = (sw != ev->width || sh != ev->height); dirty = (sw != ev->width || sh != ev->height);
@ -1262,9 +1257,11 @@ configurerequest(XEvent *e)
{ {
Client *c; Client *c;
Monitor *m; Monitor *m;
#if BAR_ANYBAR_PATCH
Bar *bar;
#endif // BAR_ANYBAR_PATCH
XConfigureRequestEvent *ev = &e->xconfigurerequest; XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc; XWindowChanges wc;
if ((c = wintoclient(ev->window))) { if ((c = wintoclient(ev->window))) {
if (ev->value_mask & CWBorderWidth) if (ev->value_mask & CWBorderWidth)
c->bw = ev->border_width; c->bw = ev->border_width;
@ -1316,6 +1313,15 @@ configurerequest(XEvent *e)
} else { } else {
wc.x = ev->x; wc.x = ev->x;
wc.y = ev->y; 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.width = ev->width;
wc.height = ev->height; wc.height = ev->height;
wc.border_width = ev->border_width; wc.border_width = ev->border_width;
@ -1412,11 +1418,13 @@ createmon(void)
m->bar = bar; m->bar = bar;
istopbar = !istopbar; istopbar = !istopbar;
bar->showbar = 1; bar->showbar = 1;
bar->external = 0;
#if BAR_BORDER_PATCH #if BAR_BORDER_PATCH
bar->borderpx = borderpx; bar->borderpx = borderpx;
#else #else
bar->borderpx = 0; bar->borderpx = 0;
#endif // BAR_BORDER_PATCH #endif // BAR_BORDER_PATCH
bar->bh = bh + bar->borderpx * 2;
bar->borderscheme = SchemeNorm; bar->borderscheme = SchemeNorm;
} }
@ -1576,11 +1584,6 @@ dirtomon(int dir)
void void
drawbar(Monitor *m) drawbar(Monitor *m)
{ {
#if BAR_ANYBAR_PATCH
if (usealtbar)
return;
#endif // BAR_ANYBAR_PATCH
Bar *bar; Bar *bar;
for (bar = m->bar; bar; bar = bar->next) for (bar = m->bar; bar; bar = bar->next)
drawbarwin(bar); drawbarwin(bar);
@ -1597,7 +1600,7 @@ drawbars(void)
void void
drawbarwin(Bar *bar) drawbarwin(Bar *bar)
{ {
if (!bar->win) if (!bar->win || bar->external)
return; return;
int r, w, total_drawn = 0; int r, w, total_drawn = 0;
int rx, lx, rw, lw; // bar size, split between left and right if a center module is added 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; bh = drw->fonts->h + 2;
#endif // BAR_HEIGHT_PATCH #endif // BAR_HEIGHT_PATCH
#endif // BAR_STATUSPADDING_PATCH #endif // BAR_STATUSPADDING_PATCH
#if BAR_ANYBAR_PATCH
if (usealtbar)
bh = 0;
#endif // BAR_ANYBAR_PATCH
updategeom(); updategeom();
/* init atoms */ /* init atoms */
utf8string = XInternAtom(dpy, "UTF8_STRING", False); utf8string = XInternAtom(dpy, "UTF8_STRING", False);
@ -3781,10 +3780,6 @@ unmapnotify(XEvent *e)
void void
updatebars(void) updatebars(void)
{ {
#if BAR_ANYBAR_PATCH
if (usealtbar)
return;
#endif // BAR_ANYBAR_PATCH
Bar *bar; Bar *bar;
Monitor *m; Monitor *m;
XSetWindowAttributes wa = { XSetWindowAttributes wa = {
@ -3801,6 +3796,8 @@ updatebars(void)
XClassHint ch = {"dwm", "dwm"}; XClassHint ch = {"dwm", "dwm"};
for (m = mons; m; m = m->next) { for (m = mons; m; m = m->next) {
for (bar = m->bar; bar; bar = bar->next) { for (bar = m->bar; bar; bar = bar->next) {
if (bar->external)
continue;
if (!bar->win) { if (!bar->win) {
#if BAR_ALPHA_PATCH #if BAR_ALPHA_PATCH
bar->win = XCreateWindow(dpy, root, bar->bx, bar->by, bar->bw, bar->bh, 0, depth, 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) { for (bar = m->bar; bar; bar = bar->next) {
bar->bx = m->wx + x_pad; bar->bx = m->wx + x_pad;
bar->bw = m->ww - 2 * x_pad; bar->bw = m->ww - 2 * x_pad;
bar->bh = bh + bar->borderpx * 2;
} }
for (bar = m->bar; bar; bar = bar->next) for (bar = m->bar; bar; bar = bar->next)
if (!m->showbar || !bar->showbar) if (!m->showbar || !bar->showbar)
bar->by = -bh - bar->borderpx * 2 - y_pad; bar->by = -bar->bh - y_pad;
if (!m->showbar) if (!m->showbar)
return; return;
for (bar = m->bar; bar; bar = bar->next) { for (bar = m->bar; bar; bar = bar->next) {
if (!bar->showbar) if (!bar->showbar)
continue; continue;
if (bar->topbar) if (bar->topbar)
m->wy = m->wy + bh + bar->borderpx * 2 + y_pad; m->wy = m->wy + bar->bh + y_pad;
m->wh -= y_pad + bh + bar->borderpx * 2; m->wh -= y_pad + bar->bh;
} }
for (bar = m->bar; bar; bar = bar->next) 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 void

View File

@ -2,17 +2,32 @@ void
managealtbar(Window win, XWindowAttributes *wa) managealtbar(Window win, XWindowAttributes *wa)
{ {
Monitor *m; Monitor *m;
Bar *bar;
int i;
if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height))) if (!(m = recttomon(wa->x, wa->y, wa->width, wa->height)))
return; return;
for (i = 0, bar = m->bar; bar && bar->win && bar->next; bar = bar->next, ++i); // find last bar
m->bar->win = win; if (!bar) {
m->bar->by = wa->y; bar = m->bar = ecalloc(1, sizeof(Bar));
bh = m->bar->bh = wa->height; 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); updatebarpos(m);
arrange(m); arrange(m);
XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask); XSelectInput(dpy, win, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
XMoveResizeWindow(dpy, win, wa->x, wa->y, wa->width, wa->height);
XMapWindow(dpy, win); 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, XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend,
(unsigned char *) &win, 1); (unsigned char *) &win, 1);
} }
@ -27,16 +42,21 @@ spawnbar()
void void
unmanagealtbar(Window w) unmanagealtbar(Window w)
{ {
Monitor *m = wintomon(w); Monitor *m = wintomon(w);
Bar *bar;
if (!m) if (!m)
return; return;
m->bar->win = 0; for (bar = m->bar; bar && bar->win; bar = bar->next)
m->bar->by = 0; if (bar->win == w) {
m->bar->bh = 0; bar->win = 0;
updatebarpos(m); bar->by = 0;
arrange(m); bar->bh = 0;
break;
}
updatebarpos(m);
arrange(m);
} }
int int

View File

@ -188,8 +188,8 @@
* dwm treats the external bar as it would its own, so all regular dwm commands such as * 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. * 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 * NB: Unless you want both anybar + dwm bar(s) then the recommendation is to disable all
* enabled the recommendation is to disable all bar modules and have { 0 } in the barrules. * bar modules and have { 0 } in the barrules.
* *
* https://dwm.suckless.org/patches/anybar/ * https://dwm.suckless.org/patches/anybar/
*/ */