From d29259c26ab90caa657ed1cbeab03c2039ef5fce Mon Sep 17 00:00:00 2001 From: Guido Cella Date: Mon, 28 Sep 2026 13:18:49 +0200 Subject: [PATCH] refactor focusclient() --- dwl.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/dwl.c b/dwl.c index 3e94fa21190dfc0b496b1fe46d889f51f4da3737..e07a269f40019b2daf92e6a2165b9c0380396bbb 100644 --- a/dwl.c +++ b/dwl.c @@ -1517,7 +1517,7 @@ dirtomon(enum wlr_direction dir) void focusclient(Client *c, LayerSurface *l, int lift) { - struct wlr_surface *old = seat->keyboard_state.focused_surface; + struct wlr_surface *surface, *old = seat->keyboard_state.focused_surface; int unused_lx, unused_ly, old_client_type; Client *old_c = NULL; LayerSurface *old_l = NULL; @@ -1573,30 +1573,22 @@ focusclient(Client *c, LayerSurface *l, int lift) } printstatus(); - if (l) { - /* Focus a layer surface and let the input method follow it */ - input_method_relay_set_focus(input_method_relay, l->layer_surface->surface); - client_notify_enter(l->layer_surface->surface, wlr_seat_get_keyboard(seat)); - return; - } - - if (!c) { + if (!c && !l) { /* With no client, all we have left is to clear focus */ input_method_relay_set_focus(input_method_relay, NULL); wlr_seat_keyboard_notify_clear_focus(seat); return; } - /* Change cursor surface */ - motionnotify(0, NULL, 0, 0, 0, 0); + surface = c ? client_surface(c) : l->layer_surface->surface; + input_method_relay_set_focus(input_method_relay, surface); + client_notify_enter(surface, wlr_seat_get_keyboard(seat)); - input_method_relay_set_focus(input_method_relay, client_surface(c)); - - /* Have a client, so focus its top-level wlr_surface */ - client_notify_enter(client_surface(c), wlr_seat_get_keyboard(seat)); + if (l) + return; - /* Activate the new client */ - client_activate_surface(client_surface(c), 1); + client_activate_surface(surface, 1); + motionnotify(0, NULL, 0, 0, 0, 0); if (!client_is_unmanaged(c)) focused_client = c;