Fix top layer-shell surfaces keeping keyboard focus during fullscreen
Browse files at this commit19cafffe0f3f1eefc6984dc446134b0fd93d1e28Parent: 136f2721 changed file +27 -15
- src/niri.rs +27 -15
src/niri.rsmodified+27 -15
| @@ -28,7 +28,9 @@ use smithay::desktop::utils::{ | ||
| 28 | 28 | surface_primary_scanout_output, take_presentation_feedback_surface_tree, |
| 29 | 29 | under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback, |
| 30 | 30 | }; |
| 31 | -use smithay::desktop::{layer_map_for_output, PopupManager, Space, Window, WindowSurfaceType}; | |
| 31 | +use smithay::desktop::{ | |
| 32 | + layer_map_for_output, LayerSurface, PopupManager, Space, Window, WindowSurfaceType, | |
| 33 | +}; | |
| 32 | 34 | use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig, XkbContextHandler}; |
| 33 | 35 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; |
| 34 | 36 | use smithay::input::{Seat, SeatState}; |
| @@ -370,13 +372,34 @@ impl State { | ||
| 370 | 372 | self.niri.lock_surface_focus() |
| 371 | 373 | } else if self.niri.screenshot_ui.is_open() { |
| 372 | 374 | None |
| 373 | - } else { | |
| 374 | - self.niri.layer_surface_focus().or_else(|| { | |
| 375 | + } else if let Some(output) = self.niri.layout.active_output() { | |
| 376 | + let mon = self.niri.layout.monitor_for_output(output).unwrap(); | |
| 377 | + let layers = layer_map_for_output(output); | |
| 378 | + | |
| 379 | + let layout_focus = || { | |
| 375 | 380 | self.niri |
| 376 | 381 | .layout |
| 377 | 382 | .focus() |
| 378 | 383 | .map(|win| win.toplevel().wl_surface().clone()) |
| 379 | - }) | |
| 384 | + }; | |
| 385 | + let layer_focus = |surface: &LayerSurface| { | |
| 386 | + surface | |
| 387 | + .can_receive_keyboard_focus() | |
| 388 | + .then(|| surface.wl_surface().clone()) | |
| 389 | + }; | |
| 390 | + | |
| 391 | + let mut surface = layers.layers_on(Layer::Overlay).find_map(layer_focus); | |
| 392 | + if mon.render_above_top_layer() { | |
| 393 | + surface = surface.or_else(layout_focus); | |
| 394 | + surface = surface.or_else(|| layers.layers_on(Layer::Top).find_map(layer_focus)); | |
| 395 | + } else { | |
| 396 | + surface = surface.or_else(|| layers.layers_on(Layer::Top).find_map(layer_focus)); | |
| 397 | + surface = surface.or_else(layout_focus); | |
| 398 | + } | |
| 399 | + | |
| 400 | + surface | |
| 401 | + } else { | |
| 402 | + None | |
| 380 | 403 | }; |
| 381 | 404 | |
| 382 | 405 | let keyboard = self.niri.seat.get_keyboard().unwrap(); |
| @@ -1145,17 +1168,6 @@ impl Niri { | ||
| 1145 | 1168 | state.lock_surface.as_ref().map(|s| s.wl_surface()).cloned() |
| 1146 | 1169 | } |
| 1147 | 1170 | |
| 1148 | - fn layer_surface_focus(&self) -> Option<WlSurface> { | |
| 1149 | - let output = self.layout.active_output()?; | |
| 1150 | - let layers = layer_map_for_output(output); | |
| 1151 | - let surface = layers | |
| 1152 | - .layers_on(Layer::Overlay) | |
| 1153 | - .chain(layers.layers_on(Layer::Top)) | |
| 1154 | - .find(|surface| surface.can_receive_keyboard_focus())?; | |
| 1155 | - | |
| 1156 | - Some(surface.wl_surface().clone()) | |
| 1157 | - } | |
| 1158 | - | |
| 1159 | 1171 | /// Schedules an immediate redraw on all outputs if one is not already scheduled. |
| 1160 | 1172 | pub fn queue_redraw_all(&mut self) { |
| 1161 | 1173 | let outputs: Vec<_> = self.output_state.keys().cloned().collect(); |