From 155c153658c6c076763301df2abd52a5ff1ae6dd Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 10 Feb 2026 20:17:46 +0000 Subject: [PATCH] layers: restrict layer-shell on-demand focus on map ...so that clients with on-demand keyboard interactivity in the background/bottom/top layers do not steal focus. The reason for this is to avoid desktop components like panels and desktops from stealing keyboard focus if they are re-started. We still let such clients in the overlay layer get focus on map so that for example labnag with its default setting take keyboard focus on map, whilst still letting users click on something else to move focus away. Fixes: #3167 --- src/layers.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/layers.c b/src/layers.c index e8fa6825..4a2ef653 100644 --- a/src/layers.c +++ b/src/layers.c @@ -382,12 +382,19 @@ handle_unmap(struct wl_listener *listener, void *data) layer->being_unmapped = false; } +static bool +is_overlay(struct wlr_layer_surface_v1 *layer_surface) +{ + return layer_surface->current.layer == ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY; +} + static void handle_map(struct wl_listener *listener, void *data) { struct lab_layer_surface *layer = wl_container_of(listener, layer, map); - struct wlr_output *wlr_output = - layer->scene_layer_surface->layer_surface->output; + struct wlr_layer_surface_v1 *layer_surface = + layer->scene_layer_surface->layer_surface; + struct wlr_output *wlr_output = layer_surface->output; if (wlr_output) { output_update_usable_area(wlr_output->data); } @@ -399,6 +406,23 @@ handle_map(struct wl_listener *listener, void *data) * the scene. See wlr_scene_surface_create() documentation. */ + /* + * Layer-shell clients with exclusive interactivity always get focus, + * whereas on-demand ones only get it when in the overlay layer. We + * could make this configurable, but for the time being this default + * behaviour strikes a balance between: + * + * 1. Giving overlay, on-demand clients (like labnag with the default + * settings) keyboard focus. + * 2. Preventing desktop components like panels and desktops from + * stealing keyboard focus on re-start. On compositor start, this + * is not really a problem, but if any such client restarts later, + * focus-stealing is unlikely to be desirable. + */ + if (!is_overlay(layer_surface) && is_on_demand(layer_surface)) { + return; + } + struct seat *seat = &layer->server->seat; layer_try_set_focus(seat, layer->scene_layer_surface->layer_surface); }