diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-22 10:09:35 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-25 02:00:18 -0700 |
| commit | ffd6acc0aabddf6e7a647aeadc5b656125267e33 (patch) | |
| tree | 8444c1c6f1cff666c254514fcdc22542107443c5 | |
| parent | cee11dc329684fda261db43cedfe3c46a2c309d7 (diff) | |
| download | niri-ffd6acc0aabddf6e7a647aeadc5b656125267e33.tar.gz niri-ffd6acc0aabddf6e7a647aeadc5b656125267e33.tar.bz2 niri-ffd6acc0aabddf6e7a647aeadc5b656125267e33.zip | |
layout/monitor: Extract WorkspaceSwitchGesture::min_max()
| -rw-r--r-- | src/layout/monitor.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 4f44f328..2c2ea0f8 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -131,6 +131,14 @@ impl WorkspaceSwitch { } } +impl WorkspaceSwitchGesture { + fn min_max(&self, workspace_count: usize) -> (f64, f64) { + let min = self.center_idx.saturating_sub(1) as f64; + let max = (self.center_idx + 1).min(workspace_count - 1) as f64; + (min, max) + } +} + impl<W: LayoutElement> Monitor<W> { pub fn new( output: Output, @@ -1020,8 +1028,7 @@ impl<W: LayoutElement> Monitor<W> { }; let pos = gesture.tracker.pos() / total_height; - let min = gesture.center_idx.saturating_sub(1) as f64; - let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64; + let (min, max) = gesture.min_max(self.workspaces.len()); let new_idx = gesture.start_idx + pos; let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); @@ -1056,8 +1063,7 @@ impl<W: LayoutElement> Monitor<W> { let current_pos = gesture.tracker.pos() / total_height; let pos = gesture.tracker.projected_end_pos() / total_height; - let min = gesture.center_idx.saturating_sub(1) as f64; - let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64; + let (min, max) = gesture.min_max(self.workspaces.len()); let new_idx = gesture.start_idx + pos; let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); |
