From 360d9023a4322a09dedaac9f97802e6da89f12cd Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 29 Dec 2007 15:47:28 +0100 Subject: [PATCH] allow textbox widgets to have their own font --- config.c | 1 + config.h | 1 + statusbar.c | 5 +++++ widgets/textbox.c | 21 +++++++++++++-------- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config.c b/config.c index 2ed84daa..fd54ed8a 100644 --- a/config.c +++ b/config.c @@ -520,6 +520,7 @@ config_parse(const char *confpatharg) CFG_STR((char *) "text", (char *) NULL, CFGF_NONE), CFG_STR((char *) "fg", (char *) NULL, CFGF_NONE), CFG_STR((char *) "bg", (char *) NULL, CFGF_NONE), + CFG_STR((char *) "font", (char *) NULL, CFGF_NONE), CFG_END() }; static cfg_opt_t widget_progressbar_opts[] = diff --git a/config.h b/config.h index b17a5dff..f86a2302 100644 --- a/config.h +++ b/config.h @@ -235,6 +235,7 @@ struct Widget int location; int width; Button *buttons; + XftFont *font; Widget *next; }; diff --git a/statusbar.c b/statusbar.c index 098bcbed..d5b45959 100644 --- a/statusbar.c +++ b/statusbar.c @@ -108,6 +108,7 @@ statusbar_draw(int screen) void statusbar_init(int screen) { + Widget *widget; XSetWindowAttributes wa; int phys_screen = get_phys_screen(screen); Area area = get_screen_area(screen, @@ -117,6 +118,10 @@ statusbar_init(int screen) 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) statusbar->width = area.height; else diff --git a/widgets/textbox.c b/widgets/textbox.c index 0d186952..bea6f784 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -46,17 +46,16 @@ static int textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - VirtScreen vscreen = globalconf.screens[widget->statusbar->screen]; 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->width, offset, widget->alignment); 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; } @@ -72,7 +71,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config) { Widget *w; Data *d; - char *color; + char *buf; w = p_new(Widget, 1); widget_common_new(w, statusbar, config); @@ -81,16 +80,22 @@ textbox_new(Statusbar *statusbar, cfg_t *config) w->data = d = p_new(Data, 1); - if ((color = cfg_getstr(config, "fg"))) - d->fg = initxcolor(statusbar->screen, color); + if((buf = cfg_getstr(config, "fg"))) + d->fg = initxcolor(statusbar->screen, buf); else d->fg = globalconf.screens[statusbar->screen].colors_normal[ColFG]; - if ((color = cfg_getstr(config, "bg"))) - d->bg = initxcolor(statusbar->screen, color); + if((buf = cfg_getstr(config, "bg"))) + d->bg = initxcolor(statusbar->screen, buf); else 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")); return w; }