Add move-column-to-workspace* binds
Browse files at this commitcc4acdf24a0864e061e7ea54d6b3589402f2082dParent: 2506d435 changed files +205 -1
- niri-config/src/lib.rs +3 -0
- src/input.rs +16 -0
- src/layout/mod.rs +37 -0
- src/layout/monitor.rs +76 -1
- src/layout/workspace.rs +73 -0
niri-config/src/lib.rsmodified+3 -0
| @@ -408,6 +408,9 @@ pub enum Action { | ||
| 408 | 408 | MoveWindowToWorkspaceDown, |
| 409 | 409 | MoveWindowToWorkspaceUp, |
| 410 | 410 | MoveWindowToWorkspace(#[knuffel(argument)] u8), |
| 411 | + MoveColumnToWorkspaceDown, | |
| 412 | + MoveColumnToWorkspaceUp, | |
| 413 | + MoveColumnToWorkspace(#[knuffel(argument)] u8), | |
| 411 | 414 | MoveWorkspaceDown, |
| 412 | 415 | MoveWorkspaceUp, |
| 413 | 416 | FocusMonitorLeft, |
src/input.rsmodified+16 -0
| @@ -458,6 +458,22 @@ impl State { | ||
| 458 | 458 | // FIXME: granular |
| 459 | 459 | self.niri.queue_redraw_all(); |
| 460 | 460 | } |
| 461 | + Action::MoveColumnToWorkspaceDown => { | |
| 462 | + self.niri.layout.move_column_to_workspace_down(); | |
| 463 | + // FIXME: granular | |
| 464 | + self.niri.queue_redraw_all(); | |
| 465 | + } | |
| 466 | + Action::MoveColumnToWorkspaceUp => { | |
| 467 | + self.niri.layout.move_column_to_workspace_up(); | |
| 468 | + // FIXME: granular | |
| 469 | + self.niri.queue_redraw_all(); | |
| 470 | + } | |
| 471 | + Action::MoveColumnToWorkspace(idx) => { | |
| 472 | + let idx = idx.saturating_sub(1) as usize; | |
| 473 | + self.niri.layout.move_column_to_workspace(idx); | |
| 474 | + // FIXME: granular | |
| 475 | + self.niri.queue_redraw_all(); | |
| 476 | + } | |
| 461 | 477 | Action::FocusWorkspaceDown => { |
| 462 | 478 | self.niri.layout.switch_workspace_down(); |
| 463 | 479 | // FIXME: granular |
src/layout/mod.rsmodified+37 -0
| @@ -897,6 +897,27 @@ impl<W: LayoutElement> Layout<W> { | ||
| 897 | 897 | monitor.move_to_workspace(idx); |
| 898 | 898 | } |
| 899 | 899 | |
| 900 | + pub fn move_column_to_workspace_up(&mut self) { | |
| 901 | + let Some(monitor) = self.active_monitor() else { | |
| 902 | + return; | |
| 903 | + }; | |
| 904 | + monitor.move_column_to_workspace_up(); | |
| 905 | + } | |
| 906 | + | |
| 907 | + pub fn move_column_to_workspace_down(&mut self) { | |
| 908 | + let Some(monitor) = self.active_monitor() else { | |
| 909 | + return; | |
| 910 | + }; | |
| 911 | + monitor.move_column_to_workspace_down(); | |
| 912 | + } | |
| 913 | + | |
| 914 | + pub fn move_column_to_workspace(&mut self, idx: usize) { | |
| 915 | + let Some(monitor) = self.active_monitor() else { | |
| 916 | + return; | |
| 917 | + }; | |
| 918 | + monitor.move_column_to_workspace(idx); | |
| 919 | + } | |
| 920 | + | |
| 900 | 921 | pub fn switch_workspace_up(&mut self) { |
| 901 | 922 | let Some(monitor) = self.active_monitor() else { |
| 902 | 923 | return; |
| @@ -1608,6 +1629,9 @@ mod tests { | ||
| 1608 | 1629 | MoveWindowToWorkspaceDown, |
| 1609 | 1630 | MoveWindowToWorkspaceUp, |
| 1610 | 1631 | MoveWindowToWorkspace(#[proptest(strategy = "0..=4usize")] usize), |
| 1632 | + MoveColumnToWorkspaceDown, | |
| 1633 | + MoveColumnToWorkspaceUp, | |
| 1634 | + MoveColumnToWorkspace(#[proptest(strategy = "0..=4usize")] usize), | |
| 1611 | 1635 | MoveWorkspaceDown, |
| 1612 | 1636 | MoveWorkspaceUp, |
| 1613 | 1637 | MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8), |
| @@ -1729,6 +1753,9 @@ mod tests { | ||
| 1729 | 1753 | Op::MoveWindowToWorkspaceDown => layout.move_to_workspace_down(), |
| 1730 | 1754 | Op::MoveWindowToWorkspaceUp => layout.move_to_workspace_up(), |
| 1731 | 1755 | Op::MoveWindowToWorkspace(idx) => layout.move_to_workspace(idx), |
| 1756 | + Op::MoveColumnToWorkspaceDown => layout.move_column_to_workspace_down(), | |
| 1757 | + Op::MoveColumnToWorkspaceUp => layout.move_column_to_workspace_up(), | |
| 1758 | + Op::MoveColumnToWorkspace(idx) => layout.move_column_to_workspace(idx), | |
| 1732 | 1759 | Op::MoveWindowToOutput(id) => { |
| 1733 | 1760 | let name = format!("output{id}"); |
| 1734 | 1761 | let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else { |
| @@ -1855,6 +1882,11 @@ mod tests { | ||
| 1855 | 1882 | Op::MoveWindowToWorkspace(1), |
| 1856 | 1883 | Op::MoveWindowToWorkspace(2), |
| 1857 | 1884 | Op::MoveWindowToWorkspace(3), |
| 1885 | + Op::MoveColumnToWorkspaceDown, | |
| 1886 | + Op::MoveColumnToWorkspaceUp, | |
| 1887 | + Op::MoveColumnToWorkspace(1), | |
| 1888 | + Op::MoveColumnToWorkspace(2), | |
| 1889 | + Op::MoveColumnToWorkspace(3), | |
| 1858 | 1890 | Op::MoveWindowDown, |
| 1859 | 1891 | Op::MoveWindowDownOrToWorkspaceDown, |
| 1860 | 1892 | Op::MoveWindowUp, |
| @@ -1977,6 +2009,11 @@ mod tests { | ||
| 1977 | 2009 | Op::MoveWindowToWorkspace(1), |
| 1978 | 2010 | Op::MoveWindowToWorkspace(2), |
| 1979 | 2011 | Op::MoveWindowToWorkspace(3), |
| 2012 | + Op::MoveColumnToWorkspaceDown, | |
| 2013 | + Op::MoveColumnToWorkspaceUp, | |
| 2014 | + Op::MoveColumnToWorkspace(1), | |
| 2015 | + Op::MoveColumnToWorkspace(2), | |
| 2016 | + Op::MoveColumnToWorkspace(3), | |
| 1980 | 2017 | Op::MoveWindowDown, |
| 1981 | 2018 | Op::MoveWindowDownOrToWorkspaceDown, |
| 1982 | 2019 | Op::MoveWindowUp, |
src/layout/monitor.rsmodified+76 -1
| @@ -12,7 +12,7 @@ use smithay::output::Output; | ||
| 12 | 12 | use smithay::utils::{Logical, Point, Rectangle, Scale}; |
| 13 | 13 | |
| 14 | 14 | use super::workspace::{ |
| 15 | - compute_working_area, ColumnWidth, OutputId, Workspace, WorkspaceRenderElement, | |
| 15 | + compute_working_area, Column, ColumnWidth, OutputId, Workspace, WorkspaceRenderElement, | |
| 16 | 16 | }; |
| 17 | 17 | use super::{LayoutElement, Options}; |
| 18 | 18 | use crate::animation::Animation; |
| @@ -127,6 +127,25 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | + pub fn add_column(&mut self, workspace_idx: usize, column: Column<W>, activate: bool) { | |
| 131 | + let workspace = &mut self.workspaces[workspace_idx]; | |
| 132 | + | |
| 133 | + workspace.add_column(column, activate); | |
| 134 | + | |
| 135 | + // After adding a new window, workspace becomes this output's own. | |
| 136 | + workspace.original_output = OutputId::new(&self.output); | |
| 137 | + | |
| 138 | + if workspace_idx == self.workspaces.len() - 1 { | |
| 139 | + // Insert a new empty workspace. | |
| 140 | + let ws = Workspace::new(self.output.clone(), self.options.clone()); | |
| 141 | + self.workspaces.push(ws); | |
| 142 | + } | |
| 143 | + | |
| 144 | + if activate { | |
| 145 | + self.activate_workspace(workspace_idx); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 130 | 149 | fn clean_up_workspaces(&mut self) { |
| 131 | 150 | assert!(self.workspace_switch.is_none()); |
| 132 | 151 | |
| @@ -323,6 +342,62 @@ impl<W: LayoutElement> Monitor<W> { | ||
| 323 | 342 | self.clean_up_workspaces(); |
| 324 | 343 | } |
| 325 | 344 | |
| 345 | + pub fn move_column_to_workspace_up(&mut self) { | |
| 346 | + let source_workspace_idx = self.active_workspace_idx; | |
| 347 | + | |
| 348 | + let new_idx = source_workspace_idx.saturating_sub(1); | |
| 349 | + if new_idx == source_workspace_idx { | |
| 350 | + return; | |
| 351 | + } | |
| 352 | + | |
| 353 | + let workspace = &mut self.workspaces[source_workspace_idx]; | |
| 354 | + if workspace.columns.is_empty() { | |
| 355 | + return; | |
| 356 | + } | |
| 357 | + | |
| 358 | + let column = workspace.remove_column_by_idx(workspace.active_column_idx); | |
| 359 | + self.add_column(new_idx, column, true); | |
| 360 | + } | |
| 361 | + | |
| 362 | + pub fn move_column_to_workspace_down(&mut self) { | |
| 363 | + let source_workspace_idx = self.active_workspace_idx; | |
| 364 | + | |
| 365 | + let new_idx = min(source_workspace_idx + 1, self.workspaces.len() - 1); | |
| 366 | + if new_idx == source_workspace_idx { | |
| 367 | + return; | |
| 368 | + } | |
| 369 | + | |
| 370 | + let workspace = &mut self.workspaces[source_workspace_idx]; | |
| 371 | + if workspace.columns.is_empty() { | |
| 372 | + return; | |
| 373 | + } | |
| 374 | + | |
| 375 | + let column = workspace.remove_column_by_idx(workspace.active_column_idx); | |
| 376 | + self.add_column(new_idx, column, true); | |
| 377 | + } | |
| 378 | + | |
| 379 | + pub fn move_column_to_workspace(&mut self, idx: usize) { | |
| 380 | + let source_workspace_idx = self.active_workspace_idx; | |
| 381 | + | |
| 382 | + let new_idx = min(idx, self.workspaces.len() - 1); | |
| 383 | + if new_idx == source_workspace_idx { | |
| 384 | + return; | |
| 385 | + } | |
| 386 | + | |
| 387 | + let workspace = &mut self.workspaces[source_workspace_idx]; | |
| 388 | + if workspace.columns.is_empty() { | |
| 389 | + return; | |
| 390 | + } | |
| 391 | + | |
| 392 | + let column = workspace.remove_column_by_idx(workspace.active_column_idx); | |
| 393 | + self.add_column(new_idx, column, true); | |
| 394 | + | |
| 395 | + // Don't animate this action. | |
| 396 | + self.workspace_switch = None; | |
| 397 | + | |
| 398 | + self.clean_up_workspaces(); | |
| 399 | + } | |
| 400 | + | |
| 326 | 401 | pub fn switch_workspace_up(&mut self) { |
| 327 | 402 | self.activate_workspace(self.active_workspace_idx.saturating_sub(1)); |
| 328 | 403 | } |
src/layout/workspace.rsmodified+73 -0
| @@ -574,6 +574,43 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 574 | 574 | } |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | + pub fn add_column(&mut self, mut column: Column<W>, activate: bool) { | |
| 578 | + for tile in &column.tiles { | |
| 579 | + self.enter_output_for_window(tile.window()); | |
| 580 | + } | |
| 581 | + | |
| 582 | + let was_empty = self.columns.is_empty(); | |
| 583 | + | |
| 584 | + let idx = if self.columns.is_empty() { | |
| 585 | + 0 | |
| 586 | + } else { | |
| 587 | + self.active_column_idx + 1 | |
| 588 | + }; | |
| 589 | + | |
| 590 | + column.set_view_size(self.view_size, self.working_area); | |
| 591 | + let width = column.width(); | |
| 592 | + self.columns.insert(idx, column); | |
| 593 | + | |
| 594 | + if activate { | |
| 595 | + // If this is the first window on an empty workspace, skip the animation from whatever | |
| 596 | + // view_offset was left over. | |
| 597 | + if was_empty { | |
| 598 | + if self.options.center_focused_column == CenterFocusedColumn::Always { | |
| 599 | + self.view_offset = | |
| 600 | + -(self.working_area.size.w - width) / 2 - self.working_area.loc.x; | |
| 601 | + } else { | |
| 602 | + // Try to make the code produce a left-aligned offset, even in presence of left | |
| 603 | + // exclusive zones. | |
| 604 | + self.view_offset = self.compute_new_view_offset_for_column(self.column_x(0), 0); | |
| 605 | + } | |
| 606 | + self.view_offset_anim = None; | |
| 607 | + } | |
| 608 | + | |
| 609 | + self.activate_column(idx); | |
| 610 | + self.activate_prev_column_on_removal = true; | |
| 611 | + } | |
| 612 | + } | |
| 613 | + | |
| 577 | 614 | pub fn remove_window_by_idx(&mut self, column_idx: usize, window_idx: usize) -> W { |
| 578 | 615 | let column = &mut self.columns[column_idx]; |
| 579 | 616 | let window = column.tiles.remove(window_idx).into_window(); |
| @@ -618,6 +655,42 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 618 | 655 | window |
| 619 | 656 | } |
| 620 | 657 | |
| 658 | + pub fn remove_column_by_idx(&mut self, column_idx: usize) -> Column<W> { | |
| 659 | + let column = self.columns.remove(column_idx); | |
| 660 | + | |
| 661 | + if let Some(output) = &self.output { | |
| 662 | + for tile in &column.tiles { | |
| 663 | + tile.window().output_leave(output); | |
| 664 | + } | |
| 665 | + } | |
| 666 | + | |
| 667 | + if column_idx + 1 == self.active_column_idx { | |
| 668 | + // The previous column, that we were going to activate upon removal of the active | |
| 669 | + // column, has just been itself removed. | |
| 670 | + self.activate_prev_column_on_removal = false; | |
| 671 | + } | |
| 672 | + | |
| 673 | + // FIXME: activate_column below computes current view position to compute the new view | |
| 674 | + // position, which can include the column we're removing here. This leads to unwanted | |
| 675 | + // view jumps. | |
| 676 | + if self.columns.is_empty() { | |
| 677 | + return column; | |
| 678 | + } | |
| 679 | + | |
| 680 | + if self.active_column_idx > column_idx | |
| 681 | + || (self.active_column_idx == column_idx && self.activate_prev_column_on_removal) | |
| 682 | + { | |
| 683 | + // A column to the left was removed; preserve the current position. | |
| 684 | + // FIXME: preserve activate_prev_column_on_removal. | |
| 685 | + // Or, the active column was removed, and we needed to activate the previous column. | |
| 686 | + self.activate_column(self.active_column_idx.saturating_sub(1)); | |
| 687 | + } else { | |
| 688 | + self.activate_column(min(self.active_column_idx, self.columns.len() - 1)); | |
| 689 | + } | |
| 690 | + | |
| 691 | + column | |
| 692 | + } | |
| 693 | + | |
| 621 | 694 | pub fn remove_window(&mut self, window: &W) { |
| 622 | 695 | let column_idx = self |
| 623 | 696 | .columns |