Fix find_window_and_output() returning None with no outputs

As far as I can tell, this would mess up a ton of the logic. Not sure
how anything worked with no outputs before?
This commit is contained in:
Ivan Molodetskikh
2025-02-05 09:32:47 +03:00
parent f18b1a7043
commit 734e3a6d3c
5 changed files with 60 additions and 36 deletions
+11 -3
View File
@@ -166,7 +166,9 @@ impl CompositorHandler for State {
// None. If the configured output is set, that means it was set explicitly // None. If the configured output is set, that means it was set explicitly
// by a window rule or a fullscreen request. // by a window rule or a fullscreen request.
.filter(|(_, parent_output)| { .filter(|(_, parent_output)| {
output.is_none() || output.as_ref() == Some(*parent_output) parent_output.is_none()
|| output.is_none()
|| output.as_ref() == *parent_output
}) })
.map(|(mapped, _)| mapped.window.clone()); .map(|(mapped, _)| mapped.window.clone());
@@ -223,7 +225,7 @@ impl CompositorHandler for State {
// This is a commit of a previously-mapped root or a non-toplevel root. // This is a commit of a previously-mapped root or a non-toplevel root.
if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) { if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {
let window = mapped.window.clone(); let window = mapped.window.clone();
let output = output.clone(); let output = output.cloned();
#[cfg(feature = "xdp-gnome-screencast")] #[cfg(feature = "xdp-gnome-screencast")]
let id = mapped.id(); let id = mapped.id();
@@ -280,7 +282,9 @@ impl CompositorHandler for State {
let unmapped = Unmapped::new(window); let unmapped = Unmapped::new(window);
self.niri.unmapped_windows.insert(surface.clone(), unmapped); self.niri.unmapped_windows.insert(surface.clone(), unmapped);
if let Some(output) = output {
self.niri.queue_redraw(&output); self.niri.queue_redraw(&output);
}
return; return;
} }
@@ -323,7 +327,9 @@ impl CompositorHandler for State {
// Popup placement depends on window size which might have changed. // Popup placement depends on window size which might have changed.
self.update_reactive_popups(&window); self.update_reactive_popups(&window);
if let Some(output) = output {
self.niri.queue_redraw(&output); self.niri.queue_redraw(&output);
}
return; return;
} }
@@ -334,10 +340,12 @@ impl CompositorHandler for State {
let root_window_output = self.niri.layout.find_window_and_output(&root_surface); let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
if let Some((mapped, output)) = root_window_output { if let Some((mapped, output)) = root_window_output {
let window = mapped.window.clone(); let window = mapped.window.clone();
let output = output.clone(); let output = output.cloned();
window.on_commit(); window.on_commit();
self.niri.layout.update_window(&window, None); self.niri.layout.update_window(&window, None);
if let Some(output) = output {
self.niri.queue_redraw(&output); self.niri.queue_redraw(&output);
}
return; return;
} }
+1 -1
View File
@@ -536,7 +536,7 @@ impl ForeignToplevelHandler for State {
let window = mapped.window.clone(); let window = mapped.window.clone();
if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
if &requested_output != current_output { if Some(&requested_output) != current_output {
self.niri self.niri
.layout .layout
.move_to_output(Some(&window), &requested_output, None); .move_to_output(Some(&window), &requested_output, None);
+11 -5
View File
@@ -123,6 +123,10 @@ impl XdgShellHandler for State {
return; return;
}; };
let Some(output) = output else {
return;
};
let window = mapped.window.clone(); let window = mapped.window.clone();
let output = output.clone(); let output = output.clone();
@@ -434,7 +438,7 @@ impl XdgShellHandler for State {
let window = mapped.window.clone(); let window = mapped.window.clone();
if let Some(requested_output) = requested_output { if let Some(requested_output) = requested_output {
if &requested_output != current_output { if Some(&requested_output) != current_output {
self.niri self.niri
.layout .layout
.move_to_output(Some(&window), &requested_output, None); .move_to_output(Some(&window), &requested_output, None);
@@ -467,7 +471,7 @@ impl XdgShellHandler for State {
toplevel toplevel
.parent() .parent()
.and_then(|parent| self.niri.layout.find_window_and_output(&parent)) .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
.map(|(_win, output)| output) .and_then(|(_win, output)| output)
.and_then(|o| self.niri.layout.monitor_for_output(o)) .and_then(|o| self.niri.layout.monitor_for_output(o))
.map(|mon| (mon, true)) .map(|mon| (mon, true))
}) })
@@ -556,7 +560,7 @@ impl XdgShellHandler for State {
.and_then(|parent| { .and_then(|parent| {
self.niri.layout.find_window_and_output(&parent) self.niri.layout.find_window_and_output(&parent)
}) })
.map(|(_win, output)| output) .and_then(|(_win, output)| output)
.and_then(|o| self.niri.layout.monitor_for_output(o)) .and_then(|o| self.niri.layout.monitor_for_output(o))
.map(|mon| (mon, true)) .map(|mon| (mon, true))
}) })
@@ -642,7 +646,7 @@ impl XdgShellHandler for State {
return; return;
}; };
let window = mapped.window.clone(); let window = mapped.window.clone();
let output = output.clone(); let output = output.cloned();
#[cfg(feature = "xdp-gnome-screencast")] #[cfg(feature = "xdp-gnome-screencast")]
self.niri self.niri
@@ -678,8 +682,10 @@ impl XdgShellHandler for State {
self.maybe_warp_cursor_to_focus(); self.maybe_warp_cursor_to_focus();
} }
if let Some(output) = output {
self.niri.queue_redraw(&output); self.niri.queue_redraw(&output);
} }
}
fn popup_destroyed(&mut self, surface: PopupSurface) { fn popup_destroyed(&mut self, surface: PopupSurface) {
if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) { if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) {
@@ -862,7 +868,7 @@ impl State {
toplevel toplevel
.parent() .parent()
.and_then(|parent| self.niri.layout.find_window_and_output(&parent)) .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
.map(|(_win, output)| output) .and_then(|(_win, output)| output)
.and_then(|o| self.niri.layout.monitor_for_output(o)) .and_then(|o| self.niri.layout.monitor_for_output(o))
.map(|mon| (mon, true)) .map(|mon| (mon, true))
}); });
+29 -20
View File
@@ -1142,26 +1142,6 @@ impl<W: LayoutElement> Layout<W> {
} }
} }
pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
if move_.tile.window().is_wl_surface(wl_surface) {
return Some((move_.tile.window(), &move_.output));
}
}
if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
for mon in monitors {
for ws in &mon.workspaces {
if let Some(window) = ws.find_wl_surface(wl_surface) {
return Some((window, &mon.output));
}
}
}
}
None
}
pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> { pub fn find_workspace_by_id(&self, id: WorkspaceId) -> Option<(usize, &Workspace<W>)> {
match &self.monitor_set { match &self.monitor_set {
MonitorSet::Normal { ref monitors, .. } => { MonitorSet::Normal { ref monitors, .. } => {
@@ -1278,6 +1258,35 @@ impl<W: LayoutElement> Layout<W> {
} }
} }
pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, Option<&Output>)> {
if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
if move_.tile.window().is_wl_surface(wl_surface) {
return Some((move_.tile.window(), Some(&move_.output)));
}
}
match &self.monitor_set {
MonitorSet::Normal { monitors, .. } => {
for mon in monitors {
for ws in &mon.workspaces {
if let Some(window) = ws.find_wl_surface(wl_surface) {
return Some((window, Some(&mon.output)));
}
}
}
}
MonitorSet::NoOutputs { workspaces } => {
for ws in workspaces {
if let Some(window) = ws.find_wl_surface(wl_surface) {
return Some((window, None));
}
}
}
}
None
}
pub fn find_window_and_output_mut( pub fn find_window_and_output_mut(
&mut self, &mut self,
wl_surface: &WlSurface, wl_surface: &WlSurface,
+4 -3
View File
@@ -2898,6 +2898,9 @@ impl Niri {
// Check the main layout. // Check the main layout.
let win_out = self.layout.find_window_and_output(root); let win_out = self.layout.find_window_and_output(root);
let layout_output = win_out.map(|(_, output)| output); let layout_output = win_out.map(|(_, output)| output);
if let Some(output) = layout_output {
return output;
}
// Check layer-shell. // Check layer-shell.
let has_layer_surface = |o: &&Output| { let has_layer_surface = |o: &&Output| {
@@ -2905,9 +2908,7 @@ impl Niri {
.layer_for_surface(root, WindowSurfaceType::TOPLEVEL) .layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
.is_some() .is_some()
}; };
let layer_shell_output = || self.layout.outputs().find(has_layer_surface); self.layout.outputs().find(has_layer_surface)
layout_output.or_else(layer_shell_output)
} }
pub fn lock_surface_focus(&self) -> Option<WlSurface> { pub fn lock_surface_focus(&self) -> Option<WlSurface> {