using a global stack for focus recovery on arrange() - seems to work great 15abade2
Anselm R. Garbe · 2006-09-07 17:53 4 file(s) · +26 −8
client.c +14 −2
11 11
/* static functions */
12 12
13 13
static void
14 +
detachstack(Client *c)
15 +
{
16 +
	Client **tc;
17 +
	for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
18 +
	*tc = c->snext;
19 +
}
20 +
21 +
static void
14 22
grabbuttons(Client *c, Bool focus)
15 23
{
16 24
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
99 107
		}
100 108
	}
101 109
	if(c) {
110 +
		detachstack(c);
111 +
		c->snext = stack;
112 +
		stack = c;
102 113
		grabbuttons(c, True);
103 114
		drawtitle(c);
104 115
		XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
198 209
void
199 210
manage(Window w, XWindowAttributes *wa)
200 211
{
201 -
	unsigned int i;
202 212
	Client *c;
203 213
	Window trans;
204 214
	XSetWindowAttributes twa;
247 257
	if(clients)
248 258
		clients->prev = c;
249 259
	c->next = clients;
250 -
	clients = c;
260 +
	c->snext = stack;
261 +
	stack = clients = c;
251 262
252 263
	settitle(c);
253 264
	ban(c);
421 432
	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
422 433
	XDestroyWindow(dpy, c->twin);
423 434
435 +
	detachstack(c);
424 436
	free(c->tags);
425 437
	free(c);
426 438
dwm.h +2 −1
61 61
	Bool *tags;
62 62
	Client *next;
63 63
	Client *prev;
64 +
	Client *snext;
64 65
	Window win;
65 66
	Window twin;
66 67
};
73 74
extern void (*arrange)(Arg *);
74 75
extern Atom wmatom[WMLast], netatom[NetLast];
75 76
extern Bool running, issel, maximized, *seltag;
76 -
extern Client *clients, *sel;
77 +
extern Client *clients, *sel, *stack;
77 78
extern Cursor cursor[CurLast];
78 79
extern DC dc;
79 80
extern Display *dpy;
main.c +1 −0
27 27
Bool maximized = False;
28 28
Client *clients = NULL;
29 29
Client *sel = NULL;
30 +
Client *stack = NULL;
30 31
Cursor cursor[CurLast];
31 32
Display *dpy;
32 33
DC dc = {0};
view.c +9 −5
76 76
		else
77 77
			ban(c);
78 78
	}
79 -
	if(!sel || !isvisible(sel))
80 -
		focus(getnext(clients));
79 +
	if(!sel || !isvisible(sel)) {
80 +
		for(sel = stack; sel && !isvisible(sel); sel = sel->snext);
81 +
		focus(sel);
82 +
	}
81 83
	restack();
82 84
}
83 85
138 140
		else
139 141
			ban(c);
140 142
	}
141 -
	if(!sel || !isvisible(sel))
142 -
		focus(getnext(clients));
143 +
	if(!sel || !isvisible(sel)) {
144 +
		for(sel = stack; sel && !isvisible(sel); sel = sel->snext);
145 +
		focus(sel);
146 +
	}
143 147
	restack();
144 148
}
145 149
227 231
		XRaiseWindow(dpy, sel->win);
228 232
		XRaiseWindow(dpy, sel->twin);
229 233
	}
230 -
	if(arrange != dofloat) 
234 +
	if(arrange != dofloat)
231 235
		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
232 236
			XLowerWindow(dpy, c->twin);
233 237
			XLowerWindow(dpy, c->win);