anybar: make sure to free the bar when unmanaging an external bar plus misc improvements ref. #118

This commit is contained in:
bakkeby 2021-04-27 13:31:41 +02:00
parent a7dfcc17d5
commit eb66da79ca
3 changed files with 23 additions and 8 deletions

5
dwm.c
View File

@ -1559,6 +1559,7 @@ createmon(void)
n = MAX(br->bar, n); n = MAX(br->bar, n);
} }
m->bar = NULL;
for (i = 0; i <= n && i < max_bars; i++) { for (i = 0; i <= n && i < max_bars; i++) {
bar = ecalloc(1, sizeof(Bar)); bar = ecalloc(1, sizeof(Bar));
bar->mon = m; bar->mon = m;
@ -2337,7 +2338,7 @@ manage(Window w, XWindowAttributes *wa)
c->y = c->mon->my + c->mon->mh - HEIGHT(c); c->y = c->mon->my + c->mon->mh - HEIGHT(c);
c->x = MAX(c->x, c->mon->mx); c->x = MAX(c->x, c->mon->mx);
/* only fix client y-offset, if the client center might cover the bar */ /* only fix client y-offset, if the client center might cover the bar */
c->y = MAX(c->y, ((c->mon->bar->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx) c->y = MAX(c->y, ((!c->mon->bar || c->mon->bar->by == c->mon->my) && (c->x + (c->w / 2) >= c->mon->wx)
&& (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my); && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww)) ? bh : c->mon->my);
wc.border_width = c->bw; wc.border_width = c->bw;
@ -2988,7 +2989,7 @@ restack(Monitor *m)
return; return;
if (m->sel->isfloating || !m->lt[m->sellt]->arrange) if (m->sel->isfloating || !m->lt[m->sellt]->arrange)
XRaiseWindow(dpy, m->sel->win); XRaiseWindow(dpy, m->sel->win);
if (m->lt[m->sellt]->arrange) { if (m->lt[m->sellt]->arrange && m->bar) {
wc.stack_mode = Below; wc.stack_mode = Below;
wc.sibling = m->bar->win; wc.sibling = m->bar->win;
for (c = m->stack; c; c = c->snext) for (c = m->stack; c; c = c->snext)

View File

@ -12,7 +12,11 @@ managealtbar(Window win, XWindowAttributes *wa)
bar->topbar = topbar; bar->topbar = topbar;
} else if (bar && bar->win) { } else if (bar && bar->win) {
bar->next = ecalloc(1, sizeof(Bar)); bar->next = ecalloc(1, sizeof(Bar));
#if BAR_ANYBAR_STACK_BARS_PATCH
bar->next->topbar = topbar;
#else
bar->next->topbar = !bar->topbar; bar->next->topbar = !bar->topbar;
#endif // BAR_ANYBAR_STACK_BARS_PATCH
bar = bar->next; bar = bar->next;
} }
bar->external = 1; bar->external = 1;
@ -43,18 +47,23 @@ void
unmanagealtbar(Window w) unmanagealtbar(Window w)
{ {
Monitor *m = wintomon(w); Monitor *m = wintomon(w);
Bar *bar; Bar *bar, *next, *prev = NULL;
if (!m) if (!m)
return; return;
for (bar = m->bar; bar && bar->win; bar = bar->next) for (bar = m->bar; bar && bar->win; bar = next) {
next = bar->next;
if (bar->win == w) { if (bar->win == w) {
bar->win = 0; if (prev)
bar->by = 0; prev->next = next;
bar->bh = 0; else
m->bar = next;
free(bar);
break; break;
} }
prev = bar;
}
updatebarpos(m); updatebarpos(m);
arrange(m); arrange(m);
} }

View File

@ -223,12 +223,17 @@
* togglebar affect the external bar in the same way. * togglebar affect the external bar in the same way.
* *
* NB: Unless you want both anybar + dwm bar(s) then the recommendation is to disable all * NB: Unless you want both anybar + dwm bar(s) then the recommendation is to disable all
* bar modules and have { 0 } in the barrules. * bar modules and have { -2 } in the barrules.
* *
* https://dwm.suckless.org/patches/anybar/ * https://dwm.suckless.org/patches/anybar/
*/ */
#define BAR_ANYBAR_PATCH 0 #define BAR_ANYBAR_PATCH 0
/* Anybar option to stack multiple external bars at the top or at the bottom of the monitor
* instead of adding a second bar at the opposite side.
*/
#define BAR_ANYBAR_STACK_BARS_PATCH 0
/* This patch adds a border around the status bar(s) just like the border of client windows. /* This patch adds a border around the status bar(s) just like the border of client windows.
* https://codemadness.org/paste/dwm-border-bar.patch * https://codemadness.org/paste/dwm-border-bar.patch
*/ */