diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-17 11:30:45 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-04-25 02:00:18 -0700 |
| commit | d3a79faeecc5f399b616e2b1a21a48f7b26cd720 (patch) | |
| tree | 7aa159fab9d428d9e3d6d00068fc8618b3734156 | |
| parent | 21630ddb5ebd078c5a6400d6d56c44f0903f1d44 (diff) | |
| download | niri-d3a79faeecc5f399b616e2b1a21a48f7b26cd720.tar.gz niri-d3a79faeecc5f399b616e2b1a21a48f7b26cd720.tar.bz2 niri-d3a79faeecc5f399b616e2b1a21a48f7b26cd720.zip | |
layout/monitor: Extract workspace_render_idx()
| -rw-r--r-- | src/layout/monitor.rs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 8f300812..023738fe 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -232,11 +232,7 @@ impl<W: LayoutElement> Monitor<W> { } // FIXME: also compute and use current velocity. - let current_idx = self - .workspace_switch - .as_ref() - .map(|s| s.current_idx()) - .unwrap_or(self.active_workspace_idx as f64); + let current_idx = self.workspace_render_idx(); self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id()); @@ -833,6 +829,14 @@ impl<W: LayoutElement> Monitor<W> { Some(rect) } + pub fn workspace_render_idx(&self) -> f64 { + if let Some(switch) = &self.workspace_switch { + switch.current_idx() + } else { + self.active_workspace_idx as f64 + } + } + pub fn workspaces_render_geo(&self) -> impl Iterator<Item = Rectangle<f64, Logical>> { let scale = self.output.current_scale().fractional_scale(); let size = output_size(&self.output); @@ -840,13 +844,7 @@ impl<W: LayoutElement> Monitor<W> { // Ceil the workspace size in physical pixels. let ws_size = size.to_physical_precise_ceil(scale).to_logical(scale); - let render_idx = if let Some(switch) = &self.workspace_switch { - switch.current_idx() - } else { - self.active_workspace_idx as f64 - }; - - let first_ws_y = -render_idx * ws_size.h; + let first_ws_y = -self.workspace_render_idx() * ws_size.h; (0..self.workspaces.len()).map(move |idx| { let y = first_ws_y + idx as f64 * ws_size.h; @@ -973,11 +971,7 @@ impl<W: LayoutElement> Monitor<W> { pub fn workspace_switch_gesture_begin(&mut self, is_touchpad: bool) { let center_idx = self.active_workspace_idx; - let current_idx = self - .workspace_switch - .as_ref() - .map(|s| s.current_idx()) - .unwrap_or(center_idx as f64); + let current_idx = self.workspace_render_idx(); let gesture = WorkspaceSwitchGesture { center_idx, |
