diff --git a/cmd/wm/client.c b/cmd/wm/client.c index 139ac056..2a89aaf6 100644 --- a/cmd/wm/client.c +++ b/cmd/wm/client.c @@ -36,6 +36,24 @@ set_client_state(Client * c, int state) (unsigned char *) data, 2); } +void +focus_client(Client *new, Client *old) +{ + if(old && (old != new)) { + ungrab_client(old, AnyModifier, AnyButton); + grab_client(old, AnyModifier, AnyButton); + draw_frame(old->frame); + } + ungrab_client(new, AnyModifier, AnyButton); + grab_client(new, Mod1Mask, Button1); + grab_client(new, Mod1Mask, Button3); + XRaiseWindow(dpy, new->win); + XSetInputFocus(dpy, new->win, RevertToPointerRoot, CurrentTime); + draw_frame(new->frame); + invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); + XSync(dpy, False); +} + void map_client(Client * c) { diff --git a/cmd/wm/layout_column.c b/cmd/wm/layout_column.c index 54bd2458..008857b2 100644 --- a/cmd/wm/layout_column.c +++ b/cmd/wm/layout_column.c @@ -180,6 +180,7 @@ detach_frame(Layout *l, Frame * old) acme->frames = old->next; if(old->next) old->next->prev = old->prev; + old->prev = old->next = nil; old->aux = nil; detach_frame_from_layout(old); acme->nframes--; @@ -424,19 +425,7 @@ focus_col(Layout *l, Client *c, Bool raise) XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->rect.width / 2, c->rect.height / 2); - if(old && (old != c)) { - ungrab_client(old, AnyModifier, AnyButton); - grab_client(old, AnyModifier, AnyButton); - draw_frame(old->frame); - } - ungrab_client(c, AnyModifier, AnyButton); - grab_client(c, Mod1Mask, Button1); - grab_client(c, Mod1Mask, Button3); - XRaiseWindow(dpy, c->win); - XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); - draw_frame(c->frame); - invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); - XSync(dpy, False); + focus_client(c, old); } static Frame * @@ -504,7 +493,7 @@ select_frame(void *obj, char *arg) for(cell = col->cells; cell && i != idx; cell = cell->next) i++; } - if(cell && cell != col) + if(cell && cell != col->sel) focus_col(l, cell->frame->sel, True); } diff --git a/cmd/wm/layout_float.c b/cmd/wm/layout_float.c index d18f0a98..5504ce8d 100644 --- a/cmd/wm/layout_float.c +++ b/cmd/wm/layout_float.c @@ -108,6 +108,7 @@ detach_frame(Layout *l, Frame * old) if(fl->sel == old) fl->sel = fl->frames; + old->prev = old->next = nil; detach_frame_from_layout(old); fl->nframes--; } @@ -193,18 +194,7 @@ focus_float(Layout *l, Client *c, Bool raise) c->rect.width / 2, c->rect.height / 2); } - if(old && (old != c)) { - grab_client(old, AnyModifier, AnyButton); - draw_frame(old->frame); - } - ungrab_client(c, AnyModifier, AnyButton); - grab_client(c, Mod1Mask, Button1); - grab_client(c, Mod1Mask, Button3); - XRaiseWindow(dpy, c->win); - XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); - draw_frame(c->frame); - invoke_wm_event(def[WM_EVENT_CLIENT_UPDATE]); - XSync(dpy, False); + focus_client(c, old); } static Frame * diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h index 7c587022..2e568ad5 100644 --- a/cmd/wm/wm.h +++ b/cmd/wm/wm.h @@ -229,6 +229,7 @@ Client *sel_client(); Client *clientat(Client * clients, size_t idx); void detach_detached(Client * c); void attach_detached(Client * c); +void focus_client(Client *new, Client *old); /* frame.c */ Frame *win_to_frame(Window w);