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
+14 -6
View File
@@ -166,7 +166,9 @@ impl CompositorHandler for State {
// None. If the configured output is set, that means it was set explicitly
// by a window rule or a fullscreen request.
.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());
@@ -223,7 +225,7 @@ impl CompositorHandler for State {
// 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) {
let window = mapped.window.clone();
let output = output.clone();
let output = output.cloned();
#[cfg(feature = "xdp-gnome-screencast")]
let id = mapped.id();
@@ -280,7 +282,9 @@ impl CompositorHandler for State {
let unmapped = Unmapped::new(window);
self.niri.unmapped_windows.insert(surface.clone(), unmapped);
self.niri.queue_redraw(&output);
if let Some(output) = output {
self.niri.queue_redraw(&output);
}
return;
}
@@ -323,7 +327,9 @@ impl CompositorHandler for State {
// Popup placement depends on window size which might have changed.
self.update_reactive_popups(&window);
self.niri.queue_redraw(&output);
if let Some(output) = output {
self.niri.queue_redraw(&output);
}
return;
}
@@ -334,10 +340,12 @@ impl CompositorHandler for State {
let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
if let Some((mapped, output)) = root_window_output {
let window = mapped.window.clone();
let output = output.clone();
let output = output.cloned();
window.on_commit();
self.niri.layout.update_window(&window, None);
self.niri.queue_redraw(&output);
if let Some(output) = output {
self.niri.queue_redraw(&output);
}
return;
}
+1 -1
View File
@@ -536,7 +536,7 @@ impl ForeignToplevelHandler for State {
let window = mapped.window.clone();
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
.layout
.move_to_output(Some(&window), &requested_output, None);
+12 -6
View File
@@ -123,6 +123,10 @@ impl XdgShellHandler for State {
return;
};
let Some(output) = output else {
return;
};
let window = mapped.window.clone();
let output = output.clone();
@@ -434,7 +438,7 @@ impl XdgShellHandler for State {
let window = mapped.window.clone();
if let Some(requested_output) = requested_output {
if &requested_output != current_output {
if Some(&requested_output) != current_output {
self.niri
.layout
.move_to_output(Some(&window), &requested_output, None);
@@ -467,7 +471,7 @@ impl XdgShellHandler for State {
toplevel
.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))
.map(|mon| (mon, true))
})
@@ -556,7 +560,7 @@ impl XdgShellHandler for State {
.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))
.map(|mon| (mon, true))
})
@@ -642,7 +646,7 @@ impl XdgShellHandler for State {
return;
};
let window = mapped.window.clone();
let output = output.clone();
let output = output.cloned();
#[cfg(feature = "xdp-gnome-screencast")]
self.niri
@@ -678,7 +682,9 @@ impl XdgShellHandler for State {
self.maybe_warp_cursor_to_focus();
}
self.niri.queue_redraw(&output);
if let Some(output) = output {
self.niri.queue_redraw(&output);
}
}
fn popup_destroyed(&mut self, surface: PopupSurface) {
@@ -862,7 +868,7 @@ impl State {
toplevel
.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))
.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>)> {
match &self.monitor_set {
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(
&mut self,
wl_surface: &WlSurface,
+4 -3
View File
@@ -2898,6 +2898,9 @@ impl Niri {
// Check the main layout.
let win_out = self.layout.find_window_and_output(root);
let layout_output = win_out.map(|(_, output)| output);
if let Some(output) = layout_output {
return output;
}
// Check layer-shell.
let has_layer_surface = |o: &&Output| {
@@ -2905,9 +2908,7 @@ impl Niri {
.layer_for_surface(root, WindowSurfaceType::TOPLEVEL)
.is_some()
};
let layer_shell_output = || self.layout.outputs().find(has_layer_surface);
layout_output.or_else(layer_shell_output)
self.layout.outputs().find(has_layer_surface)
}
pub fn lock_surface_focus(&self) -> Option<WlSurface> {