layout/monitor: Extract WorkspaceSwitchGesture::min_max()
Browse files at this commitffd6acc0aabddf6e7a647aeadc5b656125267e33Parent: cee11dc1 changed file +10 -4
- src/layout/monitor.rs +10 -4
src/layout/monitor.rsmodified+10 -4
| @@ -131,6 +131,14 @@ impl WorkspaceSwitch { | |||
| 131 | } | 131 | } |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | +impl WorkspaceSwitchGesture { | ||
| 135 | + fn min_max(&self, workspace_count: usize) -> (f64, f64) { | ||
| 136 | + let min = self.center_idx.saturating_sub(1) as f64; | ||
| 137 | + let max = (self.center_idx + 1).min(workspace_count - 1) as f64; | ||
| 138 | + (min, max) | ||
| 139 | + } | ||
| 140 | +} | ||
| 141 | + | ||
| 134 | impl<W: LayoutElement> Monitor<W> { | 142 | impl<W: LayoutElement> Monitor<W> { |
| 135 | pub fn new( | 143 | pub fn new( |
| 136 | output: Output, | 144 | output: Output, |
| @@ -1020,8 +1028,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1020 | }; | 1028 | }; |
| 1021 | let pos = gesture.tracker.pos() / total_height; | 1029 | let pos = gesture.tracker.pos() / total_height; |
| 1022 | 1030 | ||
| 1023 | - let min = gesture.center_idx.saturating_sub(1) as f64; | 1031 | + let (min, max) = gesture.min_max(self.workspaces.len()); |
| 1024 | - let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64; | ||
| 1025 | let new_idx = gesture.start_idx + pos; | 1032 | let new_idx = gesture.start_idx + pos; |
| 1026 | let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); | 1033 | let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); |
| 1027 | 1034 | ||
| @@ -1056,8 +1063,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1056 | let current_pos = gesture.tracker.pos() / total_height; | 1063 | let current_pos = gesture.tracker.pos() / total_height; |
| 1057 | let pos = gesture.tracker.projected_end_pos() / total_height; | 1064 | let pos = gesture.tracker.projected_end_pos() / total_height; |
| 1058 | 1065 | ||
| 1059 | - let min = gesture.center_idx.saturating_sub(1) as f64; | 1066 | + let (min, max) = gesture.min_max(self.workspaces.len()); |
| 1060 | - let max = (gesture.center_idx + 1).min(self.workspaces.len() - 1) as f64; | ||
| 1061 | let new_idx = gesture.start_idx + pos; | 1067 | let new_idx = gesture.start_idx + pos; |
| 1062 | 1068 | ||
| 1063 | let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); | 1069 | let new_idx = WORKSPACE_GESTURE_RUBBER_BAND.clamp(min, max, new_idx); |