X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Ffonts.c;h=6067bf2327ba1a5d0f07c5c39c398e980bab9cfa;hb=6526b47b2c63c9f46b63d3a5e72cbe71b04d60ac;hp=10f2186b9a58e838ad402362391cdf485d7b1db0;hpb=f05829ad9a32082fa80c43a921471716ce76d22b;p=monky diff --git a/src/fonts.c b/src/fonts.c index 10f2186..6067bf2 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -1,4 +1,7 @@ -/* Conky, a system monitor, based on torsmo +/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- + * vim: ts=4 sw=4 noet ai cindent syntax=c + * + * Conky, a system monitor, based on torsmo * * Any original torsmo code is licensed under the BSD license * @@ -7,7 +10,7 @@ * Please see COPYING for details * * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen - * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. * (see AUTHORS) * All rights reserved. * @@ -31,31 +34,43 @@ int selected_font = 0; int font_count = -1; struct font_list *fonts = NULL; +char fontloaded = 0; void set_font(void) { - if ((output_methods & TO_X) == 0) +#ifdef XFT + if (use_xft) return; +#endif /* XFT */ + if (font_count > -1 && fonts[selected_font].font) { + XSetFont(display, window.gc, fonts[selected_font].font->fid); + } +} + +void setup_fonts(void) +{ + if ((output_methods & TO_X) == 0) { return; + } #ifdef XFT if (use_xft) { - if (window.xftdraw != NULL) { + if (window.xftdraw) { XftDrawDestroy(window.xftdraw); + window.xftdraw = 0; } window.xftdraw = XftDrawCreate(display, window.drawable, - DefaultVisual(display, screen), DefaultColormap(display, screen)); - } else -#endif - { - XSetFont(display, window.gc, fonts[selected_font].font->fid); + window.visual, window.colourmap); } +#endif /* XFT */ + set_font(); } -int addfont(const char *data_in) +int add_font(const char *data_in) { - if ((output_methods & TO_X) == 0) + if ((output_methods & TO_X) == 0) { return 0; + } if (font_count > MAX_FONTS) { - CRIT_ERR("you don't need that many fonts, sorry."); + CRIT_ERR(NULL, NULL, "you don't need that many fonts, sorry."); } font_count++; if (font_count == 0) { @@ -64,14 +79,14 @@ int addfont(const char *data_in) } if ((fonts = (struct font_list *) malloc(sizeof(struct font_list))) == NULL) { - CRIT_ERR("malloc"); + CRIT_ERR(NULL, NULL, "malloc"); } memset(fonts, 0, sizeof(struct font_list)); } fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1))); memset(&fonts[font_count], 0, sizeof(struct font_list)); if (fonts == NULL) { - CRIT_ERR("realloc in addfont"); + CRIT_ERR(NULL, NULL, "realloc in add_font"); } // must account for null terminator if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) { @@ -80,19 +95,20 @@ int addfont(const char *data_in) fonts[font_count].font_alpha = 0xffff; #endif } else { - CRIT_ERR("Oops...looks like something overflowed in addfont()."); + CRIT_ERR(NULL, NULL, "Oops...looks like something overflowed in add_font()."); } return font_count; } void set_first_font(const char *data_in) { - if ((output_methods & TO_X) == 0) + if ((output_methods & TO_X) == 0) { return; + } if (font_count < 0) { if ((fonts = (struct font_list *) malloc(sizeof(struct font_list))) == NULL) { - CRIT_ERR("malloc"); + CRIT_ERR(NULL, NULL, "malloc"); } memset(fonts, 0, sizeof(struct font_list)); font_count++; @@ -109,15 +125,26 @@ void free_fonts(void) { int i; - if ((output_methods & TO_X) == 0) + if ((output_methods & TO_X) == 0) { return; + } + if(fontloaded == 0) { + free(fonts); + return; + } for (i = 0; i <= font_count; i++) { #ifdef XFT if (use_xft) { - XftFontClose(display, fonts[i].xftfont); + /* + * Do we not need to close fonts with Xft? Unsure. Not freeing the + * fonts seems to incur a slight memory leak, but it also prevents + * a crash. + * + * XftFontClose(display, fonts[i].xftfont); + */ fonts[i].xftfont = 0; } else -#endif +#endif /* XFT */ { XFreeFont(display, fonts[i].font); fonts[i].font = 0; @@ -127,6 +154,12 @@ void free_fonts(void) fonts = 0; font_count = -1; selected_font = 0; +#ifdef XFT + if (window.xftdraw) { + XftDrawDestroy(window.xftdraw); + window.xftdraw = 0; + } +#endif /* XFT */ } void load_fonts(void) @@ -141,25 +174,22 @@ void load_fonts(void) if (use_xft && fonts[i].xftfont) { continue; } else if (use_xft) { - /* if (fonts[i].xftfont != NULL && selected_font == 0) { - XftFontClose(display, fonts[i].xftfont); - } */ fonts[i].xftfont = XftFontOpenName(display, screen, fonts[i].name); - if (fonts[i].xftfont != NULL) { + if (fonts[i].xftfont) { continue; } - ERR("can't load Xft font '%s'", fonts[i].name); + NORM_ERR("can't load Xft font '%s'", fonts[i].name); if ((fonts[i].xftfont = XftFontOpenName(display, screen, "courier-12")) != NULL) { continue; } - ERR("can't load Xft font '%s'", "courier-12"); + NORM_ERR("can't load Xft font '%s'", "courier-12"); if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { - CRIT_ERR("can't load font '%s'", "fixed"); + CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); } use_xft = 0; @@ -167,17 +197,12 @@ void load_fonts(void) } #endif /* load normal font */ - /* if (fonts[i].font != NULL) { - XFreeFont(display, fonts[i].font); - } */ - - if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) { - ERR("can't load font '%s'", fonts[i].name); + if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) { + NORM_ERR("can't load font '%s'", fonts[i].name); if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) { - CRIT_ERR("can't load font '%s'", "fixed"); - printf("loaded fixed?\n"); + CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed"); } } } + fontloaded = 1; } -