Fix some cases of incomplete search for surface output
Browse files at this commitc29a049245ffa0eb737114774da4c01c09897dfcParent: d6b62ad4 changed files +36 -23
- src/handlers/compositor.rs +8 -7
- src/handlers/mod.rs +3 -5
- src/handlers/xdg_shell.rs +9 -11
- src/niri.rs +16 -0
src/handlers/compositor.rsmodified+8 -7
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | use std::collections::hash_map::Entry; |
| 2 | 2 | |
| 3 | 3 | use smithay::backend::renderer::utils::{on_commit_buffer_handler, with_renderer_surface_state}; |
| 4 | -use smithay::desktop::find_popup_root_surface; | |
| 5 | 4 | use smithay::input::pointer::CursorImageStatus; |
| 6 | 5 | use smithay::reexports::calloop::Interest; |
| 7 | 6 | use smithay::reexports::wayland_server::protocol::wl_buffer; |
| @@ -30,7 +29,12 @@ impl CompositorHandler for State { | ||
| 30 | 29 | } |
| 31 | 30 | |
| 32 | 31 | fn new_subsurface(&mut self, surface: &WlSurface, parent: &WlSurface) { |
| 33 | - if let Some((_, output)) = self.niri.layout.find_window_and_output(parent) { | |
| 32 | + let mut root = parent.clone(); | |
| 33 | + while let Some(parent) = get_parent(&root) { | |
| 34 | + root = parent; | |
| 35 | + } | |
| 36 | + | |
| 37 | + if let Some(output) = self.niri.output_for_root(&root) { | |
| 34 | 38 | let scale = output.current_scale().integer_scale(); |
| 35 | 39 | let transform = output.current_transform(); |
| 36 | 40 | with_states(surface, |data| { |
| @@ -150,11 +154,8 @@ impl CompositorHandler for State { | ||
| 150 | 154 | // This might be a popup. |
| 151 | 155 | self.popups_handle_commit(surface); |
| 152 | 156 | if let Some(popup) = self.niri.popups.find_popup(surface) { |
| 153 | - if let Ok(root) = find_popup_root_surface(&popup) { | |
| 154 | - let root_window_output = self.niri.layout.find_window_and_output(&root); | |
| 155 | - if let Some((_window, output)) = root_window_output { | |
| 156 | - self.niri.queue_redraw(output); | |
| 157 | - } | |
| 157 | + if let Some(output) = self.output_for_popup(&popup) { | |
| 158 | + self.niri.queue_redraw(output); | |
| 158 | 159 | } |
| 159 | 160 | } |
| 160 | 161 |
src/handlers/mod.rsmodified+3 -5
| @@ -80,10 +80,8 @@ delegate_text_input_manager!(State); | ||
| 80 | 80 | |
| 81 | 81 | impl InputMethodHandler for State { |
| 82 | 82 | fn new_popup(&mut self, surface: PopupSurface) { |
| 83 | - if let Some((_, output)) = surface | |
| 84 | - .get_parent() | |
| 85 | - .and_then(|parent| self.niri.layout.find_window_and_output(&parent.surface)) | |
| 86 | - { | |
| 83 | + let popup = PopupKind::from(surface.clone()); | |
| 84 | + if let Some(output) = self.output_for_popup(&popup) { | |
| 87 | 85 | let scale = output.current_scale().integer_scale(); |
| 88 | 86 | let transform = output.current_transform(); |
| 89 | 87 | let wl_surface = surface.wl_surface(); |
| @@ -91,7 +89,7 @@ impl InputMethodHandler for State { | ||
| 91 | 89 | send_surface_state(wl_surface, data, scale, transform); |
| 92 | 90 | }); |
| 93 | 91 | } |
| 94 | - if let Err(err) = self.niri.popups.track_popup(PopupKind::from(surface)) { | |
| 92 | + if let Err(err) = self.niri.popups.track_popup(popup) { | |
| 95 | 93 | warn!("error tracking ime popup {err:?}"); |
| 96 | 94 | } |
| 97 | 95 | } |
src/handlers/xdg_shell.rsmodified+9 -11
| @@ -175,11 +175,8 @@ impl XdgShellHandler for State { | ||
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | fn popup_destroyed(&mut self, surface: PopupSurface) { |
| 178 | - if let Ok(root) = find_popup_root_surface(&surface.into()) { | |
| 179 | - let root_window_output = self.niri.layout.find_window_and_output(&root); | |
| 180 | - if let Some((_window, output)) = root_window_output { | |
| 181 | - self.niri.queue_redraw(output); | |
| 182 | - } | |
| 178 | + if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) { | |
| 179 | + self.niri.queue_redraw(output); | |
| 183 | 180 | } |
| 184 | 181 | } |
| 185 | 182 | } |
| @@ -271,12 +268,8 @@ impl State { | ||
| 271 | 268 | .initial_configure_sent |
| 272 | 269 | }); |
| 273 | 270 | if !initial_configure_sent { |
| 274 | - if let Some(output) = popup.get_parent_surface().and_then(|parent| { | |
| 275 | - self.niri | |
| 276 | - .layout | |
| 277 | - .find_window_and_output(&parent) | |
| 278 | - .map(|(_, output)| output) | |
| 279 | - }) { | |
| 271 | + if let Some(output) = self.output_for_popup(&PopupKind::Xdg(popup.clone())) | |
| 272 | + { | |
| 280 | 273 | let scale = output.current_scale().integer_scale(); |
| 281 | 274 | let transform = output.current_transform(); |
| 282 | 275 | with_states(surface, |data| { |
| @@ -291,4 +284,9 @@ impl State { | ||
| 291 | 284 | } |
| 292 | 285 | } |
| 293 | 286 | } |
| 287 | + | |
| 288 | + pub fn output_for_popup(&self, popup: &PopupKind) -> Option<Output> { | |
| 289 | + let root = find_popup_root_surface(popup).ok()?; | |
| 290 | + self.niri.output_for_root(&root) | |
| 291 | + } | |
| 294 | 292 | } |
src/niri.rsmodified+16 -0
| @@ -1211,6 +1211,22 @@ impl Niri { | ||
| 1211 | 1211 | .or_else(|| self.global_space.outputs().next()) |
| 1212 | 1212 | } |
| 1213 | 1213 | |
| 1214 | + pub fn output_for_root(&self, root: &WlSurface) -> Option<Output> { | |
| 1215 | + // Check the main layout. | |
| 1216 | + let win_out = self.layout.find_window_and_output(root); | |
| 1217 | + let layout_output = win_out.map(|(_, output)| output); | |
| 1218 | + | |
| 1219 | + // Check layer-shell. | |
| 1220 | + let has_layer_surface = |o: &&Output| { | |
| 1221 | + layer_map_for_output(o) | |
| 1222 | + .layer_for_surface(root, WindowSurfaceType::TOPLEVEL) | |
| 1223 | + .is_some() | |
| 1224 | + }; | |
| 1225 | + let layer_shell_output = || self.layout.outputs().find(has_layer_surface).cloned(); | |
| 1226 | + | |
| 1227 | + layout_output.or_else(layer_shell_output) | |
| 1228 | + } | |
| 1229 | + | |
| 1214 | 1230 | fn lock_surface_focus(&self) -> Option<WlSurface> { |
| 1215 | 1231 | let output_under_cursor = self.output_under_cursor(); |
| 1216 | 1232 | let output = output_under_cursor |