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