mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Simplified Pango integration by settling on common function signatures.
This commit is contained in:
parent
46ebaea58f
commit
81f44b036c
41
drw.c
41
drw.c
@ -9,7 +9,7 @@
|
||||
#include "drw.h"
|
||||
#include "util.h"
|
||||
|
||||
#if !PANGO_PATCH
|
||||
#if !BAR_PANGO_PATCH
|
||||
#define UTF_INVALID 0xFFFD
|
||||
#define UTF_SIZ 4
|
||||
|
||||
@ -118,11 +118,7 @@ drw_free(Drw *drw)
|
||||
{
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
XFreeGC(drw->dpy, drw->gc);
|
||||
#if BAR_PANGO_PATCH
|
||||
drw_font_free(drw->font);
|
||||
#else
|
||||
drw_fontset_free(drw->fonts);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
free(drw);
|
||||
}
|
||||
|
||||
@ -247,7 +243,7 @@ drw_font_create(Drw* drw, const char font[])
|
||||
|
||||
fnt = xfont_create(drw, font);
|
||||
|
||||
return (drw->font = fnt);
|
||||
return (drw->fonts = fnt);
|
||||
}
|
||||
#else
|
||||
Fnt*
|
||||
@ -269,23 +265,16 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
}
|
||||
#endif // BAR_PANGO_PATCH
|
||||
|
||||
#if BAR_PANGO_PATCH
|
||||
void
|
||||
drw_font_free(Fnt *font)
|
||||
{
|
||||
if (font)
|
||||
xfont_free(font);
|
||||
}
|
||||
#else
|
||||
void
|
||||
drw_fontset_free(Fnt *font)
|
||||
{
|
||||
if (font) {
|
||||
#if !BAR_PANGO_PATCH
|
||||
drw_fontset_free(font->next);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
xfont_free(font);
|
||||
}
|
||||
}
|
||||
#endif // BAR_PANGO_PATCH
|
||||
|
||||
void
|
||||
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;
|
||||
int render = x || y || w || h;
|
||||
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->font)
|
||||
if (!drw || (render && !drw->scheme) || !text || !drw->fonts)
|
||||
return 0;
|
||||
|
||||
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);
|
||||
|
||||
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 */
|
||||
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) {
|
||||
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
|
||||
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];
|
||||
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);
|
||||
}
|
||||
|
||||
#if BAR_PANGO_PATCH
|
||||
unsigned int
|
||||
drw_font_getwidth(Drw *drw, const char *text, Bool markup)
|
||||
{
|
||||
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)
|
||||
drw_fontset_getwidth(Drw *drw, const char *text, Bool ignored)
|
||||
{
|
||||
if (!drw || !drw->fonts || !text)
|
||||
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
|
||||
void
|
||||
|
10
drw.h
10
drw.h
@ -52,15 +52,13 @@ void drw_free(Drw *drw);
|
||||
/* Fnt abstraction */
|
||||
#if BAR_PANGO_PATCH
|
||||
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);
|
||||
#else
|
||||
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);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
void drw_fontset_free(Fnt* set);
|
||||
unsigned int drw_fontset_getwidth(Drw *drw, const char *text, Bool markup);
|
||||
|
||||
/* Colorscheme abstraction */
|
||||
void drw_clr_create(
|
||||
@ -95,11 +93,7 @@ void drw_settrans(Drw *drw, Clr *psc, Clr *nsc);
|
||||
|
||||
/* Drawing functions */
|
||||
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);
|
||||
#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
|
||||
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
|
||||
|
8
dwm.c
8
dwm.c
@ -86,12 +86,8 @@
|
||||
#else
|
||||
#define TAGMASK ((1 << LENGTH(tags)) - 1)
|
||||
#endif // SCRATCHPADS_PATCH
|
||||
#if BAR_PANGO_PATCH
|
||||
#define TEXTW(X) (drw_font_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
|
||||
#define TEXTWM(X) (drw_fontset_getwidth(drw, (X), True) + lrpad)
|
||||
#define TEXTW(X) (drw_fontset_getwidth(drw, (X), False) + lrpad)
|
||||
|
||||
/* enums */
|
||||
enum {
|
||||
|
@ -44,11 +44,7 @@ draw_awesomebar(Bar *bar, BarDrawArg *a)
|
||||
#endif // BAR_CENTEREDWINDOWNAME_PATCH
|
||||
|
||||
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);
|
||||
#else
|
||||
drw_text(drw, x, 0, tabw + (i < remainder ? 1 : 0), bh, pad, c->name, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
if (c->isfloating)
|
||||
drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype);
|
||||
x += tabw + (i < remainder ? 1 : 0);
|
||||
|
@ -52,11 +52,7 @@ draw_fancybar(Bar *bar, BarDrawArg *a)
|
||||
ftw = MIN(m->sel == c ? w : mw, TEXTW(c->name));
|
||||
drw_setscheme(drw, scheme[m->sel == c ? SchemeTitleSel : SchemeTitleNorm]);
|
||||
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);
|
||||
#else
|
||||
drw_text(drw, x, 0, ftw, bh, lrpad / 2, c->name, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
if (c->isfloating)
|
||||
drawindicator(c->mon, c, 1, x, w, 0, 0, c->isfixed, floatindicatortype);
|
||||
x += ftw;
|
||||
|
@ -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;
|
||||
#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)
|
||||
drawindicator(m, c, 1, x + 2, w, 0, 0, 0, floatindicatortype);
|
||||
|
||||
|
@ -7,11 +7,7 @@ width_ltsymbol(Bar *bar, BarWidthArg *a)
|
||||
int
|
||||
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);
|
||||
#else
|
||||
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, bar->mon->ltsymbol, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -1,44 +1,28 @@
|
||||
int
|
||||
width_status(Bar *bar, BarWidthArg *a)
|
||||
{
|
||||
#if BAR_PANGO_PATCH
|
||||
return TEXTWM(stext);
|
||||
#else
|
||||
return TEXTW(stext);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
|
||||
#if BAR_EXTRASTATUS_PATCH
|
||||
int
|
||||
width_status_es(Bar *bar, BarWidthArg *a)
|
||||
{
|
||||
#if BAR_PANGO_PATCH
|
||||
return TEXTWM(estext) - lrpad;
|
||||
#else
|
||||
return TEXTW(estext) - lrpad;
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
#endif // BAR_EXTRASTATUS_PATCH
|
||||
|
||||
int
|
||||
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);
|
||||
#else
|
||||
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, stext, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
|
||||
#if BAR_EXTRASTATUS_PATCH
|
||||
int
|
||||
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);
|
||||
#else
|
||||
return drw_text(drw, a->x, 0, a->w, bh, 0, estext, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
#endif // BAR_EXTRASTATUS_PATCH
|
||||
|
||||
|
@ -83,13 +83,8 @@ drawstatusbar(int x, char* stext)
|
||||
isCode = 1;
|
||||
|
||||
text[i] = '\0';
|
||||
#if BAR_PANGO_PATCH
|
||||
w = TEXTWM(text) - lrpad;
|
||||
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;
|
||||
|
||||
@ -156,13 +151,8 @@ drawstatusbar(int x, char* stext)
|
||||
}
|
||||
}
|
||||
if (!isCode) {
|
||||
#if BAR_PANGO_PATCH
|
||||
w = TEXTWM(text) - lrpad;
|
||||
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;
|
||||
}
|
||||
free(p);
|
||||
@ -197,11 +187,7 @@ status2dtextlength(char* stext)
|
||||
if (!isCode) {
|
||||
isCode = 1;
|
||||
text[i] = '\0';
|
||||
#if BAR_PANGO_PATCH
|
||||
w += TEXTWM(text) - lrpad;
|
||||
#else
|
||||
w += TEXTW(text) - lrpad;
|
||||
#endif // BAR_PANGO_PATCH
|
||||
text[i] = '^';
|
||||
if (text[++i] == 'f')
|
||||
w += atoi(text + ++i);
|
||||
@ -213,11 +199,7 @@ status2dtextlength(char* stext)
|
||||
}
|
||||
}
|
||||
if (!isCode)
|
||||
#if BAR_PANGO_PATCH
|
||||
w += TEXTWM(text) - lrpad;
|
||||
#else
|
||||
w += TEXTW(text) - lrpad;
|
||||
#endif // BAR_PANGO_PATCH
|
||||
free(p);
|
||||
return w;
|
||||
}
|
@ -7,11 +7,7 @@ width_stbutton(Bar *bar, BarWidthArg *a)
|
||||
int
|
||||
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);
|
||||
#else
|
||||
return drw_text(drw, a->x, 0, a->w, bh, lrpad / 2, buttonbar, 0);
|
||||
#endif // BAR_PANGO_PATCH
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -35,11 +35,9 @@ click_statuscmd_text(Arg *arg, int rel_x, char *text)
|
||||
text[i] = '\0';
|
||||
#if BAR_STATUS2D_PATCH && !BAR_BAR_STATUSCOLORS_PATCH
|
||||
x += status2dtextlength(text);
|
||||
#elif BAR_PANGO_PATCH
|
||||
x += TEXTWM(text) - lrpad;
|
||||
#else
|
||||
x += TEXTW(text) - lrpad;
|
||||
#endif // STATUS2D_PATCH
|
||||
x += TEXTWM(text) - lrpad;
|
||||
#endif // BAR_STATUS2D_PATCH
|
||||
text[i] = ch;
|
||||
text += i+1;
|
||||
i = -1;
|
||||
|
@ -63,14 +63,10 @@ draw_tags(Bar *bar, BarDrawArg *a)
|
||||
? SchemeUrg
|
||||
: 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);
|
||||
#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
|
||||
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
|
||||
drawindicator(m, NULL, occ, x, w, i, -1, invert, tagindicatortype);
|
||||
x += w;
|
||||
|
@ -17,6 +17,7 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
|
||||
int x = a->x, w = a->w;
|
||||
#endif // BAR_TITLE_LEFT_PAD_PATCH | BAR_TITLE_RIGHT_PAD_PATCH
|
||||
Monitor *m = bar->mon;
|
||||
int pad = lrpad / 2;
|
||||
|
||||
if (!m->sel) {
|
||||
drw_setscheme(drw, scheme[SchemeTitleNorm]);
|
||||
@ -29,19 +30,9 @@ draw_wintitle(Bar *bar, BarDrawArg *a)
|
||||
XSetErrorHandler(xerrordummy);
|
||||
#endif // BAR_IGNORE_XFT_ERRORS_WHEN_DRAWING_TEXT_PATCH
|
||||
#if BAR_CENTEREDWINDOWNAME_PATCH
|
||||
int mid = (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
|
||||
pad = (m->ww - TEXTW(m->sel->name)) / 2 - x;
|
||||
#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
|
||||
XSync(dpy, False);
|
||||
XSetErrorHandler(xerror);
|
||||
|
Loading…
Reference in New Issue
Block a user