1 /* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
3 * Conky, a system monitor, based on torsmo
5 * Any original torsmo code is licensed under the BSD license
7 * All code written since the fork of torsmo is licensed under the GPL
9 * Please see COPYING for details
11 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
12 * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
14 * All rights reserved.
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * vim: ts=4 sw=4 noet ai cindent syntax=c
35 int selected_font = 0;
37 struct font_list *fonts = NULL;
45 if (font_count > -1 && fonts[selected_font].font) {
46 XSetFont(display, window.gc, fonts[selected_font].font->fid);
50 void setup_fonts(void)
52 if ((output_methods & TO_X) == 0) {
58 XftDrawDestroy(window.xftdraw);
61 window.xftdraw = XftDrawCreate(display, window.drawable,
62 DefaultVisual(display, screen), DefaultColormap(display, screen));
68 int add_font(const char *data_in)
70 if ((output_methods & TO_X) == 0) {
73 if (font_count > MAX_FONTS) {
74 CRIT_ERR(NULL, NULL, "you don't need that many fonts, sorry.");
77 if (font_count == 0) {
81 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
83 CRIT_ERR(NULL, NULL, "malloc");
85 memset(fonts, 0, sizeof(struct font_list));
87 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
88 memset(&fonts[font_count], 0, sizeof(struct font_list));
90 CRIT_ERR(NULL, NULL, "realloc in add_font");
92 // must account for null terminator
93 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
94 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
96 fonts[font_count].font_alpha = 0xffff;
99 CRIT_ERR(NULL, NULL, "Oops...looks like something overflowed in add_font().");
104 void set_first_font(const char *data_in)
106 if ((output_methods & TO_X) == 0) {
109 if (font_count < 0) {
110 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
112 CRIT_ERR(NULL, NULL, "malloc");
114 memset(fonts, 0, sizeof(struct font_list));
117 if (strlen(data_in) > 1) {
118 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
120 fonts[0].font_alpha = 0xffff;
125 void free_fonts(void)
129 if ((output_methods & TO_X) == 0) {
132 if(fontloaded == 0) {
136 for (i = 0; i <= font_count; i++) {
139 XftFontClose(display, fonts[i].xftfont);
140 fonts[i].xftfont = 0;
144 XFreeFont(display, fonts[i].font);
153 if (window.xftdraw) {
154 XftDrawDestroy(window.xftdraw);
160 void load_fonts(void)
164 if ((output_methods & TO_X) == 0)
166 for (i = 0; i <= font_count; i++) {
169 if (use_xft && fonts[i].xftfont) {
171 } else if (use_xft) {
172 fonts[i].xftfont = XftFontOpenName(display, screen,
174 if (fonts[i].xftfont) {
178 NORM_ERR("can't load Xft font '%s'", fonts[i].name);
179 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
180 "courier-12")) != NULL) {
184 NORM_ERR("can't load Xft font '%s'", "courier-12");
186 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
187 CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");
194 /* load normal font */
195 if (!fonts[i].font && (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
196 NORM_ERR("can't load font '%s'", fonts[i].name);
197 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
198 CRIT_ERR(NULL, NULL, "can't load font '%s'", "fixed");