diff --git a/README.md b/README.md index efc7e4c..1c0fc65 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t ### Changelog: +2020-08-22 - Added logic to auto-hide bars if nothing is drawn on them (e.g. for standalone bars that only show certain clients) + 2020-08-21 - Simplification of color configuration; settling on a set of color schemes that is shared between multiple patches (urgentborder, floatborder and titlecolor patches made non-optional) 2020-08-20 - Added experimental flexwintitle patch based on bartabgroups diff --git a/dwm.c b/dwm.c index a6d1ca8..43e1104 100644 --- a/dwm.c +++ b/dwm.c @@ -225,6 +225,7 @@ struct Bar { Monitor *mon; Bar *next; int idx; + int showbar; int topbar; int bx, by, bw, bh; /* bar geometry */ int w[BARRULES]; // width, array length == barrules, then use r index for lookup purposes @@ -1361,6 +1362,7 @@ createmon(void) bar->topbar = istopbar; m->bar = bar; istopbar = !istopbar; + bar->showbar = 1; } #if FLEXTILE_DELUXE_LAYOUT @@ -1523,7 +1525,7 @@ drawbarwin(Bar *bar) if (!bar->win) return; Monitor *mon; - int r, w, mi; + int r, w, mi, total_drawn = 0; int rx, lx, rw, lw; // bar size, split between left and right if a center module is added const BarRule *br; BarWidthArg warg = { 0 }; @@ -1610,9 +1612,22 @@ drawbarwin(Bar *bar) bar->w[r] = w; darg.x = bar->x[r]; darg.w = bar->w[r]; - br->drawfunc(bar, &darg); + total_drawn += br->drawfunc(bar, &darg); } - drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh); + if (total_drawn == 0 && bar->showbar) { + bar->showbar = 0; + updatebarpos(bar->mon); + XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); + arrange(bar->mon); + } + else if (total_drawn > 0 && !bar->showbar) { + bar->showbar = 1; + updatebarpos(bar->mon); + XMoveResizeWindow(dpy, bar->win, bar->bx, bar->by, bar->bw, bar->bh); + drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh); + arrange(bar->mon); + } else + drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh); } #if !FOCUSONCLICK_PATCH @@ -3611,15 +3626,19 @@ updatebarpos(Monitor *m) bar->bh = bh; } - if (!m->showbar) { - for (bar = m->bar; bar; bar = bar->next) + for (bar = m->bar; bar; bar = bar->next) + if (!m->showbar || !bar->showbar) bar->by = -bh - y_pad; + if (!m->showbar) return; - } - for (num_bars = 0, bar = m->bar; bar; bar = bar->next, num_bars++) + for (num_bars = 0, bar = m->bar; bar; bar = bar->next) { + if (!bar->showbar) + continue; if (bar->topbar) m->wy = m->wy + bh + y_pad; + num_bars++; + } m->wh = m->wh - y_pad * num_bars - bh * num_bars; for (bar = m->bar; bar; bar = bar->next) diff --git a/patch/bar_awesomebar.c b/patch/bar_awesomebar.c index 613e8d9..750c99a 100644 --- a/patch/bar_awesomebar.c +++ b/patch/bar_awesomebar.c @@ -46,7 +46,7 @@ draw_awesomebar(Bar *bar, BarDrawArg *a) x += tabw + (i < remainder ? 1 : 0); } } - return a->x + a->w; + return n; } int diff --git a/patch/bar_fancybar.c b/patch/bar_fancybar.c index b32181d..0ddf7ed 100644 --- a/patch/bar_fancybar.c +++ b/patch/bar_fancybar.c @@ -65,7 +65,7 @@ draw_fancybar(Bar *bar, BarDrawArg *a) w -= ftw; } } - return x + w; + return n; } int diff --git a/patch/bar_flexwintitle.c b/patch/bar_flexwintitle.c index 603af8f..cb43048 100644 --- a/patch/bar_flexwintitle.c +++ b/patch/bar_flexwintitle.c @@ -44,8 +44,7 @@ int draw_flexwintitle(Bar *bar, BarDrawArg *a) { drw_rect(drw, a->x, 0, a->w, bh, 1, 1); - flextitlecalculate(bar->mon, a->x, a->w, -1, flextitledraw, NULL); - return a->x + a->w; + return flextitlecalculate(bar->mon, a->x, a->w, -1, flextitledraw, NULL); } int @@ -244,7 +243,7 @@ flextitleclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg * arg->v = c; } -void +int flextitlecalculate( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg @@ -310,7 +309,7 @@ flextitlecalculate( n = clientsnmaster + clientsnstack + clientsnstack2 + clientsnfloating + clientsnhidden; if (n == 0) - return; + return 0; #if FLEXTILE_DELUXE_LAYOUT else if (m->lt[m->sellt]->arrange == &flextile) { int layout = m->ltaxis[LAYOUT]; @@ -448,4 +447,5 @@ flextitlecalculate( rr -= clientsnhidden; c = flextitledrawarea(m, m->clients, flt_x, rr, w * FLEXWINTITLE_FLOATWEIGHT + rw, clientsnfloating, SCHEMEFOR(GRP_FLOAT), 0, 0, 1, passx, tabfn, arg); // floating } + return 1; } \ No newline at end of file diff --git a/patch/bar_flexwintitle.h b/patch/bar_flexwintitle.h index 56647c6..be7b675 100644 --- a/patch/bar_flexwintitle.h +++ b/patch/bar_flexwintitle.h @@ -4,7 +4,7 @@ static int click_flexwintitle(Bar *bar, Arg *arg, BarClickArg *a); static void flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg); static void flextitleclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg); -static void flextitlecalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg); +static int flextitlecalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg); static int getschemefor(Monitor *m, int group, int activegroup); static int getselschemefor(int scheme); static Client *flextitledrawarea(Monitor *m, Client *c, int x, int r, int w, int max_clients, int tabscheme, int draw_tiled, int draw_hidden, int draw_floating, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg); \ No newline at end of file diff --git a/patch/bar_powerline_tags.c b/patch/bar_powerline_tags.c index 20f9227..b5cf390 100644 --- a/patch/bar_powerline_tags.c +++ b/patch/bar_powerline_tags.c @@ -90,7 +90,7 @@ draw_pwrl_tags(Bar *bar, BarDrawArg *a) #else drw_arrow(drw, x, 0, plw, bh, 1, 0); #endif // BAR_POWERLINE_TAGS_SLASH_PATCH - return a->x + a->w; + return 1; } int diff --git a/patch/bar_status2d.c b/patch/bar_status2d.c index d4a1e06..744fa18 100644 --- a/patch/bar_status2d.c +++ b/patch/bar_status2d.c @@ -164,7 +164,7 @@ drawstatusbar(int x, char* stext) free(p); drw_setscheme(drw, scheme[SchemeNorm]); - return x; + return i; } int diff --git a/patch/bar_systray.c b/patch/bar_systray.c index 0ff730d..dc267fb 100644 --- a/patch/bar_systray.c +++ b/patch/bar_systray.c @@ -17,7 +17,7 @@ int draw_systray(Bar *bar, BarDrawArg *a) { if (!showsystray) - return a->x; + return 0; XSetWindowAttributes wa; Client *i; @@ -61,7 +61,7 @@ draw_systray(Bar *bar, BarDrawArg *a) fprintf(stderr, "dwm: unable to obtain system tray.\n"); free(systray); systray = NULL; - return a->x; + return 0; } } @@ -86,7 +86,7 @@ draw_systray(Bar *bar, BarDrawArg *a) } XMoveResizeWindow(dpy, systray->win, bar->bx + a->x + lrpad / 2, (w ? bar->by : -bar->by), MAX(w, 1), bar->bh); - return a->x + a->w; + return w; } int diff --git a/patch/bar_tabgroups.c b/patch/bar_tabgroups.c index 7036882..b4b2b0a 100644 --- a/patch/bar_tabgroups.c +++ b/patch/bar_tabgroups.c @@ -34,8 +34,7 @@ int draw_bartabgroups(Bar *bar, BarDrawArg *a) { drw_rect(drw, a->x, 0, a->w, bh, 1, 1); - bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL); - return a->x + a->w; + return bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL); } int @@ -105,7 +104,7 @@ bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg arg->v = c; } -void +int bartabcalculate( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg @@ -143,7 +142,7 @@ bartabcalculate( } if (clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden == 0) - return; + return 0; tgactive = 1; num = tabw; @@ -230,4 +229,5 @@ bartabcalculate( } #endif // BARTAB_FLOATWEIGHT } + return 1; } \ No newline at end of file diff --git a/patch/bar_tabgroups.h b/patch/bar_tabgroups.h index 15f6876..113701f 100644 --- a/patch/bar_tabgroups.h +++ b/patch/bar_tabgroups.h @@ -4,4 +4,4 @@ static int click_bartabgroups(Bar *bar, Arg *arg, BarClickArg *a); static void bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg); static void bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg); -static void bartabcalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg); \ No newline at end of file +static int bartabcalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg); \ No newline at end of file diff --git a/patch/bar_taggrid.c b/patch/bar_taggrid.c index ebd07c1..0bdf105 100644 --- a/patch/bar_taggrid.c +++ b/patch/bar_taggrid.c @@ -53,7 +53,7 @@ draw_taggrid(Bar *bar, BarDrawArg *a) } y += h; } - return max_x; + return 1; } int diff --git a/patch/bar_tags.c b/patch/bar_tags.c index f122602..0a7e628 100644 --- a/patch/bar_tags.c +++ b/patch/bar_tags.c @@ -92,7 +92,7 @@ draw_tags(Bar *bar, BarDrawArg *a) x += w; } - return x; + return 1; } int diff --git a/patch/bar_wintitle.c b/patch/bar_wintitle.c index ca30138..7f28fd3 100644 --- a/patch/bar_wintitle.c +++ b/patch/bar_wintitle.c @@ -23,42 +23,43 @@ draw_wintitle(Bar *bar, BarDrawArg *a) #endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH Monitor *m = bar->mon; - if (m->sel) { - drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); - #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH - XSetErrorHandler(xerrordummy); - #endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH - #if BAR_CENTEREDWINDOWNAME_PATCH - int mid = (m->ww - TEXTW(m->sel->name)) / 2 - x; - #if BAR_PANGO_PATCH - drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0, False); - #else - drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0); - #endif // BAR_PANGO_PATCH - #else - #if BAR_PANGO_PATCH - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False); - #else - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); - #endif // BAR_PANGO_PATCH - #endif // BAR_CENTEREDWINDOWNAME_PATCH - #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH - XSync(dpy, False); - XSetErrorHandler(xerror); - #endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH - if (m->sel->isfloating) - #if BAR_ACTIVETAGINDICATORBAR_PATCH - drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, m->sel->isfixed, 0); - #elif BAR_ACTIVETAGINDICATORBAR_ALT1_PATCH - drw_rect(drw, x + boxw, bh - boxw/2, w - ( 2 * boxw + 1), boxw/2, 0); - #else - drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); - #endif // BAR_ACTIVETAGINDICATORBAR_PATCH - } else { + if (!m->sel) { drw_setscheme(drw, scheme[SchemeTitleNorm]); drw_rect(drw, x, 0, w, bh, 1, 1); + return 0; } - return x + w; + + drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); + #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH + XSetErrorHandler(xerrordummy); + #endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH + #if BAR_CENTEREDWINDOWNAME_PATCH + int mid = (m->ww - TEXTW(m->sel->name)) / 2 - x; + #if BAR_PANGO_PATCH + drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0, False); + #else + drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0); + #endif // BAR_PANGO_PATCH + #else + #if BAR_PANGO_PATCH + drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False); + #else + drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); + #endif // BAR_PANGO_PATCH + #endif // BAR_CENTEREDWINDOWNAME_PATCH + #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH + XSync(dpy, False); + XSetErrorHandler(xerror); + #endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH + if (m->sel->isfloating) + #if BAR_ACTIVETAGINDICATORBAR_PATCH + drw_rect(drw, x + boxw, 0, w - ( 2 * boxw + 1), boxw, m->sel->isfixed, 0); + #elif BAR_ACTIVETAGINDICATORBAR_ALT1_PATCH + drw_rect(drw, x + boxw, bh - boxw/2, w - ( 2 * boxw + 1), boxw/2, 0); + #else + drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); + #endif // BAR_ACTIVETAGINDICATORBAR_PATCH + return 1; } int diff --git a/patch/bar_wintitle_floating.c b/patch/bar_wintitle_floating.c index 3fea3c2..e4aea1d 100644 --- a/patch/bar_wintitle_floating.c +++ b/patch/bar_wintitle_floating.c @@ -8,8 +8,7 @@ int draw_wintitle_floating(Bar *bar, BarDrawArg *a) { drw_rect(drw, a->x, 0, a->w, bh, 1, 1); - calc_wintitle_floating(bar->mon, a->x, a->w, -1, flextitledraw, NULL); - return a->x + a->w; + return calc_wintitle_floating(bar->mon, a->x, a->w, -1, flextitledraw, NULL);; } int @@ -19,7 +18,7 @@ click_wintitle_floating(Bar *bar, Arg *arg, BarClickArg *a) return ClkWinTitle; } -void +int calc_wintitle_floating( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg @@ -36,9 +35,10 @@ calc_wintitle_floating( } if (!clientsnfloating) - return; + return 0; w = tabw / clientsnfloating; r = tabw % clientsnfloating; c = flextitledrawarea(m, m->clients, offx, r, w, clientsnfloating, SCHEMEFOR(GRP_FLOAT), 0, 0, 1, passx, tabfn, arg); + return 1; } \ No newline at end of file diff --git a/patch/bar_wintitle_floating.h b/patch/bar_wintitle_floating.h index 3e6164a..7c6a5c1 100644 --- a/patch/bar_wintitle_floating.h +++ b/patch/bar_wintitle_floating.h @@ -1,7 +1,7 @@ static int width_wintitle_floating(Bar *bar, BarWidthArg *a); static int draw_wintitle_floating(Bar *bar, BarDrawArg *a); static int click_wintitle_floating(Bar *bar, Arg *arg, BarClickArg *a); -static void calc_wintitle_floating( +static int calc_wintitle_floating( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg ); \ No newline at end of file diff --git a/patch/bar_wintitle_hidden.c b/patch/bar_wintitle_hidden.c index 729f6aa..95e8378 100644 --- a/patch/bar_wintitle_hidden.c +++ b/patch/bar_wintitle_hidden.c @@ -8,8 +8,7 @@ int draw_wintitle_hidden(Bar *bar, BarDrawArg *a) { drw_rect(drw, a->x, 0, a->w, bh, 1, 1); - calc_wintitle_hidden(bar->mon, a->x, a->w, -1, flextitledraw, NULL); - return a->x + a->w; + return calc_wintitle_hidden(bar->mon, a->x, a->w, -1, flextitledraw, NULL);; } int @@ -19,7 +18,7 @@ click_wintitle_hidden(Bar *bar, Arg *arg, BarClickArg *a) return ClkWinTitle; } -void +int calc_wintitle_hidden( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg @@ -36,9 +35,10 @@ calc_wintitle_hidden( } if (!clientsnhidden) - return; + return 0; w = tabw / clientsnhidden; r = tabw % clientsnhidden; c = flextitledrawarea(m, m->clients, offx, r, w, clientsnhidden, SCHEMEFOR(GRP_HIDDEN), 0, 1, 0, passx, tabfn, arg); + return 1; } \ No newline at end of file diff --git a/patch/bar_wintitle_hidden.h b/patch/bar_wintitle_hidden.h index 2382e91..aaa1be7 100644 --- a/patch/bar_wintitle_hidden.h +++ b/patch/bar_wintitle_hidden.h @@ -1,7 +1,7 @@ static int width_wintitle_hidden(Bar *bar, BarWidthArg *a); static int draw_wintitle_hidden(Bar *bar, BarDrawArg *a); static int click_wintitle_hidden(Bar *bar, Arg *arg, BarClickArg *a); -static void calc_wintitle_hidden( +static int calc_wintitle_hidden( Monitor *m, int offx, int tabw, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg ); \ No newline at end of file