summaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-13 11:43:05 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-13 11:43:05 +0200
commit9e8b3258a06de01c53e60243ffe3419b47d016dd (patch)
treea39ebed6cc97e75dc71f7ffb54ebb66342fef48d /draw.c
parentadded dev.c instead of kb.c (diff)
downloaddwm-9e8b3258a06de01c53e60243ffe3419b47d016dd.tar.gz
dwm-9e8b3258a06de01c53e60243ffe3419b47d016dd.zip
changed default colors
Diffstat (limited to '')
-rw-r--r--draw.c89
1 files changed, 38 insertions, 51 deletions
diff --git a/draw.c b/draw.c
index 455c137..fc269a2 100644
--- a/draw.c
+++ b/draw.c
@@ -8,7 +8,7 @@
8 8
9#include <X11/Xlocale.h> 9#include <X11/Xlocale.h>
10 10
11#include "wm.h" 11#include "dwm.h"
12 12
13static void 13static void
14drawborder(void) 14drawborder(void)
@@ -59,7 +59,7 @@ draw(Bool border, const char *text)
59 x = dc.x + (h / 2); 59 x = dc.x + (h / 2);
60 60
61 /* shorten text if necessary */ 61 /* shorten text if necessary */
62 while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h) 62 while(len && (w = textnw(buf, len)) > dc.w - h)
63 buf[--len] = 0; 63 buf[--len] = 0;
64 64
65 if(w > dc.w) 65 if(w > dc.w)
@@ -79,93 +79,80 @@ draw(Bool border, const char *text)
79 } 79 }
80} 80}
81 81
82static unsigned long 82unsigned long
83xinitcolors(Colormap cmap, const char *colstr) 83initcolor(const char *colstr)
84{ 84{
85 XColor color; 85 XColor color;
86 Colormap cmap = DefaultColormap(dpy, screen);
87
86 XAllocNamedColor(dpy, cmap, colstr, &color, &color); 88 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
87 return color.pixel; 89 return color.pixel;
88} 90}
89 91
90void
91initcolors(const char *bg, const char *fg, const char *border)
92{
93 Colormap cmap = DefaultColormap(dpy, screen);
94 dc.bg = xinitcolors(cmap, bg);
95 dc.fg = xinitcolors(cmap, fg);
96 dc.border = xinitcolors(cmap, border);
97}
98
99unsigned int 92unsigned int
100textnw(Fnt *font, char *text, unsigned int len) 93textnw(char *text, unsigned int len)
101{ 94{
102 XRectangle r; 95 XRectangle r;
103 if(font->set) { 96 if(dc.font.set) {
104 XmbTextExtents(font->set, text, len, NULL, &r); 97 XmbTextExtents(dc.font.set, text, len, NULL, &r);
105 return r.width; 98 return r.width;
106 } 99 }
107 return XTextWidth(font->xfont, text, len); 100 return XTextWidth(dc.font.xfont, text, len);
108}
109
110unsigned int
111textw(Fnt *font, char *text)
112{
113 return textnw(font, text, strlen(text));
114} 101}
115 102
116unsigned int 103unsigned int
117texth(Fnt *font) 104textw(char *text)
118{ 105{
119 return font->height + 4; 106 return textnw(text, strlen(text));
120} 107}
121 108
122void 109void
123initfont(Fnt *font, const char *fontstr) 110initfont(const char *fontstr)
124{ 111{
125 char **missing, *def; 112 char **missing, *def;
126 int i, n; 113 int i, n;
127 114
128 missing = NULL; 115 missing = NULL;
129 setlocale(LC_ALL, ""); 116 setlocale(LC_ALL, "");
130 if(font->set) 117 if(dc.font.set)
131 XFreeFontSet(dpy, font->set); 118 XFreeFontSet(dpy, dc.font.set);
132 font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); 119 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
133 if(missing) { 120 if(missing) {
134 while(n--) 121 while(n--)
135 fprintf(stderr, "missing fontset: %s\n", missing[n]); 122 fprintf(stderr, "missing fontset: %s\n", missing[n]);
136 XFreeStringList(missing); 123 XFreeStringList(missing);
137 if(font->set) { 124 if(dc.font.set) {
138 XFreeFontSet(dpy, font->set); 125 XFreeFontSet(dpy, dc.font.set);
139 font->set = NULL; 126 dc.font.set = NULL;
140 } 127 }
141 } 128 }
142 if(font->set) { 129 if(dc.font.set) {
143 XFontSetExtents *font_extents; 130 XFontSetExtents *font_extents;
144 XFontStruct **xfonts; 131 XFontStruct **xfonts;
145 char **font_names; 132 char **font_names;
146 133
147 font->ascent = font->descent = 0; 134 dc.font.ascent = dc.font.descent = 0;
148 font_extents = XExtentsOfFontSet(font->set); 135 font_extents = XExtentsOfFontSet(dc.font.set);
149 n = XFontsOfFontSet(font->set, &xfonts, &font_names); 136 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
150 for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) { 137 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
151 if(font->ascent < (*xfonts)->ascent) 138 if(dc.font.ascent < (*xfonts)->ascent)
152 font->ascent = (*xfonts)->ascent; 139 dc.font.ascent = (*xfonts)->ascent;
153 if(font->descent < (*xfonts)->descent) 140 if(dc.font.descent < (*xfonts)->descent)
154 font->descent = (*xfonts)->descent; 141 dc.font.descent = (*xfonts)->descent;
155 xfonts++; 142 xfonts++;
156 } 143 }
157 } 144 }
158 else { 145 else {
159 if(font->xfont) 146 if(dc.font.xfont)
160 XFreeFont(dpy, font->xfont); 147 XFreeFont(dpy, dc.font.xfont);
161 font->xfont = NULL; 148 dc.font.xfont = NULL;
162 font->xfont = XLoadQueryFont(dpy, fontstr); 149 dc.font.xfont = XLoadQueryFont(dpy, fontstr);
163 if (!font->xfont) 150 if (!dc.font.xfont)
164 font->xfont = XLoadQueryFont(dpy, "fixed"); 151 dc.font.xfont = XLoadQueryFont(dpy, "fixed");
165 if (!font->xfont) 152 if (!dc.font.xfont)
166 error("error, cannot init 'fixed' font\n"); 153 error("error, cannot init 'fixed' font\n");
167 font->ascent = font->xfont->ascent; 154 dc.font.ascent = dc.font.xfont->ascent;
168 font->descent = font->xfont->descent; 155 dc.font.descent = dc.font.xfont->descent;
169 } 156 }
170 font->height = font->ascent + font->descent; 157 dc.font.height = dc.font.ascent + dc.font.descent;
171} 158}