Add cycle back feature for presets of column/window width/height.
Browse files at this commit0c3223ac72f3bee35c954764c2012f0d495deeb0Parent: 1ffda919 changed files +187 -52
- niri-config/src/binds.rs +20 -0
- niri-ipc/src/lib.rs +18 -0
- resources/default-config.kdl +2 -0
- src/input/mod.rs +28 -5
- src/layout/floating.rs +38 -10
- src/layout/mod.rs +6 -6
- src/layout/scrolling.rs +44 -18
- src/layout/tests.rs +22 -4
- src/layout/workspace.rs +9 -9
niri-config/src/binds.rsmodified+20 -0
| @@ -277,12 +277,19 @@ pub enum Action { | |||
| 277 | #[knuffel(skip)] | 277 | #[knuffel(skip)] |
| 278 | ResetWindowHeightById(u64), | 278 | ResetWindowHeightById(u64), |
| 279 | SwitchPresetColumnWidth, | 279 | SwitchPresetColumnWidth, |
| 280 | + SwitchPresetColumnWidthBack, | ||
| 280 | SwitchPresetWindowWidth, | 281 | SwitchPresetWindowWidth, |
| 282 | + SwitchPresetWindowWidthBack, | ||
| 281 | #[knuffel(skip)] | 283 | #[knuffel(skip)] |
| 282 | SwitchPresetWindowWidthById(u64), | 284 | SwitchPresetWindowWidthById(u64), |
| 285 | + #[knuffel(skip)] | ||
| 286 | + SwitchPresetWindowWidthBackById(u64), | ||
| 283 | SwitchPresetWindowHeight, | 287 | SwitchPresetWindowHeight, |
| 288 | + SwitchPresetWindowHeightBack, | ||
| 284 | #[knuffel(skip)] | 289 | #[knuffel(skip)] |
| 285 | SwitchPresetWindowHeightById(u64), | 290 | SwitchPresetWindowHeightById(u64), |
| 291 | + #[knuffel(skip)] | ||
| 292 | + SwitchPresetWindowHeightBackById(u64), | ||
| 286 | MaximizeColumn, | 293 | MaximizeColumn, |
| 287 | SetColumnWidth(#[knuffel(argument, str)] SizeChange), | 294 | SetColumnWidth(#[knuffel(argument, str)] SizeChange), |
| 288 | ExpandColumnToAvailableWidth, | 295 | ExpandColumnToAvailableWidth, |
| @@ -525,16 +532,29 @@ impl From<niri_ipc::Action> for Action { | |||
| 525 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, | 532 | niri_ipc::Action::ResetWindowHeight { id: None } => Self::ResetWindowHeight, |
| 526 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), | 533 | niri_ipc::Action::ResetWindowHeight { id: Some(id) } => Self::ResetWindowHeightById(id), |
| 527 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, | 534 | niri_ipc::Action::SwitchPresetColumnWidth {} => Self::SwitchPresetColumnWidth, |
| 535 | + niri_ipc::Action::SwitchPresetColumnWidthBack {} => Self::SwitchPresetColumnWidthBack, | ||
| 528 | niri_ipc::Action::SwitchPresetWindowWidth { id: None } => Self::SwitchPresetWindowWidth, | 536 | niri_ipc::Action::SwitchPresetWindowWidth { id: None } => Self::SwitchPresetWindowWidth, |
| 537 | + niri_ipc::Action::SwitchPresetWindowWidthBack { id: None } => { | ||
| 538 | + Self::SwitchPresetWindowWidthBack | ||
| 539 | + } | ||
| 529 | niri_ipc::Action::SwitchPresetWindowWidth { id: Some(id) } => { | 540 | niri_ipc::Action::SwitchPresetWindowWidth { id: Some(id) } => { |
| 530 | Self::SwitchPresetWindowWidthById(id) | 541 | Self::SwitchPresetWindowWidthById(id) |
| 531 | } | 542 | } |
| 543 | + niri_ipc::Action::SwitchPresetWindowWidthBack { id: Some(id) } => { | ||
| 544 | + Self::SwitchPresetWindowWidthBackById(id) | ||
| 545 | + } | ||
| 532 | niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { | 546 | niri_ipc::Action::SwitchPresetWindowHeight { id: None } => { |
| 533 | Self::SwitchPresetWindowHeight | 547 | Self::SwitchPresetWindowHeight |
| 534 | } | 548 | } |
| 549 | + niri_ipc::Action::SwitchPresetWindowHeightBack { id: None } => { | ||
| 550 | + Self::SwitchPresetWindowHeightBack | ||
| 551 | + } | ||
| 535 | niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => { | 552 | niri_ipc::Action::SwitchPresetWindowHeight { id: Some(id) } => { |
| 536 | Self::SwitchPresetWindowHeightById(id) | 553 | Self::SwitchPresetWindowHeightById(id) |
| 537 | } | 554 | } |
| 555 | + niri_ipc::Action::SwitchPresetWindowHeightBack { id: Some(id) } => { | ||
| 556 | + Self::SwitchPresetWindowHeightBackById(id) | ||
| 557 | + } | ||
| 538 | niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, | 558 | niri_ipc::Action::MaximizeColumn {} => Self::MaximizeColumn, |
| 539 | niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), | 559 | niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change), |
| 540 | niri_ipc::Action::ExpandColumnToAvailableWidth {} => Self::ExpandColumnToAvailableWidth, | 560 | niri_ipc::Action::ExpandColumnToAvailableWidth {} => Self::ExpandColumnToAvailableWidth, |
niri-ipc/src/lib.rsmodified+18 -0
| @@ -677,6 +677,8 @@ pub enum Action { | |||
| 677 | }, | 677 | }, |
| 678 | /// Switch between preset column widths. | 678 | /// Switch between preset column widths. |
| 679 | SwitchPresetColumnWidth {}, | 679 | SwitchPresetColumnWidth {}, |
| 680 | + /// Switch between preset column widths backwards. | ||
| 681 | + SwitchPresetColumnWidthBack {}, | ||
| 680 | /// Switch between preset window widths. | 682 | /// Switch between preset window widths. |
| 681 | SwitchPresetWindowWidth { | 683 | SwitchPresetWindowWidth { |
| 682 | /// Id of the window whose width to switch. | 684 | /// Id of the window whose width to switch. |
| @@ -685,6 +687,14 @@ pub enum Action { | |||
| 685 | #[cfg_attr(feature = "clap", arg(long))] | 687 | #[cfg_attr(feature = "clap", arg(long))] |
| 686 | id: Option<u64>, | 688 | id: Option<u64>, |
| 687 | }, | 689 | }, |
| 690 | + /// Switch between preset window widths backwards. | ||
| 691 | + SwitchPresetWindowWidthBack { | ||
| 692 | + /// Id of the window whose width to switch. | ||
| 693 | + /// | ||
| 694 | + /// If `None`, uses the focused window. | ||
| 695 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 696 | + id: Option<u64>, | ||
| 697 | + }, | ||
| 688 | /// Switch between preset window heights. | 698 | /// Switch between preset window heights. |
| 689 | SwitchPresetWindowHeight { | 699 | SwitchPresetWindowHeight { |
| 690 | /// Id of the window whose height to switch. | 700 | /// Id of the window whose height to switch. |
| @@ -693,6 +703,14 @@ pub enum Action { | |||
| 693 | #[cfg_attr(feature = "clap", arg(long))] | 703 | #[cfg_attr(feature = "clap", arg(long))] |
| 694 | id: Option<u64>, | 704 | id: Option<u64>, |
| 695 | }, | 705 | }, |
| 706 | + /// Switch between preset window heights backwards. | ||
| 707 | + SwitchPresetWindowHeightBack { | ||
| 708 | + /// Id of the window whose height to switch. | ||
| 709 | + /// | ||
| 710 | + /// If `None`, uses the focused window. | ||
| 711 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 712 | + id: Option<u64>, | ||
| 713 | + }, | ||
| 696 | /// Toggle the maximized state of the focused column. | 714 | /// Toggle the maximized state of the focused column. |
| 697 | MaximizeColumn {}, | 715 | MaximizeColumn {}, |
| 698 | /// Change the width of the focused column. | 716 | /// Change the width of the focused column. |
resources/default-config.kdlmodified+2 -0
| @@ -540,6 +540,8 @@ binds { | |||
| 540 | Mod+Period { expel-window-from-column; } | 540 | Mod+Period { expel-window-from-column; } |
| 541 | 541 | ||
| 542 | Mod+R { switch-preset-column-width; } | 542 | Mod+R { switch-preset-column-width; } |
| 543 | + // Cycling through the presets in reverse order is also possible. | ||
| 544 | + // Mod+R { switch-preset-column-width-back; } | ||
| 543 | Mod+Shift+R { switch-preset-window-height; } | 545 | Mod+Shift+R { switch-preset-window-height; } |
| 544 | Mod+Ctrl+R { reset-window-height; } | 546 | Mod+Ctrl+R { reset-window-height; } |
| 545 | Mod+F { maximize-column; } | 547 | Mod+F { maximize-column; } |
src/input/mod.rsmodified+28 -5
| @@ -1442,26 +1442,49 @@ impl State { | |||
| 1442 | self.niri.queue_redraw_all(); | 1442 | self.niri.queue_redraw_all(); |
| 1443 | } | 1443 | } |
| 1444 | Action::SwitchPresetColumnWidth => { | 1444 | Action::SwitchPresetColumnWidth => { |
| 1445 | - self.niri.layout.toggle_width(); | 1445 | + self.niri.layout.toggle_width(true); |
| 1446 | + } | ||
| 1447 | + Action::SwitchPresetColumnWidthBack => { | ||
| 1448 | + self.niri.layout.toggle_width(false); | ||
| 1446 | } | 1449 | } |
| 1447 | Action::SwitchPresetWindowWidth => { | 1450 | Action::SwitchPresetWindowWidth => { |
| 1448 | - self.niri.layout.toggle_window_width(None); | 1451 | + self.niri.layout.toggle_window_width(None, true); |
| 1452 | + } | ||
| 1453 | + Action::SwitchPresetWindowWidthBack => { | ||
| 1454 | + self.niri.layout.toggle_window_width(None, false); | ||
| 1449 | } | 1455 | } |
| 1450 | Action::SwitchPresetWindowWidthById(id) => { | 1456 | Action::SwitchPresetWindowWidthById(id) => { |
| 1451 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | 1457 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); |
| 1452 | let window = window.map(|(_, m)| m.window.clone()); | 1458 | let window = window.map(|(_, m)| m.window.clone()); |
| 1453 | if let Some(window) = window { | 1459 | if let Some(window) = window { |
| 1454 | - self.niri.layout.toggle_window_width(Some(&window)); | 1460 | + self.niri.layout.toggle_window_width(Some(&window), true); |
| 1461 | + } | ||
| 1462 | + } | ||
| 1463 | + Action::SwitchPresetWindowWidthBackById(id) => { | ||
| 1464 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1465 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1466 | + if let Some(window) = window { | ||
| 1467 | + self.niri.layout.toggle_window_width(Some(&window), false); | ||
| 1455 | } | 1468 | } |
| 1456 | } | 1469 | } |
| 1457 | Action::SwitchPresetWindowHeight => { | 1470 | Action::SwitchPresetWindowHeight => { |
| 1458 | - self.niri.layout.toggle_window_height(None); | 1471 | + self.niri.layout.toggle_window_height(None, true); |
| 1472 | + } | ||
| 1473 | + Action::SwitchPresetWindowHeightBack => { | ||
| 1474 | + self.niri.layout.toggle_window_height(None, false); | ||
| 1459 | } | 1475 | } |
| 1460 | Action::SwitchPresetWindowHeightById(id) => { | 1476 | Action::SwitchPresetWindowHeightById(id) => { |
| 1461 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | 1477 | let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); |
| 1462 | let window = window.map(|(_, m)| m.window.clone()); | 1478 | let window = window.map(|(_, m)| m.window.clone()); |
| 1463 | if let Some(window) = window { | 1479 | if let Some(window) = window { |
| 1464 | - self.niri.layout.toggle_window_height(Some(&window)); | 1480 | + self.niri.layout.toggle_window_height(Some(&window), true); |
| 1481 | + } | ||
| 1482 | + } | ||
| 1483 | + Action::SwitchPresetWindowHeightBackById(id) => { | ||
| 1484 | + let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id); | ||
| 1485 | + let window = window.map(|(_, m)| m.window.clone()); | ||
| 1486 | + if let Some(window) = window { | ||
| 1487 | + self.niri.layout.toggle_window_height(Some(&window), false); | ||
| 1465 | } | 1488 | } |
| 1466 | } | 1489 | } |
| 1467 | Action::CenterColumn => { | 1490 | Action::CenterColumn => { |
src/layout/floating.rsmodified+38 -10
| @@ -624,7 +624,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 624 | } | 624 | } |
| 625 | } | 625 | } |
| 626 | 626 | ||
| 627 | - pub fn toggle_window_width(&mut self, id: Option<&W::Id>) { | 627 | + pub fn toggle_window_width(&mut self, id: Option<&W::Id>, forwards: bool) { |
| 628 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { | 628 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { |
| 629 | return; | 629 | return; |
| 630 | }; | 630 | }; |
| @@ -632,18 +632,22 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 632 | 632 | ||
| 633 | let available_size = self.working_area.size.w; | 633 | let available_size = self.working_area.size.w; |
| 634 | 634 | ||
| 635 | + let len = self.options.preset_column_widths.len(); | ||
| 635 | let tile = &mut self.tiles[idx]; | 636 | let tile = &mut self.tiles[idx]; |
| 636 | let preset_idx = if let Some(idx) = tile.floating_preset_width_idx { | 637 | let preset_idx = if let Some(idx) = tile.floating_preset_width_idx { |
| 637 | - (idx + 1) % self.options.preset_column_widths.len() | 638 | + (idx + if forwards { 1 } else { len - 1 }) % len |
| 638 | } else { | 639 | } else { |
| 639 | let current_window = tile.window_expected_or_current_size().w; | 640 | let current_window = tile.window_expected_or_current_size().w; |
| 640 | let current_tile = tile.tile_expected_or_current_size().w; | 641 | let current_tile = tile.tile_expected_or_current_size().w; |
| 641 | 642 | ||
| 642 | - self.options | 643 | + let mut it = self |
| 644 | + .options | ||
| 643 | .preset_column_widths | 645 | .preset_column_widths |
| 644 | .iter() | 646 | .iter() |
| 645 | - .position(|preset| { | 647 | + .map(|preset| resolve_preset_size(*preset, available_size)); |
| 646 | - let resolved = resolve_preset_size(*preset, available_size); | 648 | + |
| 649 | + if forwards { | ||
| 650 | + it.position(|resolved| { | ||
| 647 | match resolved { | 651 | match resolved { |
| 648 | // Some allowance for fractional scaling purposes. | 652 | // Some allowance for fractional scaling purposes. |
| 649 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, | 653 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, |
| @@ -651,6 +655,16 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 651 | } | 655 | } |
| 652 | }) | 656 | }) |
| 653 | .unwrap_or(0) | 657 | .unwrap_or(0) |
| 658 | + } else { | ||
| 659 | + it.rposition(|resolved| { | ||
| 660 | + match resolved { | ||
| 661 | + // Some allowance for fractional scaling purposes. | ||
| 662 | + ResolvedSize::Tile(resolved) => resolved + 1. < current_tile, | ||
| 663 | + ResolvedSize::Window(resolved) => resolved + 1. < current_window, | ||
| 664 | + } | ||
| 665 | + }) | ||
| 666 | + .unwrap_or(len - 1) | ||
| 667 | + } | ||
| 654 | }; | 668 | }; |
| 655 | 669 | ||
| 656 | let preset = self.options.preset_column_widths[preset_idx]; | 670 | let preset = self.options.preset_column_widths[preset_idx]; |
| @@ -670,7 +684,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 670 | true | 684 | true |
| 671 | } | 685 | } |
| 672 | 686 | ||
| 673 | - pub fn toggle_window_height(&mut self, id: Option<&W::Id>) { | 687 | + pub fn toggle_window_height(&mut self, id: Option<&W::Id>, forwards: bool) { |
| 674 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { | 688 | let Some(id) = id.or(self.active_window_id.as_ref()).cloned() else { |
| 675 | return; | 689 | return; |
| 676 | }; | 690 | }; |
| @@ -678,18 +692,22 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 678 | 692 | ||
| 679 | let available_size = self.working_area.size.h; | 693 | let available_size = self.working_area.size.h; |
| 680 | 694 | ||
| 695 | + let len = self.options.preset_window_heights.len(); | ||
| 681 | let tile = &mut self.tiles[idx]; | 696 | let tile = &mut self.tiles[idx]; |
| 682 | let preset_idx = if let Some(idx) = tile.floating_preset_height_idx { | 697 | let preset_idx = if let Some(idx) = tile.floating_preset_height_idx { |
| 683 | - (idx + 1) % self.options.preset_window_heights.len() | 698 | + (idx + if forwards { 1 } else { len - 1 }) % len |
| 684 | } else { | 699 | } else { |
| 685 | let current_window = tile.window_expected_or_current_size().h; | 700 | let current_window = tile.window_expected_or_current_size().h; |
| 686 | let current_tile = tile.tile_expected_or_current_size().h; | 701 | let current_tile = tile.tile_expected_or_current_size().h; |
| 687 | 702 | ||
| 688 | - self.options | 703 | + let mut it = self |
| 704 | + .options | ||
| 689 | .preset_window_heights | 705 | .preset_window_heights |
| 690 | .iter() | 706 | .iter() |
| 691 | - .position(|preset| { | 707 | + .map(|preset| resolve_preset_size(*preset, available_size)); |
| 692 | - let resolved = resolve_preset_size(*preset, available_size); | 708 | + |
| 709 | + if forwards { | ||
| 710 | + it.position(|resolved| { | ||
| 693 | match resolved { | 711 | match resolved { |
| 694 | // Some allowance for fractional scaling purposes. | 712 | // Some allowance for fractional scaling purposes. |
| 695 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, | 713 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, |
| @@ -697,6 +715,16 @@ impl<W: LayoutElement> FloatingSpace<W> { | |||
| 697 | } | 715 | } |
| 698 | }) | 716 | }) |
| 699 | .unwrap_or(0) | 717 | .unwrap_or(0) |
| 718 | + } else { | ||
| 719 | + it.rposition(|resolved| { | ||
| 720 | + match resolved { | ||
| 721 | + // Some allowance for fractional scaling purposes. | ||
| 722 | + ResolvedSize::Tile(resolved) => resolved + 1. < current_tile, | ||
| 723 | + ResolvedSize::Window(resolved) => resolved + 1. < current_window, | ||
| 724 | + } | ||
| 725 | + }) | ||
| 726 | + .unwrap_or(len - 1) | ||
| 727 | + } | ||
| 700 | }; | 728 | }; |
| 701 | 729 | ||
| 702 | let preset = self.options.preset_window_heights[preset_idx]; | 730 | let preset = self.options.preset_window_heights[preset_idx]; |
src/layout/mod.rsmodified+6 -6
| @@ -3179,14 +3179,14 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3179 | self.options = options; | 3179 | self.options = options; |
| 3180 | } | 3180 | } |
| 3181 | 3181 | ||
| 3182 | - pub fn toggle_width(&mut self) { | 3182 | + pub fn toggle_width(&mut self, forwards: bool) { |
| 3183 | let Some(workspace) = self.active_workspace_mut() else { | 3183 | let Some(workspace) = self.active_workspace_mut() else { |
| 3184 | return; | 3184 | return; |
| 3185 | }; | 3185 | }; |
| 3186 | - workspace.toggle_width(); | 3186 | + workspace.toggle_width(forwards); |
| 3187 | } | 3187 | } |
| 3188 | 3188 | ||
| 3189 | - pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | 3189 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 3190 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 3190 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 3191 | if window.is_none() || window == Some(move_.tile.window().id()) { | 3191 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| 3192 | return; | 3192 | return; |
| @@ -3206,10 +3206,10 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3206 | let Some(workspace) = workspace else { | 3206 | let Some(workspace) = workspace else { |
| 3207 | return; | 3207 | return; |
| 3208 | }; | 3208 | }; |
| 3209 | - workspace.toggle_window_width(window); | 3209 | + workspace.toggle_window_width(window, forwards); |
| 3210 | } | 3210 | } |
| 3211 | 3211 | ||
| 3212 | - pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 3212 | + pub fn toggle_window_height(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 3213 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 3213 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 3214 | if window.is_none() || window == Some(move_.tile.window().id()) { | 3214 | if window.is_none() || window == Some(move_.tile.window().id()) { |
| 3215 | return; | 3215 | return; |
| @@ -3229,7 +3229,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3229 | let Some(workspace) = workspace else { | 3229 | let Some(workspace) = workspace else { |
| 3230 | return; | 3230 | return; |
| 3231 | }; | 3231 | }; |
| 3232 | - workspace.toggle_window_height(window); | 3232 | + workspace.toggle_window_height(window, forwards); |
| 3233 | } | 3233 | } |
| 3234 | 3234 | ||
| 3235 | pub fn toggle_full_width(&mut self) { | 3235 | pub fn toggle_full_width(&mut self) { |
src/layout/scrolling.rsmodified+44 -18
| @@ -2522,13 +2522,13 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2522 | None | 2522 | None |
| 2523 | } | 2523 | } |
| 2524 | 2524 | ||
| 2525 | - pub fn toggle_width(&mut self) { | 2525 | + pub fn toggle_width(&mut self, forwards: bool) { |
| 2526 | if self.columns.is_empty() { | 2526 | if self.columns.is_empty() { |
| 2527 | return; | 2527 | return; |
| 2528 | } | 2528 | } |
| 2529 | 2529 | ||
| 2530 | let col = &mut self.columns[self.active_column_idx]; | 2530 | let col = &mut self.columns[self.active_column_idx]; |
| 2531 | - col.toggle_width(None); | 2531 | + col.toggle_width(None, forwards); |
| 2532 | 2532 | ||
| 2533 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2533 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2534 | } | 2534 | } |
| @@ -2616,7 +2616,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2616 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2616 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2617 | } | 2617 | } |
| 2618 | 2618 | ||
| 2619 | - pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | 2619 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 2620 | if self.columns.is_empty() { | 2620 | if self.columns.is_empty() { |
| 2621 | return; | 2621 | return; |
| 2622 | } | 2622 | } |
| @@ -2635,12 +2635,12 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2635 | (&mut self.columns[self.active_column_idx], None) | 2635 | (&mut self.columns[self.active_column_idx], None) |
| 2636 | }; | 2636 | }; |
| 2637 | 2637 | ||
| 2638 | - col.toggle_width(tile_idx); | 2638 | + col.toggle_width(tile_idx, forwards); |
| 2639 | 2639 | ||
| 2640 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2640 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2641 | } | 2641 | } |
| 2642 | 2642 | ||
| 2643 | - pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 2643 | + pub fn toggle_window_height(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 2644 | if self.columns.is_empty() { | 2644 | if self.columns.is_empty() { |
| 2645 | return; | 2645 | return; |
| 2646 | } | 2646 | } |
| @@ -2659,7 +2659,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2659 | (&mut self.columns[self.active_column_idx], None) | 2659 | (&mut self.columns[self.active_column_idx], None) |
| 2660 | }; | 2660 | }; |
| 2661 | 2661 | ||
| 2662 | - col.toggle_window_height(tile_idx, true); | 2662 | + col.toggle_window_height(tile_idx, true, forwards); |
| 2663 | 2663 | ||
| 2664 | cancel_resize_for_column(&mut self.interactive_resize, col); | 2664 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2665 | } | 2665 | } |
| @@ -4557,7 +4557,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 4557 | true | 4557 | true |
| 4558 | } | 4558 | } |
| 4559 | 4559 | ||
| 4560 | - fn toggle_width(&mut self, tile_idx: Option<usize>) { | 4560 | + fn toggle_width(&mut self, tile_idx: Option<usize>, forwards: bool) { |
| 4561 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); | 4561 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 4562 | 4562 | ||
| 4563 | let preset_idx = if self.is_full_width { | 4563 | let preset_idx = if self.is_full_width { |
| @@ -4566,24 +4566,39 @@ impl<W: LayoutElement> Column<W> { | |||
| 4566 | self.preset_width_idx | 4566 | self.preset_width_idx |
| 4567 | }; | 4567 | }; |
| 4568 | 4568 | ||
| 4569 | + let len = self.options.preset_column_widths.len(); | ||
| 4569 | let preset_idx = if let Some(idx) = preset_idx { | 4570 | let preset_idx = if let Some(idx) = preset_idx { |
| 4570 | - (idx + 1) % self.options.preset_column_widths.len() | 4571 | + (idx + if forwards { 1 } else { len - 1 }) % len |
| 4571 | } else { | 4572 | } else { |
| 4572 | let tile = &self.tiles[tile_idx]; | 4573 | let tile = &self.tiles[tile_idx]; |
| 4573 | let current_window = tile.window_expected_or_current_size().w; | 4574 | let current_window = tile.window_expected_or_current_size().w; |
| 4574 | let current_tile = tile.tile_expected_or_current_size().w; | 4575 | let current_tile = tile.tile_expected_or_current_size().w; |
| 4575 | 4576 | ||
| 4576 | - self.options | 4577 | + let mut it = self |
| 4578 | + .options | ||
| 4577 | .preset_column_widths | 4579 | .preset_column_widths |
| 4578 | .iter() | 4580 | .iter() |
| 4579 | - .position(|prop| { | 4581 | + .map(|preset| self.resolve_preset_width(*preset)); |
| 4580 | - match self.resolve_preset_width(*prop) { | 4582 | + |
| 4583 | + if forwards { | ||
| 4584 | + it.position(|resolved| { | ||
| 4585 | + match resolved { | ||
| 4581 | // Some allowance for fractional scaling purposes. | 4586 | // Some allowance for fractional scaling purposes. |
| 4582 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, | 4587 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, |
| 4583 | ResolvedSize::Window(resolved) => current_window + 1. < resolved, | 4588 | ResolvedSize::Window(resolved) => current_window + 1. < resolved, |
| 4584 | } | 4589 | } |
| 4585 | }) | 4590 | }) |
| 4586 | .unwrap_or(0) | 4591 | .unwrap_or(0) |
| 4592 | + } else { | ||
| 4593 | + it.rposition(|resolved| { | ||
| 4594 | + match resolved { | ||
| 4595 | + // Some allowance for fractional scaling purposes. | ||
| 4596 | + ResolvedSize::Tile(resolved) => resolved + 1. < current_tile, | ||
| 4597 | + ResolvedSize::Window(resolved) => resolved + 1. < current_window, | ||
| 4598 | + } | ||
| 4599 | + }) | ||
| 4600 | + .unwrap_or(len - 1) | ||
| 4601 | + } | ||
| 4587 | }; | 4602 | }; |
| 4588 | 4603 | ||
| 4589 | let preset = self.options.preset_column_widths[preset_idx]; | 4604 | let preset = self.options.preset_column_widths[preset_idx]; |
| @@ -4744,7 +4759,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 4744 | self.update_tile_sizes(animate); | 4759 | self.update_tile_sizes(animate); |
| 4745 | } | 4760 | } |
| 4746 | 4761 | ||
| 4747 | - fn toggle_window_height(&mut self, tile_idx: Option<usize>, animate: bool) { | 4762 | + fn toggle_window_height(&mut self, tile_idx: Option<usize>, animate: bool, forwards: bool) { |
| 4748 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); | 4763 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 4749 | 4764 | ||
| 4750 | // Start by converting all heights to automatic, since only one window in the column can be | 4765 | // Start by converting all heights to automatic, since only one window in the column can be |
| @@ -4756,28 +4771,39 @@ impl<W: LayoutElement> Column<W> { | |||
| 4756 | self.convert_heights_to_auto(); | 4771 | self.convert_heights_to_auto(); |
| 4757 | } | 4772 | } |
| 4758 | 4773 | ||
| 4774 | + let len = self.options.preset_window_heights.len(); | ||
| 4759 | let preset_idx = match self.data[tile_idx].height { | 4775 | let preset_idx = match self.data[tile_idx].height { |
| 4760 | - WindowHeight::Preset(idx) => (idx + 1) % self.options.preset_window_heights.len(), | 4776 | + WindowHeight::Preset(idx) => (idx + if forwards { 1 } else { len - 1 }) % len, |
| 4761 | _ => { | 4777 | _ => { |
| 4762 | let current = self.data[tile_idx].size.h; | 4778 | let current = self.data[tile_idx].size.h; |
| 4763 | let tile = &self.tiles[tile_idx]; | 4779 | let tile = &self.tiles[tile_idx]; |
| 4764 | - self.options | 4780 | + |
| 4781 | + let mut it = self | ||
| 4782 | + .options | ||
| 4765 | .preset_window_heights | 4783 | .preset_window_heights |
| 4766 | .iter() | 4784 | .iter() |
| 4767 | .copied() | 4785 | .copied() |
| 4768 | - .position(|preset| { | 4786 | + .map(|preset| { |
| 4769 | let window_height = match self.resolve_preset_height(preset) { | 4787 | let window_height = match self.resolve_preset_height(preset) { |
| 4770 | ResolvedSize::Tile(h) => tile.window_height_for_tile_height(h), | 4788 | ResolvedSize::Tile(h) => tile.window_height_for_tile_height(h), |
| 4771 | ResolvedSize::Window(h) => h, | 4789 | ResolvedSize::Window(h) => h, |
| 4772 | }; | 4790 | }; |
| 4773 | - let resolved = tile.tile_height_for_window_height( | 4791 | + tile.tile_height_for_window_height(window_height.round().clamp(1., 100000.)) |
| 4774 | - window_height.round().clamp(1., 100000.), | 4792 | + }); |
| 4775 | - ); | ||
| 4776 | 4793 | ||
| 4794 | + if forwards { | ||
| 4795 | + it.position(|resolved| { | ||
| 4777 | // Some allowance for fractional scaling purposes. | 4796 | // Some allowance for fractional scaling purposes. |
| 4778 | current + 1. < resolved | 4797 | current + 1. < resolved |
| 4779 | }) | 4798 | }) |
| 4780 | .unwrap_or(0) | 4799 | .unwrap_or(0) |
| 4800 | + } else { | ||
| 4801 | + it.rposition(|resolved| { | ||
| 4802 | + // Some allowance for fractional scaling purposes. | ||
| 4803 | + resolved + 1. < current | ||
| 4804 | + }) | ||
| 4805 | + .unwrap_or(len - 1) | ||
| 4806 | + } | ||
| 4781 | } | 4807 | } |
| 4782 | }; | 4808 | }; |
| 4783 | self.data[tile_idx].height = WindowHeight::Preset(preset_idx); | 4809 | self.data[tile_idx].height = WindowHeight::Preset(preset_idx); |
src/layout/tests.rsmodified+22 -4
| @@ -548,14 +548,23 @@ enum Op { | |||
| 548 | activate: bool, | 548 | activate: bool, |
| 549 | }, | 549 | }, |
| 550 | SwitchPresetColumnWidth, | 550 | SwitchPresetColumnWidth, |
| 551 | + SwitchPresetColumnWidthBack, | ||
| 551 | SwitchPresetWindowWidth { | 552 | SwitchPresetWindowWidth { |
| 552 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] | 553 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] |
| 553 | id: Option<usize>, | 554 | id: Option<usize>, |
| 554 | }, | 555 | }, |
| 556 | + SwitchPresetWindowWidthBack { | ||
| 557 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | ||
| 558 | + id: Option<usize>, | ||
| 559 | + }, | ||
| 555 | SwitchPresetWindowHeight { | 560 | SwitchPresetWindowHeight { |
| 556 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] | 561 | #[proptest(strategy = "proptest::option::of(1..=5usize)")] |
| 557 | id: Option<usize>, | 562 | id: Option<usize>, |
| 558 | }, | 563 | }, |
| 564 | + SwitchPresetWindowHeightBack { | ||
| 565 | + #[proptest(strategy = "proptest::option::of(1..=5usize)")] | ||
| 566 | + id: Option<usize>, | ||
| 567 | + }, | ||
| 559 | MaximizeColumn, | 568 | MaximizeColumn, |
| 560 | SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), | 569 | SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange), |
| 561 | SetWindowWidth { | 570 | SetWindowWidth { |
| @@ -1231,14 +1240,23 @@ impl Op { | |||
| 1231 | 1240 | ||
| 1232 | layout.move_workspace_to_output_by_id(old_idx, Some(old_output), output); | 1241 | layout.move_workspace_to_output_by_id(old_idx, Some(old_output), output); |
| 1233 | } | 1242 | } |
| 1234 | - Op::SwitchPresetColumnWidth => layout.toggle_width(), | 1243 | + Op::SwitchPresetColumnWidth => layout.toggle_width(true), |
| 1244 | + Op::SwitchPresetColumnWidthBack => layout.toggle_width(false), | ||
| 1235 | Op::SwitchPresetWindowWidth { id } => { | 1245 | Op::SwitchPresetWindowWidth { id } => { |
| 1236 | let id = id.filter(|id| layout.has_window(id)); | 1246 | let id = id.filter(|id| layout.has_window(id)); |
| 1237 | - layout.toggle_window_width(id.as_ref()); | 1247 | + layout.toggle_window_width(id.as_ref(), true); |
| 1248 | + } | ||
| 1249 | + Op::SwitchPresetWindowWidthBack { id } => { | ||
| 1250 | + let id = id.filter(|id| layout.has_window(id)); | ||
| 1251 | + layout.toggle_window_width(id.as_ref(), false); | ||
| 1238 | } | 1252 | } |
| 1239 | Op::SwitchPresetWindowHeight { id } => { | 1253 | Op::SwitchPresetWindowHeight { id } => { |
| 1240 | let id = id.filter(|id| layout.has_window(id)); | 1254 | let id = id.filter(|id| layout.has_window(id)); |
| 1241 | - layout.toggle_window_height(id.as_ref()); | 1255 | + layout.toggle_window_height(id.as_ref(), true); |
| 1256 | + } | ||
| 1257 | + Op::SwitchPresetWindowHeightBack { id } => { | ||
| 1258 | + let id = id.filter(|id| layout.has_window(id)); | ||
| 1259 | + layout.toggle_window_height(id.as_ref(), false); | ||
| 1242 | } | 1260 | } |
| 1243 | Op::MaximizeColumn => layout.toggle_full_width(), | 1261 | Op::MaximizeColumn => layout.toggle_full_width(), |
| 1244 | Op::SetColumnWidth(change) => layout.set_column_width(change), | 1262 | Op::SetColumnWidth(change) => layout.set_column_width(change), |
| @@ -3250,7 +3268,7 @@ fn preset_column_width_fixed_correct_with_border() { | |||
| 3250 | assert_eq!(win.requested_size().unwrap().w, 490); | 3268 | assert_eq!(win.requested_size().unwrap().w, 490); |
| 3251 | 3269 | ||
| 3252 | // However, preset fixed width will still work correctly. | 3270 | // However, preset fixed width will still work correctly. |
| 3253 | - layout.toggle_width(); | 3271 | + layout.toggle_width(true); |
| 3254 | let win = layout.windows().next().unwrap().1; | 3272 | let win = layout.windows().next().unwrap().1; |
| 3255 | assert_eq!(win.requested_size().unwrap().w, 500); | 3273 | assert_eq!(win.requested_size().unwrap().w, 500); |
| 3256 | } | 3274 | } |
src/layout/workspace.rsmodified+9 -9
| @@ -1107,11 +1107,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1107 | self.scrolling.center_visible_columns(); | 1107 | self.scrolling.center_visible_columns(); |
| 1108 | } | 1108 | } |
| 1109 | 1109 | ||
| 1110 | - pub fn toggle_width(&mut self) { | 1110 | + pub fn toggle_width(&mut self, forwards: bool) { |
| 1111 | if self.floating_is_active.get() { | 1111 | if self.floating_is_active.get() { |
| 1112 | - self.floating.toggle_window_width(None); | 1112 | + self.floating.toggle_window_width(None, forwards); |
| 1113 | } else { | 1113 | } else { |
| 1114 | - self.scrolling.toggle_width(); | 1114 | + self.scrolling.toggle_width(forwards); |
| 1115 | } | 1115 | } |
| 1116 | } | 1116 | } |
| 1117 | 1117 | ||
| @@ -1161,23 +1161,23 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1161 | self.scrolling.reset_window_height(window); | 1161 | self.scrolling.reset_window_height(window); |
| 1162 | } | 1162 | } |
| 1163 | 1163 | ||
| 1164 | - pub fn toggle_window_width(&mut self, window: Option<&W::Id>) { | 1164 | + pub fn toggle_window_width(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 1165 | if window.map_or(self.floating_is_active.get(), |id| { | 1165 | if window.map_or(self.floating_is_active.get(), |id| { |
| 1166 | self.floating.has_window(id) | 1166 | self.floating.has_window(id) |
| 1167 | }) { | 1167 | }) { |
| 1168 | - self.floating.toggle_window_width(window); | 1168 | + self.floating.toggle_window_width(window, forwards); |
| 1169 | } else { | 1169 | } else { |
| 1170 | - self.scrolling.toggle_window_width(window); | 1170 | + self.scrolling.toggle_window_width(window, forwards); |
| 1171 | } | 1171 | } |
| 1172 | } | 1172 | } |
| 1173 | 1173 | ||
| 1174 | - pub fn toggle_window_height(&mut self, window: Option<&W::Id>) { | 1174 | + pub fn toggle_window_height(&mut self, window: Option<&W::Id>, forwards: bool) { |
| 1175 | if window.map_or(self.floating_is_active.get(), |id| { | 1175 | if window.map_or(self.floating_is_active.get(), |id| { |
| 1176 | self.floating.has_window(id) | 1176 | self.floating.has_window(id) |
| 1177 | }) { | 1177 | }) { |
| 1178 | - self.floating.toggle_window_height(window); | 1178 | + self.floating.toggle_window_height(window, forwards); |
| 1179 | } else { | 1179 | } else { |
| 1180 | - self.scrolling.toggle_window_height(window); | 1180 | + self.scrolling.toggle_window_height(window, forwards); |
| 1181 | } | 1181 | } |
| 1182 | } | 1182 | } |
| 1183 | 1183 | ||