several other focus fixes, introduced unfocus() 18b13124
Anselm R Garbe · 2009-06-24 19:45 1 file(s) · +29 −9
dwm.c +29 −9
1 -
//#define XINULATOR /* debug, simulates dual head */
1 +
#define XINULATOR /* debug, simulates dual head */
2 2
/* See LICENSE file for copyright and license details.
3 3
 *
4 4
 * dynamic window manager is designed like any other X client as well. It is
211 211
static void togglefloating(const Arg *arg);
212 212
static void toggletag(const Arg *arg);
213 213
static void toggleview(const Arg *arg);
214 +
static void unfocus(Client *c);
214 215
static void unmanage(Client *c);
215 216
static void unmapnotify(XEvent *e);
216 217
static void updategeom(void);
391 392
	unsigned int i, x, click;
392 393
	Arg arg = {0};
393 394
	Client *c;
395 +
	Monitor *m;
394 396
	XButtonPressedEvent *ev = &e->xbutton;
395 397
396 398
	click = ClkRootWin;
399 +
	/* focus monitor if necessary */
400 +
	for(m = mons; m; m = m->next)
401 +
		if(ev->window == m->barwin) {
402 +
			if(m != selmon) {
403 +
				if(selmon->stack)
404 +
					focus(selmon->stack);
405 +
				else {
406 +
					selmon = m;
407 +
					focus(NULL);
408 +
				}
409 +
			}
410 +
			break;
411 +
		}
397 412
	if(ev->window == selmon->barwin && ev->x >= selmon->btx) {
398 413
		i = 0;
399 414
		x = selmon->btx;
757 772
focus(Client *c) {
758 773
	if(!c || !ISVISIBLE(c))
759 774
		for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
760 -
	if(selmon->sel && selmon->sel != c) {
761 -
		grabbuttons(selmon->sel, False);
762 -
		XSetWindowBorder(dpy, selmon->sel->win, dc.norm[ColBorder]);
763 -
	}
775 +
	if(selmon->sel)
776 +
		unfocus(selmon->sel);
764 777
	if(c) {
765 778
		if(c->mon != selmon)
766 779
			selmon = c->mon;
797 810
			if(m->stack)
798 811
				focus(m->stack);
799 812
			else {
813 +
				unfocus(selmon->stack);
800 814
				selmon = m;
801 815
				focus(NULL);
802 816
			}
1219 1233
		c->w = wc.width = w;
1220 1234
		c->h = wc.height = h;
1221 1235
		wc.border_width = c->bw;
1222 -
		XConfigureWindow(dpy, c->win,
1223 -
				CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1236 +
		XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
1224 1237
		configure(c);
1225 1238
		XSync(dpy, False);
1226 1239
	}
1590 1603
}
1591 1604
1592 1605
void
1606 +
unfocus(Client *c) {
1607 +
	if(!c)
1608 +
		return;
1609 +
	grabbuttons(c, False);
1610 +
	XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
1611 +
}
1612 +
1613 +
void
1593 1614
unmanage(Client *c) {
1594 1615
	XWindowChanges wc;
1595 1616
1732 1753
	}
1733 1754
1734 1755
	/* reassign left over clients of disappeared monitors */
1735 -
	for(tm = mons; tm; tm = tm->next) {
1756 +
	for(tm = mons; tm; tm = tm->next)
1736 1757
		while(tm->clients) {
1737 1758
			c = tm->clients;
1738 1759
			tm->clients = c->next;
1741 1762
			attach(c);
1742 1763
			attachstack(c);
1743 1764
		}
1744 -
	}
1745 1765
1746 1766
	/* select focused monitor */
1747 1767
	selmon = newmons;