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 | surface_primary_scanout_output, take_presentation_feedback_surface_tree, | 28 | surface_primary_scanout_output, take_presentation_feedback_surface_tree, |
| 29 | under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback, | 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 | use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig, XkbContextHandler}; | 34 | use smithay::input::keyboard::{Layout as KeyboardLayout, XkbConfig, XkbContextHandler}; |
| 33 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; | 35 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; |
| 34 | use smithay::input::{Seat, SeatState}; | 36 | use smithay::input::{Seat, SeatState}; |
| @@ -370,13 +372,34 @@ impl State { | |||
| 370 | self.niri.lock_surface_focus() | 372 | self.niri.lock_surface_focus() |
| 371 | } else if self.niri.screenshot_ui.is_open() { | 373 | } else if self.niri.screenshot_ui.is_open() { |
| 372 | None | 374 | None |
| 373 | - } else { | 375 | + } else if let Some(output) = self.niri.layout.active_output() { |
| 374 | - self.niri.layer_surface_focus().or_else(|| { | 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 | self.niri | 380 | self.niri |
| 376 | .layout | 381 | .layout |
| 377 | .focus() | 382 | .focus() |
| 378 | .map(|win| win.toplevel().wl_surface().clone()) | 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 | let keyboard = self.niri.seat.get_keyboard().unwrap(); | 405 | let keyboard = self.niri.seat.get_keyboard().unwrap(); |
| @@ -1145,17 +1168,6 @@ impl Niri { | |||
| 1145 | state.lock_surface.as_ref().map(|s| s.wl_surface()).cloned() | 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 | /// Schedules an immediate redraw on all outputs if one is not already scheduled. | 1171 | /// Schedules an immediate redraw on all outputs if one is not already scheduled. |
| 1160 | pub fn queue_redraw_all(&mut self) { | 1172 | pub fn queue_redraw_all(&mut self) { |
| 1161 | let outputs: Vec<_> = self.output_state.keys().cloned().collect(); | 1173 | let outputs: Vec<_> = self.output_state.keys().cloned().collect(); |