Add move-column-{left/right}-or-to-monitor-{left/right} (#528)
Browse files at this commit4 changed files +96 -0
- niri-config/src/lib.rs +6 -0
- niri-ipc/src/lib.rs +4 -0
- src/input/mod.rs +34 -0
- src/layout/mod.rs +52 -0
niri-config/src/lib.rsmodified+6 -0
| @@ -995,6 +995,8 @@ pub enum Action { | ||
| 995 | 995 | MoveColumnRight, |
| 996 | 996 | MoveColumnToFirst, |
| 997 | 997 | MoveColumnToLast, |
| 998 | + MoveColumnLeftOrToMonitorLeft, | |
| 999 | + MoveColumnRightOrToMonitorRight, | |
| 998 | 1000 | MoveWindowDown, |
| 999 | 1001 | MoveWindowUp, |
| 1000 | 1002 | MoveWindowDownOrToWorkspaceDown, |
| @@ -1075,6 +1077,10 @@ impl From<niri_ipc::Action> for Action { | ||
| 1075 | 1077 | niri_ipc::Action::MoveColumnRight => Self::MoveColumnRight, |
| 1076 | 1078 | niri_ipc::Action::MoveColumnToFirst => Self::MoveColumnToFirst, |
| 1077 | 1079 | niri_ipc::Action::MoveColumnToLast => Self::MoveColumnToLast, |
| 1080 | + niri_ipc::Action::MoveColumnLeftOrToMonitorLeft => Self::MoveColumnLeftOrToMonitorLeft, | |
| 1081 | + niri_ipc::Action::MoveColumnRightOrToMonitorRight => { | |
| 1082 | + Self::MoveColumnRightOrToMonitorRight | |
| 1083 | + } | |
| 1078 | 1084 | niri_ipc::Action::MoveWindowDown => Self::MoveWindowDown, |
| 1079 | 1085 | niri_ipc::Action::MoveWindowUp => Self::MoveWindowUp, |
| 1080 | 1086 | niri_ipc::Action::MoveWindowDownOrToWorkspaceDown => { |
niri-ipc/src/lib.rsmodified+4 -0
| @@ -152,6 +152,10 @@ pub enum Action { | ||
| 152 | 152 | MoveColumnToFirst, |
| 153 | 153 | /// Move the focused column to the end of the workspace. |
| 154 | 154 | MoveColumnToLast, |
| 155 | + /// Move the focused column to the left or to the monitor to the left. | |
| 156 | + MoveColumnLeftOrToMonitorLeft, | |
| 157 | + /// Move the focused column to the right or to the monitor to the right. | |
| 158 | + MoveColumnRightOrToMonitorRight, | |
| 155 | 159 | /// Move the focused window down in a column. |
| 156 | 160 | MoveWindowDown, |
| 157 | 161 | /// Move the focused window up in a column. |
src/input/mod.rsmodified+34 -0
| @@ -571,6 +571,40 @@ impl State { | ||
| 571 | 571 | // FIXME: granular |
| 572 | 572 | self.niri.queue_redraw_all(); |
| 573 | 573 | } |
| 574 | + Action::MoveColumnLeftOrToMonitorLeft => { | |
| 575 | + if let Some(output) = self.niri.output_left() { | |
| 576 | + if self.niri.layout.move_column_left_or_to_output(&output) | |
| 577 | + && !self.maybe_warp_cursor_to_focus_centered() | |
| 578 | + { | |
| 579 | + self.move_cursor_to_output(&output); | |
| 580 | + } else { | |
| 581 | + self.maybe_warp_cursor_to_focus(); | |
| 582 | + } | |
| 583 | + } else { | |
| 584 | + self.niri.layout.move_left(); | |
| 585 | + self.maybe_warp_cursor_to_focus(); | |
| 586 | + } | |
| 587 | + | |
| 588 | + // FIXME: granular | |
| 589 | + self.niri.queue_redraw_all(); | |
| 590 | + } | |
| 591 | + Action::MoveColumnRightOrToMonitorRight => { | |
| 592 | + if let Some(output) = self.niri.output_right() { | |
| 593 | + if self.niri.layout.move_column_right_or_to_output(&output) | |
| 594 | + && !self.maybe_warp_cursor_to_focus_centered() | |
| 595 | + { | |
| 596 | + self.move_cursor_to_output(&output); | |
| 597 | + } else { | |
| 598 | + self.maybe_warp_cursor_to_focus(); | |
| 599 | + } | |
| 600 | + } else { | |
| 601 | + self.niri.layout.move_right(); | |
| 602 | + self.maybe_warp_cursor_to_focus(); | |
| 603 | + } | |
| 604 | + | |
| 605 | + // FIXME: granular | |
| 606 | + self.niri.queue_redraw_all(); | |
| 607 | + } | |
| 574 | 608 | Action::MoveWindowDown => { |
| 575 | 609 | self.niri.layout.move_down(); |
| 576 | 610 | self.maybe_warp_cursor_to_focus(); |
src/layout/mod.rsmodified+52 -0
| @@ -1196,6 +1196,36 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1196 | 1196 | monitor.move_column_to_last(); |
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | + pub fn move_column_left_or_to_output(&mut self, output: &Output) -> bool { | |
| 1200 | + if let Some(monitor) = self.active_monitor() { | |
| 1201 | + let workspace = monitor.active_workspace(); | |
| 1202 | + let curr_idx = workspace.active_column_idx; | |
| 1203 | + | |
| 1204 | + if !workspace.columns.is_empty() && curr_idx != 0 { | |
| 1205 | + monitor.move_left(); | |
| 1206 | + return false; | |
| 1207 | + } | |
| 1208 | + } | |
| 1209 | + | |
| 1210 | + self.move_column_to_output(output); | |
| 1211 | + true | |
| 1212 | + } | |
| 1213 | + | |
| 1214 | + pub fn move_column_right_or_to_output(&mut self, output: &Output) -> bool { | |
| 1215 | + if let Some(monitor) = self.active_monitor() { | |
| 1216 | + let workspace = monitor.active_workspace(); | |
| 1217 | + let curr_idx = workspace.active_column_idx; | |
| 1218 | + | |
| 1219 | + if !workspace.columns.is_empty() && curr_idx != workspace.columns.len() - 1 { | |
| 1220 | + monitor.move_right(); | |
| 1221 | + return false; | |
| 1222 | + } | |
| 1223 | + } | |
| 1224 | + | |
| 1225 | + self.move_column_to_output(output); | |
| 1226 | + true | |
| 1227 | + } | |
| 1228 | + | |
| 1199 | 1229 | pub fn move_down(&mut self) { |
| 1200 | 1230 | let Some(monitor) = self.active_monitor() else { |
| 1201 | 1231 | return; |
| @@ -2797,6 +2827,8 @@ mod tests { | ||
| 2797 | 2827 | MoveColumnRight, |
| 2798 | 2828 | MoveColumnToFirst, |
| 2799 | 2829 | MoveColumnToLast, |
| 2830 | + MoveColumnLeftOrToMonitorLeft(#[proptest(strategy = "1..=2u8")] u8), | |
| 2831 | + MoveColumnRightOrToMonitorRight(#[proptest(strategy = "1..=2u8")] u8), | |
| 2800 | 2832 | MoveWindowDown, |
| 2801 | 2833 | MoveWindowUp, |
| 2802 | 2834 | MoveWindowDownOrToWorkspaceDown, |
| @@ -3154,6 +3186,22 @@ mod tests { | ||
| 3154 | 3186 | Op::MoveColumnRight => layout.move_right(), |
| 3155 | 3187 | Op::MoveColumnToFirst => layout.move_column_to_first(), |
| 3156 | 3188 | Op::MoveColumnToLast => layout.move_column_to_last(), |
| 3189 | + Op::MoveColumnLeftOrToMonitorLeft(id) => { | |
| 3190 | + let name = format!("output{id}"); | |
| 3191 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3192 | + return; | |
| 3193 | + }; | |
| 3194 | + | |
| 3195 | + layout.move_column_left_or_to_output(&output); | |
| 3196 | + } | |
| 3197 | + Op::MoveColumnRightOrToMonitorRight(id) => { | |
| 3198 | + let name = format!("output{id}"); | |
| 3199 | + let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { | |
| 3200 | + return; | |
| 3201 | + }; | |
| 3202 | + | |
| 3203 | + layout.move_column_right_or_to_output(&output); | |
| 3204 | + } | |
| 3157 | 3205 | Op::MoveWindowDown => layout.move_down(), |
| 3158 | 3206 | Op::MoveWindowUp => layout.move_up(), |
| 3159 | 3207 | Op::MoveWindowDownOrToWorkspaceDown => layout.move_down_or_to_workspace_down(), |
| @@ -3384,6 +3432,8 @@ mod tests { | ||
| 3384 | 3432 | Op::FocusWindowOrWorkspaceDown, |
| 3385 | 3433 | Op::MoveColumnLeft, |
| 3386 | 3434 | Op::MoveColumnRight, |
| 3435 | + Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 3436 | + Op::MoveColumnRightOrToMonitorRight(1), | |
| 3387 | 3437 | Op::ConsumeWindowIntoColumn, |
| 3388 | 3438 | Op::ExpelWindowFromColumn, |
| 3389 | 3439 | Op::CenterColumn, |
| @@ -3563,6 +3613,8 @@ mod tests { | ||
| 3563 | 3613 | Op::FocusWindowOrWorkspaceDown, |
| 3564 | 3614 | Op::MoveColumnLeft, |
| 3565 | 3615 | Op::MoveColumnRight, |
| 3616 | + Op::MoveColumnLeftOrToMonitorLeft(0), | |
| 3617 | + Op::MoveColumnRightOrToMonitorRight(1), | |
| 3566 | 3618 | Op::ConsumeWindowIntoColumn, |
| 3567 | 3619 | Op::ExpelWindowFromColumn, |
| 3568 | 3620 | Op::CenterColumn, |