Mercurial > aewl
annotate draw.c @ 364:d955a84b7d4b
updated man page of dwm
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Fri, 25 Aug 2006 16:21:45 +0200 |
parents | ba6c55e1b9b2 |
children | fc9d35252ab4 |
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 |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
25 drawtext(const char *text, unsigned long col[ColLast], 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; |
352 | 30 XGCValues gcv; |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
31 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
|
32 |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
33 XSetForeground(dpy, dc.gc, col[ColBG]); |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
342
diff
changeset
|
34 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
237
7f8f7f14e9cd
readded border color, this sucks least
Anselm R.Garbe <arg@10ksloc.org>
parents:
236
diff
changeset
|
35 |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
36 if(!text) |
2 | 37 return; |
38 | |
218 | 39 w = 0; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
40 olen = len = strlen(text); |
2 | 41 if(len >= sizeof(buf)) |
42 len = sizeof(buf) - 1; | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
43 memcpy(buf, text, len); |
2 | 44 buf[len] = 0; |
45 | |
34 | 46 h = dc.font.ascent + dc.font.descent; |
47 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; | |
48 x = dc.x + (h / 2); | |
2 | 49 |
50 /* shorten text if necessary */ | |
43 | 51 while(len && (w = textnw(buf, len)) > dc.w - h) |
2 | 52 buf[--len] = 0; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
53 if(len < olen) { |
273 | 54 if(len > 1) |
55 buf[len - 1] = '.'; | |
56 if(len > 2) | |
57 buf[len - 2] = '.'; | |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
58 if(len > 3) |
273 | 59 buf[len - 3] = '.'; |
269
bf6792e3e700
fixed string cutting in draw.c
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
60 } |
2 | 61 |
34 | 62 if(w > dc.w) |
2 | 63 return; /* too long */ |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
64 gcv.foreground = col[ColFG]; |
352 | 65 if(dc.font.set) { |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
66 XChangeGC(dpy, dc.gc, GCForeground, &gcv); |
342 | 67 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); |
352 | 68 } |
2 | 69 else { |
352 | 70 gcv.font = dc.font.xfont->fid; |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
71 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv); |
342 | 72 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
73 } | |
345 | 74 if(highlight) { |
352 | 75 r.x = dc.x + 2; |
76 r.y = dc.y + 2; | |
77 r.width = r.height = 3; | |
78 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | |
2 | 79 } |
80 } | |
81 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
82 /* extern */ |
77 | 83 |
84 void | |
85 drawall() | |
86 { | |
87 Client *c; | |
88 | |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
124
diff
changeset
|
89 for(c = clients; c; c = getnext(c->next)) |
77 | 90 drawtitle(c); |
91 drawstatus(); | |
92 } | |
93 | |
94 void | |
95 drawstatus() | |
96 { | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
97 int i, x; |
77 | 98 |
99 dc.x = dc.y = 0; | |
100 dc.w = bw; | |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
101 |
362
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
102 drawtext(NULL, dc.status, False); |
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
|
103 for(i = 0; i < ntags; i++) { |
77 | 104 dc.w = textw(tags[i]); |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
105 if(seltag[i]) |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
106 drawtext(tags[i], dc.sel, sel && sel->tags[i]); |
77 | 107 else |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
108 drawtext(tags[i], dc.norm, sel && sel->tags[i]); |
362
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
109 dc.x += dc.w; |
77 | 110 } |
362
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
111 |
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
112 dc.w = bmw; |
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
113 drawtext(arrange == dotile ? TILESYMBOL : FLOATSYMBOL, dc.status, False); |
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
361
diff
changeset
|
114 |
361
728e74820e1d
removed small 1px gap, somehow without it things feel better
Anselm R. Garbe <arg@10kloc.org>
parents:
360
diff
changeset
|
115 x = dc.x + dc.w; |
77 | 116 dc.w = textw(stext); |
117 dc.x = bx + bw - dc.w; | |
342 | 118 if(dc.x < x) { |
119 dc.x = x; | |
120 dc.w = bw - x; | |
121 } | |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
122 drawtext(stext, dc.status, False); |
340
ae0affabdc02
implemented right tag drawing in the status bar and titlebars
Anselm R. Garbe <arg@10kloc.org>
parents:
334
diff
changeset
|
123 |
342 | 124 if(sel && ((dc.w = dc.x - x) > bh)) { |
125 dc.x = x; | |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
126 drawtext(sel->name, dc.sel, False); |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
127 } |
77 | 128 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
|
129 XSync(dpy, False); |
77 | 130 } |
131 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
132 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
133 drawtitle(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
134 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
135 int i; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
136 |
239
e5390f8e06b9
applied sumik's multihead patch
Anselm R.Garbe <arg@10ksloc.org>
parents:
237
diff
changeset
|
137 if(c == sel && issel) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
138 drawstatus(); |
342 | 139 XUnmapWindow(dpy, c->twin); |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
140 XSetWindowBorder(dpy, c->win, dc.sel[ColBG]); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
141 return; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
142 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
143 |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
144 XSetWindowBorder(dpy, c->win, dc.norm[ColBG]); |
342 | 145 XMapWindow(dpy, c->twin); |
146 dc.x = dc.y = 0; | |
147 dc.w = c->tw; | |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
148 drawtext(c->name, dc.norm, False); |
342 | 149 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
|
150 XSync(dpy, False); |
76
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 |
43 | 153 unsigned long |
74 | 154 getcolor(const char *colstr) |
2 | 155 { |
123 | 156 Colormap cmap = DefaultColormap(dpy, screen); |
2 | 157 XColor color; |
43 | 158 |
2 | 159 XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
160 return color.pixel; | |
161 } | |
162 | |
163 void | |
74 | 164 setfont(const char *fontstr) |
2 | 165 { |
166 char **missing, *def; | |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
167 int i, n; |
2 | 168 |
7 | 169 missing = NULL; |
2 | 170 setlocale(LC_ALL, ""); |
43 | 171 if(dc.font.set) |
172 XFreeFontSet(dpy, dc.font.set); | |
173 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
2 | 174 if(missing) { |
175 while(n--) | |
176 fprintf(stderr, "missing fontset: %s\n", missing[n]); | |
177 XFreeStringList(missing); | |
43 | 178 if(dc.font.set) { |
179 XFreeFontSet(dpy, dc.font.set); | |
180 dc.font.set = NULL; | |
2 | 181 } |
182 } | |
43 | 183 if(dc.font.set) { |
2 | 184 XFontSetExtents *font_extents; |
185 XFontStruct **xfonts; | |
186 char **font_names; | |
187 | |
43 | 188 dc.font.ascent = dc.font.descent = 0; |
189 font_extents = XExtentsOfFontSet(dc.font.set); | |
190 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
191 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | |
192 if(dc.font.ascent < (*xfonts)->ascent) | |
193 dc.font.ascent = (*xfonts)->ascent; | |
194 if(dc.font.descent < (*xfonts)->descent) | |
195 dc.font.descent = (*xfonts)->descent; | |
2 | 196 xfonts++; |
197 } | |
198 } | |
199 else { | |
43 | 200 if(dc.font.xfont) |
201 XFreeFont(dpy, dc.font.xfont); | |
202 dc.font.xfont = NULL; | |
203 dc.font.xfont = XLoadQueryFont(dpy, fontstr); | |
204 if (!dc.font.xfont) | |
205 dc.font.xfont = XLoadQueryFont(dpy, "fixed"); | |
206 if (!dc.font.xfont) | |
75 | 207 eprint("error, cannot init 'fixed' font\n"); |
43 | 208 dc.font.ascent = dc.font.xfont->ascent; |
209 dc.font.descent = dc.font.xfont->descent; | |
2 | 210 } |
43 | 211 dc.font.height = dc.font.ascent + dc.font.descent; |
2 | 212 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
213 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
214 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
|
215 textw(const char *text) |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
216 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
217 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
|
218 } |