Fix find_window_and_output() returning None with no outputs
Browse files at this commit734e3a6d3cea277e56baf4531695e989b2d1bddaParent: f18b1a75 changed files +60 -36
- src/handlers/compositor.rs +14 -6
- src/handlers/mod.rs +1 -1
- src/handlers/xdg_shell.rs +12 -6
- src/layout/mod.rs +29 -20
- src/niri.rs +4 -3
src/handlers/compositor.rsmodified+14 -6
| @@ -166,7 +166,9 @@ impl CompositorHandler for State { | ||
| 166 | 166 | // None. If the configured output is set, that means it was set explicitly |
| 167 | 167 | // by a window rule or a fullscreen request. |
| 168 | 168 | .filter(|(_, parent_output)| { |
| 169 | - output.is_none() || output.as_ref() == Some(*parent_output) | |
| 169 | + parent_output.is_none() | |
| 170 | + || output.is_none() | |
| 171 | + || output.as_ref() == *parent_output | |
| 170 | 172 | }) |
| 171 | 173 | .map(|(mapped, _)| mapped.window.clone()); |
| 172 | 174 | |
| @@ -223,7 +225,7 @@ impl CompositorHandler for State { | ||
| 223 | 225 | // This is a commit of a previously-mapped root or a non-toplevel root. |
| 224 | 226 | if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) { |
| 225 | 227 | let window = mapped.window.clone(); |
| 226 | - let output = output.clone(); | |
| 228 | + let output = output.cloned(); | |
| 227 | 229 | |
| 228 | 230 | #[cfg(feature = "xdp-gnome-screencast")] |
| 229 | 231 | let id = mapped.id(); |
| @@ -280,7 +282,9 @@ impl CompositorHandler for State { | ||
| 280 | 282 | let unmapped = Unmapped::new(window); |
| 281 | 283 | self.niri.unmapped_windows.insert(surface.clone(), unmapped); |
| 282 | 284 | |
| 283 | - self.niri.queue_redraw(&output); | |
| 285 | + if let Some(output) = output { | |
| 286 | + self.niri.queue_redraw(&output); | |
| 287 | + } | |
| 284 | 288 | return; |
| 285 | 289 | } |
| 286 | 290 | |
| @@ -323,7 +327,9 @@ impl CompositorHandler for State { | ||
| 323 | 327 | // Popup placement depends on window size which might have changed. |
| 324 | 328 | self.update_reactive_popups(&window); |
| 325 | 329 | |
| 326 | - self.niri.queue_redraw(&output); | |
| 330 | + if let Some(output) = output { | |
| 331 | + self.niri.queue_redraw(&output); | |
| 332 | + } | |
| 327 | 333 | return; |
| 328 | 334 | } |
| 329 | 335 | |
| @@ -334,10 +340,12 @@ impl CompositorHandler for State { | ||
| 334 | 340 | let root_window_output = self.niri.layout.find_window_and_output(&root_surface); |
| 335 | 341 | if let Some((mapped, output)) = root_window_output { |
| 336 | 342 | let window = mapped.window.clone(); |
| 337 | - let output = output.clone(); | |
| 343 | + let output = output.cloned(); | |
| 338 | 344 | window.on_commit(); |
| 339 | 345 | self.niri.layout.update_window(&window, None); |
| 340 | - self.niri.queue_redraw(&output); | |
| 346 | + if let Some(output) = output { | |
| 347 | + self.niri.queue_redraw(&output); | |
| 348 | + } | |
| 341 | 349 | return; |
| 342 | 350 | } |
| 343 | 351 |
src/handlers/mod.rsmodified+1 -1
| @@ -536,7 +536,7 @@ impl ForeignToplevelHandler for State { | ||
| 536 | 536 | let window = mapped.window.clone(); |
| 537 | 537 | |
| 538 | 538 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { |
| 539 | - if &requested_output != current_output { | |
| 539 | + if Some(&requested_output) != current_output { | |
| 540 | 540 | self.niri |
| 541 | 541 | .layout |
| 542 | 542 | .move_to_output(Some(&window), &requested_output, None); |
src/handlers/xdg_shell.rsmodified+12 -6
| @@ -123,6 +123,10 @@ impl XdgShellHandler for State { | ||
| 123 | 123 | return; |
| 124 | 124 | }; |
| 125 | 125 | |
| 126 | + let Some(output) = output else { | |
| 127 | + return; | |
| 128 | + }; | |
| 129 | + | |
| 126 | 130 | let window = mapped.window.clone(); |
| 127 | 131 | let output = output.clone(); |
| 128 | 132 | |
| @@ -434,7 +438,7 @@ impl XdgShellHandler for State { | ||
| 434 | 438 | let window = mapped.window.clone(); |
| 435 | 439 | |
| 436 | 440 | if let Some(requested_output) = requested_output { |
| 437 | - if &requested_output != current_output { | |
| 441 | + if Some(&requested_output) != current_output { | |
| 438 | 442 | self.niri |
| 439 | 443 | .layout |
| 440 | 444 | .move_to_output(Some(&window), &requested_output, None); |
| @@ -467,7 +471,7 @@ impl XdgShellHandler for State { | ||
| 467 | 471 | toplevel |
| 468 | 472 | .parent() |
| 469 | 473 | .and_then(|parent| self.niri.layout.find_window_and_output(&parent)) |
| 470 | - .map(|(_win, output)| output) | |
| 474 | + .and_then(|(_win, output)| output) | |
| 471 | 475 | .and_then(|o| self.niri.layout.monitor_for_output(o)) |
| 472 | 476 | .map(|mon| (mon, true)) |
| 473 | 477 | }) |
| @@ -556,7 +560,7 @@ impl XdgShellHandler for State { | ||
| 556 | 560 | .and_then(|parent| { |
| 557 | 561 | self.niri.layout.find_window_and_output(&parent) |
| 558 | 562 | }) |
| 559 | - .map(|(_win, output)| output) | |
| 563 | + .and_then(|(_win, output)| output) | |
| 560 | 564 | .and_then(|o| self.niri.layout.monitor_for_output(o)) |
| 561 | 565 | .map(|mon| (mon, true)) |
| 562 | 566 | }) |
| @@ -642,7 +646,7 @@ impl XdgShellHandler for State { | ||
| 642 | 646 | return; |
| 643 | 647 | }; |
| 644 | 648 | let window = mapped.window.clone(); |
| 645 | - let output = output.clone(); | |
| 649 | + let output = output.cloned(); | |
| 646 | 650 | |
| 647 | 651 | #[cfg(feature = "xdp-gnome-screencast")] |
| 648 | 652 | self.niri |
| @@ -678,7 +682,9 @@ impl XdgShellHandler for State { | ||
| 678 | 682 | self.maybe_warp_cursor_to_focus(); |
| 679 | 683 | } |
| 680 | 684 | |
| 681 | - self.niri.queue_redraw(&output); | |
| 685 | + if let Some(output) = output { | |
| 686 | + self.niri.queue_redraw(&output); | |
| 687 | + } | |
| 682 | 688 | } |
| 683 | 689 | |
| 684 | 690 | fn popup_destroyed(&mut self, surface: PopupSurface) { |
| @@ -862,7 +868,7 @@ impl State { | ||
| 862 | 868 | toplevel |
| 863 | 869 | .parent() |
| 864 | 870 | .and_then(|parent| self.niri.layout.find_window_and_output(&parent)) |
| 865 | - .map(|(_win, output)| output) | |
| 871 | + .and_then(|(_win, output)| output) | |
| 866 | 872 | .and_then(|o| self.niri.layout.monitor_for_output(o)) |
| 867 | 873 | .map(|mon| (mon, true)) |
| 868 | 874 | }); |
src/layout/mod.rsmodified+29 -20
| @@ -1142,26 +1142,6 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1142 | 1142 | } |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> { | |
| 1146 | - if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { | |
| 1147 | - if move_.tile.window().is_wl_surface(wl_surface) { | |
| 1148 | - return Some((move_.tile.window(), &move_.output)); | |
| 1149 | - } | |
| 1150 | - } | |
| 1151 | - | |
| 1152 | - if let MonitorSet::Normal { monitors, .. } = &self.monitor_set { | |
| 1153 | - for mon in monitors { | |
| 1154 | - for ws in &mon.workspaces { | |
| 1155 | - if let Some(window) = ws.find_wl_surface(wl_surface) { | |
| 1156 | - return Some((window, &mon.output)); | |
| 1157 | - } | |
| 1158 | - } | |
| 1159 | - } | |
| 1160 | - } | |
| 1161 | - | |
| 1162 | - None | |
| 1163 | - } | |
| 1164 | - | |
| 1165 | 1145 | pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> { |
| 1166 | 1146 | match &self.monitor_set { |
| 1167 | 1147 | MonitorSet::Normal { ref monitors, .. } => { |
| @@ -1278,6 +1258,35 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1278 | 1258 | } |
| 1279 | 1259 | } |
| 1280 | 1260 | |
| 1261 | + pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, Option<&Output>)> { | |
| 1262 | + if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move { | |
| 1263 | + if move_.tile.window().is_wl_surface(wl_surface) { | |
| 1264 | + return Some((move_.tile.window(), Some(&move_.output))); | |
| 1265 | + } | |
| 1266 | + } | |
| 1267 | + | |
| 1268 | + match &self.monitor_set { | |
| 1269 | + MonitorSet::Normal { monitors, .. } => { | |
| 1270 | + for mon in monitors { | |
| 1271 | + for ws in &mon.workspaces { | |
| 1272 | + if let Some(window) = ws.find_wl_surface(wl_surface) { | |
| 1273 | + return Some((window, Some(&mon.output))); | |
| 1274 | + } | |
| 1275 | + } | |
| 1276 | + } | |
| 1277 | + } | |
| 1278 | + MonitorSet::NoOutputs { workspaces } => { | |
| 1279 | + for ws in workspaces { | |
| 1280 | + if let Some(window) = ws.find_wl_surface(wl_surface) { | |
| 1281 | + return Some((window, None)); | |
| 1282 | + } | |
| 1283 | + } | |
| 1284 | + } | |
| 1285 | + } | |
| 1286 | + | |
| 1287 | + None | |
| 1288 | + } | |
| 1289 | + | |
| 1281 | 1290 | pub fn find_window_and_output_mut( |
| 1282 | 1291 | &mut self, |
| 1283 | 1292 | wl_surface: &WlSurface, |
src/niri.rsmodified+4 -3
| @@ -2898,6 +2898,9 @@ impl Niri { | ||
| 2898 | 2898 | // Check the main layout. |
| 2899 | 2899 | let win_out = self.layout.find_window_and_output(root); |
| 2900 | 2900 | let layout_output = win_out.map(|(_, output)| output); |
| 2901 | + if let Some(output) = layout_output { | |
| 2902 | + return output; | |
| 2903 | + } | |
| 2901 | 2904 | |
| 2902 | 2905 | // Check layer-shell. |
| 2903 | 2906 | let has_layer_surface = |o: &&Output| { |
| @@ -2905,9 +2908,7 @@ impl Niri { | ||
| 2905 | 2908 | .layer_for_surface(root, WindowSurfaceType::TOPLEVEL) |
| 2906 | 2909 | .is_some() |
| 2907 | 2910 | }; |
| 2908 | - let layer_shell_output = || self.layout.outputs().find(has_layer_surface); | |
| 2909 | - | |
| 2910 | - layout_output.or_else(layer_shell_output) | |
| 2911 | + self.layout.outputs().find(has_layer_surface) | |
| 2911 | 2912 | } |
| 2912 | 2913 | |
| 2913 | 2914 | pub fn lock_surface_focus(&self) -> Option<WlSurface> { |