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