Free the previously opened font if changing it via widget_tell in textbox

This commit is contained in:
Julien Danjou 2008-03-13 08:06:01 +01:00
parent 77827ee364
commit 5f26ab448c
1 changed files with 9 additions and 5 deletions

View File

@ -68,6 +68,7 @@ static widget_tell_status_t
textbox_tell(Widget *widget, char *property, char *command) textbox_tell(Widget *widget, char *property, char *command)
{ {
Data *d = widget->data; Data *d = widget->data;
XftFont *newfont;
if(!command) if(!command)
return WIDGET_ERROR_NOVALUE; return WIDGET_ERROR_NOVALUE;
@ -90,13 +91,16 @@ textbox_tell(Widget *widget, char *property, char *command)
return WIDGET_ERROR_FORMAT_COLOR; return WIDGET_ERROR_FORMAT_COLOR;
else if(!a_strcmp(property, "font")) else if(!a_strcmp(property, "font"))
{ {
widget->font = XftFontOpenName(globalconf.display, if(a_strlen(command)
get_phys_screen(widget->statusbar->screen), command); && (newfont = XftFontOpenName(globalconf.display,
if(!widget->font) get_phys_screen(widget->statusbar->screen), command)))
{ {
widget->font = globalconf.screens[widget->statusbar->screen].font; if(widget->font != globalconf.screens[widget->statusbar->screen].font)
return WIDGET_ERROR_FORMAT_FONT; XftFontClose(globalconf.display, widget->font);
widget->font = newfont;
} }
else
return WIDGET_ERROR_FORMAT_FONT;
} }
else if(!a_strcmp(property, "width")) else if(!a_strcmp(property, "width"))
d->width = atoi(command); d->width = atoi(command);