overview: Add DnD up/down scrolling
Browse files at this commit31e76cf451eaf8c5f2bc139b3867f2153e72ee1dParent: b8a9be53 changed files +354 -46
- niri-config/src/lib.rs +31 -0
- src/layout/mod.rs +66 -15
- src/layout/monitor.rs +257 -31
niri-config/src/lib.rsmodified+31 -0
| @@ -1208,6 +1208,8 @@ pub struct SpringParams { | |||
| 1208 | pub struct Gestures { | 1208 | pub struct Gestures { |
| 1209 | #[knuffel(child, default)] | 1209 | #[knuffel(child, default)] |
| 1210 | pub dnd_edge_view_scroll: DndEdgeViewScroll, | 1210 | pub dnd_edge_view_scroll: DndEdgeViewScroll, |
| 1211 | + #[knuffel(child, default)] | ||
| 1212 | + pub dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch, | ||
| 1211 | } | 1213 | } |
| 1212 | 1214 | ||
| 1213 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 1215 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| @@ -1230,6 +1232,26 @@ impl Default for DndEdgeViewScroll { | |||
| 1230 | } | 1232 | } |
| 1231 | } | 1233 | } |
| 1232 | 1234 | ||
| 1235 | +#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | ||
| 1236 | +pub struct DndEdgeWorkspaceSwitch { | ||
| 1237 | + #[knuffel(child, unwrap(argument), default = Self::default().trigger_height)] | ||
| 1238 | + pub trigger_height: FloatOrInt<0, 65535>, | ||
| 1239 | + #[knuffel(child, unwrap(argument), default = Self::default().delay_ms)] | ||
| 1240 | + pub delay_ms: u16, | ||
| 1241 | + #[knuffel(child, unwrap(argument), default = Self::default().max_speed)] | ||
| 1242 | + pub max_speed: FloatOrInt<0, 1_000_000>, | ||
| 1243 | +} | ||
| 1244 | + | ||
| 1245 | +impl Default for DndEdgeWorkspaceSwitch { | ||
| 1246 | + fn default() -> Self { | ||
| 1247 | + Self { | ||
| 1248 | + trigger_height: FloatOrInt(50.), | ||
| 1249 | + delay_ms: 100, | ||
| 1250 | + max_speed: FloatOrInt(1500.), | ||
| 1251 | + } | ||
| 1252 | + } | ||
| 1253 | +} | ||
| 1254 | + | ||
| 1233 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 1255 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 1234 | pub struct Overview { | 1256 | pub struct Overview { |
| 1235 | #[knuffel(child, unwrap(argument), default = Self::default().zoom)] | 1257 | #[knuffel(child, unwrap(argument), default = Self::default().zoom)] |
| @@ -4556,6 +4578,15 @@ mod tests { | |||
| 4556 | 50.0, | 4578 | 50.0, |
| 4557 | ), | 4579 | ), |
| 4558 | }, | 4580 | }, |
| 4581 | + dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch { | ||
| 4582 | + trigger_height: FloatOrInt( | ||
| 4583 | + 50.0, | ||
| 4584 | + ), | ||
| 4585 | + delay_ms: 100, | ||
| 4586 | + max_speed: FloatOrInt( | ||
| 4587 | + 1500.0, | ||
| 4588 | + ), | ||
| 4589 | + }, | ||
| 4559 | }, | 4590 | }, |
| 4560 | overview: Overview { | 4591 | overview: Overview { |
| 4561 | zoom: FloatOrInt( | 4592 | zoom: FloatOrInt( |
src/layout/mod.rsmodified+66 -15
| @@ -1177,6 +1177,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1177 | unreachable!() | 1177 | unreachable!() |
| 1178 | }; | 1178 | }; |
| 1179 | 1179 | ||
| 1180 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 1181 | + for mon in monitors { | ||
| 1182 | + mon.dnd_scroll_gesture_end(); | ||
| 1183 | + } | ||
| 1184 | + } | ||
| 1185 | + | ||
| 1180 | // Unlock the view on the workspaces. | 1186 | // Unlock the view on the workspaces. |
| 1181 | for ws in self.workspaces_mut() { | 1187 | for ws in self.workspaces_mut() { |
| 1182 | ws.dnd_scroll_gesture_end(); | 1188 | ws.dnd_scroll_gesture_end(); |
| @@ -2750,33 +2756,40 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2750 | 2756 | ||
| 2751 | let mut dnd_scroll = None; | 2757 | let mut dnd_scroll = None; |
| 2752 | if let Some(dnd) = &self.dnd { | 2758 | if let Some(dnd) = &self.dnd { |
| 2753 | - dnd_scroll = Some((dnd.output.clone(), dnd.pointer_pos_within_output)); | 2759 | + dnd_scroll = Some((dnd.output.clone(), dnd.pointer_pos_within_output, true)); |
| 2754 | } | 2760 | } |
| 2755 | 2761 | ||
| 2756 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { | 2762 | if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move { |
| 2757 | move_.tile.advance_animations(); | 2763 | move_.tile.advance_animations(); |
| 2758 | 2764 | ||
| 2759 | - if !move_.is_floating && dnd_scroll.is_none() { | 2765 | + if dnd_scroll.is_none() { |
| 2760 | - dnd_scroll = Some((move_.output.clone(), move_.pointer_pos_within_output)); | 2766 | + dnd_scroll = Some(( |
| 2767 | + move_.output.clone(), | ||
| 2768 | + move_.pointer_pos_within_output, | ||
| 2769 | + !move_.is_floating, | ||
| 2770 | + )); | ||
| 2761 | } | 2771 | } |
| 2762 | } | 2772 | } |
| 2763 | 2773 | ||
| 2764 | // Scroll the view if needed. | 2774 | // Scroll the view if needed. |
| 2765 | - if let Some((output, pos_within_output)) = dnd_scroll { | 2775 | + if let Some((output, pos_within_output, is_scrolling)) = dnd_scroll { |
| 2766 | if let Some(mon) = self.monitor_for_output_mut(&output) { | 2776 | if let Some(mon) = self.monitor_for_output_mut(&output) { |
| 2767 | let zoom = mon.overview_zoom(); | 2777 | let zoom = mon.overview_zoom(); |
| 2778 | + mon.dnd_scroll_gesture_scroll(pos_within_output, 1. / zoom); | ||
| 2768 | 2779 | ||
| 2769 | - if let Some((ws, geo)) = mon.workspace_under(pos_within_output) { | 2780 | + if is_scrolling { |
| 2770 | - let ws_id = ws.id(); | 2781 | + if let Some((ws, geo)) = mon.workspace_under(pos_within_output) { |
| 2771 | - let ws = mon | 2782 | + let ws_id = ws.id(); |
| 2772 | - .workspaces | 2783 | + let ws = mon |
| 2773 | - .iter_mut() | 2784 | + .workspaces |
| 2774 | - .find(|ws| ws.id() == ws_id) | 2785 | + .iter_mut() |
| 2775 | - .unwrap(); | 2786 | + .find(|ws| ws.id() == ws_id) |
| 2776 | - // As far as the DnD scroll gesture is concerned, the workspace spans across | 2787 | + .unwrap(); |
| 2777 | - // the whole monitor horizontally. | 2788 | + // As far as the DnD scroll gesture is concerned, the workspace spans across |
| 2778 | - let ws_pos = Point::from((0., geo.loc.y)); | 2789 | + // the whole monitor horizontally. |
| 2779 | - ws.dnd_scroll_gesture_scroll(pos_within_output - ws_pos, 1. / zoom); | 2790 | + let ws_pos = Point::from((0., geo.loc.y)); |
| 2791 | + ws.dnd_scroll_gesture_scroll(pos_within_output - ws_pos, 1. / zoom); | ||
| 2792 | + } | ||
| 2780 | } | 2793 | } |
| 2781 | } | 2794 | } |
| 2782 | } | 2795 | } |
| @@ -3948,6 +3961,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3948 | pointer_ratio_within_window, | 3961 | pointer_ratio_within_window, |
| 3949 | }); | 3962 | }); |
| 3950 | 3963 | ||
| 3964 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 3965 | + for mon in monitors { | ||
| 3966 | + mon.dnd_scroll_gesture_begin(); | ||
| 3967 | + } | ||
| 3968 | + } | ||
| 3969 | + | ||
| 3951 | // Lock the view for scrolling interactive move. | 3970 | // Lock the view for scrolling interactive move. |
| 3952 | if !is_floating { | 3971 | if !is_floating { |
| 3953 | for ws in self.workspaces_mut() { | 3972 | for ws in self.workspaces_mut() { |
| @@ -4181,6 +4200,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4181 | unreachable!() | 4200 | unreachable!() |
| 4182 | }; | 4201 | }; |
| 4183 | 4202 | ||
| 4203 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 4204 | + for mon in monitors { | ||
| 4205 | + mon.dnd_scroll_gesture_end(); | ||
| 4206 | + } | ||
| 4207 | + } | ||
| 4208 | + | ||
| 4184 | let mut ws_id = None; | 4209 | let mut ws_id = None; |
| 4185 | for ws in self.workspaces_mut() { | 4210 | for ws in self.workspaces_mut() { |
| 4186 | let id = ws.id(); | 4211 | let id = ws.id(); |
| @@ -4244,6 +4269,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4244 | unreachable!() | 4269 | unreachable!() |
| 4245 | }; | 4270 | }; |
| 4246 | 4271 | ||
| 4272 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 4273 | + for mon in monitors { | ||
| 4274 | + mon.dnd_scroll_gesture_end(); | ||
| 4275 | + } | ||
| 4276 | + } | ||
| 4277 | + | ||
| 4247 | // Unlock the view on the workspaces. | 4278 | // Unlock the view on the workspaces. |
| 4248 | if !move_.is_floating { | 4279 | if !move_.is_floating { |
| 4249 | for ws in self.workspaces_mut() { | 4280 | for ws in self.workspaces_mut() { |
| @@ -4431,6 +4462,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4431 | }); | 4462 | }); |
| 4432 | 4463 | ||
| 4433 | if begin_gesture { | 4464 | if begin_gesture { |
| 4465 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 4466 | + for mon in monitors { | ||
| 4467 | + mon.dnd_scroll_gesture_begin(); | ||
| 4468 | + } | ||
| 4469 | + } | ||
| 4470 | + | ||
| 4434 | for ws in self.workspaces_mut() { | 4471 | for ws in self.workspaces_mut() { |
| 4435 | ws.dnd_scroll_gesture_begin(); | 4472 | ws.dnd_scroll_gesture_begin(); |
| 4436 | } | 4473 | } |
| @@ -4444,6 +4481,12 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4444 | 4481 | ||
| 4445 | self.dnd = None; | 4482 | self.dnd = None; |
| 4446 | 4483 | ||
| 4484 | + if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | ||
| 4485 | + for mon in monitors { | ||
| 4486 | + mon.dnd_scroll_gesture_end(); | ||
| 4487 | + } | ||
| 4488 | + } | ||
| 4489 | + | ||
| 4447 | for ws in self.workspaces_mut() { | 4490 | for ws in self.workspaces_mut() { |
| 4448 | ws.dnd_scroll_gesture_end(); | 4491 | ws.dnd_scroll_gesture_end(); |
| 4449 | } | 4492 | } |
| @@ -4912,6 +4955,14 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4912 | let is_active = self.is_active | 4955 | let is_active = self.is_active |
| 4913 | && idx == *active_monitor_idx | 4956 | && idx == *active_monitor_idx |
| 4914 | && !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))); | 4957 | && !matches!(self.interactive_move, Some(InteractiveMoveState::Moving(_))); |
| 4958 | + | ||
| 4959 | + if ongoing_scrolling_dnd.is_some() && self.overview_open { | ||
| 4960 | + // Begin the scroll on new monitors and when opening the overview. | ||
| 4961 | + mon.dnd_scroll_gesture_begin(); | ||
| 4962 | + } else if !self.overview_open { | ||
| 4963 | + mon.dnd_scroll_gesture_end(); | ||
| 4964 | + } | ||
| 4965 | + | ||
| 4915 | for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() { | 4966 | for (ws_idx, ws) in mon.workspaces.iter_mut().enumerate() { |
| 4916 | ws.refresh(is_active); | 4967 | ws.refresh(is_active); |
| 4917 | 4968 | ||
src/layout/monitor.rsmodified+257 -31
| @@ -38,6 +38,11 @@ const WORKSPACE_GESTURE_RUBBER_BAND: RubberBand = RubberBand { | |||
| 38 | limit: 0.05, | 38 | limit: 0.05, |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| 41 | +/// Amount of DnD edge scrolling to scroll the height of one workspace. | ||
| 42 | +/// | ||
| 43 | +/// This constant is tied to the default dnd-edge-workspace-switch max-speed setting. | ||
| 44 | +const WORKSPACE_DND_EDGE_SCROLL_MOVEMENT: f64 = 1500.; | ||
| 45 | + | ||
| 41 | #[derive(Debug)] | 46 | #[derive(Debug)] |
| 42 | pub struct Monitor<W: LayoutElement> { | 47 | pub struct Monitor<W: LayoutElement> { |
| 43 | /// Output for this monitor. | 48 | /// Output for this monitor. |
| @@ -96,11 +101,23 @@ pub struct WorkspaceSwitchGesture { | |||
| 96 | start_idx: f64, | 101 | start_idx: f64, |
| 97 | /// Current, fractional workspace index. | 102 | /// Current, fractional workspace index. |
| 98 | pub(super) current_idx: f64, | 103 | pub(super) current_idx: f64, |
| 104 | + /// Animation for the extra offset to the current position. | ||
| 105 | + /// | ||
| 106 | + /// For example, if there's a workspace switch during a DnD scroll. | ||
| 107 | + animation: Option<Animation>, | ||
| 99 | tracker: SwipeTracker, | 108 | tracker: SwipeTracker, |
| 100 | /// Whether the gesture is controlled by the touchpad. | 109 | /// Whether the gesture is controlled by the touchpad. |
| 101 | is_touchpad: bool, | 110 | is_touchpad: bool, |
| 102 | /// Whether the gesture is clamped to +-1 workspace around the center. | 111 | /// Whether the gesture is clamped to +-1 workspace around the center. |
| 103 | is_clamped: bool, | 112 | is_clamped: bool, |
| 113 | + | ||
| 114 | + // If this gesture is for drag-and-drop scrolling, this is the last event's unadjusted | ||
| 115 | + // timestamp. | ||
| 116 | + dnd_last_event_time: Option<Duration>, | ||
| 117 | + // Time when the drag-and-drop scroll delta became non-zero, used for debouncing. | ||
| 118 | + // | ||
| 119 | + // If `None` then the scroll delta is currently zero. | ||
| 120 | + dnd_nonzero_start_time: Option<Duration>, | ||
| 104 | } | 121 | } |
| 105 | 122 | ||
| 106 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 123 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -161,7 +178,9 @@ impl WorkspaceSwitch { | |||
| 161 | pub fn current_idx(&self) -> f64 { | 178 | pub fn current_idx(&self) -> f64 { |
| 162 | match self { | 179 | match self { |
| 163 | WorkspaceSwitch::Animation(anim) => anim.value(), | 180 | WorkspaceSwitch::Animation(anim) => anim.value(), |
| 164 | - WorkspaceSwitch::Gesture(gesture) => gesture.current_idx, | 181 | + WorkspaceSwitch::Gesture(gesture) => { |
| 182 | + gesture.current_idx + gesture.animation.as_ref().map_or(0., |anim| anim.value()) | ||
| 183 | + } | ||
| 165 | } | 184 | } |
| 166 | } | 185 | } |
| 167 | 186 | ||
| @@ -187,12 +206,11 @@ impl WorkspaceSwitch { | |||
| 187 | } | 206 | } |
| 188 | } | 207 | } |
| 189 | 208 | ||
| 190 | - /// Returns `true` if the workspace switch is [`Animation`]. | 209 | + fn is_animation_ongoing(&self) -> bool { |
| 191 | - /// | 210 | + match self { |
| 192 | - /// [`Animation`]: WorkspaceSwitch::Animation | 211 | + WorkspaceSwitch::Animation(_) => true, |
| 193 | - #[must_use] | 212 | + WorkspaceSwitch::Gesture(gesture) => gesture.animation.is_some(), |
| 194 | - fn is_animation(&self) -> bool { | 213 | + } |
| 195 | - matches!(self, Self::Animation(..)) | ||
| 196 | } | 214 | } |
| 197 | } | 215 | } |
| 198 | 216 | ||
| @@ -206,6 +224,11 @@ impl WorkspaceSwitchGesture { | |||
| 206 | (0., (workspace_count - 1) as f64) | 224 | (0., (workspace_count - 1) as f64) |
| 207 | } | 225 | } |
| 208 | } | 226 | } |
| 227 | + | ||
| 228 | + fn animate_from(&mut self, from: f64, clock: Clock, config: niri_config::Animation) { | ||
| 229 | + let current = self.animation.as_ref().map_or(0., Animation::value); | ||
| 230 | + self.animation = Some(Animation::new(clock, from + current, 0., 0., config)); | ||
| 231 | + } | ||
| 209 | } | 232 | } |
| 210 | 233 | ||
| 211 | impl OverviewProgress { | 234 | impl OverviewProgress { |
| @@ -344,25 +367,47 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 344 | idx: usize, | 367 | idx: usize, |
| 345 | config: Option<niri_config::Animation>, | 368 | config: Option<niri_config::Animation>, |
| 346 | ) { | 369 | ) { |
| 347 | - if self.active_workspace_idx == idx { | ||
| 348 | - return; | ||
| 349 | - } | ||
| 350 | - | ||
| 351 | // FIXME: also compute and use current velocity. | 370 | // FIXME: also compute and use current velocity. |
| 352 | let current_idx = self.workspace_render_idx(); | 371 | let current_idx = self.workspace_render_idx(); |
| 353 | 372 | ||
| 354 | - self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id()); | 373 | + if self.active_workspace_idx != idx { |
| 374 | + self.previous_workspace_id = Some(self.workspaces[self.active_workspace_idx].id()); | ||
| 375 | + } | ||
| 355 | 376 | ||
| 377 | + let prev_active_idx = self.active_workspace_idx; | ||
| 356 | self.active_workspace_idx = idx; | 378 | self.active_workspace_idx = idx; |
| 357 | 379 | ||
| 358 | let config = config.unwrap_or(self.options.animations.workspace_switch.0); | 380 | let config = config.unwrap_or(self.options.animations.workspace_switch.0); |
| 359 | - self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( | 381 | + |
| 360 | - self.clock.clone(), | 382 | + match &mut self.workspace_switch { |
| 361 | - current_idx, | 383 | + // During a DnD scroll, we want to visually animate even if idx matches the active idx. |
| 362 | - idx as f64, | 384 | + Some(WorkspaceSwitch::Gesture(gesture)) if gesture.dnd_last_event_time.is_some() => { |
| 363 | - 0., | 385 | + gesture.center_idx = idx; |
| 364 | - config, | 386 | + |
| 365 | - ))); | 387 | + // Adjust start_idx to make current_idx point at idx. |
| 388 | + let current_pos = gesture.current_idx - gesture.start_idx; | ||
| 389 | + gesture.start_idx = idx as f64 - current_pos; | ||
| 390 | + let prev_current_idx = gesture.current_idx; | ||
| 391 | + gesture.current_idx = idx as f64; | ||
| 392 | + | ||
| 393 | + let current_idx_delta = gesture.current_idx - prev_current_idx; | ||
| 394 | + gesture.animate_from(-current_idx_delta, self.clock.clone(), config); | ||
| 395 | + } | ||
| 396 | + _ => { | ||
| 397 | + // Don't animate if nothing changed. | ||
| 398 | + if prev_active_idx == idx { | ||
| 399 | + return; | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( | ||
| 403 | + self.clock.clone(), | ||
| 404 | + current_idx, | ||
| 405 | + idx as f64, | ||
| 406 | + 0., | ||
| 407 | + config, | ||
| 408 | + ))); | ||
| 409 | + } | ||
| 410 | + } | ||
| 366 | } | 411 | } |
| 367 | 412 | ||
| 368 | pub fn add_window( | 413 | pub fn add_window( |
| @@ -725,14 +770,31 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 725 | } | 770 | } |
| 726 | 771 | ||
| 727 | pub fn switch_workspace_up(&mut self) { | 772 | pub fn switch_workspace_up(&mut self) { |
| 728 | - self.activate_workspace(self.active_workspace_idx.saturating_sub(1)); | 773 | + let new_idx = match &self.workspace_switch { |
| 774 | + // During a DnD scroll, select the prev apparent workspace. | ||
| 775 | + Some(WorkspaceSwitch::Gesture(gesture)) if gesture.dnd_last_event_time.is_some() => { | ||
| 776 | + let current = gesture.current_idx; | ||
| 777 | + let new = current.ceil() - 1.; | ||
| 778 | + new.clamp(0., (self.workspaces.len() - 1) as f64) as usize | ||
| 779 | + } | ||
| 780 | + _ => self.active_workspace_idx.saturating_sub(1), | ||
| 781 | + }; | ||
| 782 | + | ||
| 783 | + self.activate_workspace(new_idx); | ||
| 729 | } | 784 | } |
| 730 | 785 | ||
| 731 | pub fn switch_workspace_down(&mut self) { | 786 | pub fn switch_workspace_down(&mut self) { |
| 732 | - self.activate_workspace(min( | 787 | + let new_idx = match &self.workspace_switch { |
| 733 | - self.active_workspace_idx + 1, | 788 | + // During a DnD scroll, select the next apparent workspace. |
| 734 | - self.workspaces.len() - 1, | 789 | + Some(WorkspaceSwitch::Gesture(gesture)) if gesture.dnd_last_event_time.is_some() => { |
| 735 | - )); | 790 | + let current = gesture.current_idx; |
| 791 | + let new = current.floor() + 1.; | ||
| 792 | + new.clamp(0., (self.workspaces.len() - 1) as f64) as usize | ||
| 793 | + } | ||
| 794 | + _ => min(self.active_workspace_idx + 1, self.workspaces.len() - 1), | ||
| 795 | + }; | ||
| 796 | + | ||
| 797 | + self.activate_workspace(new_idx); | ||
| 736 | } | 798 | } |
| 737 | 799 | ||
| 738 | fn previous_workspace_idx(&self) -> Option<usize> { | 800 | fn previous_workspace_idx(&self) -> Option<usize> { |
| @@ -767,11 +829,38 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 767 | } | 829 | } |
| 768 | 830 | ||
| 769 | pub fn advance_animations(&mut self) { | 831 | pub fn advance_animations(&mut self) { |
| 770 | - if let Some(WorkspaceSwitch::Animation(anim)) = &mut self.workspace_switch { | 832 | + match &mut self.workspace_switch { |
| 771 | - if anim.is_done() { | 833 | + Some(WorkspaceSwitch::Animation(anim)) => { |
| 772 | - self.workspace_switch = None; | 834 | + if anim.is_done() { |
| 773 | - self.clean_up_workspaces(); | 835 | + self.workspace_switch = None; |
| 836 | + self.clean_up_workspaces(); | ||
| 837 | + } | ||
| 774 | } | 838 | } |
| 839 | + Some(WorkspaceSwitch::Gesture(gesture)) => { | ||
| 840 | + // Make sure the last event time doesn't go too much out of date (for | ||
| 841 | + // monitors not under cursor), causing sudden jumps. | ||
| 842 | + // | ||
| 843 | + // This happens after any dnd_scroll_gesture_scroll() calls (in | ||
| 844 | + // Layout::advance_animations()), so it doesn't mess up the time delta there. | ||
| 845 | + if let Some(last_time) = &mut gesture.dnd_last_event_time { | ||
| 846 | + let now = self.clock.now_unadjusted(); | ||
| 847 | + if *last_time != now { | ||
| 848 | + *last_time = now; | ||
| 849 | + | ||
| 850 | + // If last_time was already == now, then dnd_scroll_gesture_scroll() must've | ||
| 851 | + // updated the gesture already. Therefore, when this code runs, the pointer | ||
| 852 | + // must be outside the DnD scrolling zone. | ||
| 853 | + gesture.dnd_nonzero_start_time = None; | ||
| 854 | + } | ||
| 855 | + } | ||
| 856 | + | ||
| 857 | + if let Some(anim) = &mut gesture.animation { | ||
| 858 | + if anim.is_done() { | ||
| 859 | + gesture.animation = None; | ||
| 860 | + } | ||
| 861 | + } | ||
| 862 | + } | ||
| 863 | + None => (), | ||
| 775 | } | 864 | } |
| 776 | 865 | ||
| 777 | for ws in &mut self.workspaces { | 866 | for ws in &mut self.workspaces { |
| @@ -782,7 +871,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 782 | pub(super) fn are_animations_ongoing(&self) -> bool { | 871 | pub(super) fn are_animations_ongoing(&self) -> bool { |
| 783 | self.workspace_switch | 872 | self.workspace_switch |
| 784 | .as_ref() | 873 | .as_ref() |
| 785 | - .is_some_and(|s| s.is_animation()) | 874 | + .is_some_and(|s| s.is_animation_ongoing()) |
| 786 | || self.workspaces.iter().any(|ws| ws.are_animations_ongoing()) | 875 | || self.workspaces.iter().any(|ws| ws.are_animations_ongoing()) |
| 787 | } | 876 | } |
| 788 | 877 | ||
| @@ -1330,9 +1419,44 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1330 | center_idx, | 1419 | center_idx, |
| 1331 | start_idx: current_idx, | 1420 | start_idx: current_idx, |
| 1332 | current_idx, | 1421 | current_idx, |
| 1422 | + animation: None, | ||
| 1333 | tracker: SwipeTracker::new(), | 1423 | tracker: SwipeTracker::new(), |
| 1334 | is_touchpad, | 1424 | is_touchpad, |
| 1335 | is_clamped: !self.overview_open, | 1425 | is_clamped: !self.overview_open, |
| 1426 | + dnd_last_event_time: None, | ||
| 1427 | + dnd_nonzero_start_time: None, | ||
| 1428 | + }; | ||
| 1429 | + self.workspace_switch = Some(WorkspaceSwitch::Gesture(gesture)); | ||
| 1430 | + } | ||
| 1431 | + | ||
| 1432 | + pub fn dnd_scroll_gesture_begin(&mut self) { | ||
| 1433 | + if let Some(WorkspaceSwitch::Gesture(WorkspaceSwitchGesture { | ||
| 1434 | + dnd_last_event_time: Some(_), | ||
| 1435 | + .. | ||
| 1436 | + })) = &self.workspace_switch | ||
| 1437 | + { | ||
| 1438 | + // Already active. | ||
| 1439 | + return; | ||
| 1440 | + } | ||
| 1441 | + | ||
| 1442 | + if !self.overview_open { | ||
| 1443 | + // This gesture is only for the overview. | ||
| 1444 | + return; | ||
| 1445 | + } | ||
| 1446 | + | ||
| 1447 | + let center_idx = self.active_workspace_idx; | ||
| 1448 | + let current_idx = self.workspace_render_idx(); | ||
| 1449 | + | ||
| 1450 | + let gesture = WorkspaceSwitchGesture { | ||
| 1451 | + center_idx, | ||
| 1452 | + start_idx: current_idx, | ||
| 1453 | + current_idx, | ||
| 1454 | + animation: None, | ||
| 1455 | + tracker: SwipeTracker::new(), | ||
| 1456 | + is_touchpad: false, | ||
| 1457 | + is_clamped: false, | ||
| 1458 | + dnd_last_event_time: Some(self.clock.now_unadjusted()), | ||
| 1459 | + dnd_nonzero_start_time: None, | ||
| 1336 | }; | 1460 | }; |
| 1337 | self.workspace_switch = Some(WorkspaceSwitch::Gesture(gesture)); | 1461 | self.workspace_switch = Some(WorkspaceSwitch::Gesture(gesture)); |
| 1338 | } | 1462 | } |
| @@ -1347,7 +1471,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1347 | return None; | 1471 | return None; |
| 1348 | }; | 1472 | }; |
| 1349 | 1473 | ||
| 1350 | - if gesture.is_touchpad != is_touchpad { | 1474 | + if gesture.is_touchpad != is_touchpad || gesture.dnd_last_event_time.is_some() { |
| 1351 | return None; | 1475 | return None; |
| 1352 | } | 1476 | } |
| 1353 | 1477 | ||
| @@ -1389,6 +1513,91 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1389 | Some(true) | 1513 | Some(true) |
| 1390 | } | 1514 | } |
| 1391 | 1515 | ||
| 1516 | + pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>, speed: f64) -> bool { | ||
| 1517 | + let zoom = self.overview_zoom(); | ||
| 1518 | + | ||
| 1519 | + let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | ||
| 1520 | + return false; | ||
| 1521 | + }; | ||
| 1522 | + | ||
| 1523 | + let Some(last_time) = gesture.dnd_last_event_time else { | ||
| 1524 | + // Not a DnD scroll. | ||
| 1525 | + return false; | ||
| 1526 | + }; | ||
| 1527 | + | ||
| 1528 | + let config = &self.options.gestures.dnd_edge_workspace_switch; | ||
| 1529 | + let trigger_height = config.trigger_height.0; | ||
| 1530 | + | ||
| 1531 | + // Restrict the scrolling horizontally to the strip of workspaces to avoid unwanted trigger | ||
| 1532 | + // after using the hot corner or during horizontal scroll. | ||
| 1533 | + let width = self.view_size.w * zoom; | ||
| 1534 | + let x = pos.x - (self.view_size.w - width) / 2.; | ||
| 1535 | + | ||
| 1536 | + // Consider the working area so layer-shell docks and such don't prevent scrolling. | ||
| 1537 | + let y = pos.y - self.working_area.loc.y; | ||
| 1538 | + let height = self.working_area.size.h; | ||
| 1539 | + | ||
| 1540 | + let y = y.clamp(0., height); | ||
| 1541 | + let trigger_height = trigger_height.clamp(0., height / 2.); | ||
| 1542 | + | ||
| 1543 | + let delta = if x < 0. || width <= x { | ||
| 1544 | + // Outside the bounds horizontally. | ||
| 1545 | + 0. | ||
| 1546 | + } else if y < trigger_height { | ||
| 1547 | + -(trigger_height - y) | ||
| 1548 | + } else if height - y < trigger_height { | ||
| 1549 | + trigger_height - (height - y) | ||
| 1550 | + } else { | ||
| 1551 | + 0. | ||
| 1552 | + }; | ||
| 1553 | + | ||
| 1554 | + let delta = if trigger_height < 0.01 { | ||
| 1555 | + // Sanity check for trigger-height 0 or small window sizes. | ||
| 1556 | + 0. | ||
| 1557 | + } else { | ||
| 1558 | + // Normalize to [0, 1]. | ||
| 1559 | + delta / trigger_height | ||
| 1560 | + }; | ||
| 1561 | + let delta = delta * speed; | ||
| 1562 | + | ||
| 1563 | + let now = self.clock.now_unadjusted(); | ||
| 1564 | + gesture.dnd_last_event_time = Some(now); | ||
| 1565 | + | ||
| 1566 | + if delta == 0. { | ||
| 1567 | + // We're outside the scrolling zone. | ||
| 1568 | + gesture.dnd_nonzero_start_time = None; | ||
| 1569 | + return false; | ||
| 1570 | + } | ||
| 1571 | + | ||
| 1572 | + let nonzero_start = *gesture.dnd_nonzero_start_time.get_or_insert(now); | ||
| 1573 | + | ||
| 1574 | + // Delay starting the gesture a bit to avoid unwanted movement when dragging across | ||
| 1575 | + // monitors. | ||
| 1576 | + let delay = Duration::from_millis(u64::from(config.delay_ms)); | ||
| 1577 | + if now.saturating_sub(nonzero_start) < delay { | ||
| 1578 | + return true; | ||
| 1579 | + } | ||
| 1580 | + | ||
| 1581 | + let time_delta = now.saturating_sub(last_time).as_secs_f64(); | ||
| 1582 | + | ||
| 1583 | + let delta = delta * time_delta * config.max_speed.0; | ||
| 1584 | + | ||
| 1585 | + gesture.tracker.push(delta, now); | ||
| 1586 | + | ||
| 1587 | + let total_height = WORKSPACE_DND_EDGE_SCROLL_MOVEMENT; | ||
| 1588 | + let pos = gesture.tracker.pos() / total_height; | ||
| 1589 | + let unclamped = gesture.start_idx + pos; | ||
| 1590 | + | ||
| 1591 | + let (min, max) = gesture.min_max(self.workspaces.len()); | ||
| 1592 | + let clamped = unclamped.clamp(min, max); | ||
| 1593 | + | ||
| 1594 | + // Make sure that DnD scrolling too much outside the min/max does not "build up". | ||
| 1595 | + gesture.start_idx += clamped - unclamped; | ||
| 1596 | + gesture.current_idx = clamped; | ||
| 1597 | + | ||
| 1598 | + true | ||
| 1599 | + } | ||
| 1600 | + | ||
| 1392 | pub fn workspace_switch_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { | 1601 | pub fn workspace_switch_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { |
| 1393 | let Some(WorkspaceSwitch::Gesture(gesture)) = &self.workspace_switch else { | 1602 | let Some(WorkspaceSwitch::Gesture(gesture)) = &self.workspace_switch else { |
| 1394 | return false; | 1603 | return false; |
| @@ -1399,7 +1608,9 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1399 | } | 1608 | } |
| 1400 | 1609 | ||
| 1401 | let zoom = self.overview_zoom(); | 1610 | let zoom = self.overview_zoom(); |
| 1402 | - let total_height = if gesture.is_touchpad { | 1611 | + let total_height = if gesture.dnd_last_event_time.is_some() { |
| 1612 | + WORKSPACE_DND_EDGE_SCROLL_MOVEMENT | ||
| 1613 | + } else if gesture.is_touchpad { | ||
| 1403 | WORKSPACE_GESTURE_MOVEMENT | 1614 | WORKSPACE_GESTURE_MOVEMENT |
| 1404 | } else { | 1615 | } else { |
| 1405 | self.workspace_size_with_gap(1.).h | 1616 | self.workspace_size_with_gap(1.).h |
| @@ -1442,6 +1653,21 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1442 | true | 1653 | true |
| 1443 | } | 1654 | } |
| 1444 | 1655 | ||
| 1656 | + pub fn dnd_scroll_gesture_end(&mut self) { | ||
| 1657 | + if !matches!( | ||
| 1658 | + self.workspace_switch, | ||
| 1659 | + Some(WorkspaceSwitch::Gesture(WorkspaceSwitchGesture { | ||
| 1660 | + dnd_last_event_time: Some(_), | ||
| 1661 | + .. | ||
| 1662 | + })) | ||
| 1663 | + ) { | ||
| 1664 | + // Not a DnD scroll. | ||
| 1665 | + return; | ||
| 1666 | + }; | ||
| 1667 | + | ||
| 1668 | + self.workspace_switch_gesture_end(None); | ||
| 1669 | + } | ||
| 1670 | + | ||
| 1445 | pub fn scale(&self) -> smithay::output::Scale { | 1671 | pub fn scale(&self) -> smithay::output::Scale { |
| 1446 | self.scale | 1672 | self.scale |
| 1447 | } | 1673 | } |