speedwm-personal/bar/title.c
2022-12-04 12:45:51 +01:00

77 lines
1.7 KiB
C

int
width_title(Bar *bar, BarWidthArg *a)
{
return a->max_width;
}
int
draw_title(Bar *bar, BarDrawArg *a)
{
int n = 0, scm, remainder = 0, tabw, padding;
unsigned int i;
int x = a->x, w = a->w;
Client *c;
for (c = bar->mon->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) {
remainder = w % n;
tabw = w / n;
for (i = 0, c = bar->mon->clients; c; c = c->next, i++) {
if (!ISVISIBLE(c))
continue;
if (bar->mon->sel == c && colorselectedtitle)
scm = SchemeTitleSel;
else if (!colorselectedtitle)
scm = SchemeTitleNorm;
else if (HIDDEN(c))
scm = SchemeTitleHidden;
else
scm = SchemeTitleNorm;
padding = lrpad / 2;
if (TEXTW(c->name) < tabw && titleposition)
padding = (tabw - TEXTW(c->name) + lrpad) / 2;
drw_setscheme(drw, scheme[scm]);
#if USEWINICON
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, padding + (c->name ? c->icw + iconspacing : 0), c->name, 0, False);
if (c->icon)
drw_pic(drw, x + padding, (bh - c->ich) / 2, c->icw, c->ich, c->icon);
#else
drw_text(drw, x, 0, tabw + padding (i < remainder ? 1 : 0), bh, padding, c->name, 0, False);
#endif
x += tabw + (i < remainder ? 1 : 0);
}
}
return a->x + a->w;
}
int
click_title(Bar *bar, Arg *arg, BarClickArg *a)
{
int x = 0, n = 0;
Client *c;
for (c = bar->mon->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
c = bar->mon->clients;
do {
if (!c || !ISVISIBLE(c))
continue;
else
x += (1.0 / (double)n) * a->rel_w;
} while (c && a->rel_x > x && (c = c->next));
if (c) {
arg->v = c;
return ClkWinTitle;
}
return -1;
}