simplify focusclient
This arranges the function into some logical tasks: deactivate the old client, update wlroots' keyboard focus, update our data structures, and activate the new client. The last two only need to be done when focusing something new, so an early return saves some horizontal space.
This commit is contained in:
parent
0a59f47c18
commit
90d80c0de9
1 changed files with 32 additions and 47 deletions
67
dwl.c
67
dwl.c
|
@ -681,63 +681,48 @@ dirtomon(int dir)
|
||||||
void
|
void
|
||||||
focusclient(Client *c, struct wlr_surface *surface, int lift)
|
focusclient(Client *c, struct wlr_surface *surface, int lift)
|
||||||
{
|
{
|
||||||
Client *sel = selclient();
|
Client *old = selclient();
|
||||||
struct wlr_keyboard *kb;
|
struct wlr_keyboard *kb = wlr_seat_get_keyboard(seat);
|
||||||
/* Previously focused surface */
|
|
||||||
struct wlr_surface *psurface = seat->keyboard_state.focused_surface;
|
|
||||||
|
|
||||||
if (c) {
|
/* Use top-level wlr_surface if nothing more specific is given */
|
||||||
/* assert(VISIBLEON(c, c->mon)); ? */
|
if (c && !surface)
|
||||||
/* Use top-level wlr_surface if nothing more specific given */
|
|
||||||
if (!surface)
|
|
||||||
surface = WLR_SURFACE(c);
|
surface = WLR_SURFACE(c);
|
||||||
|
|
||||||
/* Focus the correct monitor (must come after selclient!) */
|
/* Deactivate old client if focus is changing */
|
||||||
selmon = c->mon;
|
if (c != old && old) {
|
||||||
|
if (old->type != XDGShell)
|
||||||
|
wlr_xwayland_surface_activate(old->xwayland_surface, 0);
|
||||||
|
else
|
||||||
|
wlr_xdg_toplevel_set_activated(old->xdg_surface, 0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Move the client to the front of the focus stack */
|
/* Update wlroots' keyboard focus */
|
||||||
|
if (!c) {
|
||||||
|
/* With no client, all we have left is to clear focus */
|
||||||
|
wlr_seat_keyboard_notify_clear_focus(seat);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Otherwise, update the focus if it has changed */
|
||||||
|
if (surface != seat->keyboard_state.focused_surface)
|
||||||
|
wlr_seat_keyboard_notify_enter(seat, surface,
|
||||||
|
kb->keycodes, kb->num_keycodes, &kb->modifiers);
|
||||||
|
|
||||||
|
/* Select client's monitor, move it to the top of the focus stack, and
|
||||||
|
* raise it in the stacking order if requested. */
|
||||||
|
selmon = c->mon;
|
||||||
wl_list_remove(&c->flink);
|
wl_list_remove(&c->flink);
|
||||||
wl_list_insert(&fstack, &c->flink);
|
wl_list_insert(&fstack, &c->flink);
|
||||||
|
|
||||||
/* Also raise client in stacking order if requested */
|
|
||||||
if (lift) {
|
if (lift) {
|
||||||
wl_list_remove(&c->slink);
|
wl_list_remove(&c->slink);
|
||||||
wl_list_insert(&stack, &c->slink);
|
wl_list_insert(&stack, &c->slink);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/* Activate the new client */
|
||||||
* If the focused surface has changed, tell the seat to have the
|
|
||||||
* keyboard enter the new surface. wlroots will keep track of this and
|
|
||||||
* automatically send key events to the appropriate clients. If surface
|
|
||||||
* is NULL, we clear the focus instead.
|
|
||||||
*/
|
|
||||||
if (!surface) {
|
|
||||||
wlr_seat_keyboard_notify_clear_focus(seat);
|
|
||||||
} else if (surface != psurface) {
|
|
||||||
kb = wlr_seat_get_keyboard(seat);
|
|
||||||
wlr_seat_keyboard_notify_enter(seat, surface,
|
|
||||||
kb->keycodes, kb->num_keycodes, &kb->modifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* If the focused toplevel has changed, deactivate the old one. Always
|
|
||||||
* activate the current one. This lets the clients know to repaint
|
|
||||||
* accordingly, e.g. show/hide a caret.
|
|
||||||
*/
|
|
||||||
if (c != sel && sel) {
|
|
||||||
if (sel->type != XDGShell)
|
|
||||||
wlr_xwayland_surface_activate(sel->xwayland_surface, 0);
|
|
||||||
else
|
|
||||||
wlr_xdg_toplevel_set_activated(sel->xdg_surface, 0);
|
|
||||||
}
|
|
||||||
if (c) {
|
|
||||||
if (c->type != XDGShell)
|
if (c->type != XDGShell)
|
||||||
wlr_xwayland_surface_activate(c->xwayland_surface, 1);
|
wlr_xwayland_surface_activate(c->xwayland_surface, 1);
|
||||||
else
|
else
|
||||||
wlr_xdg_toplevel_set_activated(c->xdg_surface, 1);
|
wlr_xdg_toplevel_set_activated(c->xdg_surface, 1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
focusmon(const Arg *arg)
|
focusmon(const Arg *arg)
|
||||||
|
|
Loading…
Reference in a new issue