Added logic to auto-hide bars if nothing is drawn on them (e.g. for standalone bars that only show certain clients)

This commit is contained in:
bakkeby 2020-08-22 08:43:07 +02:00
parent 81488b4862
commit 110cc7d240
18 changed files with 91 additions and 69 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog: ### 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-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 2020-08-20 - Added experimental flexwintitle patch based on bartabgroups

29
dwm.c
View File

@ -225,6 +225,7 @@ struct Bar {
Monitor *mon; Monitor *mon;
Bar *next; Bar *next;
int idx; int idx;
int showbar;
int topbar; int topbar;
int bx, by, bw, bh; /* bar geometry */ int bx, by, bw, bh; /* bar geometry */
int w[BARRULES]; // width, array length == barrules, then use r index for lookup purposes int w[BARRULES]; // width, array length == barrules, then use r index for lookup purposes
@ -1361,6 +1362,7 @@ createmon(void)
bar->topbar = istopbar; bar->topbar = istopbar;
m->bar = bar; m->bar = bar;
istopbar = !istopbar; istopbar = !istopbar;
bar->showbar = 1;
} }
#if FLEXTILE_DELUXE_LAYOUT #if FLEXTILE_DELUXE_LAYOUT
@ -1523,7 +1525,7 @@ drawbarwin(Bar *bar)
if (!bar->win) if (!bar->win)
return; return;
Monitor *mon; 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 int rx, lx, rw, lw; // bar size, split between left and right if a center module is added
const BarRule *br; const BarRule *br;
BarWidthArg warg = { 0 }; BarWidthArg warg = { 0 };
@ -1610,8 +1612,21 @@ drawbarwin(Bar *bar)
bar->w[r] = w; bar->w[r] = w;
darg.x = bar->x[r]; darg.x = bar->x[r];
darg.w = bar->w[r]; darg.w = bar->w[r];
br->drawfunc(bar, &darg); total_drawn += br->drawfunc(bar, &darg);
} }
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); drw_map(drw, bar->win, 0, 0, bar->bw, bar->bh);
} }
@ -3611,15 +3626,19 @@ updatebarpos(Monitor *m)
bar->bh = bh; 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; bar->by = -bh - y_pad;
if (!m->showbar)
return; 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) if (bar->topbar)
m->wy = m->wy + bh + y_pad; m->wy = m->wy + bh + y_pad;
num_bars++;
}
m->wh = m->wh - y_pad * num_bars - bh * num_bars; m->wh = m->wh - y_pad * num_bars - bh * num_bars;
for (bar = m->bar; bar; bar = bar->next) for (bar = m->bar; bar; bar = bar->next)

View File

@ -46,7 +46,7 @@ draw_awesomebar(Bar *bar, BarDrawArg *a)
x += tabw + (i < remainder ? 1 : 0); x += tabw + (i < remainder ? 1 : 0);
} }
} }
return a->x + a->w; return n;
} }
int int

View File

@ -65,7 +65,7 @@ draw_fancybar(Bar *bar, BarDrawArg *a)
w -= ftw; w -= ftw;
} }
} }
return x + w; return n;
} }
int int

View File

@ -44,8 +44,7 @@ int
draw_flexwintitle(Bar *bar, BarDrawArg *a) draw_flexwintitle(Bar *bar, BarDrawArg *a)
{ {
drw_rect(drw, a->x, 0, a->w, bh, 1, 1); drw_rect(drw, a->x, 0, a->w, bh, 1, 1);
flextitlecalculate(bar->mon, a->x, a->w, -1, flextitledraw, NULL); return flextitlecalculate(bar->mon, a->x, a->w, -1, flextitledraw, NULL);
return a->x + a->w;
} }
int int
@ -244,7 +243,7 @@ flextitleclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *
arg->v = c; arg->v = c;
} }
void int
flextitlecalculate( flextitlecalculate(
Monitor *m, int offx, int tabw, int passx, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
@ -310,7 +309,7 @@ flextitlecalculate(
n = clientsnmaster + clientsnstack + clientsnstack2 + clientsnfloating + clientsnhidden; n = clientsnmaster + clientsnstack + clientsnstack2 + clientsnfloating + clientsnhidden;
if (n == 0) if (n == 0)
return; return 0;
#if FLEXTILE_DELUXE_LAYOUT #if FLEXTILE_DELUXE_LAYOUT
else if (m->lt[m->sellt]->arrange == &flextile) { else if (m->lt[m->sellt]->arrange == &flextile) {
int layout = m->ltaxis[LAYOUT]; int layout = m->ltaxis[LAYOUT];
@ -448,4 +447,5 @@ flextitlecalculate(
rr -= clientsnhidden; 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 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;
} }

View File

@ -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 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 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 getschemefor(Monitor *m, int group, int activegroup);
static int getselschemefor(int scheme); 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); 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);

View File

@ -90,7 +90,7 @@ draw_pwrl_tags(Bar *bar, BarDrawArg *a)
#else #else
drw_arrow(drw, x, 0, plw, bh, 1, 0); drw_arrow(drw, x, 0, plw, bh, 1, 0);
#endif // BAR_POWERLINE_TAGS_SLASH_PATCH #endif // BAR_POWERLINE_TAGS_SLASH_PATCH
return a->x + a->w; return 1;
} }
int int

View File

@ -164,7 +164,7 @@ drawstatusbar(int x, char* stext)
free(p); free(p);
drw_setscheme(drw, scheme[SchemeNorm]); drw_setscheme(drw, scheme[SchemeNorm]);
return x; return i;
} }
int int

View File

@ -17,7 +17,7 @@ int
draw_systray(Bar *bar, BarDrawArg *a) draw_systray(Bar *bar, BarDrawArg *a)
{ {
if (!showsystray) if (!showsystray)
return a->x; return 0;
XSetWindowAttributes wa; XSetWindowAttributes wa;
Client *i; Client *i;
@ -61,7 +61,7 @@ draw_systray(Bar *bar, BarDrawArg *a)
fprintf(stderr, "dwm: unable to obtain system tray.\n"); fprintf(stderr, "dwm: unable to obtain system tray.\n");
free(systray); free(systray);
systray = NULL; 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); 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 int

View File

@ -34,8 +34,7 @@ int
draw_bartabgroups(Bar *bar, BarDrawArg *a) draw_bartabgroups(Bar *bar, BarDrawArg *a)
{ {
drw_rect(drw, a->x, 0, a->w, bh, 1, 1); drw_rect(drw, a->x, 0, a->w, bh, 1, 1);
bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL); return bartabcalculate(bar->mon, a->x, a->w, -1, bartabdraw, NULL);
return a->x + a->w;
} }
int int
@ -105,7 +104,7 @@ bartabclick(Monitor *m, Client *c, int passx, int x, int w, int unused, Arg *arg
arg->v = c; arg->v = c;
} }
void int
bartabcalculate( bartabcalculate(
Monitor *m, int offx, int tabw, int passx, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
@ -143,7 +142,7 @@ bartabcalculate(
} }
if (clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden == 0) if (clientsnmaster + clientsnstack + clientsnfloating + clientsnhidden == 0)
return; return 0;
tgactive = 1; tgactive = 1;
num = tabw; num = tabw;
@ -230,4 +229,5 @@ bartabcalculate(
} }
#endif // BARTAB_FLOATWEIGHT #endif // BARTAB_FLOATWEIGHT
} }
return 1;
} }

View File

@ -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 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 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); static int bartabcalculate(Monitor *m, int offx, int w, int passx, void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg);

View File

@ -53,7 +53,7 @@ draw_taggrid(Bar *bar, BarDrawArg *a)
} }
y += h; y += h;
} }
return max_x; return 1;
} }
int int

View File

@ -92,7 +92,7 @@ draw_tags(Bar *bar, BarDrawArg *a)
x += w; x += w;
} }
return x; return 1;
} }
int int

View File

@ -23,7 +23,12 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
#endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH #endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH
Monitor *m = bar->mon; Monitor *m = bar->mon;
if (m->sel) { if (!m->sel) {
drw_setscheme(drw, scheme[SchemeTitleNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1);
return 0;
}
drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]); drw_setscheme(drw, scheme[m == selmon ? SchemeTitleSel : SchemeTitleNorm]);
#if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
XSetErrorHandler(xerrordummy); XSetErrorHandler(xerrordummy);
@ -54,11 +59,7 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
#else #else
drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0);
#endif // BAR_ACTIVETAGINDICATORBAR_PATCH #endif // BAR_ACTIVETAGINDICATORBAR_PATCH
} else { return 1;
drw_setscheme(drw, scheme[SchemeTitleNorm]);
drw_rect(drw, x, 0, w, bh, 1, 1);
}
return x + w;
} }
int int

View File

@ -8,8 +8,7 @@ int
draw_wintitle_floating(Bar *bar, BarDrawArg *a) draw_wintitle_floating(Bar *bar, BarDrawArg *a)
{ {
drw_rect(drw, a->x, 0, a->w, bh, 1, 1); drw_rect(drw, a->x, 0, a->w, bh, 1, 1);
calc_wintitle_floating(bar->mon, a->x, a->w, -1, flextitledraw, NULL); return calc_wintitle_floating(bar->mon, a->x, a->w, -1, flextitledraw, NULL);;
return a->x + a->w;
} }
int int
@ -19,7 +18,7 @@ click_wintitle_floating(Bar *bar, Arg *arg, BarClickArg *a)
return ClkWinTitle; return ClkWinTitle;
} }
void int
calc_wintitle_floating( calc_wintitle_floating(
Monitor *m, int offx, int tabw, int passx, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
@ -36,9 +35,10 @@ calc_wintitle_floating(
} }
if (!clientsnfloating) if (!clientsnfloating)
return; return 0;
w = tabw / clientsnfloating; w = tabw / clientsnfloating;
r = tabw % clientsnfloating; r = tabw % clientsnfloating;
c = flextitledrawarea(m, m->clients, offx, r, w, clientsnfloating, SCHEMEFOR(GRP_FLOAT), 0, 0, 1, passx, tabfn, arg); c = flextitledrawarea(m, m->clients, offx, r, w, clientsnfloating, SCHEMEFOR(GRP_FLOAT), 0, 0, 1, passx, tabfn, arg);
return 1;
} }

View File

@ -1,7 +1,7 @@
static int width_wintitle_floating(Bar *bar, BarWidthArg *a); static int width_wintitle_floating(Bar *bar, BarWidthArg *a);
static int draw_wintitle_floating(Bar *bar, BarDrawArg *a); static int draw_wintitle_floating(Bar *bar, BarDrawArg *a);
static int click_wintitle_floating(Bar *bar, Arg *arg, BarClickArg *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, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
); );

View File

@ -8,8 +8,7 @@ int
draw_wintitle_hidden(Bar *bar, BarDrawArg *a) draw_wintitle_hidden(Bar *bar, BarDrawArg *a)
{ {
drw_rect(drw, a->x, 0, a->w, bh, 1, 1); drw_rect(drw, a->x, 0, a->w, bh, 1, 1);
calc_wintitle_hidden(bar->mon, a->x, a->w, -1, flextitledraw, NULL); return calc_wintitle_hidden(bar->mon, a->x, a->w, -1, flextitledraw, NULL);;
return a->x + a->w;
} }
int int
@ -19,7 +18,7 @@ click_wintitle_hidden(Bar *bar, Arg *arg, BarClickArg *a)
return ClkWinTitle; return ClkWinTitle;
} }
void int
calc_wintitle_hidden( calc_wintitle_hidden(
Monitor *m, int offx, int tabw, int passx, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
@ -36,9 +35,10 @@ calc_wintitle_hidden(
} }
if (!clientsnhidden) if (!clientsnhidden)
return; return 0;
w = tabw / clientsnhidden; w = tabw / clientsnhidden;
r = tabw % clientsnhidden; r = tabw % clientsnhidden;
c = flextitledrawarea(m, m->clients, offx, r, w, clientsnhidden, SCHEMEFOR(GRP_HIDDEN), 0, 1, 0, passx, tabfn, arg); c = flextitledrawarea(m, m->clients, offx, r, w, clientsnhidden, SCHEMEFOR(GRP_HIDDEN), 0, 1, 0, passx, tabfn, arg);
return 1;
} }

View File

@ -1,7 +1,7 @@
static int width_wintitle_hidden(Bar *bar, BarWidthArg *a); static int width_wintitle_hidden(Bar *bar, BarWidthArg *a);
static int draw_wintitle_hidden(Bar *bar, BarDrawArg *a); static int draw_wintitle_hidden(Bar *bar, BarDrawArg *a);
static int click_wintitle_hidden(Bar *bar, Arg *arg, BarClickArg *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, Monitor *m, int offx, int tabw, int passx,
void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg void(*tabfn)(Monitor *, Client *, int, int, int, int, Arg *arg), Arg *arg
); );