Mercurial > aewl
annotate draw.c @ 235:60e73ebaab27
removed unnecessary border color
author | Anselm R.Garbe <arg@10ksloc.org> |
---|---|
date | Thu, 10 Aug 2006 10:27:08 +0200 |
parents | c674a0baac63 |
children | ebecb98a1c29 |
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]; |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
29 unsigned int len; |
2 | 30 XGCValues gcv; |
34 | 31 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
2 | 32 |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
33 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); |
34 | 34 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
2 | 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; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
40 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; |
53 | |
34 | 54 if(w > dc.w) |
2 | 55 return; /* too long */ |
56 | |
66
50450aa24a46
removed a bunch of lines through swap removal
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
57 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
|
58 gcv.background = invert ? dc.fg : dc.bg; |
34 | 59 if(dc.font.set) { |
60 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); | |
61 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, | |
2 | 62 x, y, buf, len); |
63 } | |
64 else { | |
34 | 65 gcv.font = dc.font.xfont->fid; |
66 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); | |
67 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); | |
2 | 68 } |
69 } | |
70 | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
71 /* extern */ |
77 | 72 |
73 void | |
74 drawall() | |
75 { | |
76 Client *c; | |
77 | |
142
9b9deafa0508
committed a patch which fixes the hints of Jukka
arg@10ksloc.org
parents:
124
diff
changeset
|
78 for(c = clients; c; c = getnext(c->next)) |
77 | 79 drawtitle(c); |
80 drawstatus(); | |
81 } | |
82 | |
83 void | |
84 drawstatus() | |
85 { | |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
86 int i, x; |
77 | 87 Bool istile = arrange == dotile; |
88 | |
89 dc.x = dc.y = 0; | |
90 dc.w = bw; | |
218 | 91 drawtext(NULL, !istile); |
77 | 92 |
93 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
|
94 for(i = 0; i < ntags; i++) { |
77 | 95 dc.x += dc.w; |
96 dc.w = textw(tags[i]); | |
97 if(istile) | |
218 | 98 drawtext(tags[i], (i == tsel)); |
77 | 99 else |
218 | 100 drawtext(tags[i], (i != tsel)); |
77 | 101 } |
124
75576e44c1d8
made status bar drawing more robust, implemented togglemax and togglemode, works quite well
arg@10ksloc.org
parents:
123
diff
changeset
|
102 x = dc.x + dc.w; |
77 | 103 dc.w = textw(stext); |
104 dc.x = bx + bw - dc.w; | |
218 | 105 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
|
106 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
|
107 dc.x = x; |
218 | 108 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
|
109 } |
77 | 110 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
|
111 XSync(dpy, False); |
77 | 112 } |
113 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
114 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
115 drawtitle(Client *c) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
116 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
117 int i; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
118 Bool istile = arrange == dotile; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
119 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
120 if(c == sel) { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
121 drawstatus(); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
122 XUnmapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
123 XSetWindowBorder(dpy, c->win, dc.fg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
124 return; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
125 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
126 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
127 XSetWindowBorder(dpy, c->win, dc.bg); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
128 XMapWindow(dpy, c->title); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
129 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
130 dc.x = dc.y = 0; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
131 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
132 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
|
133 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
|
134 if(c->tags[i]) { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
135 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
|
136 dc.w = textw(tags[i]); |
218 | 137 drawtext(tags[i], !istile); |
76
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 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
140 dc.x += dc.w; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
141 dc.w = textw(c->name); |
218 | 142 drawtext(c->name, !istile); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
143 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
|
144 XSync(dpy, False); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
145 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
146 |
43 | 147 unsigned long |
74 | 148 getcolor(const char *colstr) |
2 | 149 { |
123 | 150 Colormap cmap = DefaultColormap(dpy, screen); |
2 | 151 XColor color; |
43 | 152 |
2 | 153 XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
154 return color.pixel; | |
155 } | |
156 | |
157 void | |
74 | 158 setfont(const char *fontstr) |
2 | 159 { |
160 char **missing, *def; | |
33
e90449e03167
new stuff (some warning elimination)
Anselm R. Garbe <garbeam@wmii.de>
parents:
32
diff
changeset
|
161 int i, n; |
2 | 162 |
7 | 163 missing = NULL; |
2 | 164 setlocale(LC_ALL, ""); |
43 | 165 if(dc.font.set) |
166 XFreeFontSet(dpy, dc.font.set); | |
167 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); | |
2 | 168 if(missing) { |
169 while(n--) | |
170 fprintf(stderr, "missing fontset: %s\n", missing[n]); | |
171 XFreeStringList(missing); | |
43 | 172 if(dc.font.set) { |
173 XFreeFontSet(dpy, dc.font.set); | |
174 dc.font.set = NULL; | |
2 | 175 } |
176 } | |
43 | 177 if(dc.font.set) { |
2 | 178 XFontSetExtents *font_extents; |
179 XFontStruct **xfonts; | |
180 char **font_names; | |
181 | |
43 | 182 dc.font.ascent = dc.font.descent = 0; |
183 font_extents = XExtentsOfFontSet(dc.font.set); | |
184 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); | |
185 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { | |
186 if(dc.font.ascent < (*xfonts)->ascent) | |
187 dc.font.ascent = (*xfonts)->ascent; | |
188 if(dc.font.descent < (*xfonts)->descent) | |
189 dc.font.descent = (*xfonts)->descent; | |
2 | 190 xfonts++; |
191 } | |
192 } | |
193 else { | |
43 | 194 if(dc.font.xfont) |
195 XFreeFont(dpy, dc.font.xfont); | |
196 dc.font.xfont = NULL; | |
197 dc.font.xfont = XLoadQueryFont(dpy, fontstr); | |
198 if (!dc.font.xfont) | |
199 dc.font.xfont = XLoadQueryFont(dpy, "fixed"); | |
200 if (!dc.font.xfont) | |
75 | 201 eprint("error, cannot init 'fixed' font\n"); |
43 | 202 dc.font.ascent = dc.font.xfont->ascent; |
203 dc.font.descent = dc.font.xfont->descent; | |
2 | 204 } |
43 | 205 dc.font.height = dc.font.ascent + dc.font.descent; |
2 | 206 } |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
207 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
208 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
|
209 textw(const char *text) |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
210 { |
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 } |