Mercurial > dwm-meillo
annotate draw.c @ 314:8bafc3ac9f58
made a new client position strategy similiar to that one proposed by Sander, but which takes top bar into account
author | Anselm R.Garbe <arg@10ksloc.org> |
---|---|
date | Fri, 18 Aug 2006 08:39:33 +0200 |
parents | ffc73b32084a |
children | 0ed2de01e9f7 |
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]; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
29 unsigned int len, olen; |
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; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
54 olen = 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; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
67 if(len < olen) { |
273 | 68 if(len > 1) |
69 buf[len - 1] = '.'; | |
70 if(len > 2) | |
71 buf[len - 2] = '.'; | |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
72 if(len > 3) |
273 | 73 buf[len - 3] = '.'; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
74 } |
2 | 75 |
34 | 76 if(w > dc.w) |
2 | 77 return; /* too long */ |
78 | |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
79 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
|
80 gcv.background = invert ? dc.fg : dc.bg; |
34 | 81 if(dc.font.set) { |
82 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); | |
83 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, | |
2 | 84 x, y, buf, len); |
85 } | |
86 else { | |
34 | 87 gcv.font = dc.font.xfont->fid; |
88 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); | |
89 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); | |
2 | 90 } |
91 } | |
92 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
93 /* extern */ |
77 | 94 |
95 void | |
96 drawall() | |
97 { | |
98 Client *c; | |
99 | |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
124
diff
changeset
|
100 for(c = clients; c; c = getnext(c->next)) |
77 | 101 drawtitle(c); |
102 drawstatus(); | |
103 } | |
104 | |
105 void | |
106 drawstatus() | |
107 { | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
108 int i, x; |
77 | 109 Bool istile = arrange == dotile; |
110 | |
111 dc.x = dc.y = 0; | |
112 dc.w = bw; | |
218 | 113 drawtext(NULL, !istile); |
77 | 114 |
115 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
|
116 for(i = 0; i < ntags; i++) { |
77 | 117 dc.x += dc.w; |
118 dc.w = textw(tags[i]); | |
119 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
|
120 drawtext(tags[i], seltag[i]); |
77 | 121 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
|
122 drawtext(tags[i], !seltag[i]); |
77 | 123 } |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
124 x = dc.x + dc.w; |
77 | 125 dc.w = textw(stext); |
126 dc.x = bx + bw - dc.w; | |
218 | 127 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
|
128 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
|
129 dc.x = x; |
218 | 130 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
|
131 } |
77 | 132 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
|
133 XSync(dpy, False); |
77 | 134 } |
135 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
136 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
137 drawtitle(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
138 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
139 int i; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
140 Bool istile = arrange == dotile; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
141 |
239
e5390f8e06b9
applied sumik's multihead patch
Anselm R.Garbe <arg@10ksloc.org>
parents:
237
diff
changeset
|
142 if(c == sel && issel) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
143 drawstatus(); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
144 XUnmapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
145 XSetWindowBorder(dpy, c->win, dc.fg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
146 return; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
147 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
148 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
149 XSetWindowBorder(dpy, c->win, dc.bg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
150 XMapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
151 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
152 dc.x = dc.y = 0; |
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.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
|
155 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
|
156 if(c->tags[i]) { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
157 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
|
158 dc.w = textw(tags[i]); |
218 | 159 drawtext(tags[i], !istile); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
160 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
161 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
162 dc.x += dc.w; |
273 | 163 dc.w = c->tw - dc.x; |
218 | 164 drawtext(c->name, !istile); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
165 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
|
166 XSync(dpy, False); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
167 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
168 |
43 | 169 unsigned long |
74 | 170 getcolor(const char *colstr) |
2 | 171 { |
123 | 172 Colormap cmap = DefaultColormap(dpy, screen); |
2 | 173 XColor color; |
43 | 174 |
2 | 175 XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
176 return color.pixel; | |
177 } | |
178 | |
179 void | |
74 | 180 setfont(const char *fontstr) |
2 | 181 { |
182 char **missing, *def; | |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
183 int i, n; |
2 | 184 |
7 | 185 missing = NULL; |
2 | 186 setlocale(LC_ALL, ""); |
43 | 187 if(dc.font.set) |
188 XFreeFontSet(dpy, dc.font.set); | |
189 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
2 | 190 if(missing) { |
191 while(n--) | |
192 fprintf(stderr, "missing fontset: %s\n", missing[n]); | |
193 XFreeStringList(missing); | |
43 | 194 if(dc.font.set) { |
195 XFreeFontSet(dpy, dc.font.set); | |
196 dc.font.set = NULL; | |
2 | 197 } |
198 } | |
43 | 199 if(dc.font.set) { |
2 | 200 XFontSetExtents *font_extents; |
201 XFontStruct **xfonts; | |
202 char **font_names; | |
203 | |
43 | 204 dc.font.ascent = dc.font.descent = 0; |
205 font_extents = XExtentsOfFontSet(dc.font.set); | |
206 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
207 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | |
208 if(dc.font.ascent < (*xfonts)->ascent) | |
209 dc.font.ascent = (*xfonts)->ascent; | |
210 if(dc.font.descent < (*xfonts)->descent) | |
211 dc.font.descent = (*xfonts)->descent; | |
2 | 212 xfonts++; |
213 } | |
214 } | |
215 else { | |
43 | 216 if(dc.font.xfont) |
217 XFreeFont(dpy, dc.font.xfont); | |
218 dc.font.xfont = NULL; | |
219 dc.font.xfont = XLoadQueryFont(dpy, fontstr); | |
220 if (!dc.font.xfont) | |
221 dc.font.xfont = XLoadQueryFont(dpy, "fixed"); | |
222 if (!dc.font.xfont) | |
75 | 223 eprint("error, cannot init 'fixed' font\n"); |
43 | 224 dc.font.ascent = dc.font.xfont->ascent; |
225 dc.font.descent = dc.font.xfont->descent; | |
2 | 226 } |
43 | 227 dc.font.height = dc.font.ascent + dc.font.descent; |
2 | 228 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
229 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
230 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
|
231 textw(const char *text) |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
232 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
233 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
|
234 } |