forge
Explore
Log in

Don't you dare go Hollow

Add find_root_shell_surface() that goes through popups

Browse files at this commit

788c9c6c545c016687b024d28f2806055ddb9fc8Ivan MolodetskikhParent: a10705f
src/handlers/mod.rsmodified+6 -7
@@ -343,13 +343,12 @@ impl ClientDndGrabHandler for State {
343343 // example. On successful drop, additionally activate the target window.
344344 let mut activate_output = true;
345345 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;
353352 }
354353 }
355354
src/niri.rsmodified+18 -2
@@ -41,8 +41,8 @@ use smithay::desktop::utils::{
4141 under_from_surface_tree, update_surface_primary_scanout_output, OutputPresentationFeedback,
4242 };
4343 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,
4646 };
4747 use smithay::input::keyboard::Layout as KeyboardLayout;
4848 use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent};
@@ -4907,6 +4907,22 @@ impl Niri {
49074907 }
49084908 }
49094909
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+
49104926 #[cfg(feature = "dbus")]
49114927 pub fn on_ipc_outputs_changed(&self) {
49124928 let _span = tracy_client::span!("Niri::on_ipc_outputs_changed");