applied Gottox' patches, and also removed usegrab 56569708
Anselm R Garbe · 2009-03-17 19:53 2 file(s) · +55 −67
config.def.h +0 −2
12 12
static unsigned int snap            = 32;       /* snap pixel */
13 13
static Bool showbar                 = True;     /* False means no bar */
14 14
static Bool topbar                  = True;     /* False means bottom bar */
15 -
static Bool usegrab                 = False;    /* True means grabbing the X server
16 -
                                                   during mouse-based resizals */
17 15
18 16
/* tagging */
19 17
static const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
dwm.c +55 −65
129 129
130 130
/* function declarations */
131 131
static void applyrules(Client *c);
132 -
static void applysizehints(Client *c, int *w, int *h);
132 +
static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h);
133 133
static void arrange(void);
134 134
static void attach(Client *c);
135 135
static void attachstack(Client *c);
252 252
	XClassHint ch = { 0 };
253 253
254 254
	/* rule matching */
255 +
	c->isfloating = c->tags = 0;
255 256
	if(XGetClassHint(dpy, c->win, &ch)) {
256 257
		for(i = 0; i < LENGTH(rules); i++) {
257 258
			r = &rules[i];
259 260
			&& (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
260 261
			&& (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
261 262
				c->isfloating = r->isfloating;
262 -
				c->tags |= r->tags & TAGMASK ? r->tags & TAGMASK : tagset[seltags]; 
263 +
				c->tags |= r->tags; 
263 264
			}
264 265
		}
265 266
		if(ch.res_class)
267 268
		if(ch.res_name)
268 269
			XFree(ch.res_name);
269 270
	}
270 -
	if(!c->tags)
271 -
		c->tags = tagset[seltags];
271 +
	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : tagset[seltags];
272 272
}
273 273
274 -
void
275 -
applysizehints(Client *c, int *w, int *h) {
274 +
Bool
275 +
applysizehints(Client *c, int *x, int *y, int *w, int *h) {
276 276
	Bool baseismin;
277 277
278 -
	if(!resizehints && !c->isfloating)
279 -
		return;
280 -
281 -
	/* see last two sentences in ICCCM 4.1.2.3 */
282 -
	baseismin = c->basew == c->minw && c->baseh == c->minh;
283 -
284 278
	/* set minimum possible */
285 279
	*w = MAX(1, *w);
286 280
	*h = MAX(1, *h);
287 281
288 -
	if(!baseismin) { /* temporarily remove base dimensions */
289 -
		*w -= c->basew;
290 -
		*h -= c->baseh;
291 -
	}
282 +
	if(*x > sx + sw)
283 +
		*x = sw - WIDTH(c);
284 +
	if(*y > sy + sh)
285 +
		*y = sh - HEIGHT(c);
286 +
	if(*x + *w + 2 * c->bw < sx)
287 +
		*x = sx;
288 +
	if(*y + *h + 2 * c->bw < sy)
289 +
		*y = sy;
290 +
	if(*h < bh)
291 +
		*h = bh;
292 +
	if(*w < bh)
293 +
		*w = bh;
294 +
295 +
	if(resizehints || c->isfloating) {
296 +
		/* see last two sentences in ICCCM 4.1.2.3 */
297 +
		baseismin = c->basew == c->minw && c->baseh == c->minh;
298 +
299 +
		if(!baseismin) { /* temporarily remove base dimensions */
300 +
			*w -= c->basew;
301 +
			*h -= c->baseh;
302 +
		}
292 303
293 -
	/* adjust for aspect limits */
294 -
	if(c->mina > 0 && c->maxa > 0) {
295 -
		if(c->maxa < (float)*w / *h)
296 -
			*w = *h * c->maxa;
297 -
		else if(c->mina < (float)*h / *w)
298 -
			*h = *w * c->mina;
299 -
	}
304 +
		/* adjust for aspect limits */
305 +
		if(c->mina > 0 && c->maxa > 0) {
306 +
			if(c->maxa < (float)*w / *h)
307 +
				*w = *h * c->maxa;
308 +
			else if(c->mina < (float)*h / *w)
309 +
				*h = *w * c->mina;
310 +
		}
300 311
301 -
	if(baseismin) { /* increment calculation requires this */
302 -
		*w -= c->basew;
303 -
		*h -= c->baseh;
304 -
	}
312 +
		if(baseismin) { /* increment calculation requires this */
313 +
			*w -= c->basew;
314 +
			*h -= c->baseh;
315 +
		}
305 316
306 -
	/* adjust for increment value */
307 -
	if(c->incw)
308 -
		*w -= *w % c->incw;
309 -
	if(c->inch)
310 -
		*h -= *h % c->inch;
317 +
		/* adjust for increment value */
318 +
		if(c->incw)
319 +
			*w -= *w % c->incw;
320 +
		if(c->inch)
321 +
			*h -= *h % c->inch;
311 322
312 -
	/* restore base dimensions */
313 -
	*w += c->basew;
314 -
	*h += c->baseh;
323 +
		/* restore base dimensions */
324 +
		*w += c->basew;
325 +
		*h += c->baseh;
315 326
316 -
	*w = MAX(*w, c->minw);
317 -
	*h = MAX(*h, c->minh);
327 +
		*w = MAX(*w, c->minw);
328 +
		*h = MAX(*h, c->minh);
318 329
319 -
	if(c->maxw)
320 -
		*w = MIN(*w, c->maxw);
330 +
		if(c->maxw)
331 +
			*w = MIN(*w, c->maxw);
321 332
322 -
	if(c->maxh)
323 -
		*h = MIN(*h, c->maxh);
333 +
		if(c->maxh)
334 +
			*h = MIN(*h, c->maxh);
335 +
	}
336 +
	return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
324 337
}
325 338
326 339
void
1005 1018
	None, cursor[CurMove], CurrentTime) != GrabSuccess)
1006 1019
		return;
1007 1020
	XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
1008 -
	if(usegrab)
1009 -
		XGrabServer(dpy);
1010 1021
	do {
1011 1022
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1012 1023
		switch (ev.type) {
1037 1048
		}
1038 1049
	}
1039 1050
	while(ev.type != ButtonRelease);
1040 -
	if(usegrab)
1041 -
		XUngrabServer(dpy);
1042 1051
	XUngrabPointer(dpy, CurrentTime);
1043 1052
}
1044 1053
1091 1100
resize(Client *c, int x, int y, int w, int h) {
1092 1101
	XWindowChanges wc;
1093 1102
1094 -
	applysizehints(c, &w, &h);
1095 -
	if(w <= 0 || h <= 0)
1096 -
		return;
1097 -
	if(x > sx + sw)
1098 -
		x = sw - WIDTH(c);
1099 -
	if(y > sy + sh)
1100 -
		y = sh - HEIGHT(c);
1101 -
	if(x + w + 2 * c->bw < sx)
1102 -
		x = sx;
1103 -
	if(y + h + 2 * c->bw < sy)
1104 -
		y = sy;
1105 -
	if(h < bh)
1106 -
		h = bh;
1107 -
	if(w < bh)
1108 -
		w = bh;
1109 -
	if(c->x != x || c->y != y || c->w != w || c->h != h) {
1103 +
	if(applysizehints(c, &x, &y, &w, &h)) {
1110 1104
		c->x = wc.x = x;
1111 1105
		c->y = wc.y = y;
1112 1106
		c->w = wc.width = w;
1135 1129
	None, cursor[CurResize], CurrentTime) != GrabSuccess)
1136 1130
		return;
1137 1131
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
1138 -
	if(usegrab)
1139 -
		XGrabServer(dpy);
1140 1132
	do {
1141 1133
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
1142 1134
		switch(ev.type) {
1161 1153
		}
1162 1154
	}
1163 1155
	while(ev.type != ButtonRelease);
1164 -
	if(usegrab)
1165 -
		XUngrabServer(dpy);
1166 1156
	XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
1167 1157
	XUngrabPointer(dpy, CurrentTime);
1168 1158
	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));