summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-19 15:17:31 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-19 15:17:31 +0100
commitf8415019d4edc1cd4f310adb256e6656e85bfe75 (patch)
tree2813e15f6dbd4a3c1326a3d2c08ab2bcea3c61af
parentrenamed view.c into screen.c (diff)
downloaddwm-f8415019d4edc1cd4f310adb256e6656e85bfe75.tar.gz
dwm-f8415019d4edc1cd4f310adb256e6656e85bfe75.zip
draw.c is useless (belongs to main.c now)
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--client.c12
-rw-r--r--draw.c175
-rw-r--r--dwm.h11
-rw-r--r--event.c8
-rw-r--r--main.c165
6 files changed, 178 insertions, 195 deletions
diff --git a/Makefile b/Makefile
index a9f129d..221efa4 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = client.c draw.c event.c main.c screen.c util.c 6SRC = client.c event.c main.c screen.c util.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/client.c b/client.c
index eaf4a10..0251445 100644
--- a/client.c
+++ b/client.c
@@ -200,16 +200,6 @@ focusprev(Arg *arg) {
200 } 200 }
201} 201}
202 202
203Client *
204getclient(Window w) {
205 Client *c;
206
207 for(c = clients; c; c = c->next)
208 if(c->win == w)
209 return c;
210 return NULL;
211}
212
213void 203void
214killclient(Arg *arg) { 204killclient(Arg *arg) {
215 if(!sel) 205 if(!sel)
@@ -259,7 +249,7 @@ manage(Window w, XWindowAttributes *wa) {
259 XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]); 249 XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
260 configure(c); /* propagates border_width, if size doesn't change */ 250 configure(c); /* propagates border_width, if size doesn't change */
261 updatetitle(c); 251 updatetitle(c);
262 t = getclient(trans); 252 for(t = clients; t && t->win != c->win; t = t->next);
263 settags(c, t); 253 settags(c, t);
264 if(!c->isfloat) 254 if(!c->isfloat)
265 c->isfloat = (t != 0) || c->isfixed; 255 c->isfloat = (t != 0) || c->isfixed;
diff --git a/draw.c b/draw.c
deleted file mode 100644
index 0e02d6c..0000000
--- a/draw.c
+++ /dev/null
@@ -1,175 +0,0 @@
1/* (C)opyright MMIV-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4#include "dwm.h"
5#include <stdio.h>
6#include <string.h>
7
8/* static */
9
10static Bool
11isoccupied(unsigned int t)
12{
13 Client *c;
14 for(c = clients; c; c = c->next)
15 if(c->tags[t])
16 return True;
17 return False;
18}
19
20static unsigned int
21textnw(const char *text, unsigned int len) {
22 XRectangle r;
23
24 if(dc.font.set) {
25 XmbTextExtents(dc.font.set, text, len, NULL, &r);
26 return r.width;
27 }
28 return XTextWidth(dc.font.xfont, text, len);
29}
30
31static void
32drawtext(const char *text, unsigned long col[ColLast], Bool filledsquare, Bool emptysquare) {
33 int x, y, w, h;
34 static char buf[256];
35 unsigned int len, olen;
36 XGCValues gcv;
37 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
38
39 XSetForeground(dpy, dc.gc, col[ColBG]);
40 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
41 if(!text)
42 return;
43 w = 0;
44 olen = len = strlen(text);
45 if(len >= sizeof buf)
46 len = sizeof buf - 1;
47 memcpy(buf, text, len);
48 buf[len] = 0;
49 h = dc.font.ascent + dc.font.descent;
50 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
51 x = dc.x + (h / 2);
52 /* shorten text if necessary */
53 while(len && (w = textnw(buf, len)) > dc.w - h)
54 buf[--len] = 0;
55 if(len < olen) {
56 if(len > 1)
57 buf[len - 1] = '.';
58 if(len > 2)
59 buf[len - 2] = '.';
60 if(len > 3)
61 buf[len - 3] = '.';
62 }
63 if(w > dc.w)
64 return; /* too long */
65 gcv.foreground = col[ColFG];
66 if(dc.font.set) {
67 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
68 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
69 }
70 else {
71 gcv.font = dc.font.xfont->fid;
72 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
73 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
74 }
75 x = (h + 2) / 4;
76 r.x = dc.x + 1;
77 r.y = dc.y + 1;
78 if(filledsquare) {
79 r.width = r.height = x + 1;
80 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
81 }
82 else if(emptysquare) {
83 r.width = r.height = x;
84 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
85 }
86}
87
88/* extern */
89
90void
91drawstatus(void) {
92 int i, x;
93
94 dc.x = dc.y = 0;
95 for(i = 0; i < ntags; i++) {
96 dc.w = textw(tags[i]);
97 if(seltag[i])
98 drawtext(tags[i], dc.sel, sel && sel->tags[i], isoccupied(i));
99 else
100 drawtext(tags[i], dc.norm, sel && sel->tags[i], isoccupied(i));
101 dc.x += dc.w;
102 }
103 dc.w = bmw;
104 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, False);
105 x = dc.x + dc.w;
106 dc.w = textw(stext);
107 dc.x = sw - dc.w;
108 if(dc.x < x) {
109 dc.x = x;
110 dc.w = sw - x;
111 }
112 drawtext(stext, dc.norm, False, False);
113 if((dc.w = dc.x - x) > bh) {
114 dc.x = x;
115 drawtext(sel ? sel->name : NULL, sel ? dc.sel : dc.norm, False, False);
116 }
117 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
118 XSync(dpy, False);
119}
120
121unsigned long
122getcolor(const char *colstr) {
123 Colormap cmap = DefaultColormap(dpy, screen);
124 XColor color;
125
126 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
127 eprint("error, cannot allocate color '%s'\n", colstr);
128 return color.pixel;
129}
130
131void
132setfont(const char *fontstr) {
133 char *def, **missing;
134 int i, n;
135
136 missing = NULL;
137 if(dc.font.set)
138 XFreeFontSet(dpy, dc.font.set);
139 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
140 if(missing) {
141 while(n--)
142 fprintf(stderr, "missing fontset: %s\n", missing[n]);
143 XFreeStringList(missing);
144 }
145 if(dc.font.set) {
146 XFontSetExtents *font_extents;
147 XFontStruct **xfonts;
148 char **font_names;
149 dc.font.ascent = dc.font.descent = 0;
150 font_extents = XExtentsOfFontSet(dc.font.set);
151 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
152 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
153 if(dc.font.ascent < (*xfonts)->ascent)
154 dc.font.ascent = (*xfonts)->ascent;
155 if(dc.font.descent < (*xfonts)->descent)
156 dc.font.descent = (*xfonts)->descent;
157 xfonts++;
158 }
159 }
160 else {
161 if(dc.font.xfont)
162 XFreeFont(dpy, dc.font.xfont);
163 dc.font.xfont = NULL;
164 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
165 eprint("error, cannot load font: '%s'\n", fontstr);
166 dc.font.ascent = dc.font.xfont->ascent;
167 dc.font.descent = dc.font.xfont->descent;
168 }
169 dc.font.height = dc.font.ascent + dc.font.descent;
170}
171
172unsigned int
173textw(const char *text) {
174 return textnw(text, strlen(text)) + dc.font.height;
175}
diff --git a/dwm.h b/dwm.h
index 57fab91..2ec0bf7 100644
--- a/dwm.h
+++ b/dwm.h
@@ -103,28 +103,23 @@ extern void configure(Client *c); /* send synthetic configure event */
103extern void focus(Client *c); /* focus c, c may be NULL */ 103extern void focus(Client *c); /* focus c, c may be NULL */
104extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ 104extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
105extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ 105extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
106extern Client *getclient(Window w); /* return client of w */
107extern void killclient(Arg *arg); /* kill c nicely */ 106extern void killclient(Arg *arg); /* kill c nicely */
108extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ 107extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
109Client *nexttiled(Client *c); /* returns tiled successor of c */ 108Client *nexttiled(Client *c); /* returns tiled successor of c */
110extern void resize(Client *c, int x, int y, 109extern void resize(Client *c, int x, int y,
111 int w, int h, Bool sizehints); /* resize c*/ 110 int w, int h, Bool sizehints); /* resize with given coordinates c*/
112extern void updatesizehints(Client *c); /* update the size hint variables of c */ 111extern void updatesizehints(Client *c); /* update the size hint variables of c */
113extern void updatetitle(Client *c); /* update the name of c */ 112extern void updatetitle(Client *c); /* update the name of c */
114extern void unmanage(Client *c); /* destroy c */ 113extern void unmanage(Client *c); /* destroy c */
115extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */ 114extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
116 115
117/* draw.c */
118extern void drawstatus(void); /* draw the bar */
119extern unsigned long getcolor(const char *colstr); /* return color of colstr */
120extern void setfont(const char *fontstr); /* set the font for DC */
121extern unsigned int textw(const char *text); /* return the width of text in px*/
122
123/* event.c */ 116/* event.c */
124extern void grabkeys(void); /* grab all keys defined in config.h */ 117extern void grabkeys(void); /* grab all keys defined in config.h */
125extern void procevent(void); /* process pending X events */ 118extern void procevent(void); /* process pending X events */
126 119
127/* main.c */ 120/* main.c */
121extern void drawstatus(void); /* draw the bar */
122extern unsigned int textw(const char *text); /* return the width of text in px*/
128extern void quit(Arg *arg); /* quit dwm nicely */ 123extern void quit(Arg *arg); /* quit dwm nicely */
129extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ 124extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
130extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 125extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
diff --git a/event.c b/event.c
index db3ce46..dfe2552 100644
--- a/event.c
+++ b/event.c
@@ -20,6 +20,14 @@ KEYS
20#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) 20#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
21#define MOUSEMASK (BUTTONMASK | PointerMotionMask) 21#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
22 22
23static Client *
24getclient(Window w) {
25 Client *c;
26
27 for(c = clients; c && c->win != w; c = c->next);
28 return c;
29}
30
23static void 31static void
24movemouse(Client *c) { 32movemouse(Client *c) {
25 int x1, y1, ocx, ocy, di, nx, ny; 33 int x1, y1, ocx, ocy, di, nx, ny;
diff --git a/main.c b/main.c
index 20450db..77ce0df 100644
--- a/main.c
+++ b/main.c
@@ -61,6 +61,94 @@ cleanup(void) {
61 free(seltag); 61 free(seltag);
62} 62}
63 63
64static unsigned int
65textnw(const char *text, unsigned int len) {
66 XRectangle r;
67
68 if(dc.font.set) {
69 XmbTextExtents(dc.font.set, text, len, NULL, &r);
70 return r.width;
71 }
72 return XTextWidth(dc.font.xfont, text, len);
73}
74
75static void
76drawtext(const char *text, unsigned long col[ColLast], Bool filledsquare, Bool emptysquare) {
77 int x, y, w, h;
78 static char buf[256];
79 unsigned int len, olen;
80 XGCValues gcv;
81 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
82
83 XSetForeground(dpy, dc.gc, col[ColBG]);
84 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
85 if(!text)
86 return;
87 w = 0;
88 olen = len = strlen(text);
89 if(len >= sizeof buf)
90 len = sizeof buf - 1;
91 memcpy(buf, text, len);
92 buf[len] = 0;
93 h = dc.font.ascent + dc.font.descent;
94 y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
95 x = dc.x + (h / 2);
96 /* shorten text if necessary */
97 while(len && (w = textnw(buf, len)) > dc.w - h)
98 buf[--len] = 0;
99 if(len < olen) {
100 if(len > 1)
101 buf[len - 1] = '.';
102 if(len > 2)
103 buf[len - 2] = '.';
104 if(len > 3)
105 buf[len - 3] = '.';
106 }
107 if(w > dc.w)
108 return; /* too long */
109 gcv.foreground = col[ColFG];
110 if(dc.font.set) {
111 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
112 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
113 }
114 else {
115 gcv.font = dc.font.xfont->fid;
116 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
117 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
118 }
119 x = (h + 2) / 4;
120 r.x = dc.x + 1;
121 r.y = dc.y + 1;
122 if(filledsquare) {
123 r.width = r.height = x + 1;
124 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
125 }
126 else if(emptysquare) {
127 r.width = r.height = x;
128 XDrawRectangles(dpy, dc.drawable, dc.gc, &r, 1);
129 }
130}
131
132static unsigned long
133getcolor(const char *colstr) {
134 Colormap cmap = DefaultColormap(dpy, screen);
135 XColor color;
136
137 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
138 eprint("error, cannot allocate color '%s'\n", colstr);
139 return color.pixel;
140}
141
142static Bool
143isoccupied(unsigned int t) {
144 Client *c;
145
146 for(c = clients; c; c = c->next)
147 if(c->tags[t])
148 return True;
149 return False;
150}
151
64static void 152static void
65scan(void) { 153scan(void) {
66 unsigned int i, num; 154 unsigned int i, num;
@@ -82,6 +170,47 @@ scan(void) {
82} 170}
83 171
84static void 172static void
173setfont(const char *fontstr) {
174 char *def, **missing;
175 int i, n;
176
177 missing = NULL;
178 if(dc.font.set)
179 XFreeFontSet(dpy, dc.font.set);
180 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
181 if(missing) {
182 while(n--)
183 fprintf(stderr, "missing fontset: %s\n", missing[n]);
184 XFreeStringList(missing);
185 }
186 if(dc.font.set) {
187 XFontSetExtents *font_extents;
188 XFontStruct **xfonts;
189 char **font_names;
190 dc.font.ascent = dc.font.descent = 0;
191 font_extents = XExtentsOfFontSet(dc.font.set);
192 n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
193 for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
194 if(dc.font.ascent < (*xfonts)->ascent)
195 dc.font.ascent = (*xfonts)->ascent;
196 if(dc.font.descent < (*xfonts)->descent)
197 dc.font.descent = (*xfonts)->descent;
198 xfonts++;
199 }
200 }
201 else {
202 if(dc.font.xfont)
203 XFreeFont(dpy, dc.font.xfont);
204 dc.font.xfont = NULL;
205 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
206 eprint("error, cannot load font: '%s'\n", fontstr);
207 dc.font.ascent = dc.font.xfont->ascent;
208 dc.font.descent = dc.font.xfont->descent;
209 }
210 dc.font.height = dc.font.ascent + dc.font.descent;
211}
212
213static void
85setup(void) { 214setup(void) {
86 int i, j; 215 int i, j;
87 unsigned int mask; 216 unsigned int mask;
@@ -171,6 +300,37 @@ xerrorstart(Display *dsply, XErrorEvent *ee) {
171/* extern */ 300/* extern */
172 301
173void 302void
303drawstatus(void) {
304 int i, x;
305
306 dc.x = dc.y = 0;
307 for(i = 0; i < ntags; i++) {
308 dc.w = textw(tags[i]);
309 if(seltag[i])
310 drawtext(tags[i], dc.sel, sel && sel->tags[i], isoccupied(i));
311 else
312 drawtext(tags[i], dc.norm, sel && sel->tags[i], isoccupied(i));
313 dc.x += dc.w;
314 }
315 dc.w = bmw;
316 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, False);
317 x = dc.x + dc.w;
318 dc.w = textw(stext);
319 dc.x = sw - dc.w;
320 if(dc.x < x) {
321 dc.x = x;
322 dc.w = sw - x;
323 }
324 drawtext(stext, dc.norm, False, False);
325 if((dc.w = dc.x - x) > bh) {
326 dc.x = x;
327 drawtext(sel ? sel->name : NULL, sel ? dc.sel : dc.norm, False, False);
328 }
329 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, sw, bh, 0, 0);
330 XSync(dpy, False);
331}
332
333void
174sendevent(Window w, Atom a, long value) { 334sendevent(Window w, Atom a, long value) {
175 XEvent e; 335 XEvent e;
176 336
@@ -184,6 +344,11 @@ sendevent(Window w, Atom a, long value) {
184 XSync(dpy, False); 344 XSync(dpy, False);
185} 345}
186 346
347unsigned int
348textw(const char *text) {
349 return textnw(text, strlen(text)) + dc.font.height;
350}
351
187void 352void
188quit(Arg *arg) { 353quit(Arg *arg) {
189 readin = running = False; 354 readin = running = False;