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 {
166166 // None. If the configured output is set, that means it was set explicitly
167167 // by a window rule or a fullscreen request.
168168 .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
170172 })
171173 .map(|(mapped, _)| mapped.window.clone());
172174
@@ -223,7 +225,7 @@ impl CompositorHandler for State {
223225 // This is a commit of a previously-mapped root or a non-toplevel root.
224226 if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {
225227 let window = mapped.window.clone();
226- let output = output.clone();
228+ let output = output.cloned();
227229
228230 #[cfg(feature = "xdp-gnome-screencast")]
229231 let id = mapped.id();
@@ -280,7 +282,9 @@ impl CompositorHandler for State {
280282 let unmapped = Unmapped::new(window);
281283 self.niri.unmapped_windows.insert(surface.clone(), unmapped);
282284
283- self.niri.queue_redraw(&output);
285+ if let Some(output) = output {
286+ self.niri.queue_redraw(&output);
287+ }
284288 return;
285289 }
286290
@@ -323,7 +327,9 @@ impl CompositorHandler for State {
323327 // Popup placement depends on window size which might have changed.
324328 self.update_reactive_popups(&window);
325329
326- self.niri.queue_redraw(&output);
330+ if let Some(output) = output {
331+ self.niri.queue_redraw(&output);
332+ }
327333 return;
328334 }
329335
@@ -334,10 +340,12 @@ impl CompositorHandler for State {
334340 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
335341 if let Some((mapped, output)) = root_window_output {
336342 let window = mapped.window.clone();
337- let output = output.clone();
343+ let output = output.cloned();
338344 window.on_commit();
339345 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+ }
341349 return;
342350 }
343351
src/handlers/mod.rsmodified+1 -1
@@ -536,7 +536,7 @@ impl ForeignToplevelHandler for State {
536536 let window = mapped.window.clone();
537537
538538 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 {
540540 self.niri
541541 .layout
542542 .move_to_output(Some(&window), &requested_output, None);
src/handlers/xdg_shell.rsmodified+12 -6
@@ -123,6 +123,10 @@ impl XdgShellHandler for State {
123123 return;
124124 };
125125
126+ let Some(output) = output else {
127+ return;
128+ };
129+
126130 let window = mapped.window.clone();
127131 let output = output.clone();
128132
@@ -434,7 +438,7 @@ impl XdgShellHandler for State {
434438 let window = mapped.window.clone();
435439
436440 if let Some(requested_output) = requested_output {
437- if &requested_output != current_output {
441+ if Some(&requested_output) != current_output {
438442 self.niri
439443 .layout
440444 .move_to_output(Some(&window), &requested_output, None);
@@ -467,7 +471,7 @@ impl XdgShellHandler for State {
467471 toplevel
468472 .parent()
469473 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
470- .map(|(_win, output)| output)
474+ .and_then(|(_win, output)| output)
471475 .and_then(|o| self.niri.layout.monitor_for_output(o))
472476 .map(|mon| (mon, true))
473477 })
@@ -556,7 +560,7 @@ impl XdgShellHandler for State {
556560 .and_then(|parent| {
557561 self.niri.layout.find_window_and_output(&parent)
558562 })
559- .map(|(_win, output)| output)
563+ .and_then(|(_win, output)| output)
560564 .and_then(|o| self.niri.layout.monitor_for_output(o))
561565 .map(|mon| (mon, true))
562566 })
@@ -642,7 +646,7 @@ impl XdgShellHandler for State {
642646 return;
643647 };
644648 let window = mapped.window.clone();
645- let output = output.clone();
649+ let output = output.cloned();
646650
647651 #[cfg(feature = "xdp-gnome-screencast")]
648652 self.niri
@@ -678,7 +682,9 @@ impl XdgShellHandler for State {
678682 self.maybe_warp_cursor_to_focus();
679683 }
680684
681- self.niri.queue_redraw(&output);
685+ if let Some(output) = output {
686+ self.niri.queue_redraw(&output);
687+ }
682688 }
683689
684690 fn popup_destroyed(&mut self, surface: PopupSurface) {
@@ -862,7 +868,7 @@ impl State {
862868 toplevel
863869 .parent()
864870 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
865- .map(|(_win, output)| output)
871+ .and_then(|(_win, output)| output)
866872 .and_then(|o| self.niri.layout.monitor_for_output(o))
867873 .map(|mon| (mon, true))
868874 });
src/layout/mod.rsmodified+29 -20
@@ -1142,26 +1142,6 @@ impl<W: LayoutElement> Layout<W> {
11421142 }
11431143 }
11441144
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-
11651145 pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {
11661146 match &self.monitor_set {
11671147 MonitorSet::Normal { ref monitors, .. } => {
@@ -1278,6 +1258,35 @@ impl<W: LayoutElement> Layout<W> {
12781258 }
12791259 }
12801260
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+
12811290 pub fn find_window_and_output_mut(
12821291 &mut self,
12831292 wl_surface: &WlSurface,
src/niri.rsmodified+4 -3
@@ -2898,6 +2898,9 @@ impl Niri {
28982898 // Check the main layout.
28992899 let win_out = self.layout.find_window_and_output(root);
29002900 let layout_output = win_out.map(|(_, output)| output);
2901+ if let Some(output) = layout_output {
2902+ return output;
2903+ }
29012904
29022905 // Check layer-shell.
29032906 let has_layer_surface = |o: &&Output| {
@@ -2905,9 +2908,7 @@ impl Niri {
29052908 .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
29062909 .is_some()
29072910 };
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)
29112912 }
29122913
29132914 pub fn lock_surface_focus(&self) -> Option<WlSurface> {