forge
Explore
Log in

Don't you dare go Hollow

Fix find_window_and_output() returning None with no outputs

Browse files at this commit

734e3a6d3cea277e56baf4531695e989b2d1bddaIvan MolodetskikhParent: f18b1a7
As far as I can tell, this would mess up a ton of the logic. Not sure
how anything worked with no outputs before?
src/handlers/compositor.rsmodified+14 -6
@@ -166,7 +166,9 @@ impl CompositorHandler for State {
166 // None. If the configured output is set, that means it was set explicitly166 // None. If the configured output is set, that means it was set explicitly
167 // by a window rule or a fullscreen request.167 // by a window rule or a fullscreen request.
168 .filter(|(_, parent_output)| {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 .map(|(mapped, _)| mapped.window.clone());173 .map(|(mapped, _)| mapped.window.clone());
172 174
@@ -223,7 +225,7 @@ impl CompositorHandler for State {
223 // This is a commit of a previously-mapped root or a non-toplevel root.225 // This is a commit of a previously-mapped root or a non-toplevel root.
224 if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {226 if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {
225 let window = mapped.window.clone();227 let window = mapped.window.clone();
226- let output = output.clone();228+ let output = output.cloned();
227 229
228 #[cfg(feature = "xdp-gnome-screencast")]230 #[cfg(feature = "xdp-gnome-screencast")]
229 let id = mapped.id();231 let id = mapped.id();
@@ -280,7 +282,9 @@ impl CompositorHandler for State {
280 let unmapped = Unmapped::new(window);282 let unmapped = Unmapped::new(window);
281 self.niri.unmapped_windows.insert(surface.clone(), unmapped);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 return;288 return;
285 }289 }
286 290
@@ -323,7 +327,9 @@ impl CompositorHandler for State {
323 // Popup placement depends on window size which might have changed.327 // Popup placement depends on window size which might have changed.
324 self.update_reactive_popups(&window);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 return;333 return;
328 }334 }
329 335
@@ -334,10 +340,12 @@ impl CompositorHandler for State {
334 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);340 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
335 if let Some((mapped, output)) = root_window_output {341 if let Some((mapped, output)) = root_window_output {
336 let window = mapped.window.clone();342 let window = mapped.window.clone();
337- let output = output.clone();343+ let output = output.cloned();
338 window.on_commit();344 window.on_commit();
339 self.niri.layout.update_window(&window, None);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 return;349 return;
342 }350 }
343 351
src/handlers/mod.rsmodified+1 -1
@@ -536,7 +536,7 @@ impl ForeignToplevelHandler for State {
536 let window = mapped.window.clone();536 let window = mapped.window.clone();
537 537
538 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {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 self.niri540 self.niri
541 .layout541 .layout
542 .move_to_output(Some(&window), &requested_output, None);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 return;123 return;
124 };124 };
125 125
126+ let Some(output) = output else {
127+ return;
128+ };
129+
126 let window = mapped.window.clone();130 let window = mapped.window.clone();
127 let output = output.clone();131 let output = output.clone();
128 132
@@ -434,7 +438,7 @@ impl XdgShellHandler for State {
434 let window = mapped.window.clone();438 let window = mapped.window.clone();
435 439
436 if let Some(requested_output) = requested_output {440 if let Some(requested_output) = requested_output {
437- if &requested_output != current_output {441+ if Some(&requested_output) != current_output {
438 self.niri442 self.niri
439 .layout443 .layout
440 .move_to_output(Some(&window), &requested_output, None);444 .move_to_output(Some(&window), &requested_output, None);
@@ -467,7 +471,7 @@ impl XdgShellHandler for State {
467 toplevel471 toplevel
468 .parent()472 .parent()
469 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))473 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
470- .map(|(_win, output)| output)474+ .and_then(|(_win, output)| output)
471 .and_then(|o| self.niri.layout.monitor_for_output(o))475 .and_then(|o| self.niri.layout.monitor_for_output(o))
472 .map(|mon| (mon, true))476 .map(|mon| (mon, true))
473 })477 })
@@ -556,7 +560,7 @@ impl XdgShellHandler for State {
556 .and_then(|parent| {560 .and_then(|parent| {
557 self.niri.layout.find_window_and_output(&parent)561 self.niri.layout.find_window_and_output(&parent)
558 })562 })
559- .map(|(_win, output)| output)563+ .and_then(|(_win, output)| output)
560 .and_then(|o| self.niri.layout.monitor_for_output(o))564 .and_then(|o| self.niri.layout.monitor_for_output(o))
561 .map(|mon| (mon, true))565 .map(|mon| (mon, true))
562 })566 })
@@ -642,7 +646,7 @@ impl XdgShellHandler for State {
642 return;646 return;
643 };647 };
644 let window = mapped.window.clone();648 let window = mapped.window.clone();
645- let output = output.clone();649+ let output = output.cloned();
646 650
647 #[cfg(feature = "xdp-gnome-screencast")]651 #[cfg(feature = "xdp-gnome-screencast")]
648 self.niri652 self.niri
@@ -678,7 +682,9 @@ impl XdgShellHandler for State {
678 self.maybe_warp_cursor_to_focus();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 fn popup_destroyed(&mut self, surface: PopupSurface) {690 fn popup_destroyed(&mut self, surface: PopupSurface) {
@@ -862,7 +868,7 @@ impl State {
862 toplevel868 toplevel
863 .parent()869 .parent()
864 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))870 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
865- .map(|(_win, output)| output)871+ .and_then(|(_win, output)| output)
866 .and_then(|o| self.niri.layout.monitor_for_output(o))872 .and_then(|o| self.niri.layout.monitor_for_output(o))
867 .map(|mon| (mon, true))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 pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {1145 pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {
1166 match &self.monitor_set {1146 match &self.monitor_set {
1167 MonitorSet::Normal { ref monitors, .. } => {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 pub fn find_window_and_output_mut(1290 pub fn find_window_and_output_mut(
1282 &mut self,1291 &mut self,
1283 wl_surface: &WlSurface,1292 wl_surface: &WlSurface,
src/niri.rsmodified+4 -3
@@ -2898,6 +2898,9 @@ impl Niri {
2898 // Check the main layout.2898 // Check the main layout.
2899 let win_out = self.layout.find_window_and_output(root);2899 let win_out = self.layout.find_window_and_output(root);
2900 let layout_output = win_out.map(|(_, output)| output);2900 let layout_output = win_out.map(|(_, output)| output);
2901+ if let Some(output) = layout_output {
2902+ return output;
2903+ }
2901 2904
2902 // Check layer-shell.2905 // Check layer-shell.
2903 let has_layer_surface = |o: &&Output| {2906 let has_layer_surface = |o: &&Output| {
@@ -2905,9 +2908,7 @@ impl Niri {
2905 .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)2908 .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
2906 .is_some()2909 .is_some()
2907 };2910 };
2908- let layer_shell_output = || self.layout.outputs().find(has_layer_surface);2911+ self.layout.outputs().find(has_layer_surface)
2909-
2910- layout_output.or_else(layer_shell_output)
2911 }2912 }
2912 2913
2913 pub fn lock_surface_focus(&self) -> Option<WlSurface> {2914 pub fn lock_surface_focus(&self) -> Option<WlSurface> {