1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
2 * vim: ts=4 sw=4 noet ai cindent syntax=c
4 * Conky, a system monitor, based on torsmo
6 * Any original torsmo code is licensed under the BSD license
8 * All code written since the fork of torsmo is licensed under the GPL
10 * Please see COPYING for details
12 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
13 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
15 * All rights reserved.
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 int selected_font = 0;
36 struct font_list *fonts = NULL;
44 if (font_count > -1 && fonts[selected_font].font) {
45 XSetFont(display, window.gc, fonts[selected_font].font->fid);
49 void setup_fonts(void)
51 if ((output_methods & TO_X) == 0) {
57 XftDrawDestroy(window.xftdraw);
60 window.xftdraw = XftDrawCreate(display, window.drawable,
61 window.visual, window.colourmap);
67 int add_font(const char *data_in)
69 if ((output_methods & TO_X) == 0) {
72 if (font_count > MAX_FONTS) {
73 CRIT_ERR(NULL, NULL, "you don't need that many fonts, sorry.");
76 if (font_count == 0) {
80 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
82 CRIT_ERR(NULL, NULL, "malloc");
84 memset(fonts, 0, sizeof(struct font_list));
86 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
87 memset(&fonts[font_count], 0, sizeof(struct font_list));
89 CRIT_ERR(NULL, NULL, "realloc in add_font");
91 // must account for null terminator
92 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
93 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
95 fonts[font_count].font_alpha = 0xffff;
98 CRIT_ERR(NULL, NULL, "Oops...looks like something overflowed in add_font().");
103 void set_first_font(const char *data_in)
105 if ((output_methods & TO_X) == 0) {
108 if (font_count < 0) {
109 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
111 CRIT_ERR(NULL, NULL, "malloc");
113 memset(fonts, 0, sizeof(struct font_list));
116 if (strlen(data_in) > 1) {
117 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
119 fonts[0].font_alpha = 0xffff;
124 void free_fonts(void)
128 if ((output_methods & TO_X) == 0) {
131 if(fontloaded == 0) {
135 for (i = 0; i <= font_count; i++) {
138 XftFontClose(display, fonts[i].xftfont);
139 fonts[i].xftfont = 0;
143 XFreeFont(display, fonts[i].font);
152 if (window.xftdraw) {
153 XftDrawDestroy(window.xftdraw);
159 void load_fonts(void)
163 if ((output_methods & TO_X) == 0)
165 for (i = 0; i <= font_count; i++) {
168 if (use_xft && fonts[i].xftfont) {
170 } else if (use_xft) {
171 fonts[i].xftfont = XftFontOpenName(display, screen,
173 if (fonts[i].xftfont) {
177 NORM_ERR("can't load Xft font '%s'", fonts[i].name);
178 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
179 "courier-12")) != NULL) {
183 NORM_ERR("can't load Xft font '%s'", "courier-12");
185 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
186 CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");
193 /* load normal font */
194 if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
195 NORM_ERR("can't load font '%s'", fonts[i].name);
196 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
197 CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");