From c61e860cb26a645991e6ddb1cfeab34aec2d986b Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Tue, 29 Mar 2022 14:41:41 +0200 Subject: [PATCH] focus: Set focus to exclusive layer surfaces on creation --- src/shell/handler.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/shell/handler.rs b/src/shell/handler.rs index dd4d0729..44ae9f17 100644 --- a/src/shell/handler.rs +++ b/src/shell/handler.rs @@ -16,7 +16,10 @@ use smithay::{ output::Output, seat::{PointerGrabStartData, Seat}, shell::{ - wlr_layer::{wlr_layer_shell_init, LayerShellRequest, LayerSurfaceAttributes}, + wlr_layer::{ + wlr_layer_shell_init, KeyboardInteractivity, Layer, LayerShellRequest, + LayerSurfaceAttributes, LayerSurfaceCachedState, + }, xdg::{ xdg_shell_init, Configure, XdgPopupSurfaceRoleAttributes, XdgRequest, XdgToplevelSurfaceRoleAttributes, @@ -225,9 +228,25 @@ pub fn init_shell(config: &Config, display: &mut Display) -> super::Shell { .and_then(Output::from_resource) .unwrap_or_else(|| active_output(seat, &*state)); + let focus = surface + .get_surface() + .map(|surface| { + with_states(surface, |states| { + let state = states.cached_state.current::(); + matches!(state.layer, Layer::Top | Layer::Overlay) + && state.keyboard_interactivity == KeyboardInteractivity::Exclusive + }) + .unwrap() + }) + .unwrap_or(false); + let mut map = layer_map_for_output(&output); - map.map_layer(&LayerSurface::new(surface, namespace)) + map.map_layer(&LayerSurface::new(surface.clone(), namespace)) .unwrap(); + + if focus { + state.shell.set_focus(surface.get_surface(), seat); + } } _ => {} },