aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-02-06 09:38:35 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-02-06 09:41:15 +0300
commit934e5a60335bf6abe606c02c887c78c14e312645 (patch)
treef4175721e57c7ebceae817768d67df69c823da5b /src
parent690d6355057ebeba03cbd8ce4905145b834c72f8 (diff)
downloadniri-934e5a60335bf6abe606c02c887c78c14e312645.tar.gz
niri-934e5a60335bf6abe606c02c887c78c14e312645.tar.bz2
niri-934e5a60335bf6abe606c02c887c78c14e312645.zip
layout: Preserve focused window in column when window above is closed
Might be the longest standing bug in niri?
Diffstat (limited to 'src')
-rw-r--r--src/layout/scrolling.rs8
-rw-r--r--src/layout/tests.rs25
2 files changed, 32 insertions, 1 deletions
diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs
index da193e0d..3153ed0c 100644
--- a/src/layout/scrolling.rs
+++ b/src/layout/scrolling.rs
@@ -984,7 +984,13 @@ impl<W: LayoutElement> ScrollingSpace<W> {
is_floating: false,
};
- column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1);
+ if tile_idx < column.active_tile_idx {
+ // A tile above was removed; preserve the current position.
+ column.active_tile_idx -= 1;
+ } else {
+ column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1);
+ }
+
column.update_tile_sizes_with_transaction(true, transaction);
self.data[column_idx].update(column);
let offset = prev_width - column.width();
diff --git a/src/layout/tests.rs b/src/layout/tests.rs
index 05178f01..e688c8bd 100644
--- a/src/layout/tests.rs
+++ b/src/layout/tests.rs
@@ -3013,6 +3013,31 @@ fn move_workspace_to_same_monitor_doesnt_reorder() {
}
#[test]
+fn removing_window_above_preserves_focused_window() {
+ let ops = [
+ Op::AddOutput(0),
+ Op::AddWindow {
+ params: TestWindowParams::new(0),
+ },
+ Op::AddWindow {
+ params: TestWindowParams::new(1),
+ },
+ Op::AddWindow {
+ params: TestWindowParams::new(2),
+ },
+ Op::FocusColumnFirst,
+ Op::ConsumeWindowIntoColumn,
+ Op::ConsumeWindowIntoColumn,
+ Op::FocusWindowDown,
+ Op::CloseWindow(0),
+ ];
+
+ let layout = check_ops(&ops);
+ let win = layout.focus().unwrap();
+ assert_eq!(win.0.id, 1);
+}
+
+#[test]
fn preset_column_width_fixed_correct_with_border() {
let ops = [
Op::AddOutput(0),