Mercurial > dwm-meillo
annotate draw.c @ 263:118d3e010e5e
made shortcuts like proposed by Sander, renamed viewextend to toggleview (more clear)
author | Anselm R.Garbe <arg@10ksloc.org> |
---|---|
date | Sun, 13 Aug 2006 17:58:06 +0200 |
parents | d659a2dce2b5 |
children | bf6792e3e700 |
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 |
218 | 25 drawtext(const char *text, Bool invert) |
2 | 26 { |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
27 int x, y, w, h; |
123 | 28 static char buf[256]; |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
29 unsigned int len; |
2 | 30 XGCValues gcv; |
257 | 31 XPoint points[5]; |
34 | 32 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
2 | 33 |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
34 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); |
34 | 35 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
257 | 36 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
37 XSetForeground(dpy, dc.gc, dc.border); | |
38 points[0].x = dc.x; | |
39 points[0].y = dc.y; | |
40 points[1].x = dc.w - 1; | |
41 points[1].y = 0; | |
42 points[2].x = 0; | |
43 points[2].y = dc.h - 1; | |
44 points[3].x = -(dc.w - 1); | |
45 points[3].y = 0; | |
46 points[4].x = 0; | |
47 points[4].y = -(dc.h - 1); | |
48 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
|
49 |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
50 if(!text) |
2 | 51 return; |
52 | |
218 | 53 w = 0; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
54 len = strlen(text); |
2 | 55 if(len >= sizeof(buf)) |
56 len = sizeof(buf) - 1; | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
57 memcpy(buf, text, len); |
2 | 58 buf[len] = 0; |
59 | |
34 | 60 h = dc.font.ascent + dc.font.descent; |
61 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | |
62 x = dc.x + (h / 2); | |
2 | 63 |
64 /* shorten text if necessary */ | |
43 | 65 while(len && (w = textnw(buf, len)) > dc.w - h) |
2 | 66 buf[--len] = 0; |
67 | |
34 | 68 if(w > dc.w) |
2 | 69 return; /* too long */ |
70 | |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
71 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
|
72 gcv.background = invert ? dc.fg : dc.bg; |
34 | 73 if(dc.font.set) { |
74 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); | |
75 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, | |
2 | 76 x, y, buf, len); |
77 } | |
78 else { | |
34 | 79 gcv.font = dc.font.xfont->fid; |
80 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); | |
81 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); | |
2 | 82 } |
83 } | |
84 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
85 /* extern */ |
77 | 86 |
87 void | |
88 drawall() | |
89 { | |
90 Client *c; | |
91 | |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
124
diff
changeset
|
92 for(c = clients; c; c = getnext(c->next)) |
77 | 93 drawtitle(c); |
94 drawstatus(); | |
95 } | |
96 | |
97 void | |
98 drawstatus() | |
99 { | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
100 int i, x; |
77 | 101 Bool istile = arrange == dotile; |
102 | |
103 dc.x = dc.y = 0; | |
104 dc.w = bw; | |
218 | 105 drawtext(NULL, !istile); |
77 | 106 |
107 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
|
108 for(i = 0; i < ntags; i++) { |
77 | 109 dc.x += dc.w; |
110 dc.w = textw(tags[i]); | |
111 if(istile) | |
262
d659a2dce2b5
implemented viewextend and added M-S-C-n shortcuts for extending the current view... updated man page (works great!) nice feature
Anselm R.Garbe <arg@10ksloc.org>
parents:
261
diff
changeset
|
112 drawtext(tags[i], seltag[i]); |
77 | 113 else |
262
d659a2dce2b5
implemented viewextend and added M-S-C-n shortcuts for extending the current view... updated man page (works great!) nice feature
Anselm R.Garbe <arg@10ksloc.org>
parents:
261
diff
changeset
|
114 drawtext(tags[i], !seltag[i]); |
77 | 115 } |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
116 x = dc.x + dc.w; |
77 | 117 dc.w = textw(stext); |
118 dc.x = bx + bw - dc.w; | |
218 | 119 drawtext(stext, !istile); |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
120 if(sel && ((dc.w = dc.x - x) >= bh)) { |
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
121 dc.x = x; |
218 | 122 drawtext(sel->name, istile); |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
123 } |
77 | 124 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
|
125 XSync(dpy, False); |
77 | 126 } |
127 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
128 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
129 drawtitle(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
130 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
131 int i; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
132 Bool istile = arrange == dotile; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
133 |
239
e5390f8e06b9
applied sumik's multihead patch
Anselm R.Garbe <arg@10ksloc.org>
parents:
237
diff
changeset
|
134 if(c == sel && issel) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
135 drawstatus(); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
136 XUnmapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
137 XSetWindowBorder(dpy, c->win, dc.fg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
138 return; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
139 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
140 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
141 XSetWindowBorder(dpy, c->win, dc.bg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
142 XMapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
143 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
144 dc.x = dc.y = 0; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
145 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
146 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
|
147 for(i = 0; i < ntags; i++) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
148 if(c->tags[i]) { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
149 dc.x += dc.w; |
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
|
150 dc.w = textw(tags[i]); |
218 | 151 drawtext(tags[i], !istile); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
152 } |
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 dc.x += dc.w; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
155 dc.w = textw(c->name); |
218 | 156 drawtext(c->name, !istile); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
157 XCopyArea(dpy, dc.drawable, c->title, dc.gc, 0, 0, c->tw, c->th, 0, 0); |
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
158 XSync(dpy, False); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
159 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
160 |
43 | 161 unsigned long |
74 | 162 getcolor(const char *colstr) |
2 | 163 { |
123 | 164 Colormap cmap = DefaultColormap(dpy, screen); |
2 | 165 XColor color; |
43 | 166 |
2 | 167 XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
168 return color.pixel; | |
169 } | |
170 | |
171 void | |
74 | 172 setfont(const char *fontstr) |
2 | 173 { |
174 char **missing, *def; | |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
175 int i, n; |
2 | 176 |
7 | 177 missing = NULL; |
2 | 178 setlocale(LC_ALL, ""); |
43 | 179 if(dc.font.set) |
180 XFreeFontSet(dpy, dc.font.set); | |
181 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
2 | 182 if(missing) { |
183 while(n--) | |
184 fprintf(stderr, "missing fontset: %s\n", missing[n]); | |
185 XFreeStringList(missing); | |
43 | 186 if(dc.font.set) { |
187 XFreeFontSet(dpy, dc.font.set); | |
188 dc.font.set = NULL; | |
2 | 189 } |
190 } | |
43 | 191 if(dc.font.set) { |
2 | 192 XFontSetExtents *font_extents; |
193 XFontStruct **xfonts; | |
194 char **font_names; | |
195 | |
43 | 196 dc.font.ascent = dc.font.descent = 0; |
197 font_extents = XExtentsOfFontSet(dc.font.set); | |
198 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
199 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | |
200 if(dc.font.ascent < (*xfonts)->ascent) | |
201 dc.font.ascent = (*xfonts)->ascent; | |
202 if(dc.font.descent < (*xfonts)->descent) | |
203 dc.font.descent = (*xfonts)->descent; | |
2 | 204 xfonts++; |
205 } | |
206 } | |
207 else { | |
43 | 208 if(dc.font.xfont) |
209 XFreeFont(dpy, dc.font.xfont); | |
210 dc.font.xfont = NULL; | |
211 dc.font.xfont = XLoadQueryFont(dpy, fontstr); | |
212 if (!dc.font.xfont) | |
213 dc.font.xfont = XLoadQueryFont(dpy, "fixed"); | |
214 if (!dc.font.xfont) | |
75 | 215 eprint("error, cannot init 'fixed' font\n"); |
43 | 216 dc.font.ascent = dc.font.xfont->ascent; |
217 dc.font.descent = dc.font.xfont->descent; | |
2 | 218 } |
43 | 219 dc.font.height = dc.font.ascent + dc.font.descent; |
2 | 220 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
221 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
222 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
|
223 textw(const char *text) |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
224 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
225 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
|
226 } |