1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31 int selected_font = 0;
33 struct font_list *fonts = NULL;
40 if (font_count > -1 && fonts[selected_font].font) {
41 XSetFont(display, window.gc, fonts[selected_font].font->fid);
45 void setup_fonts(void)
47 if ((output_methods & TO_X) == 0) {
53 XftDrawDestroy(window.xftdraw);
55 window.xftdraw = XftDrawCreate(display, window.drawable,
56 DefaultVisual(display, screen), DefaultColormap(display, screen));
62 int add_font(const char *data_in)
64 if ((output_methods & TO_X) == 0) {
67 if (font_count > MAX_FONTS) {
68 CRIT_ERR("you don't need that many fonts, sorry.");
71 if (font_count == 0) {
75 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
79 memset(fonts, 0, sizeof(struct font_list));
81 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
82 memset(&fonts[font_count], 0, sizeof(struct font_list));
84 CRIT_ERR("realloc in add_font");
86 // must account for null terminator
87 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
88 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
90 fonts[font_count].font_alpha = 0xffff;
93 CRIT_ERR("Oops...looks like something overflowed in add_font().");
98 void set_first_font(const char *data_in)
100 if ((output_methods & TO_X) == 0) {
103 if (font_count < 0) {
104 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
108 memset(fonts, 0, sizeof(struct font_list));
111 if (strlen(data_in) > 1) {
112 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
114 fonts[0].font_alpha = 0xffff;
119 void free_fonts(void)
123 if ((output_methods & TO_X) == 0) {
126 for (i = 0; i <= font_count; i++) {
129 XftFontClose(display, fonts[i].xftfont);
130 fonts[i].xftfont = 0;
134 XFreeFont(display, fonts[i].font);
143 if (window.xftdraw) {
144 XftDrawDestroy(window.xftdraw);
150 void load_fonts(void)
154 if ((output_methods & TO_X) == 0)
156 for (i = 0; i <= font_count; i++) {
159 if (use_xft && fonts[i].xftfont) {
161 } else if (use_xft) {
162 fonts[i].xftfont = XftFontOpenName(display, screen,
164 if (fonts[i].xftfont) {
168 ERR("can't load Xft font '%s'", fonts[i].name);
169 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
170 "courier-12")) != NULL) {
174 ERR("can't load Xft font '%s'", "courier-12");
176 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
177 CRIT_ERR("can't load font '%s'", "fixed");
184 /* load normal font */
185 if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
186 ERR("can't load font '%s'", fonts[i].name);
187 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
188 CRIT_ERR("can't load font '%s'", "fixed");