From a947f8d667ef15c3833357a0ad034f54bcdafb12 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Fri, 6 Nov 2020 19:46:42 +0100 Subject: [PATCH] systray: avoid dwm crashing when removing the monitor where the systray is running (fix ref. #70) --- dwm.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dwm.c b/dwm.c index d7087f1..5d6df39 100644 --- a/dwm.c +++ b/dwm.c @@ -1133,8 +1133,10 @@ cleanupmon(Monitor *mon) XDestroyWindow(dpy, bar->win); } mon->bar = bar->next; + #if BAR_SYSTRAY_PATCH if (systray && bar == systray->bar) systray->bar = NULL; + #endif // BAR_SYSTRAY_PATCH free(bar); } free(mon); @@ -1645,7 +1647,9 @@ drawbarwin(Bar *bar) int r, w, total_drawn = 0; int rx, lx, rw, lw; // bar size, split between left and right if a center module is added const BarRule *br; + #if BAR_SYSTRAY_PATCH Monitor *lastmon; + #endif // BAR_SYSTRAY_PATCH if (bar->borderpx) { XSetForeground(drw->dpy, drw->gc, scheme[bar->borderscheme][ColBorder].pixel); @@ -1659,7 +1663,9 @@ drawbarwin(Bar *bar) rw = lw = bar->bw - 2 * bar->borderpx; rx = lx = bar->borderpx; + #if BAR_SYSTRAY_PATCH for (lastmon = mons; lastmon && lastmon->next; lastmon = lastmon->next); + #endif // BAR_SYSTRAY_PATCH drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, lx, bar->borderpx, lw, bar->bh - 2 * bar->borderpx, 1, 1); @@ -1667,8 +1673,11 @@ drawbarwin(Bar *bar) br = &barrules[r]; if (br->bar != bar->idx || !br->widthfunc || (br->monitor == 'A' && bar->mon != selmon)) continue; - if (br->monitor != 'A' && br->monitor != -1 && br->monitor != bar->mon->index && - (br->drawfunc != draw_systray || (lastmon->index >= br->monitor && bar->mon->index == 0))) // hack: draw systray on first monitor if the designated one is not available + if (br->monitor != 'A' && br->monitor != -1 && br->monitor != bar->mon->index + #if BAR_SYSTRAY_PATCH + && (br->drawfunc != draw_systray || (lastmon->index >= br->monitor && bar->mon->index == 0)) // hack: draw systray on first monitor if the designated one is not available + #endif // BAR_SYSTRAY_PATCH + ) continue; drw_setscheme(drw, scheme[SchemeNorm]); warg.w = (br->alignment < BAR_ALIGN_RIGHT_LEFT ? lw : rw);