allow textbox widgets to have their own font

This commit is contained in:
Julien Danjou 2007-12-29 15:47:28 +01:00
parent 7816dd3d83
commit 360d9023a4
4 changed files with 20 additions and 8 deletions

View File

@ -520,6 +520,7 @@ config_parse(const char *confpatharg)
CFG_STR((char *) "text", (char *) NULL, CFGF_NONE), CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE),
CFG_STR((char *) "font", (char *) NULL, CFGF_NONE),
CFG_END() CFG_END()
}; };
static cfg_opt_t widget_progressbar_opts[] = static cfg_opt_t widget_progressbar_opts[] =

View File

@ -235,6 +235,7 @@ struct Widget
int location; int location;
int width; int width;
Button *buttons; Button *buttons;
XftFont *font;
Widget *next; Widget *next;
}; };

View File

@ -108,6 +108,7 @@ statusbar_draw(int screen)
void void
statusbar_init(int screen) statusbar_init(int screen)
{ {
Widget *widget;
XSetWindowAttributes wa; XSetWindowAttributes wa;
int phys_screen = get_phys_screen(screen); int phys_screen = get_phys_screen(screen);
Area area = get_screen_area(screen, Area area = get_screen_area(screen,
@ -117,6 +118,10 @@ statusbar_init(int screen)
statusbar->height = globalconf.screens[screen].font->height * 1.5; statusbar->height = globalconf.screens[screen].font->height * 1.5;
for(widget = statusbar->widgets; widget; widget = widget->next)
if(widget->font)
statusbar->height = MAX(statusbar->height, widget->font->height);
if(statusbar->position == BarRight || statusbar->position == BarLeft) if(statusbar->position == BarRight || statusbar->position == BarLeft)
statusbar->width = area.height; statusbar->width = area.height;
else else

View File

@ -46,17 +46,16 @@ static int
textbox_draw(Widget *widget, DrawCtx *ctx, int offset, textbox_draw(Widget *widget, DrawCtx *ctx, int offset,
int used __attribute__ ((unused))) int used __attribute__ ((unused)))
{ {
VirtScreen vscreen = globalconf.screens[widget->statusbar->screen];
Data *d = widget->data; Data *d = widget->data;
widget->width = textwidth(vscreen.font, d->text); widget->width = textwidth(widget->font, d->text);
widget->location = widget_calculate_offset(widget->statusbar->width, widget->location = widget_calculate_offset(widget->statusbar->width,
widget->width, widget->width,
offset, offset,
widget->alignment); widget->alignment);
draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height, draw_text(ctx, widget->location, 0, widget->width, widget->statusbar->height,
vscreen.font, d->text, d->fg, d->bg); widget->font, d->text, d->fg, d->bg);
return widget->width; return widget->width;
} }
@ -72,7 +71,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
{ {
Widget *w; Widget *w;
Data *d; Data *d;
char *color; char *buf;
w = p_new(Widget, 1); w = p_new(Widget, 1);
widget_common_new(w, statusbar, config); widget_common_new(w, statusbar, config);
@ -81,16 +80,22 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
w->data = d = p_new(Data, 1); w->data = d = p_new(Data, 1);
if ((color = cfg_getstr(config, "fg"))) if((buf = cfg_getstr(config, "fg")))
d->fg = initxcolor(statusbar->screen, color); d->fg = initxcolor(statusbar->screen, buf);
else else
d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG];
if ((color = cfg_getstr(config, "bg"))) if((buf = cfg_getstr(config, "bg")))
d->bg = initxcolor(statusbar->screen, color); d->bg = initxcolor(statusbar->screen, buf);
else else
d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG]; d->bg = globalconf.screens[statusbar->screen].colors_normal[ColBG];
if((buf = cfg_getstr(config, "font")))
w->font = XftFontOpenName(globalconf.display, get_phys_screen(statusbar->screen), buf);
if(!w->font)
w->font = globalconf.screens[statusbar->screen].font;
update(w, cfg_getstr(config, "text")); update(w, cfg_getstr(config, "text"));
return w; return w;
} }