Initial revision
[wmaker-crm.git] / src / resources.c
blob9859ea1e4dcf6ed83c3d4268c7b2f612b4b1290e
1 /* resources.c - manage X resources (fonts, colors etc)
2 *
3 * WindowMaker window manager
4 *
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 * USA.
23 #include "wconfig.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 #include <X11/Xlib.h>
30 #include <X11/Xutil.h>
32 #include <wraster.h>
34 #include "WindowMaker.h"
35 #include "texture.h"
36 #include "screen.h"
37 #include "pixmap.h"
41 *----------------------------------------------------------------------
42 * wLoadFont--
43 * Loads a single font into a WFont structure, initializing
44 * data in it. If the font could not be loaded, fixed will be used.
45 * If fixed can't be loaded either, the function returns NULL.
47 * Returns:
48 * The font structure or NULL on error.
50 *----------------------------------------------------------------------
52 WFont*
53 wLoadFont(char *font_name)
55 WFont *font;
56 #ifdef I18N_MB
57 char **missing;
58 int num_missing = 0;
59 char *default_string;
60 int skyline;
61 #endif
63 font = malloc(sizeof(WFont));
64 if (!font)
65 return NULL;
67 #ifdef I18N_MB
68 font->font = XCreateFontSet(dpy, font_name, &missing, &num_missing,
69 &default_string);
70 if (num_missing > 0 && font->font) {
71 wwarning(_("The following character sets are missing in %s:"),
72 font_name);
73 for (skyline = 0; skyline < num_missing; skyline++)
74 wwarning(missing[skyline]);
75 XFreeStringList(missing);
76 wwarning(_("The string \"%s\" will be used in place"),
77 default_string);
78 wwarning(_("of any characters from those sets."));
80 if (!font->font) {
81 wwarning(_("could not create font set %s. Trying fixed"), font_name);
82 font->font = XCreateFontSet(dpy, "fixed", &missing, &num_missing,
83 &default_string);
84 if (num_missing > 0) {
85 XFreeStringList(missing);
87 if (!font->font) {
88 free(font);
89 return NULL;
92 font->height = XExtentsOfFontSet(font->font)->max_logical_extent.height;
93 font->y = font->height+XExtentsOfFontSet(font->font)->max_logical_extent.y;
94 font->y = font->height-font->y;
95 #else
96 font->font = XLoadQueryFont(dpy, font_name);
97 if (!font->font) {
98 wwarning(_("could not load font %s. Trying fixed"), font_name);
99 font->font = XLoadQueryFont(dpy, "fixed");
100 if (!font->font) {
101 free(font);
102 return NULL;
105 font->height = font->font->ascent+font->font->descent;
106 font->y = font->font->ascent;
107 #endif /* !I18N_MB */
109 return font;
114 void
115 wFreeFont(WFont *font)
117 #ifdef I18N_MB
118 XFreeFontSet(dpy, font->font);
119 #else
120 XFreeFont(dpy, font->font);
121 #endif
122 free(font);
127 * wfatal(_("could not load any usable font set"));
128 wfatal(_("could not load any usable font"));
133 wGetColor(WScreen *scr, char *color_name, XColor *color)
135 if (!XParseColor(dpy, scr->colormap, color_name, color)) {
136 wwarning(_("could not parse color \"%s\""), color_name);
137 return False;
139 if (!XAllocColor(dpy, scr->colormap, color)) {
140 wwarning(_("could not allocate color \"%s\""), color_name);
141 return False;
143 return True;
147 void
148 wFreeColor(WScreen *scr, unsigned long pixel)
150 if (pixel!=scr->white_pixel && pixel!=scr->black_pixel) {
151 unsigned long colors[1];
153 colors[0] = pixel;
154 XFreeColors(dpy, scr->colormap, colors, 1, 0);