1 /* resources.c - manage X resources (fonts, colors etc)
3 * Window Maker window manager
5 * Copyright (c) 1997, 1998 Alfredo K. Kojima
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,
30 #include <X11/Xutil.h>
34 #include "WindowMaker.h"
41 *----------------------------------------------------------------------
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.
48 * The font structure or NULL on error.
50 *----------------------------------------------------------------------
53 wLoadFont(char *font_name
)
63 font
= malloc(sizeof(WFont
));
68 font
->font
= XCreateFontSet(dpy
, font_name
, &missing
, &num_missing
,
70 if (num_missing
> 0 && font
->font
) {
71 wwarning(_("The following character sets are missing in %s:"),
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"),
78 wwarning(_("of any characters from those sets."));
81 wwarning(_("could not create font set %s. Trying fixed"), font_name
);
82 font
->font
= XCreateFontSet(dpy
, "-*-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*",
83 &missing
, &num_missing
, &default_string
);
84 if (num_missing
> 0) {
85 XFreeStringList(missing
);
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
;
96 font
->font
= XLoadQueryFont(dpy
, font_name
);
98 wwarning(_("could not load font %s. Trying fixed"), font_name
);
99 font
->font
= XLoadQueryFont(dpy
, "fixed");
105 font
->height
= font
->font
->ascent
+font
->font
->descent
;
106 font
->y
= font
->font
->ascent
;
107 #endif /* !I18N_MB */
115 wFreeFont(WFont
*font
)
118 XFreeFontSet(dpy
, font
->font
);
120 XFreeFont(dpy
, font
->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
->w_colormap
, color_name
, color
)) {
136 wwarning(_("could not parse color \"%s\""), color_name
);
139 if (!XAllocColor(dpy
, scr
->w_colormap
, color
)) {
140 wwarning(_("could not allocate color \"%s\""), color_name
);
148 wFreeColor(WScreen
*scr
, unsigned long pixel
)
150 if (pixel
!=scr
->white_pixel
&& pixel
!=scr
->black_pixel
) {
151 unsigned long colors
[1];
154 XFreeColors(dpy
, scr
->w_colormap
, colors
, 1, 0);