Simplified Pango integration by settling on common function signatures.

This commit is contained in:
bakkeby 2020-08-22 20:31:17 +02:00
parent 46ebaea58f
commit 81f44b036c
13 changed files with 22 additions and 118 deletions

41
drw.c
View File

@ -9,7 +9,7 @@
#include "drw.h" #include "drw.h"
#include "util.h" #include "util.h"
#if !PANGO_PATCH #if !BAR_PANGO_PATCH
#define UTF_INVALID 0xFFFD #define UTF_INVALID 0xFFFD
#define UTF_SIZ 4 #define UTF_SIZ 4
@ -118,11 +118,7 @@ drw_free(Drw *drw)
{ {
XFreePixmap(drw->dpy, drw->drawable); XFreePixmap(drw->dpy, drw->drawable);
XFreeGC(drw->dpy, drw->gc); XFreeGC(drw->dpy, drw->gc);
#if BAR_PANGO_PATCH
drw_font_free(drw->font);
#else
drw_fontset_free(drw->fonts); drw_fontset_free(drw->fonts);
#endif // BAR_PANGO_PATCH
free(drw); free(drw);
} }
@ -247,7 +243,7 @@ drw_font_create(Drw* drw, const char font[])
fnt = xfont_create(drw, font); fnt = xfont_create(drw, font);
return (drw->font = fnt); return (drw->fonts = fnt);
} }
#else #else
Fnt* Fnt*
@ -269,23 +265,16 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
} }
#endif // BAR_PANGO_PATCH #endif // BAR_PANGO_PATCH
#if BAR_PANGO_PATCH
void
drw_font_free(Fnt *font)
{
if (font)
xfont_free(font);
}
#else
void void
drw_fontset_free(Fnt *font) drw_fontset_free(Fnt *font)
{ {
if (font) { if (font) {
#if !BAR_PANGO_PATCH
drw_fontset_free(font->next); drw_fontset_free(font->next);
#endif // BAR_PANGO_PATCH
xfont_free(font); xfont_free(font);
} }
} }
#endif // BAR_PANGO_PATCH
void void
drw_clr_create( drw_clr_create(
@ -394,7 +383,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
size_t i, len; size_t i, len;
int render = x || y || w || h; int render = x || y || w || h;
if (!drw || (render && !drw->scheme) || !text || !drw->font) if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
return 0; return 0;
if (!render) { if (!render) {
@ -416,10 +405,10 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
len = strlen(text); len = strlen(text);
if (len) { if (len) {
drw_font_getexts(drw->font, text, len, &ew, NULL, markup); drw_font_getexts(drw->fonts, text, len, &ew, NULL, markup);
/* shorten text if necessary */ /* shorten text if necessary */
for (len = MIN(len, sizeof(buf) - 1); len && ew > w; len--) for (len = MIN(len, sizeof(buf) - 1); len && ew > w; len--)
drw_font_getexts(drw->font, text, len, &ew, NULL, markup); drw_font_getexts(drw->fonts, text, len, &ew, NULL, markup);
if (len) { if (len) {
memcpy(buf, text, len); memcpy(buf, text, len);
@ -450,7 +439,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp
} }
#else #else
int int
drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool ignored)
{ {
char buf[1024]; char buf[1024];
int ty; int ty;
@ -628,23 +617,13 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
XSync(drw->dpy, False); XSync(drw->dpy, False);
} }
#if BAR_PANGO_PATCH
unsigned int unsigned int
drw_font_getwidth(Drw *drw, const char *text, Bool markup) drw_fontset_getwidth(Drw *drw, const char *text, Bool ignored)
{
if (!drw || !drw->font || !text)
return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0, markup);
}
#else
unsigned int
drw_fontset_getwidth(Drw *drw, const char *text)
{ {
if (!drw || !drw->fonts || !text) if (!drw || !drw->fonts || !text)
return 0; return 0;
return drw_text(drw, 0, 0, 0, 0, 0, text, 0); return drw_text(drw, 0, 0, 0, 0, 0, text, 0, ignored);
} }
#endif // BAR_PANGO_PATCH
#if BAR_PANGO_PATCH #if BAR_PANGO_PATCH
void void

10
drw.h
View File

@ -52,15 +52,13 @@ void drw_free(Drw *drw);
/* Fnt abstraction */ /* Fnt abstraction */
#if BAR_PANGO_PATCH #if BAR_PANGO_PATCH
Fnt *drw_font_create(Drw* drw, const char font[]); Fnt *drw_font_create(Drw* drw, const char font[]);
void drw_font_free(Fnt* set);
unsigned int drw_font_getwidth(Drw *drw, const char *text, Bool markup);
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h, Bool markup);
#else #else
Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount);
void drw_fontset_free(Fnt* set);
unsigned int drw_fontset_getwidth(Drw *drw, const char *text);
void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h);
#endif // BAR_PANGO_PATCH #endif // BAR_PANGO_PATCH
void drw_fontset_free(Fnt* set);
unsigned int drw_fontset_getwidth(Drw *drw, const char *text, Bool markup);
/* Colorscheme abstraction */ /* Colorscheme abstraction */
void drw_clr_create( void drw_clr_create(
@ -95,11 +93,7 @@ void drw_settrans(Drw *drw, Clr *psc, Clr *nsc);
/* Drawing functions */ /* Drawing functions */
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert);
#if BAR_PANGO_PATCH
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup); int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert, Bool markup);
#else
int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert);
#endif // BAR_PANGO_PATCH
#if BAR_POWERLINE_TAGS_PATCH || BAR_POWERLINE_STATUS_PATCH #if BAR_POWERLINE_TAGS_PATCH || BAR_POWERLINE_STATUS_PATCH
void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash); void drw_arrow(Drw *drw, int x, int y, unsigned int w, unsigned int h, int direction, int slash);
#endif // BAR_POWERLINE_TAGS_PATCH | BAR_POWERLINE_STATUS_PATCH #endif // BAR_POWERLINE_TAGS_PATCH | BAR_POWERLINE_STATUS_PATCH

8
dwm.c
View File

@ -86,12 +86,8 @@
#else #else
#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TAGMASK ((1 << LENGTH(tags)) - 1)
#endif // SCRATCHPADS_PATCH #endif // SCRATCHPADS_PATCH
#if BAR_PANGO_PATCH #define TEXTWM(X) (drw_fontset_getwidth(drw, (X), True) + lrpad)
#define TEXTW(X) (drw_font_getwidth(drw, (X), False) + lrpad) #define TEXTW(X) (drw_fontset_getwidth(drw, (X), False) + lrpad)
#define TEXTWM(X) (drw_font_getwidth(drw, (X), True) + lrpad)
#else
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
#endif // BAR_PANGO_PATCH
/* enums */ /* enums */
enum { enum {

View File

@ -44,11 +44,7 @@ draw_awesomebar(Bar *bar, BarDrawArg *a)
#endif // BAR_CENTEREDWINDOWNAME_PATCH #endif // BAR_CENTEREDWINDOWNAME_PATCH
drw_setscheme(drw, scheme[scm]); drw_setscheme(drw, scheme[scm]);
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, pad, c->name, 0, False); drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, pad, c->name, 0, False);
#else
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, pad, c->name, 0);
#endif // BAR_PANGO_PATCH
if (c->isfloating) if (c->isfloating)
drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype); drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype);
x += tabw + (i < remainder ? 1 : 0); x += tabw + (i < remainder ? 1 : 0);

View File

@ -52,11 +52,7 @@ draw_fancybar(Bar *bar, BarDrawArg *a)
ftw = MIN(m->sel == c ? w : mw, TEXTW(c->name)); ftw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
drw_setscheme(drw, scheme[m->sel == c ? SchemeTitleSel : SchemeTitleNorm]); drw_setscheme(drw, scheme[m->sel == c ? SchemeTitleSel : SchemeTitleNorm]);
if (ftw > 0) /* trap special handling of 0 in drw_text */ if (ftw > 0) /* trap special handling of 0 in drw_text */
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, ftw, bh, lrpad / 2, c->name, 0, False); drw_text(drw, x, 0, ftw, bh, lrpad / 2, c->name, 0, False);
#else
drw_text(drw, x, 0, ftw, bh, lrpad / 2, c->name, 0);
#endif // BAR_PANGO_PATCH
if (c->isfloating) if (c->isfloating)
drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype); drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype);
x += ftw; x += ftw;

View File

@ -188,7 +188,7 @@ flextitledraw(Monitor *m, Client *c, int unused, int x, int w, int tabscheme, Ar
pad = (w - TEXTW(c->name) + lrpad) / 2; pad = (w - TEXTW(c->name) + lrpad) / 2;
#endif // BAR_CENTEREDWINDOWNAME_PATCH #endif // BAR_CENTEREDWINDOWNAME_PATCH
drw_text(drw, x, 0, w, bh, pad, c->name, 0); drw_text(drw, x, 0, w, bh, pad, c->name, 0, False);
if (c->isfloating) if (c->isfloating)
drawindicator(m, c, 1, x + 2, w, 0, 0, 0, floatindicatortype); drawindicator(m, c, 1, x + 2, w, 0, 0, 0, floatindicatortype);

View File

@ -7,11 +7,7 @@ width_ltsymbol(Bar *bar, BarWidthArg *a)
int int
draw_ltsymbol(Bar *bar, BarDrawArg *a) draw_ltsymbol(Bar *bar, BarDrawArg *a)
{ {
#if BAR_PANGO_PATCH
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, bar->mon->ltsymbol, 0, False); return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, bar->mon->ltsymbol, 0, False);
#else
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, bar->mon->ltsymbol, 0);
#endif // BAR_PANGO_PATCH
} }
int int

View File

@ -1,44 +1,28 @@
int int
width_status(Bar *bar, BarWidthArg *a) width_status(Bar *bar, BarWidthArg *a)
{ {
#if BAR_PANGO_PATCH
return TEXTWM(stext); return TEXTWM(stext);
#else
return TEXTW(stext);
#endif // BAR_PANGO_PATCH
} }
#if BAR_EXTRASTATUS_PATCH #if BAR_EXTRASTATUS_PATCH
int int
width_status_es(Bar *bar, BarWidthArg *a) width_status_es(Bar *bar, BarWidthArg *a)
{ {
#if BAR_PANGO_PATCH
return TEXTWM(estext) - lrpad; return TEXTWM(estext) - lrpad;
#else
return TEXTW(estext) - lrpad;
#endif // BAR_PANGO_PATCH
} }
#endif // BAR_EXTRASTATUS_PATCH #endif // BAR_EXTRASTATUS_PATCH
int int
draw_status(Bar *bar, BarDrawArg *a) draw_status(Bar *bar, BarDrawArg *a)
{ {
#if BAR_PANGO_PATCH
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0, True); return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0, True);
#else
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0);
#endif // BAR_PANGO_PATCH
} }
#if BAR_EXTRASTATUS_PATCH #if BAR_EXTRASTATUS_PATCH
int int
draw_status_es(Bar *bar, BarDrawArg *a) draw_status_es(Bar *bar, BarDrawArg *a)
{ {
#if BAR_PANGO_PATCH
return drw_text(drw, a->x, 0, a->w, bh, 0, estext, 0, True); return drw_text(drw, a->x, 0, a->w, bh, 0, estext, 0, True);
#else
return drw_text(drw, a->x, 0, a->w, bh, 0, estext, 0);
#endif // BAR_PANGO_PATCH
} }
#endif // BAR_EXTRASTATUS_PATCH #endif // BAR_EXTRASTATUS_PATCH

View File

@ -83,13 +83,8 @@ drawstatusbar(int x, char* stext)
isCode = 1; isCode = 1;
text[i] = '\0'; text[i] = '\0';
#if BAR_PANGO_PATCH
w = TEXTWM(text) - lrpad; w = TEXTWM(text) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0, True); drw_text(drw, x, 0, w, bh, 0, text, 0, True);
#else
w = TEXTW(text) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0);
#endif // BAR_PANGO_PATCH
x += w; x += w;
@ -156,13 +151,8 @@ drawstatusbar(int x, char* stext)
} }
} }
if (!isCode) { if (!isCode) {
#if BAR_PANGO_PATCH
w = TEXTWM(text) - lrpad; w = TEXTWM(text) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0, True); drw_text(drw, x, 0, w, bh, 0, text, 0, True);
#else
w = TEXTW(text) - lrpad;
drw_text(drw, x, 0, w, bh, 0, text, 0);
#endif // BAR_PANGO_PATCH
x += w; x += w;
} }
free(p); free(p);
@ -197,11 +187,7 @@ status2dtextlength(char* stext)
if (!isCode) { if (!isCode) {
isCode = 1; isCode = 1;
text[i] = '\0'; text[i] = '\0';
#if BAR_PANGO_PATCH
w += TEXTWM(text) - lrpad; w += TEXTWM(text) - lrpad;
#else
w += TEXTW(text) - lrpad;
#endif // BAR_PANGO_PATCH
text[i] = '^'; text[i] = '^';
if (text[++i] == 'f') if (text[++i] == 'f')
w += atoi(text + ++i); w += atoi(text + ++i);
@ -213,11 +199,7 @@ status2dtextlength(char* stext)
} }
} }
if (!isCode) if (!isCode)
#if BAR_PANGO_PATCH
w += TEXTWM(text) - lrpad; w += TEXTWM(text) - lrpad;
#else
w += TEXTW(text) - lrpad;
#endif // BAR_PANGO_PATCH
free(p); free(p);
return w; return w;
} }

View File

@ -7,11 +7,7 @@ width_stbutton(Bar *bar, BarWidthArg *a)
int int
draw_stbutton(Bar *bar, BarDrawArg *a) draw_stbutton(Bar *bar, BarDrawArg *a)
{ {
#if BAR_PANGO_PATCH
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0, False); return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0, False);
#else
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0);
#endif // BAR_PANGO_PATCH
} }
int int

View File

@ -35,11 +35,9 @@ click_statuscmd_text(Arg *arg, int rel_x, char *text)
text[i] = '\0'; text[i] = '\0';
#if BAR_STATUS2D_PATCH && !BAR_BAR_STATUSCOLORS_PATCH #if BAR_STATUS2D_PATCH && !BAR_BAR_STATUSCOLORS_PATCH
x += status2dtextlength(text); x += status2dtextlength(text);
#elif BAR_PANGO_PATCH
x += TEXTWM(text) - lrpad;
#else #else
x += TEXTW(text) - lrpad; x += TEXTWM(text) - lrpad;
#endif // STATUS2D_PATCH #endif // BAR_STATUS2D_PATCH
text[i] = ch; text[i] = ch;
text += i+1; text += i+1;
i = -1; i = -1;

View File

@ -63,14 +63,10 @@ draw_tags(Bar *bar, BarDrawArg *a)
? SchemeUrg ? SchemeUrg
: SchemeTagsNorm : SchemeTagsNorm
]); ]);
#if BAR_ALTERNATIVE_TAGS_PATCH && BAR_PANGO_PATCH #if BAR_ALTERNATIVE_TAGS_PATCH
drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), invert, False); drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), invert, False);
#elif BAR_ALTERNATIVE_TAGS_PATCH
drw_text(drw, x, 0, w, bh, wdelta + lrpad / 2, (selmon->alttag ? tagsalt[i] : tags[i]), invert);
#elif BAR_PANGO_PATCH
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], invert, False);
#else #else
drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], invert); drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], invert, False);
#endif // BAR_ALTERNATIVE_TAGS_PATCH #endif // BAR_ALTERNATIVE_TAGS_PATCH
drawindicator(m, NULL, occ, x, w, i, -1, invert, tagindicatortype); drawindicator(m, NULL, occ, x, w, i, -1, invert, tagindicatortype);
x += w; x += w;

View File

@ -17,6 +17,7 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
int x = a->x, w = a->w; int x = a->x, w = a->w;
#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;
int pad = lrpad / 2;
if (!m->sel) { if (!m->sel) {
drw_setscheme(drw, scheme[SchemeTitleNorm]); drw_setscheme(drw, scheme[SchemeTitleNorm]);
@ -29,19 +30,9 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
XSetErrorHandler(xerrordummy); XSetErrorHandler(xerrordummy);
#endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH #endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
#if BAR_CENTEREDWINDOWNAME_PATCH #if BAR_CENTEREDWINDOWNAME_PATCH
int mid = (m->ww - TEXTW(m->sel->name)) / 2 - x; pad = (m->ww - TEXTW(m->sel->name)) / 2 - x;
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0, False);
#else
drw_text(drw, x, 0, w, bh, mid, m->sel->name, 0);
#endif // BAR_PANGO_PATCH
#else
#if BAR_PANGO_PATCH
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0, False);
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0);
#endif // BAR_PANGO_PATCH
#endif // BAR_CENTEREDWINDOWNAME_PATCH #endif // BAR_CENTEREDWINDOWNAME_PATCH
drw_text(drw, x, 0, w, bh, pad, m->sel->name, 0, False);
#if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH #if BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
XSync(dpy, False); XSync(dpy, False);
XSetErrorHandler(xerror); XSetErrorHandler(xerror);