From 5f26ab448c35394fdcb0c475bed33ff17d80fea9 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 13 Mar 2008 08:06:01 +0100 Subject: [PATCH] Free the previously opened font if changing it via widget_tell in textbox --- widgets/textbox.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/widgets/textbox.c b/widgets/textbox.c index fa332ca2c..2762e7564 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -68,6 +68,7 @@ static widget_tell_status_t textbox_tell(Widget *widget, char *property, char *command) { Data *d = widget->data; + XftFont *newfont; if(!command) return WIDGET_ERROR_NOVALUE; @@ -90,13 +91,16 @@ textbox_tell(Widget *widget, char *property, char *command) return WIDGET_ERROR_FORMAT_COLOR; else if(!a_strcmp(property, "font")) { - widget->font = XftFontOpenName(globalconf.display, - get_phys_screen(widget->statusbar->screen), command); - if(!widget->font) + if(a_strlen(command) + && (newfont = XftFontOpenName(globalconf.display, + get_phys_screen(widget->statusbar->screen), command))) { - widget->font = globalconf.screens[widget->statusbar->screen].font; - return WIDGET_ERROR_FORMAT_FONT; + if(widget->font != globalconf.screens[widget->statusbar->screen].font) + XftFontClose(globalconf.display, widget->font); + widget->font = newfont; } + else + return WIDGET_ERROR_FORMAT_FONT; } else if(!a_strcmp(property, "width")) d->width = atoi(command);