summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-20 13:46:21 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-20 13:46:21 +0100
commite7508783e85aba0ce4ab09b0dd76c40342113aed (patch)
tree849f33eb5182d16668b77bc9fbdd7e8e4e2dc3dd /main.c
parentseparating drawsquare from drawtext, made drawtext extern (diff)
downloaddwm-e7508783e85aba0ce4ab09b0dd76c40342113aed.tar.gz
dwm-e7508783e85aba0ce4ab09b0dd76c40342113aed.zip
added draw.c again (except getcolor and setfont which are helpers in main.c)
Diffstat (limited to 'main.c')
-rw-r--r--main.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/main.c b/main.c
index 9e6f5e3..1015017 100644
--- a/main.c
+++ b/main.c
@@ -61,38 +61,6 @@ cleanup(void) {
61 free(seltag); 61 free(seltag);
62} 62}
63 63
64static unsigned int
65textnw(const char *text, unsigned int len) {
66 XRectangle r;
67
68 if(dc.font.set) {
69 XmbTextExtents(dc.font.set, text, len, NULL, &r);
70 return r.width;
71 }
72 return XTextWidth(dc.font.xfont, text, len);
73}
74
75static void
76drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
77 int x;
78 XGCValues gcv;
79 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
80
81 gcv.foreground = col[ColFG];
82 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
83 x = (dc.font.ascent + dc.font.descent + 2) / 4;
84 r.x = dc.x + 1;
85 r.y = dc.y + 1;
86 if(filled) {
87 r.width = r.height = x + 1;
88 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
89 }
90 else if(empty) {
91 r.width = r.height = x;
92 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
93 }
94}
95
96static unsigned long 64static unsigned long
97getcolor(const char *colstr) { 65getcolor(const char *colstr) {
98 Colormap cmap = DefaultColormap(dpy, screen); 66 Colormap cmap = DefaultColormap(dpy, screen);
@@ -103,16 +71,6 @@ getcolor(const char *colstr) {
103 return color.pixel; 71 return color.pixel;
104} 72}
105 73
106static Bool
107isoccupied(unsigned int t) {
108 Client *c;
109
110 for(c = clients; c; c = c->next)
111 if(c->tags[t])
112 return True;
113 return False;
114}
115
116static void 74static void
117scan(void) { 75scan(void) {
118 unsigned int i, num; 76 unsigned int i, num;
@@ -264,87 +222,6 @@ xerrorstart(Display *dsply, XErrorEvent *ee) {
264/* extern */ 222/* extern */
265 223
266void 224void
267drawstatus(void) {
268 int i, x;
269
270 dc.x = dc.y = 0;
271 for(i = 0; i < ntags; i++) {
272 dc.w = textw(tags[i]);
273 if(seltag[i]) {
274 drawtext(tags[i], dc.sel);
275 drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
276 }
277 else {
278 drawtext(tags[i], dc.norm);
279 drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
280 }
281 dc.x += dc.w;
282 }
283 dc.w = blw;
284 drawtext(lt->symbol, dc.norm);
285 x = dc.x + dc.w;
286 dc.w = textw(stext);
287 dc.x = sw - dc.w;
288 if(dc.x < x) {
289 dc.x = x;
290 dc.w = sw - x;
291 }
292 drawtext(stext, dc.norm);
293 if((dc.w = dc.x - x) > bh) {
294 dc.x = x;
295 drawtext(sel ? sel->name : NULL, sel ? dc.sel : dc.norm);
296 }
297 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
298 XSync(dpy, False);
299}
300
301void
302drawtext(const char *text, unsigned long col[ColLast]) {
303 int x, y, w, h;
304 static char buf[256];
305 unsigned int len, olen;
306 XGCValues gcv;
307 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
308
309 XSetForeground(dpy, dc.gc, col[ColBG]);
310 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
311 if(!text)
312 return;
313 w = 0;
314 olen = len = strlen(text);
315 if(len >= sizeof buf)
316 len = sizeof buf - 1;
317 memcpy(buf, text, len);
318 buf[len] = 0;
319 h = dc.font.ascent + dc.font.descent;
320 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
321 x = dc.x + (h / 2);
322 /* shorten text if necessary */
323 while(len && (w = textnw(buf, len)) > dc.w - h)
324 buf[--len] = 0;
325 if(len < olen) {
326 if(len > 1)
327 buf[len - 1] = '.';
328 if(len > 2)
329 buf[len - 2] = '.';
330 if(len > 3)
331 buf[len - 3] = '.';
332 }
333 if(w > dc.w)
334 return; /* too long */
335 gcv.foreground = col[ColFG];
336 if(dc.font.set) {
337 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
338 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
339 }
340 else {
341 gcv.font = dc.font.xfont->fid;
342 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
343 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
344 }
345}
346
347void
348sendevent(Window w, Atom a, long value) { 225sendevent(Window w, Atom a, long value) {
349 XEvent e; 226 XEvent e;
350 227
@@ -358,11 +235,6 @@ sendevent(Window w, Atom a, long value) {
358 XSync(dpy, False); 235 XSync(dpy, False);
359} 236}
360 237
361unsigned int
362textw(const char *text) {
363 return textnw(text, strlen(text)) + dc.font.height;
364}
365
366void 238void
367quit(Arg *arg) { 239quit(Arg *arg) {
368 readin = running = False; 240 readin = running = False;