Add find_root_shell_surface() that goes through popups
Browse files at this commit788c9c6c545c016687b024d28f2806055ddb9fc8Parent: a10705f2 changed files +24 -9
- src/handlers/mod.rs +6 -7
- src/niri.rs +18 -2
src/handlers/mod.rsmodified+6 -7
| @@ -343,13 +343,12 @@ impl ClientDndGrabHandler for State { | ||
| 343 | 343 | // example. On successful drop, additionally activate the target window. |
| 344 | 344 | let mut activate_output = true; |
| 345 | 345 | if let Some(target) = validated.then_some(target).flatten() { |
| 346 | - if let Some(root) = self.niri.root_surface.get(&target) { | |
| 347 | - if let Some((mapped, _)) = self.niri.layout.find_window_and_output(root) { | |
| 348 | - let window = mapped.window.clone(); | |
| 349 | - self.niri.layout.activate_window(&window); | |
| 350 | - self.niri.layer_shell_on_demand_focus = None; | |
| 351 | - activate_output = false; | |
| 352 | - } | |
| 346 | + let root = self.niri.find_root_shell_surface(&target); | |
| 347 | + if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&root) { | |
| 348 | + let window = mapped.window.clone(); | |
| 349 | + self.niri.layout.activate_window(&window); | |
| 350 | + self.niri.layer_shell_on_demand_focus = None; | |
| 351 | + activate_output = false; | |
| 353 | 352 | } |
| 354 | 353 | } |
| 355 | 354 |
src/niri.rsmodified+18 -2
| @@ -41,8 +41,8 @@ use smithay::desktop::utils::{ | ||
| 41 | 41 | under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback, |
| 42 | 42 | }; |
| 43 | 43 | use smithay::desktop::{ |
| 44 | - layer_map_for_output, LayerMap, LayerSurface, PopupGrab, PopupManager, PopupUngrabStrategy, | |
| 45 | - Space, Window, WindowSurfaceType, | |
| 44 | + find_popup_root_surface, layer_map_for_output, LayerMap, LayerSurface, PopupGrab, PopupManager, | |
| 45 | + PopupUngrabStrategy, Space, Window, WindowSurfaceType, | |
| 46 | 46 | }; |
| 47 | 47 | use smithay::input::keyboard::Layout as KeyboardLayout; |
| 48 | 48 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; |
| @@ -4907,6 +4907,22 @@ impl Niri { | ||
| 4907 | 4907 | } |
| 4908 | 4908 | } |
| 4909 | 4909 | |
| 4910 | + /// Tries to find and return the root shell surface for a given surface. | |
| 4911 | + /// | |
| 4912 | + /// I.e. for popups, this function will try to find the parent toplevel or layer surface. For | |
| 4913 | + /// regular subsurfaces, it will find the root surface. | |
| 4914 | + pub fn find_root_shell_surface(&self, surface: &WlSurface) -> WlSurface { | |
| 4915 | + let Some(root) = self.root_surface.get(surface) else { | |
| 4916 | + return surface.clone(); | |
| 4917 | + }; | |
| 4918 | + | |
| 4919 | + if let Some(popup) = self.popups.find_popup(root) { | |
| 4920 | + return find_popup_root_surface(&popup).unwrap_or_else(|_| root.clone()); | |
| 4921 | + } | |
| 4922 | + | |
| 4923 | + root.clone() | |
| 4924 | + } | |
| 4925 | + | |
| 4910 | 4926 | #[cfg(feature = "dbus")] |
| 4911 | 4927 | pub fn on_ipc_outputs_changed(&self) { |
| 4912 | 4928 | let _span = tracy_client::span!("Niri::on_ipc_outputs_changed"); |