speedwm-personal/bar/title.c

110 lines
2.4 KiB
C
Raw Normal View History

int
2022-12-03 17:54:18 +01:00
width_title(Bar *bar, BarWidthArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetitle) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
return a->max_width;
}
int
2022-12-03 17:54:18 +01:00
draw_title(Bar *bar, BarDrawArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetitle) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
2022-12-03 17:54:18 +01:00
int n = 0, scm, remainder = 0, tabw, padding;
unsigned int i;
int x = a->x, w = a->w;
Client *c;
2022-12-03 17:54:18 +01:00
for (c = bar->mon->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
if (n > 0) {
if (!selmon->hideunselectedtitle) {
remainder = w % n;
tabw = w / n;
} else {
remainder = w;
tabw = w;
}
2022-12-03 17:54:18 +01:00
for (i = 0, c = bar->mon->clients; c; c = c->next, i++) {
if (!ISVISIBLE(c))
continue;
if (bar->mon->sel == c)
2022-12-03 17:54:18 +01:00
scm = SchemeTitleSel;
else if (HIDDEN(c))
2022-12-03 17:54:18 +01:00
scm = SchemeTitleHidden;
else
2022-12-03 17:54:18 +01:00
scm = SchemeTitleNorm;
if (!colorselectedtitle && !HIDDEN(c))
scm = SchemeTitleNorm;
else if (!colorselectedtitle && HIDDEN(c))
scm = SchemeTitleHidden;
/* hide unselected title */
if (bar->mon->sel != c && selmon->hideunselectedtitle) {
continue;
}
2022-12-03 17:54:18 +01:00
padding = lrpad / 2;
if (TEXTW(c->name) < tabw && titleposition)
padding = (tabw - TEXTW(c->name) + lrpad) / 2;
2023-01-12 15:25:45 +01:00
if (!selmon->hideunselectedtitle) drw_setscheme(drw, scheme[scm]);
2022-12-04 12:45:51 +01:00
#if USEWINICON
if (!selmon->hideicon) {
2023-01-12 15:43:27 +01:00
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, padding + (c->icw + iconspacing), c->name, 0, False);
} else {
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, padding, c->name, 0, False);
}
if (c->icon && !selmon->hideicon)
2022-12-04 12:45:51 +01:00
drw_pic(drw, x + padding, (bh - c->ich) / 2, c->icw, c->ich, c->icon);
#else
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, padding, c->name, 0, False);
2022-12-04 12:45:51 +01:00
#endif
2022-12-03 17:54:18 +01:00
x += tabw + (i < remainder ? 1 : 0);
}
}
2022-12-03 17:54:18 +01:00
return a->x + a->w;
}
int
2022-12-03 17:54:18 +01:00
click_title(Bar *bar, Arg *arg, BarClickArg *a)
{
2022-12-04 22:20:17 +01:00
if (selmon->hidetitle) {
2022-12-04 22:03:42 +01:00
return 0;
2022-12-04 22:20:17 +01:00
}
2022-12-04 22:03:42 +01:00
2022-12-03 17:54:18 +01:00
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;
2022-12-30 15:05:50 +01:00
return clicktitle;
2022-12-03 17:54:18 +01:00
}
return -1;
}