sanitized other stuff c09bf8da
Anselm R. Garbe · 2006-07-15 17:19 5 file(s) · +136 −142
client.c +2 −2
178 178
	if(!sel)
179 179
		return;
180 180
	if(sel->proto & WM_PROTOCOL_DELWIN)
181 -
		sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
181 +
		sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]);
182 182
	else
183 183
		XKillClient(dpy, sel->win);
184 184
}
353 353
354 354
	name.nitems = 0;
355 355
	c->name[0] = 0;
356 -
	XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
356 +
	XGetTextProperty(dpy, c->win, &name, netatom[NetWMName]);
357 357
	if(!name.nitems)
358 358
		XGetWMName(dpy, c->win, &name);
359 359
	if(!name.nitems)
draw.c +52 −52
29 29
	XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
30 30
}
31 31
32 -
/* extern functions */
33 -
34 -
void
35 -
drawall()
32 +
static unsigned int
33 +
textnw(char *text, unsigned int len)
36 34
{
37 -
	Client *c;
38 -
39 -
	for(c = clients; c; c = getnext(c->next))
40 -
		drawtitle(c);
41 -
	drawstatus();
42 -
}
43 -
44 -
void
45 -
drawstatus()
46 -
{
47 -
	int i;
48 -
	Bool istile = arrange == dotile;
49 -
50 -
	dc.x = dc.y = 0;
51 -
	dc.w = bw;
52 -
	drawtext(NULL, !istile, False);
53 -
54 -
	dc.w = 0;
55 -
	for(i = 0; i < TLast; i++) {
56 -
		dc.x += dc.w;
57 -
		dc.w = textw(tags[i]);
58 -
		if(istile)
59 -
			drawtext(tags[i], (i == tsel), True);
60 -
		else
61 -
			drawtext(tags[i], (i != tsel), True);
35 +
	XRectangle r;
36 +
	if(dc.font.set) {
37 +
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
38 +
		return r.width;
62 39
	}
63 -
	if(sel) {
64 -
		dc.x += dc.w;
65 -
		dc.w = textw(sel->name);
66 -
		drawtext(sel->name, istile, True);
67 -
	}
68 -
	dc.w = textw(stext);
69 -
	dc.x = bx + bw - dc.w;
70 -
	drawtext(stext, !istile, False);
71 -
72 -
	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
73 -
	XFlush(dpy);
40 +
	return XTextWidth(dc.font.xfont, text, len);
74 41
}
75 42
76 -
void
43 +
static void
77 44
drawtext(const char *text, Bool invert, Bool border)
78 45
{
79 46
	int x, y, w, h;
123 90
	}
124 91
}
125 92
93 +
/* extern functions */
94 +
95 +
void
96 +
drawall()
97 +
{
98 +
	Client *c;
99 +
100 +
	for(c = clients; c; c = getnext(c->next))
101 +
		drawtitle(c);
102 +
	drawstatus();
103 +
}
104 +
105 +
void
106 +
drawstatus()
107 +
{
108 +
	int i;
109 +
	Bool istile = arrange == dotile;
110 +
111 +
	dc.x = dc.y = 0;
112 +
	dc.w = bw;
113 +
	drawtext(NULL, !istile, False);
114 +
115 +
	dc.w = 0;
116 +
	for(i = 0; i < TLast; i++) {
117 +
		dc.x += dc.w;
118 +
		dc.w = textw(tags[i]);
119 +
		if(istile)
120 +
			drawtext(tags[i], (i == tsel), True);
121 +
		else
122 +
			drawtext(tags[i], (i != tsel), True);
123 +
	}
124 +
	if(sel) {
125 +
		dc.x += dc.w;
126 +
		dc.w = textw(sel->name);
127 +
		drawtext(sel->name, istile, True);
128 +
	}
129 +
	dc.w = textw(stext);
130 +
	dc.x = bx + bw - dc.w;
131 +
	drawtext(stext, !istile, False);
132 +
133 +
	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
134 +
	XFlush(dpy);
135 +
}
136 +
126 137
void
127 138
drawtitle(Client *c)
128 139
{
216 227
		dc.font.descent = dc.font.xfont->descent;
217 228
	}
218 229
	dc.font.height = dc.font.ascent + dc.font.descent;
219 -
}
220 -
221 -
unsigned int
222 -
textnw(char *text, unsigned int len)
223 -
{
224 -
	XRectangle r;
225 -
	if(dc.font.set) {
226 -
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
227 -
		return r.width;
228 -
	}
229 -
	return XTextWidth(dc.font.xfont, text, len);
230 230
}
231 231
232 232
unsigned int
dwm.h +1 −3
89 89
90 90
extern Display *dpy;
91 91
extern Window root, barwin;
92 -
extern Atom wm_atom[WMLast], net_atom[NetLast];
92 +
extern Atom wmatom[WMLast], netatom[NetLast];
93 93
extern Cursor cursor[CurLast];
94 94
extern Bool running, issel;
95 95
extern void (*handler[LASTEvent])(XEvent *);
124 124
/* draw.c */
125 125
extern void drawall();
126 126
extern void drawstatus();
127 -
extern void drawtext(const char *text, Bool invert, Bool border);
128 127
extern void drawtitle(Client *c);
129 128
extern unsigned long getcolor(const char *colstr);
130 129
extern void setfont(const char *fontstr);
131 -
extern unsigned int textnw(char *text, unsigned int len);
132 130
extern unsigned int textw(char *text);
133 131
134 132
/* event.c */
event.c +69 −72
51 51
52 52
/* static functions */
53 53
54 -
static void movemouse(Client *c);
55 -
static void resizemouse(Client *c);
54 +
static void
55 +
movemouse(Client *c)
56 +
{
57 +
	XEvent ev;
58 +
	int x1, y1, ocx, ocy, di;
59 +
	unsigned int dui;
60 +
	Window dummy;
61 +
62 +
	ocx = c->x;
63 +
	ocy = c->y;
64 +
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
65 +
				None, cursor[CurMove], CurrentTime) != GrabSuccess)
66 +
		return;
67 +
	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
68 +
	for(;;) {
69 +
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
70 +
		switch (ev.type) {
71 +
		default: break;
72 +
		case Expose:
73 +
			handler[Expose](&ev);
74 +
			break;
75 +
		case MotionNotify:
76 +
			XFlush(dpy);
77 +
			c->x = ocx + (ev.xmotion.x - x1);
78 +
			c->y = ocy + (ev.xmotion.y - y1);
79 +
			resize(c, False);
80 +
			break;
81 +
		case ButtonRelease:
82 +
			XUngrabPointer(dpy, CurrentTime);
83 +
			return;
84 +
		}
85 +
	}
86 +
}
87 +
88 +
static void
89 +
resizemouse(Client *c)
90 +
{
91 +
	XEvent ev;
92 +
	int ocx, ocy;
93 +
94 +
	ocx = c->x;
95 +
	ocy = c->y;
96 +
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
97 +
				None, cursor[CurResize], CurrentTime) != GrabSuccess)
98 +
		return;
99 +
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
100 +
	for(;;) {
101 +
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
102 +
		switch(ev.type) {
103 +
		default: break;
104 +
		case Expose:
105 +
			handler[Expose](&ev);
106 +
			break;
107 +
		case MotionNotify:
108 +
			XFlush(dpy);
109 +
			c->w = abs(ocx - ev.xmotion.x);
110 +
			c->h = abs(ocy - ev.xmotion.y);
111 +
			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
112 +
			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
113 +
			resize(c, True);
114 +
			break;
115 +
		case ButtonRelease:
116 +
			XUngrabPointer(dpy, CurrentTime);
117 +
			return;
118 +
		}
119 +
	}
120 +
}
56 121
57 122
static void
58 123
buttonpress(XEvent *e)
214 279
}
215 280
216 281
static void
217 -
movemouse(Client *c)
218 -
{
219 -
	XEvent ev;
220 -
	int x1, y1, ocx, ocy, di;
221 -
	unsigned int dui;
222 -
	Window dummy;
223 -
224 -
	ocx = c->x;
225 -
	ocy = c->y;
226 -
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
227 -
				None, cursor[CurMove], CurrentTime) != GrabSuccess)
228 -
		return;
229 -
	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
230 -
	for(;;) {
231 -
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
232 -
		switch (ev.type) {
233 -
		default: break;
234 -
		case Expose:
235 -
			handler[Expose](&ev);
236 -
			break;
237 -
		case MotionNotify:
238 -
			XFlush(dpy);
239 -
			c->x = ocx + (ev.xmotion.x - x1);
240 -
			c->y = ocy + (ev.xmotion.y - y1);
241 -
			resize(c, False);
242 -
			break;
243 -
		case ButtonRelease:
244 -
			XUngrabPointer(dpy, CurrentTime);
245 -
			return;
246 -
		}
247 -
	}
248 -
}
249 -
250 -
static void
251 282
propertynotify(XEvent *e)
252 283
{
253 284
	XPropertyEvent *ev = &e->xproperty;
258 289
		return; /* ignore */
259 290
260 291
	if((c = getclient(ev->window))) {
261 -
		if(ev->atom == wm_atom[WMProtocols]) {
292 +
		if(ev->atom == wmatom[WMProtocols]) {
262 293
			c->proto = getproto(c->win);
263 294
			return;
264 295
		}
273 304
				setsize(c);
274 305
				break;
275 306
		}
276 -
		if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
307 +
		if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
277 308
			settitle(c);
278 309
			drawtitle(c);
279 -
		}
280 -
	}
281 -
}
282 -
283 -
static void
284 -
resizemouse(Client *c)
285 -
{
286 -
	XEvent ev;
287 -
	int ocx, ocy;
288 -
289 -
	ocx = c->x;
290 -
	ocy = c->y;
291 -
	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
292 -
				None, cursor[CurResize], CurrentTime) != GrabSuccess)
293 -
		return;
294 -
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
295 -
	for(;;) {
296 -
		XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
297 -
		switch(ev.type) {
298 -
		default: break;
299 -
		case Expose:
300 -
			handler[Expose](&ev);
301 -
			break;
302 -
		case MotionNotify:
303 -
			XFlush(dpy);
304 -
			c->w = abs(ocx - ev.xmotion.x);
305 -
			c->h = abs(ocy - ev.xmotion.y);
306 -
			c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
307 -
			c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
308 -
			resize(c, True);
309 -
			break;
310 -
		case ButtonRelease:
311 -
			XUngrabPointer(dpy, CurrentTime);
312 -
			return;
313 310
		}
314 311
	}
315 312
}
main.c +12 −13
16 16
17 17
Display *dpy;
18 18
Window root, barwin;
19 -
Atom wm_atom[WMLast], net_atom[NetLast];
19 +
Atom wmatom[WMLast], netatom[NetLast];
20 20
Cursor cursor[CurLast];
21 21
Bool running = True;
22 -
Bool issel;
22 +
Bool issel = True;
23 23
24 24
int tsel = Tdev; /* default tag */
25 25
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
30 30
Client *sel = NULL;
31 31
32 32
static Bool otherwm;
33 -
static const char version[] =
34 -
	"dwm-" VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
35 33
static int (*xerrorxlib)(Display *, XErrorEvent *);
36 34
37 35
/* static functions */
109 107
	int protos = 0;
110 108
	int i;
111 109
112 -
	res = win_property(w, wm_atom[WMProtocols], XA_ATOM, 20L, &protocols);
110 +
	res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols);
113 111
	if(res <= 0) {
114 112
		return protos;
115 113
	}
116 114
	for(i = 0; i < res; i++) {
117 -
		if(protocols[i] == wm_atom[WMDelete])
115 +
		if(protocols[i] == wmatom[WMDelete])
118 116
			protos |= WM_PROTOCOL_DELWIN;
119 117
	}
120 118
	free((char *) protocols);
184 182
	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
185 183
		switch (argv[i][1]) {
186 184
		case 'v':
187 -
			fprintf(stdout, "%s", version);
185 +
			fprintf(stdout, "%s",
186 +
					"dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n");
188 187
			exit(0);
189 188
			break;
190 189
		default:
214 213
	xerrorxlib = XSetErrorHandler(xerror);
215 214
216 215
	/* init atoms */
217 -
	wm_atom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
218 -
	wm_atom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
219 -
	net_atom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
220 -
	net_atom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
221 -
	XChangeProperty(dpy, root, net_atom[NetSupported], XA_ATOM, 32,
222 -
			PropModeReplace, (unsigned char *) net_atom, NetLast);
216 +
	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
217 +
	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
218 +
	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
219 +
	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
220 +
	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
221 +
			PropModeReplace, (unsigned char *) netatom, NetLast);
223 222
224 223
	/* init cursors */
225 224
	cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);