diff --git a/calmwm.h b/calmwm.h index d65b437..e3cedd1 100644 --- a/calmwm.h +++ b/calmwm.h @@ -368,8 +368,7 @@ void client_applysizehints(struct client_ctx *); void client_config(struct client_ctx *); struct client_ctx *client_current(void); void client_cycle(struct screen_ctx *, int); -void client_cycle_leave(struct screen_ctx *, - struct client_ctx *); +void client_cycle_leave(struct screen_ctx *); void client_delete(struct client_ctx *); void client_draw_border(struct client_ctx *); struct client_ctx *client_find(Window); @@ -378,7 +377,6 @@ void client_getsizehints(struct client_ctx *); void client_hide(struct client_ctx *); void client_hmaximize(struct client_ctx *); void client_htile(struct client_ctx *); -void client_leave(struct client_ctx *); void client_lower(struct client_ctx *); void client_map(struct client_ctx *); void client_maximize(struct client_ctx *); @@ -390,7 +388,7 @@ void client_ptrwarp(struct client_ctx *); void client_raise(struct client_ctx *); void client_resize(struct client_ctx *, int); void client_send_delete(struct client_ctx *); -void client_setactive(struct client_ctx *, int); +void client_setactive(struct client_ctx *); void client_setname(struct client_ctx *); int client_snapcalc(int, int, int, int, int); void client_transient(struct client_ctx *); diff --git a/client.c b/client.c index 173c0f5..81b2d9e 100644 --- a/client.c +++ b/client.c @@ -180,53 +180,35 @@ client_delete(struct client_ctx *cc) } void -client_leave(struct client_ctx *cc) +client_setactive(struct client_ctx *cc) { - if (cc == NULL) - cc = client_current(); - if (cc == NULL) - return; -} + struct screen_ctx *sc = cc->sc; + struct client_ctx *oldcc; -void -client_setactive(struct client_ctx *cc, int fg) -{ - struct screen_ctx *sc; + XInstallColormap(X_Dpy, cc->colormap); - if (cc == NULL) - cc = client_current(); - if (cc == NULL) - return; + if ((cc->flags & CLIENT_INPUT) || + ((cc->flags & CLIENT_WM_TAKE_FOCUS) == 0)) { + XSetInputFocus(X_Dpy, cc->win, + RevertToPointerRoot, CurrentTime); + } + if (cc->flags & CLIENT_WM_TAKE_FOCUS) + client_msg(cc, cwmh[WM_TAKE_FOCUS]); - sc = cc->sc; - - if (fg) { - XInstallColormap(X_Dpy, cc->colormap); - if ((cc->flags & CLIENT_INPUT) || - ((cc->flags & CLIENT_WM_TAKE_FOCUS) == 0)) { - XSetInputFocus(X_Dpy, cc->win, - RevertToPointerRoot, CurrentTime); - } - if (cc->flags & CLIENT_WM_TAKE_FOCUS) - client_msg(cc, cwmh[WM_TAKE_FOCUS]); - conf_grab_mouse(cc->win); - /* - * If we're in the middle of alt-tabbing, don't change - * the order please. - */ - if (!sc->cycling) - client_mtf(cc); - } else - client_leave(cc); - - if (fg && cc != client_current()) { - client_setactive(NULL, 0); - _curcc = cc; - xu_ewmh_net_active_window(sc, cc->win); + if ((oldcc = client_current())) { + oldcc->active = 0; + client_draw_border(oldcc); } - cc->active = fg; + /* If we're in the middle of cycing, don't change the order. */ + if (!sc->cycling) + client_mtf(cc); + + _curcc = cc; + cc->active = 1; client_draw_border(cc); + conf_grab_mouse(cc->win); + xu_ewmh_net_active_window(sc, cc->win); } /* @@ -640,12 +622,14 @@ client_cycle(struct screen_ctx *sc, int flags) } void -client_cycle_leave(struct screen_ctx *sc, struct client_ctx *cc) +client_cycle_leave(struct screen_ctx *sc) { + struct client_ctx *cc; + sc->cycling = 0; - client_mtf(NULL); - if (cc) { + if ((cc = client_current())) { + client_mtf(cc); group_sticky_toggle_exit(cc); XUngrabKeyboard(X_Dpy, CurrentTime); } @@ -724,14 +708,8 @@ client_placecalc(struct client_ctx *cc) static void client_mtf(struct client_ctx *cc) { - struct screen_ctx *sc; + struct screen_ctx *sc = cc->sc; - if (cc == NULL) - cc = client_current(); - if (cc == NULL) - return; - - sc = cc->sc; TAILQ_REMOVE(&sc->mruq, cc, mru_entry); TAILQ_INSERT_HEAD(&sc->mruq, cc, mru_entry); } diff --git a/xevents.c b/xevents.c index 8c07f39..a1fe019 100644 --- a/xevents.c +++ b/xevents.c @@ -43,7 +43,6 @@ static void xev_handle_destroynotify(XEvent *); static void xev_handle_configurerequest(XEvent *); static void xev_handle_propertynotify(XEvent *); static void xev_handle_enternotify(XEvent *); -static void xev_handle_leavenotify(XEvent *); static void xev_handle_buttonpress(XEvent *); static void xev_handle_buttonrelease(XEvent *); static void xev_handle_keypress(XEvent *); @@ -60,7 +59,6 @@ void (*xev_handlers[LASTEvent])(XEvent *) = { [ConfigureRequest] = xev_handle_configurerequest, [PropertyNotify] = xev_handle_propertynotify, [EnterNotify] = xev_handle_enternotify, - [LeaveNotify] = xev_handle_leavenotify, [ButtonPress] = xev_handle_buttonpress, [ButtonRelease] = xev_handle_buttonrelease, [KeyPress] = xev_handle_keypress, @@ -81,7 +79,7 @@ xev_handle_maprequest(XEvent *ee) struct client_ctx *cc = NULL, *old_cc; XWindowAttributes xattr; - if ((old_cc = client_current()) != NULL) + if ((old_cc = client_current())) client_ptrsave(old_cc); if ((cc = client_find(e->window)) == NULL) { @@ -211,13 +209,7 @@ xev_handle_enternotify(XEvent *ee) struct client_ctx *cc; if ((cc = client_find(e->window)) != NULL) - client_setactive(cc, 1); -} - -static void -xev_handle_leavenotify(XEvent *ee) -{ - client_leave(NULL); + client_setactive(cc); } /* We can split this into two event handlers. */ @@ -256,7 +248,7 @@ xev_handle_buttonrelease(XEvent *ee) { struct client_ctx *cc; - if ((cc = client_current()) != NULL) + if ((cc = client_current())) group_sticky_toggle_exit(cc); } @@ -311,17 +303,15 @@ xev_handle_keyrelease(XEvent *ee) { XKeyEvent *e = &ee->xkey; struct screen_ctx *sc; - struct client_ctx *cc; KeySym keysym; u_int i; sc = screen_fromroot(e->root); - cc = client_current(); keysym = XkbKeycodeToKeysym(X_Dpy, e->keycode, 0, 0); for (i = 0; i < nitems(modkeys); i++) { if (keysym == modkeys[i]) { - client_cycle_leave(sc, cc); + client_cycle_leave(sc); break; } } @@ -344,8 +334,7 @@ xev_handle_clientmessage(XEvent *ee) client_send_delete(cc); if (e->message_type == ewmh[_NET_ACTIVE_WINDOW] && e->format == 32) { - old_cc = client_current(); - if (old_cc) + if ((old_cc = client_current())) client_ptrsave(old_cc); client_ptrwarp(cc); }