Mercurial > aewl
annotate draw.c @ 347:e438c8ba86f6
yet another fix
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Thu, 24 Aug 2006 10:20:00 +0200 |
parents | 977585eb2d35 |
children | b10852dbbffe |
rev | line source |
---|---|
2 | 1 /* |
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | |
4 */ | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
5 #include "dwm.h" |
2 | 6 #include <stdio.h> |
7 #include <string.h> | |
32 | 8 #include <X11/Xlocale.h> |
9 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
10 /* static */ |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
11 |
77 | 12 static unsigned int |
173
1db04019684e
changed Client->tags and Rule->tags to be Bool (I'll also try to remove the TLast enum)
arg@10ksloc.org
parents:
164
diff
changeset
|
13 textnw(const char *text, unsigned int len) |
75 | 14 { |
77 | 15 XRectangle r; |
123 | 16 |
77 | 17 if(dc.font.set) { |
18 XmbTextExtents(dc.font.set, text, len, NULL, &r); | |
19 return r.width; | |
20 } | |
21 return XTextWidth(dc.font.xfont, text, len); | |
75 | 22 } |
23 | |
77 | 24 static void |
345 | 25 drawtext(const char *text, Bool invert, Bool highlight) |
2 | 26 { |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
27 int x, y, w, h; |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
28 static char buf[256]; |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
29 unsigned int len, olen; |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
30 XGCValues gcv; |
257 | 31 XPoint points[5]; |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
32 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
33 |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
34 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); |
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
35 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
257 | 36 points[0].x = dc.x; |
37 points[0].y = dc.y; | |
38 points[1].x = dc.w - 1; | |
39 points[1].y = 0; | |
40 points[2].x = 0; | |
41 points[2].y = dc.h - 1; | |
42 points[3].x = -(dc.w - 1); | |
43 points[3].y = 0; | |
44 points[4].x = 0; | |
45 points[4].y = -(dc.h - 1); | |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
46 XSetForeground(dpy, dc.gc, dc.border); |
257 | 47 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); |
237
7f8f7f14e9cd
readded border color, this sucks least
Anselm R.Garbe <arg@10ksloc.org>
parents:
236
diff
changeset
|
48 |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
49 if(!text) |
2 | 50 return; |
51 | |
218 | 52 w = 0; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
53 olen = len = strlen(text); |
2 | 54 if(len >= sizeof(buf)) |
55 len = sizeof(buf) - 1; | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
56 memcpy(buf, text, len); |
2 | 57 buf[len] = 0; |
58 | |
34 | 59 h = dc.font.ascent + dc.font.descent; |
60 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | |
61 x = dc.x + (h / 2); | |
2 | 62 |
63 /* shorten text if necessary */ | |
43 | 64 while(len && (w = textnw(buf, len)) > dc.w - h) |
2 | 65 buf[--len] = 0; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
66 if(len < olen) { |
273 | 67 if(len > 1) |
68 buf[len - 1] = '.'; | |
69 if(len > 2) | |
70 buf[len - 2] = '.'; | |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
71 if(len > 3) |
273 | 72 buf[len - 3] = '.'; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
73 } |
2 | 74 |
34 | 75 if(w > dc.w) |
2 | 76 return; /* too long */ |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
77 gcv.foreground = invert ? dc.bg : dc.fg; |
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
78 gcv.background = invert ? dc.fg : dc.bg; |
34 | 79 if(dc.font.set) { |
80 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); | |
342 | 81 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); |
2 | 82 } |
83 else { | |
34 | 84 gcv.font = dc.font.xfont->fid; |
85 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); | |
342 | 86 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
87 } | |
345 | 88 if(highlight) { |
89 points[0].x = dc.x + 1; | |
90 points[0].y = dc.y + 1; | |
91 points[1].x = dc.w - 3; | |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
92 points[1].y = 0; |
345 | 93 points[2].x = 0; |
94 points[2].y = dc.h - 3; | |
95 points[3].x = -(dc.w - 3); | |
96 points[3].y = 0; | |
97 points[4].x = 0; | |
98 points[4].y = -(dc.h - 3); | |
99 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); | |
2 | 100 } |
101 } | |
102 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
103 /* extern */ |
77 | 104 |
105 void | |
106 drawall() | |
107 { | |
108 Client *c; | |
109 | |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
124
diff
changeset
|
110 for(c = clients; c; c = getnext(c->next)) |
77 | 111 drawtitle(c); |
112 drawstatus(); | |
113 } | |
114 | |
115 void | |
116 drawstatus() | |
117 { | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
118 int i, x; |
77 | 119 Bool istile = arrange == dotile; |
120 | |
121 dc.x = dc.y = 0; | |
122 dc.w = bw; | |
342 | 123 drawtext(NULL, !istile, False); |
77 | 124 |
125 dc.w = 0; | |
178
e848966a1ac6
removed TLast tag enum, now tags is simple defined as char *[] array, the rest is calculated correctly, rules take an int array for the tags
arg@10ksloc.org
parents:
173
diff
changeset
|
126 for(i = 0; i < ntags; i++) { |
77 | 127 dc.x += dc.w; |
128 dc.w = textw(tags[i]); | |
129 if(istile) | |
342 | 130 drawtext(tags[i], seltag[i], sel && sel->tags[i]); |
77 | 131 else |
342 | 132 drawtext(tags[i], !seltag[i], sel && sel->tags[i]); |
77 | 133 } |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
134 x = dc.x + dc.w; |
77 | 135 dc.w = textw(stext); |
136 dc.x = bx + bw - dc.w; | |
342 | 137 if(dc.x < x) { |
138 dc.x = x; | |
139 dc.w = bw - x; | |
140 } | |
141 drawtext(stext, !istile, False); | |
340
ae0affabdc02
implemented right tag drawing in the status bar and titlebars
Anselm R. Garbe <arg@10kloc.org>
parents:
334
diff
changeset
|
142 |
342 | 143 if(sel && ((dc.w = dc.x - x) > bh)) { |
144 dc.x = x; | |
145 drawtext(sel->name, istile, False); | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
146 } |
77 | 147 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
148 XSync(dpy, False); |
77 | 149 } |
150 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
151 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
152 drawtitle(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
153 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
154 int i; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
155 Bool istile = arrange == dotile; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
156 |
239
e5390f8e06b9
applied sumik's multihead patch
Anselm R.Garbe <arg@10ksloc.org>
parents:
237
diff
changeset
|
157 if(c == sel && issel) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
158 drawstatus(); |
342 | 159 XUnmapWindow(dpy, c->twin); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
160 XSetWindowBorder(dpy, c->win, dc.fg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
161 return; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
162 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
163 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
164 XSetWindowBorder(dpy, c->win, dc.bg); |
342 | 165 XMapWindow(dpy, c->twin); |
166 dc.x = dc.y = 0; | |
167 dc.w = c->tw; | |
168 drawtext(c->name, !istile, False); | |
169 XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0); | |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
170 XSync(dpy, False); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
171 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
172 |
43 | 173 unsigned long |
74 | 174 getcolor(const char *colstr) |
2 | 175 { |
123 | 176 Colormap cmap = DefaultColormap(dpy, screen); |
2 | 177 XColor color; |
43 | 178 |
2 | 179 XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
180 return color.pixel; | |
181 } | |
182 | |
183 void | |
74 | 184 setfont(const char *fontstr) |
2 | 185 { |
186 char **missing, *def; | |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
187 int i, n; |
2 | 188 |
7 | 189 missing = NULL; |
2 | 190 setlocale(LC_ALL, ""); |
43 | 191 if(dc.font.set) |
192 XFreeFontSet(dpy, dc.font.set); | |
193 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
2 | 194 if(missing) { |
195 while(n--) | |
196 fprintf(stderr, "missing fontset: %s\n", missing[n]); | |
197 XFreeStringList(missing); | |
43 | 198 if(dc.font.set) { |
199 XFreeFontSet(dpy, dc.font.set); | |
200 dc.font.set = NULL; | |
2 | 201 } |
202 } | |
43 | 203 if(dc.font.set) { |
2 | 204 XFontSetExtents *font_extents; |
205 XFontStruct **xfonts; | |
206 char **font_names; | |
207 | |
43 | 208 dc.font.ascent = dc.font.descent = 0; |
209 font_extents = XExtentsOfFontSet(dc.font.set); | |
210 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
211 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | |
212 if(dc.font.ascent < (*xfonts)->ascent) | |
213 dc.font.ascent = (*xfonts)->ascent; | |
214 if(dc.font.descent < (*xfonts)->descent) | |
215 dc.font.descent = (*xfonts)->descent; | |
2 | 216 xfonts++; |
217 } | |
218 } | |
219 else { | |
43 | 220 if(dc.font.xfont) |
221 XFreeFont(dpy, dc.font.xfont); | |
222 dc.font.xfont = NULL; | |
223 dc.font.xfont = XLoadQueryFont(dpy, fontstr); | |
224 if (!dc.font.xfont) | |
225 dc.font.xfont = XLoadQueryFont(dpy, "fixed"); | |
226 if (!dc.font.xfont) | |
75 | 227 eprint("error, cannot init 'fixed' font\n"); |
43 | 228 dc.font.ascent = dc.font.xfont->ascent; |
229 dc.font.descent = dc.font.xfont->descent; | |
2 | 230 } |
43 | 231 dc.font.height = dc.font.ascent + dc.font.descent; |
2 | 232 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
233 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
234 unsigned int |
173
1db04019684e
changed Client->tags and Rule->tags to be Bool (I'll also try to remove the TLast enum)
arg@10ksloc.org
parents:
164
diff
changeset
|
235 textw(const char *text) |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
236 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
237 return textnw(text, strlen(text)) + dc.font.height; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
238 } |