layout: Preserve focused window in column when window above is closed

Might be the longest standing bug in niri?
This commit is contained in:
Ivan Molodetskikh
2025-02-06 09:38:35 +03:00
parent 690d635505
commit 934e5a6033
2 changed files with 32 additions and 1 deletions
+7 -1
View File
@@ -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();
+25
View File
@@ -3012,6 +3012,31 @@ fn move_workspace_to_same_monitor_doesnt_reorder() {
assert_eq!(counts, &[1, 2, 0]);
}
#[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 = [