Mercurial > dwm-meillo
comparison draw.c @ 532:651f2c868b31
code polishing, removed unnecessary newlines
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Fri, 06 Oct 2006 11:50:15 +0200 |
parents | 451f19d48845 |
children | f05cfa7d5128 |
comparison
equal
deleted
inserted
replaced
531:96563762b4ad | 532:651f2c868b31 |
---|---|
1 /* | 1 /* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> |
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | 2 * See LICENSE file for license details. |
4 */ | 3 */ |
5 #include "dwm.h" | 4 #include "dwm.h" |
6 #include <stdio.h> | 5 #include <stdio.h> |
7 #include <string.h> | 6 #include <string.h> |
28 XGCValues gcv; | 27 XGCValues gcv; |
29 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 28 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
30 | 29 |
31 XSetForeground(dpy, dc.gc, col[ColBG]); | 30 XSetForeground(dpy, dc.gc, col[ColBG]); |
32 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | 31 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
33 | |
34 if(!text) | 32 if(!text) |
35 return; | 33 return; |
36 | |
37 w = 0; | 34 w = 0; |
38 olen = len = strlen(text); | 35 olen = len = strlen(text); |
39 if(len >= sizeof(buf)) | 36 if(len >= sizeof(buf)) |
40 len = sizeof(buf) - 1; | 37 len = sizeof(buf) - 1; |
41 memcpy(buf, text, len); | 38 memcpy(buf, text, len); |
42 buf[len] = 0; | 39 buf[len] = 0; |
43 | |
44 h = dc.font.ascent + dc.font.descent; | 40 h = dc.font.ascent + dc.font.descent; |
45 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | 41 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; |
46 x = dc.x + (h / 2); | 42 x = dc.x + (h / 2); |
47 | |
48 /* shorten text if necessary */ | 43 /* shorten text if necessary */ |
49 while(len && (w = textnw(buf, len)) > dc.w - h) | 44 while(len && (w = textnw(buf, len)) > dc.w - h) |
50 buf[--len] = 0; | 45 buf[--len] = 0; |
51 if(len < olen) { | 46 if(len < olen) { |
52 if(len > 1) | 47 if(len > 1) |
54 if(len > 2) | 49 if(len > 2) |
55 buf[len - 2] = '.'; | 50 buf[len - 2] = '.'; |
56 if(len > 3) | 51 if(len > 3) |
57 buf[len - 3] = '.'; | 52 buf[len - 3] = '.'; |
58 } | 53 } |
59 | |
60 if(w > dc.w) | 54 if(w > dc.w) |
61 return; /* too long */ | 55 return; /* too long */ |
62 gcv.foreground = col[ColFG]; | 56 gcv.foreground = col[ColFG]; |
63 if(dc.font.set) { | 57 if(dc.font.set) { |
64 XChangeGC(dpy, dc.gc, GCForeground, &gcv); | 58 XChangeGC(dpy, dc.gc, GCForeground, &gcv); |
91 void | 85 void |
92 drawstatus(void) { | 86 drawstatus(void) { |
93 int i, x; | 87 int i, x; |
94 | 88 |
95 dc.x = dc.y = 0; | 89 dc.x = dc.y = 0; |
96 | |
97 for(i = 0; i < ntags; i++) { | 90 for(i = 0; i < ntags; i++) { |
98 dc.w = textw(tags[i]); | 91 dc.w = textw(tags[i]); |
99 if(seltag[i]) | 92 if(seltag[i]) |
100 drawtext(tags[i], dc.sel, sel && sel->tags[i]); | 93 drawtext(tags[i], dc.sel, sel && sel->tags[i]); |
101 else | 94 else |
102 drawtext(tags[i], dc.norm, sel && sel->tags[i]); | 95 drawtext(tags[i], dc.norm, sel && sel->tags[i]); |
103 dc.x += dc.w; | 96 dc.x += dc.w; |
104 } | 97 } |
105 | |
106 dc.w = bmw; | 98 dc.w = bmw; |
107 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.status, False); | 99 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.status, False); |
108 | |
109 x = dc.x + dc.w; | 100 x = dc.x + dc.w; |
110 dc.w = textw(stext); | 101 dc.w = textw(stext); |
111 dc.x = bx + bw - dc.w; | 102 dc.x = bx + bw - dc.w; |
112 if(dc.x < x) { | 103 if(dc.x < x) { |
113 dc.x = x; | 104 dc.x = x; |
114 dc.w = bw - x; | 105 dc.w = bw - x; |
115 } | 106 } |
116 drawtext(stext, dc.status, False); | 107 drawtext(stext, dc.status, False); |
117 | |
118 if((dc.w = dc.x - x) > bh) { | 108 if((dc.w = dc.x - x) > bh) { |
119 dc.x = x; | 109 dc.x = x; |
120 if(sel) | 110 if(sel) |
121 drawtext(sel->name, dc.sel, False); | 111 drawtext(sel->name, dc.sel, False); |
122 else | 112 else |
132 drawstatus(); | 122 drawstatus(); |
133 XUnmapWindow(dpy, c->twin); | 123 XUnmapWindow(dpy, c->twin); |
134 XSetWindowBorder(dpy, c->win, dc.sel[ColBG]); | 124 XSetWindowBorder(dpy, c->win, dc.sel[ColBG]); |
135 return; | 125 return; |
136 } | 126 } |
137 | |
138 XSetWindowBorder(dpy, c->win, dc.norm[ColBG]); | 127 XSetWindowBorder(dpy, c->win, dc.norm[ColBG]); |
139 XMapWindow(dpy, c->twin); | 128 XMapWindow(dpy, c->twin); |
140 dc.x = dc.y = 0; | 129 dc.x = dc.y = 0; |
141 dc.w = c->tw; | 130 dc.w = c->tw; |
142 drawtext(c->name, dc.norm, False); | 131 drawtext(c->name, dc.norm, False); |
175 } | 164 } |
176 if(dc.font.set) { | 165 if(dc.font.set) { |
177 XFontSetExtents *font_extents; | 166 XFontSetExtents *font_extents; |
178 XFontStruct **xfonts; | 167 XFontStruct **xfonts; |
179 char **font_names; | 168 char **font_names; |
180 | |
181 dc.font.ascent = dc.font.descent = 0; | 169 dc.font.ascent = dc.font.descent = 0; |
182 font_extents = XExtentsOfFontSet(dc.font.set); | 170 font_extents = XExtentsOfFontSet(dc.font.set); |
183 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | 171 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); |
184 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | 172 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { |
185 if(dc.font.ascent < (*xfonts)->ascent) | 173 if(dc.font.ascent < (*xfonts)->ascent) |