using a global stack for focus recovery on arrange() - seems to work great

This commit is contained in:
Anselm R. Garbe 2006-09-07 17:53:40 +02:00
parent 7ab8c87281
commit 15abade272
4 changed files with 26 additions and 8 deletions

View file

@ -10,6 +10,14 @@
/* static functions */ /* static functions */
static void
detachstack(Client *c)
{
Client **tc;
for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
*tc = c->snext;
}
static void static void
grabbuttons(Client *c, Bool focus) grabbuttons(Client *c, Bool focus)
{ {
@ -99,6 +107,9 @@ focus(Client *c)
} }
} }
if(c) { if(c) {
detachstack(c);
c->snext = stack;
stack = c;
grabbuttons(c, True); grabbuttons(c, True);
drawtitle(c); drawtitle(c);
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
@ -198,7 +209,6 @@ killclient(Arg *arg)
void void
manage(Window w, XWindowAttributes *wa) manage(Window w, XWindowAttributes *wa)
{ {
unsigned int i;
Client *c; Client *c;
Window trans; Window trans;
XSetWindowAttributes twa; XSetWindowAttributes twa;
@ -247,7 +257,8 @@ manage(Window w, XWindowAttributes *wa)
if(clients) if(clients)
clients->prev = c; clients->prev = c;
c->next = clients; c->next = clients;
clients = c; c->snext = stack;
stack = clients = c;
settitle(c); settitle(c);
ban(c); ban(c);
@ -421,6 +432,7 @@ unmanage(Client *c)
XUngrabButton(dpy, AnyButton, AnyModifier, c->win); XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
XDestroyWindow(dpy, c->twin); XDestroyWindow(dpy, c->twin);
detachstack(c);
free(c->tags); free(c->tags);
free(c); free(c);

3
dwm.h
View file

@ -61,6 +61,7 @@ struct Client {
Bool *tags; Bool *tags;
Client *next; Client *next;
Client *prev; Client *prev;
Client *snext;
Window win; Window win;
Window twin; Window twin;
}; };
@ -73,7 +74,7 @@ extern void (*handler[LASTEvent])(XEvent *);
extern void (*arrange)(Arg *); extern void (*arrange)(Arg *);
extern Atom wmatom[WMLast], netatom[NetLast]; extern Atom wmatom[WMLast], netatom[NetLast];
extern Bool running, issel, maximized, *seltag; extern Bool running, issel, maximized, *seltag;
extern Client *clients, *sel; extern Client *clients, *sel, *stack;
extern Cursor cursor[CurLast]; extern Cursor cursor[CurLast];
extern DC dc; extern DC dc;
extern Display *dpy; extern Display *dpy;

1
main.c
View file

@ -27,6 +27,7 @@ Bool issel = True;
Bool maximized = False; Bool maximized = False;
Client *clients = NULL; Client *clients = NULL;
Client *sel = NULL; Client *sel = NULL;
Client *stack = NULL;
Cursor cursor[CurLast]; Cursor cursor[CurLast];
Display *dpy; Display *dpy;
DC dc = {0}; DC dc = {0};

14
view.c
View file

@ -76,8 +76,10 @@ dofloat(Arg *arg)
else else
ban(c); ban(c);
} }
if(!sel || !isvisible(sel)) if(!sel || !isvisible(sel)) {
focus(getnext(clients)); for(sel = stack; sel && !isvisible(sel); sel = sel->snext);
focus(sel);
}
restack(); restack();
} }
@ -138,8 +140,10 @@ dotile(Arg *arg)
else else
ban(c); ban(c);
} }
if(!sel || !isvisible(sel)) if(!sel || !isvisible(sel)) {
focus(getnext(clients)); for(sel = stack; sel && !isvisible(sel); sel = sel->snext);
focus(sel);
}
restack(); restack();
} }
@ -227,7 +231,7 @@ restack()
XRaiseWindow(dpy, sel->win); XRaiseWindow(dpy, sel->win);
XRaiseWindow(dpy, sel->twin); XRaiseWindow(dpy, sel->twin);
} }
if(arrange != dofloat) if(arrange != dofloat)
for(c = nexttiled(clients); c; c = nexttiled(c->next)) { for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
XLowerWindow(dpy, c->twin); XLowerWindow(dpy, c->twin);
XLowerWindow(dpy, c->win); XLowerWindow(dpy, c->win);