Add move-column-to-index action

This commit is contained in:
Duncan Overbruck
2025-03-13 03:09:06 +01:00
committed by Ivan Molodetskikh
parent a5d58d670b
commit f6aa8c1793
7 changed files with 40 additions and 0 deletions

View File

@@ -1509,6 +1509,7 @@ pub enum Action {
MoveColumnToLast,
MoveColumnLeftOrToMonitorLeft,
MoveColumnRightOrToMonitorRight,
MoveColumnToIndex(#[knuffel(argument)] usize),
MoveWindowDown,
MoveWindowUp,
MoveWindowDownOrToWorkspaceDown,
@@ -1704,6 +1705,7 @@ impl From<niri_ipc::Action> for Action {
niri_ipc::Action::MoveColumnRight {} => Self::MoveColumnRight,
niri_ipc::Action::MoveColumnToFirst {} => Self::MoveColumnToFirst,
niri_ipc::Action::MoveColumnToLast {} => Self::MoveColumnToLast,
niri_ipc::Action::MoveColumnToIndex { index } => Self::MoveColumnToIndex(index),
niri_ipc::Action::MoveColumnLeftOrToMonitorLeft {} => {
Self::MoveColumnLeftOrToMonitorLeft
}

View File

@@ -301,6 +301,14 @@ pub enum Action {
MoveColumnLeftOrToMonitorLeft {},
/// Move the focused column to the right or to the monitor to the right.
MoveColumnRightOrToMonitorRight {},
/// Move the focused column to a specific index on its workspace.
MoveColumnToIndex {
/// New index for the column.
///
/// The index starts from 1 for the first column.
#[cfg_attr(feature = "clap", arg())]
index: usize,
},
/// Move the focused window down in a column.
MoveWindowDown {},
/// Move the focused window up in a column.

View File

@@ -1167,6 +1167,12 @@ impl State {
self.niri.queue_redraw_all();
}
}
Action::MoveColumnToIndex(idx) => {
self.niri.layout.move_column_to_index(idx);
self.maybe_warp_cursor_to_focus();
// FIXME: granular
self.niri.queue_redraw_all();
}
Action::FocusWorkspaceDown => {
self.niri.layout.switch_workspace_down();
self.maybe_warp_cursor_to_focus();

View File

@@ -1830,6 +1830,13 @@ impl<W: LayoutElement> Layout<W> {
true
}
pub fn move_column_to_index(&mut self, index: usize) {
let Some(workspace) = self.active_workspace_mut() else {
return;
};
workspace.move_column_to_index(index);
}
pub fn move_down(&mut self) {
let Some(workspace) = self.active_workspace_mut() else {
return;

View File

@@ -1583,6 +1583,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
self.columns[self.active_column_idx].focus_bottom()
}
pub fn move_column_to_index(&mut self, index: usize) {
if self.columns.is_empty() {
return;
}
self.move_column_to(index.saturating_sub(1).min(self.columns.len() - 1));
}
fn move_column_to(&mut self, new_idx: usize) {
if self.active_column_idx == new_idx {
return;

View File

@@ -399,6 +399,7 @@ enum Op {
MoveColumnToLast,
MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8),
MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8),
MoveColumnToIndex(#[proptest(strategy = "1..=5usize")] usize),
MoveWindowDown,
MoveWindowUp,
MoveWindowDownOrToWorkspaceDown,
@@ -975,6 +976,7 @@ impl Op {
layout.move_column_right_or_to_output(&output);
}
Op::MoveColumnToIndex(index) => layout.move_column_to_index(index),
Op::MoveWindowDown => layout.move_down(),
Op::MoveWindowUp => layout.move_up(),
Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(),

View File

@@ -972,6 +972,13 @@ impl<W: LayoutElement> Workspace<W> {
self.scrolling.move_column_to_last();
}
pub fn move_column_to_index(&mut self, index: usize) {
if self.floating_is_active.get() {
return;
}
self.scrolling.move_column_to_index(index);
}
pub fn move_down(&mut self) -> bool {
if self.floating_is_active.get() {
self.floating.move_down();