mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Add consume-or-expel-window-left/right commands
This commit is contained in:
committed by
Ivan Molodetskikh
parent
6bb83757ee
commit
3a23417e98
@@ -866,6 +866,70 @@ impl<W: LayoutElement> Workspace<W> {
|
||||
self.columns[self.active_column_idx].move_up();
|
||||
}
|
||||
|
||||
pub fn consume_or_expel_window_left(&mut self) {
|
||||
if self.columns.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let source_column = &self.columns[self.active_column_idx];
|
||||
if source_column.tiles.len() == 1 {
|
||||
if self.active_column_idx == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move into adjacent column.
|
||||
let target_column_idx = self.active_column_idx - 1;
|
||||
let window = self.remove_window_by_idx(self.active_column_idx, 0);
|
||||
self.enter_output_for_window(&window);
|
||||
|
||||
let target_column = &mut self.columns[target_column_idx];
|
||||
target_column.add_window(window);
|
||||
target_column.focus_last();
|
||||
self.activate_column(target_column_idx);
|
||||
} else {
|
||||
// Move out of column.
|
||||
let width = source_column.width;
|
||||
let is_full_width = source_column.is_full_width;
|
||||
let window =
|
||||
self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx);
|
||||
|
||||
self.add_window(window, true, width, is_full_width);
|
||||
// Window was added to the right of current column, so move the new column left.
|
||||
self.move_left();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume_or_expel_window_right(&mut self) {
|
||||
if self.columns.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let source_column = &self.columns[self.active_column_idx];
|
||||
if source_column.tiles.len() == 1 {
|
||||
if self.active_column_idx + 1 == self.columns.len() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Move into adjacent column.
|
||||
let target_column_idx = self.active_column_idx;
|
||||
let window = self.remove_window_by_idx(self.active_column_idx, 0);
|
||||
self.enter_output_for_window(&window);
|
||||
|
||||
let target_column = &mut self.columns[target_column_idx];
|
||||
target_column.add_window(window);
|
||||
target_column.focus_last();
|
||||
self.activate_column(target_column_idx);
|
||||
} else {
|
||||
// Move out of column.
|
||||
let width = source_column.width;
|
||||
let is_full_width = source_column.is_full_width;
|
||||
let window =
|
||||
self.remove_window_by_idx(self.active_column_idx, source_column.active_tile_idx);
|
||||
|
||||
self.add_window(window, true, width, is_full_width);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn consume_into_column(&mut self) {
|
||||
if self.columns.len() < 2 {
|
||||
return;
|
||||
@@ -1414,6 +1478,10 @@ impl<W: LayoutElement> Column<W> {
|
||||
self.active_tile_idx = min(self.active_tile_idx + 1, self.tiles.len() - 1);
|
||||
}
|
||||
|
||||
fn focus_last(&mut self) {
|
||||
self.active_tile_idx = self.tiles.len() - 1;
|
||||
}
|
||||
|
||||
fn move_up(&mut self) {
|
||||
let new_idx = self.active_tile_idx.saturating_sub(1);
|
||||
if self.active_tile_idx == new_idx {
|
||||
|
||||
Reference in New Issue
Block a user