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