From 9b3478a3d7699f9830b82beb1d29308c3f4b5680 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Tue, 5 Dec 2023 15:28:31 +0400 Subject: Prevent stealing focus from fullscreen clients Got hit by that Syncthing disconnect dialog a few times while playing games. --- src/handlers/compositor.rs | 6 +----- src/layout.rs | 36 +++++++++++------------------------- 2 files changed, 12 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index af6f19a9..94ee8549 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -98,11 +98,7 @@ impl CompositorHandler for State { let window = entry.remove(); window.on_commit(); - if let Some(output) = self - .niri - .layout - .add_window(window, true, None, false) - .cloned() + if let Some(output) = self.niri.layout.add_window(window, None, false).cloned() { self.niri.queue_redraw(output); } diff --git a/src/layout.rs b/src/layout.rs index f27e85d8..94152d7b 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -672,7 +672,6 @@ impl Layout { pub fn add_window( &mut self, window: W, - activate: bool, width: Option, is_full_width: bool, ) -> Option<&Output> { @@ -687,6 +686,14 @@ impl Layout { .. } => { let mon = &mut monitors[*active_monitor_idx]; + + // Don't steal focus from an active fullscreen window. + let mut activate = true; + let ws = &mon.workspaces[mon.active_workspace_idx]; + if !ws.columns.is_empty() && ws.columns[ws.active_column_idx].is_fullscreen { + activate = false; + } + mon.add_window( mon.active_workspace_idx, window, @@ -703,7 +710,7 @@ impl Layout { workspaces.push(Workspace::new_no_outputs(self.options.clone())); &mut workspaces[0] }; - ws.add_window(window, activate, width, is_full_width); + ws.add_window(window, true, width, is_full_width); None } } @@ -3323,7 +3330,6 @@ mod tests { id: usize, #[proptest(strategy = "arbitrary_bbox()")] bbox: Rectangle, - activate: bool, }, CloseWindow(#[proptest(strategy = "1..=5usize")] usize), FullscreenWindow(#[proptest(strategy = "1..=5usize")] usize), @@ -3399,7 +3405,7 @@ mod tests { layout.focus_output(&output); } - Op::AddWindow { id, bbox, activate } => { + Op::AddWindow { id, bbox } => { match &mut layout.monitor_set { MonitorSet::Normal { monitors, .. } => { for mon in monitors { @@ -3424,7 +3430,7 @@ mod tests { } let win = TestWindow::new(id, bbox); - layout.add_window(win, activate, None, false); + layout.add_window(win, None, false); } Op::CloseWindow(id) => { let dummy = TestWindow::new(id, Rectangle::default()); @@ -3528,17 +3534,14 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddWindow { id: 2, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::CloseWindow(0), Op::CloseWindow(1), @@ -3596,31 +3599,26 @@ mod tests { Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::MoveWindowToWorkspaceDown, Op::AddWindow { id: 2, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddWindow { id: 3, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusColumnLeft, Op::ConsumeWindowIntoColumn, Op::AddWindow { id: 4, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddOutput(2), Op::AddWindow { id: 5, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::MoveWindowToOutput(2), Op::FocusOutput(1), @@ -3644,17 +3642,14 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddWindow { id: 2, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::CloseWindow(0), Op::CloseWindow(1), @@ -3710,13 +3705,11 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusOutput(2), Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::RemoveOutput(2), Op::FocusWorkspace(3), @@ -3733,7 +3726,6 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusWorkspaceDown, Op::CloseWindow(0), @@ -3749,7 +3741,6 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddOutput(2), Op::RemoveOutput(1), @@ -3776,7 +3767,6 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::MoveWindowToWorkspace(2), ]; @@ -3800,13 +3790,11 @@ mod tests { Op::AddWindow { id: 0, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusWorkspaceDown, Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusWorkspaceUp, Op::CloseWindow(0), @@ -3832,13 +3820,11 @@ mod tests { Op::AddWindow { id: 1, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::FocusWorkspaceDown, Op::AddWindow { id: 2, bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)), - activate: true, }, Op::AddOutput(2), Op::RemoveOutput(1), -- cgit