draw.c is useless (belongs to main.c now) f8415019
Anselm R. Garbe · 2007-02-19 15:17 6 file(s) · +178 −195
Makefile +1 −1
3 3
4 4
include config.mk
5 5
6 -
SRC = client.c draw.c event.c main.c screen.c util.c
6 +
SRC = client.c event.c main.c screen.c util.c
7 7
OBJ = ${SRC:.c=.o}
8 8
9 9
all: options dwm
client.c +1 −11
200 200
	}
201 201
}
202 202
203 -
Client *
204 -
getclient(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 -
213 203
void
214 204
killclient(Arg *arg) {
215 205
	if(!sel)
259 249
	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
260 250
	configure(c); /* propagates border_width, if size doesn't change */
261 251
	updatetitle(c);
262 -
	t = getclient(trans);
252 +
	for(t = clients; t && t->win != c->win; t = t->next);
263 253
	settags(c, t);
264 254
	if(!c->isfloat)
265 255
		c->isfloat = (t != 0) || c->isfixed;
draw.c (deleted) +0 −175
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 -
10 -
static Bool
11 -
isoccupied(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 -
20 -
static unsigned int
21 -
textnw(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 -
31 -
static void
32 -
drawtext(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 -
90 -
void
91 -
drawstatus(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 -
121 -
unsigned long
122 -
getcolor(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 -
131 -
void
132 -
setfont(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 -
172 -
unsigned int
173 -
textw(const char *text) {
174 -
	return textnw(text, strlen(text)) + dc.font.height;
175 -
}
dwm.h +3 −8
103 103
extern void focus(Client *c);			/* focus c, c may be NULL */
104 104
extern void focusnext(Arg *arg);		/* focuses next visible client, arg is ignored  */
105 105
extern void focusprev(Arg *arg);		/* focuses previous visible client, arg is ignored */
106 -
extern Client *getclient(Window w);		/* return client of w */
107 106
extern void killclient(Arg *arg);		/* kill c nicely */
108 107
extern void manage(Window w, XWindowAttributes *wa);	/* manage new client */
109 108
Client *nexttiled(Client *c);			/* returns tiled successor of c */
110 109
extern 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*/
112 111
extern void updatesizehints(Client *c);		/* update the size hint variables of c */
113 112
extern void updatetitle(Client *c);		/* update the name of c */
114 113
extern void unmanage(Client *c);		/* destroy c */
115 114
extern void zoom(Arg *arg);			/* zooms the focused client to master area, arg is ignored */
116 115
117 -
/* draw.c */
118 -
extern void drawstatus(void);			/* draw the bar */
119 -
extern unsigned long getcolor(const char *colstr);	/* return color of colstr */
120 -
extern void setfont(const char *fontstr);	/* set the font for DC */
121 -
extern unsigned int textw(const char *text);	/* return the width of text in px*/
122 -
123 116
/* event.c */
124 117
extern void grabkeys(void);			/* grab all keys defined in config.h */
125 118
extern void procevent(void);			/* process pending X events */
126 119
127 120
/* main.c */
121 +
extern void drawstatus(void);			/* draw the bar */
122 +
extern unsigned int textw(const char *text);	/* return the width of text in px*/
128 123
extern void quit(Arg *arg);			/* quit dwm nicely */
129 124
extern void sendevent(Window w, Atom a, long value);	/* send synthetic event to w */
130 125
extern int xerror(Display *dsply, XErrorEvent *ee);	/* dwm's X error handler */
event.c +8 −0
20 20
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
21 21
#define MOUSEMASK		(BUTTONMASK | PointerMotionMask)
22 22
23 +
static Client *
24 +
getclient(Window w) {
25 +
	Client *c;
26 +
27 +
	for(c = clients; c && c->win != w; c = c->next);
28 +
	return c;
29 +
}
30 +
23 31
static void
24 32
movemouse(Client *c) {
25 33
	int x1, y1, ocx, ocy, di, nx, ny;
main.c +165 −0
61 61
	free(seltag);
62 62
}
63 63
64 +
static unsigned int
65 +
textnw(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 +
75 +
static void
76 +
drawtext(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 +
132 +
static unsigned long
133 +
getcolor(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 +
142 +
static Bool
143 +
isoccupied(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 +
64 152
static void
65 153
scan(void) {
66 154
	unsigned int i, num;
82 170
}
83 171
84 172
static void
173 +
setfont(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 +
213 +
static void
85 214
setup(void) {
86 215
	int i, j;
87 216
	unsigned int mask;
171 300
/* extern */
172 301
173 302
void
303 +
drawstatus(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 +
333 +
void
174 334
sendevent(Window w, Atom a, long value) {
175 335
	XEvent e;
176 336
182 342
	e.xclient.data.l[1] = CurrentTime;
183 343
	XSendEvent(dpy, w, False, NoEventMask, &e);
184 344
	XSync(dpy, False);
345 +
}
346 +
347 +
unsigned int
348 +
textw(const char *text) {
349 +
	return textnw(text, strlen(text)) + dc.font.height;
185 350
}
186 351
187 352
void