Refactoring window title drawing with regards to icons ref. #216

This commit is contained in:
bakkeby 2022-01-18 11:04:35 +01:00
parent 406faa9cc3
commit 489ac30092
5 changed files with 201 additions and 68 deletions

View File

@ -7,8 +7,14 @@ width_awesomebar(Bar *bar, BarArg *a)
int
draw_awesomebar(Bar *bar, BarArg *a)
{
int n = 0, scm, remainder = 0, tabw, pad;
int n = 0, scm, remainder = 0, tabw, tpad, tx, tw;
unsigned int i;
#if BAR_CENTEREDWINDOWNAME_PATCH
int cpad;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
#if BAR_WINICON_PATCH
int ipad;
#endif // BAR_WINICON_PATCH
#if BAR_TITLE_LEFT_PAD_PATCH && BAR_TITLE_RIGHT_PAD_PATCH
int x = a->x + lrpad / 2, w = a->w - lrpad;
#elif BAR_TITLE_LEFT_PAD_PATCH
@ -39,22 +45,49 @@ draw_awesomebar(Bar *bar, BarArg *a)
else
scm = SchemeTitleNorm;
pad = lrpad / 2;
tpad = lrpad / 2;
#if BAR_CENTEREDWINDOWNAME_PATCH
cpad = 0;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
#if BAR_WINICON_PATCH
ipad = c->icon ? c->icon->width + ICONSPACING : 0;
#endif // BAR_WINICON_PATCH
tx = x;
tw = tabw;
#if BAR_WINICON_PATCH && BAR_CENTEREDWINDOWNAME_PATCH
if (TEXTW(c->name) + ipad < tabw)
cpad = (tabw - TEXTW(c->name) - ipad) / 2;
#elif BAR_CENTEREDWINDOWNAME_PATCH
if (TEXTW(c->name) < tabw)
pad = (tabw - TEXTW(c->name) + lrpad) / 2;
cpad = (tabw - TEXTW(c->name)) / 2;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
drw_setscheme(drw, scheme[scm]);
XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, tx, a->y, tw, a->h);
#if BAR_CENTEREDWINDOWNAME_PATCH
/* Apply center padding, if any */
tx += cpad;
tw -= cpad;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
tx += tpad;
tw -= lrpad;
#if BAR_WINICON_PATCH
drw_text(drw, x, a->y, tabw + (i < remainder ? 1 : 0), a->h, pad + (c->icon ? c->icon->width + ICONSPACING : 0), c->name, 0, False);
if (c->icon)
drw_img(drw, x + pad, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
#else
drw_text(drw, x, a->y, tabw + (i < remainder ? 1 : 0), a->h, pad, c->name, 0, False);
if (ipad) {
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
tx += ipad;
tw -= ipad;
}
#endif // BAR_WINICON_PATCH
drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
drawstateindicator(c->mon, c, 1, x, a->y, tabw + (i < remainder ? 1 : 0), a->h, 0, 0, c->isfixed);
x += tabw + (i < remainder ? 1 : 0);
}

View File

@ -7,7 +7,10 @@ width_fancybar(Bar *bar, BarArg *a)
int
draw_fancybar(Bar *bar, BarArg *a)
{
int ftw, mw, ew = 0, n = 0;
int tabw, mw, ew = 0, n = 0, tx, tw;
#if BAR_WINICON_PATCH
int ipad;
#endif // BAR_WINICON_PATCH
unsigned int i;
Client *c;
Monitor *m = bar->mon;
@ -28,25 +31,25 @@ draw_fancybar(Bar *bar, BarArg *a)
}
if (n > 0) {
ftw = TEXTW(m->sel->name);
tabw = TEXTW(m->sel->name);
#if BAR_WINICON_PATCH
if (m->sel->icon)
ftw += m->sel->icon->width + ICONSPACING;
tabw += m->sel->icon->width + ICONSPACING;
#endif // BAR_WINICON_PATCH
mw = (ftw >= w || n == 1) ? 0 : (w - ftw) / (n - 1);
mw = (tabw >= w || n == 1) ? 0 : (w - tabw) / (n - 1);
i = 0;
for (c = m->clients; c; c = c->next) {
if (!ISVISIBLE(c) || c == m->sel)
continue;
ftw = TEXTW(c->name);
tabw = TEXTW(c->name);
#if BAR_WINICON_PATCH
if (c->icon)
ftw += c->icon->width + ICONSPACING;
tabw += c->icon->width + ICONSPACING;
#endif // BAR_WINICON_PATCH
if (ftw < mw)
ew += (mw - ftw);
if (tabw < mw)
ew += (mw - tabw);
else
i++;
}
@ -57,24 +60,36 @@ draw_fancybar(Bar *bar, BarArg *a)
for (c = m->clients; c; c = c->next) {
if (!ISVISIBLE(c))
continue;
ftw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
tabw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
#if BAR_WINICON_PATCH
ipad = c->icon ? c->icon->width + ICONSPACING : 0;
tabw += ipad;
#endif // BAR_WINICON_PATCH
tx = x;
tw = tabw;
drw_setscheme(drw, scheme[m->sel == c ? SchemeTitleSel : SchemeTitleNorm]);
if (ftw > 0) { /* trap special handling of 0 in drw_text */
drw_text(drw, x, a->y, ftw, a->h, lrpad / 2, c->name, 0, False);
XSetForeground(drw->dpy, drw->gc, drw->scheme[ColBg].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, tx, a->y, tw, a->h);
#if BAR_WINICON_PATCH
drw_text(drw, x, a->y, ftw, a->h, lrpad / 2 + (c->icon ? c->icon->width + ICONSPACING : 0), c->name, 0, False);
if (c->icon)
drw_img(drw, x + lrpad / 2, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
#else
drw_text(drw, x, a->y, ftw, a->h, lrpad / 2, c->name, 0, False);
#endif // BAR_WINICON_PATCH
if (tabw <= 0) /* trap special handling of 0 in drw_text */
continue;
tx += lrpad / 2;
tw -= lrpad;
#if BAR_WINICON_PATCH
if (ipad) {
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
tx += ipad;
tw -= ipad;
}
drawstateindicator(c->mon, c, 1, x, a->y, ftw, a->h, 0, 0, c->isfixed);
x += ftw;
w -= ftw;
#endif // BAR_WINICON_PATCH
drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
drawstateindicator(c->mon, c, 1, x, a->y, tabw, a->h, 0, 0, c->isfixed);
x += tabw;
w -= tabw;
}
}
return n;

View File

@ -166,11 +166,21 @@ getselschemefor(int scheme)
}
void
flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Arg *arg, BarArg *barg)
flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Arg *arg, BarArg *a)
{
if (!c)
return;
int i, nclienttags = 0, nviewtags = 0, pad = lrpad / 2;
int i, nclienttags = 0, nviewtags = 0;
int tpad = lrpad / 2;
#if BAR_WINICON_PATCH
int ipad = c->icon ? c->icon->width + ICONSPACING : 0;
#endif // BAR_WINICON_PATCH
#if BAR_CENTEREDWINDOWNAME_PATCH
int cpad = 0;
#endif // BAR_CENTEREDWINDOWNAME_PATCH
int tx = x;
int tw = w;
int clientscheme = (
c == selmon->sel && HIDDEN(c)
? SchemeHidSel
@ -182,30 +192,49 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar
? SchemeUrg
: tabscheme
);
drw_setscheme(drw, scheme[clientscheme]);
XSetWindowBorder(dpy, c->win, scheme[clientscheme][ColBorder].pixel);
if (w <= TEXTW("A") - lrpad + pad) // reduce text padding if wintitle is too small
pad = (w - TEXTW("A") + lrpad < 0 ? 0 : (w - TEXTW("A") + lrpad) / 2);
#if BAR_CENTEREDWINDOWNAME_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)
pad = (w - TEXTW(c->name) + lrpad) / 2;
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
tx += tpad;
tw -= lrpad;
#if BAR_WINICON_PATCH
drw_text(drw, x, barg->y, w, barg->h, pad + (c->icon ? c->icon->width + ICONSPACING : 0), c->name, 0, False);
if (c->icon)
drw_img(drw, x + pad, barg->y + (barg->h - c->icon->height) / 2, c->icon, tmpicon);
#else
drw_text(drw, x, barg->y, w, barg->h, pad, c->name, 0, False);
if (ipad) {
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
tx += ipad;
tw -= ipad;
}
#endif // BAR_WINICON_PATCH
drawstateindicator(m, c, 1, x + 2, barg->y, w, barg->h, 0, 0, 0);
drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
drawstateindicator(m, c, 1, x + 2, a->y, w, a->h, 0, 0, 0);
if (FLEXWINTITLE_BORDERS) {
XSetForeground(drw->dpy, drw->gc, scheme[SchemeSel][ColBorder].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, barg->y, 1, barg->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= barg->w ? 1 : 0), barg->y, 1, barg->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, a->y, 1, a->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= a->w ? 1 : 0), a->y, 1, a->h);
}
/* Optional tags icons */
for (i = 0; i < NUMTAGS; i++) {
if ((m->tagset[m->seltags] >> i) & 1)
@ -215,7 +244,7 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar
}
if (TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1)
drawindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
drawindicator(m, c, 1, x, a->y, w, a->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
}
#ifndef HIDDEN

View File

@ -36,11 +36,21 @@ click_bartabgroups(Bar *bar, Arg *arg, BarArg *a)
}
void
bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg, BarArg *barg)
bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg *arg, BarArg *a)
{
if (!c)
return;
int i, nclienttags = 0, nviewtags = 0, pad = lrpad / 2;
int i, nclienttags = 0, nviewtags = 0;
int tpad = lrpad / 2;
#if BAR_WINICON_PATCH
int ipad = c->icon ? c->icon->width + 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->sel == c
#ifdef HIDDEN
@ -55,27 +65,44 @@ bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg
? SchemeTitleSel
: SchemeTitleNorm
]);
if (w <= TEXTW("A") - lrpad + pad) // reduce text padding if wintitle is too small
pad = (w - TEXTW("A") + lrpad < 0 ? 0 : (w - TEXTW("A") + lrpad) / 2);
#if BAR_CENTEREDWINDOWNAME_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)
pad = (w - TEXTW(c->name) + lrpad) / 2;
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
tx += tpad;
tw -= lrpad;
#if BAR_WINICON_PATCH
drw_text(drw, x, barg->y, w, barg->h, pad + (c->icon ? c->icon->width + ICONSPACING : 0), c->name, 0, False);
if (c->icon)
drw_img(drw, x + pad, barg->y + (barg->h - c->icon->height) / 2, c->icon, tmpicon);
#else
drw_text(drw, x, barg->y, w, barg->h, pad, c->name, 0, False);
if (ipad) {
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
tx += ipad;
tw -= ipad;
}
#endif // BAR_WINICON_PATCH
drawstateindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, c->isfixed);
drw_text(drw, tx, a->y, tw, a->h, 0, c->name, 0, False);
drawstateindicator(m, c, 1, x, a->y, w, a->h, 0, 0, c->isfixed);
if (BARTAB_BORDERS) {
XSetForeground(drw->dpy, drw->gc, scheme[SchemeSel][ColBorder].pixel);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, barg->y, 1, barg->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= barg->w ? 1 : 0), barg->y, 1, barg->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, a->y, 1, a->h);
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x + w - (x + w >= a->w ? 1 : 0), a->y, 1, a->h);
}
/* Optional tags icons */
for (i = 0; i < NUMTAGS; i++) {
@ -86,7 +113,7 @@ bartabdraw(Monitor *m, Client *c, int unused, int x, int w, int groupactive, Arg
}
if (TAGSINDICATOR == 2 || nclienttags > 1 || nviewtags > 1)
drawindicator(m, c, 1, x, barg->y, w, barg->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
drawindicator(m, c, 1, x, a->y, w, a->h, 0, 0, 0, INDICATOR_RIGHT_TAGS);
}
#ifndef HIDDEN

View File

@ -18,7 +18,6 @@ draw_wintitle(Bar *bar, BarArg *a)
#endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH
Monitor *m = bar->mon;
Client *c = m->sel;
int pad = lrpad / 2;
if (!c) {
drw_setscheme(drw, scheme[SchemeTitleNorm]);
@ -26,23 +25,53 @@ draw_wintitle(Bar *bar, BarArg *a)
return 0;
}
int tpad = lrpad / 2;
#if BAR_WINICON_PATCH
int ipad = c->icon ? c->icon->width + 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 BAR_CENTEREDWINDOWNAME_PATCH
if (TEXTW(c->name) < w)
pad = (w - TEXTW(c->name) + lrpad) / 2;
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
tx += tpad;
tw -= lrpad;
#if BAR_WINICON_PATCH
drw_text(drw, x, a->y, w, a->h, pad + (c->icon ? c->icon->width + ICONSPACING : 0), c->name, 0, False);
if (c->icon)
drw_img(drw, x + pad, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
#else
drw_text(drw, x, a->y, w, a->h, pad, c->name, 0, False);
if (ipad) {
drw_img(drw, tx, a->y + (a->h - c->icon->height) / 2, c->icon, tmpicon);
tx += ipad;
tw -= ipad;
}
#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);