dwm/patch/bar_wintitle.c

89 lines
2.3 KiB
C
Raw Normal View History

int
width_wintitle(Bar *bar, BarArg *a)
{
return a->w;
}
int
draw_wintitle(Bar *bar, BarArg *a)
{
#if BAR_TITLE_LEFT_PAD_PATCH && BAR_TITLE_RIGHT_PAD_PATCH
2020-07-18 13:03:30 +02:00
int x = a->x + lrpad / 2, w = a->w - lrpad;
#elif BAR_TITLE_LEFT_PAD_PATCH
2020-07-18 13:03:30 +02:00
int x = a->x + lrpad / 2, w = a->w - lrpad / 2;
#elif BAR_TITLE_RIGHT_PAD_PATCH
2020-07-18 13:03:30 +02:00
int x = a->x, w = a->w - lrpad / 2;
#else
int x = a->x, w = a->w;
#endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH
2020-07-18 13:03:30 +02:00
Monitor *m = bar->mon;
2021-07-27 13:40:53 +02:00
Client *c = m->sel;
2021-07-27 13:40:53 +02:00
if (!c) {
drw_setscheme(drw, scheme[SchemeTitleNorm]);
drw_rect(drw, x, a->y, w, a->h, 1, 1);
return 0;
}
int tpad = lrpad / 2;
#if BAR_WINICON_PATCH
int ipad = c->icon ? c->icw + ICONSPACING : 0;
#endif // BAR_WINICON_PATCH
#if BAR_CENTEREDWINDOWNAME_PATCH
int cpad = 0;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
int tx = x;
int tw = 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 (w <= TEXTW("A") - lrpad + tpad) // reduce text padding if wintitle is too small
tpad = (w - TEXTW("A") + lrpad < 0 ? 0 : (w - TEXTW("A") + lrpad) / 2);
#if BAR_WINICON_PATCH && BAR_CENTEREDWINDOWNAME_PATCH
else if (TEXTW(c->name) + ipad < w)
cpad = (w - TEXTW(c->name) - ipad) / 2;
#elif BAR_CENTEREDWINDOWNAME_PATCH
else if (TEXTW(c->name) < w)
cpad = (w - TEXTW(c->name)) / 2;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, a->y, w, a->h);
#if BAR_CENTEREDWINDOWNAME_PATCH
/* Apply center padding, if any */
tx += cpad;
tw -= cpad;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
2021-07-27 13:40:53 +02:00
tx += tpad;
tw -= lrpad;
2021-07-27 13:40:53 +02:00
#if BAR_WINICON_PATCH
if (ipad) {
drw_pic(drw, tx, a->y + (a->h - c->ich) / 2, c->icw, c->ich, c->icon);
tx += ipad;
tw -= ipad;
}
2021-07-27 13:40:53 +02:00
#endif // BAR_WINICON_PATCH
drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
#if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
XSync(dpy, False);
XSetErrorHandler(xerror);
#endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
2021-07-27 13:40:53 +02:00
drawstateindicator(m, c, 1, x, a->y, w, a->h, 0, 0, c->isfixed);
return 1;
}
int
click_wintitle(Bar *bar, Arg *arg, BarArg *a)
{
return ClkWinTitle;
}