forge
Explore
Log in

Don't you dare go Hollow

Implement DnD hold to activate window or workspace

Browse files at this commit

fae3a276418ef1f6f6baad465f160e33a6ac9d8aIvan MolodetskikhParent: 31e76cf
src/layout/mod.rsmodified+96 -4
@@ -298,7 +298,7 @@ pub struct Layout<W: LayoutElement> {
298 /// Ongoing interactive move.298 /// Ongoing interactive move.
299 interactive_move: Option<InteractiveMoveState<W>>,299 interactive_move: Option<InteractiveMoveState<W>>,
300 /// Ongoing drag-and-drop operation.300 /// Ongoing drag-and-drop operation.
301- dnd: Option<DndData>,301+ dnd: Option<DndData<W>>,
302 /// Clock for driving animations.302 /// Clock for driving animations.
303 clock: Clock,303 clock: Clock,
304 /// Time that we last updated render elements for.304 /// Time that we last updated render elements for.
@@ -433,11 +433,26 @@ struct InteractiveMoveData<W: LayoutElement> {
433 }433 }
434 434
435 #[derive(Debug)]435 #[derive(Debug)]
436-pub struct DndData {436+pub struct DndData<W: LayoutElement> {
437 /// Output where the pointer is currently located.437 /// Output where the pointer is currently located.
438 output: Output,438 output: Output,
439 /// Current pointer position within output.439 /// Current pointer position within output.
440 pointer_pos_within_output: Point<f64, Logical>,440 pointer_pos_within_output: Point<f64, Logical>,
441+ /// Ongoing DnD hold to activate something.
442+ hold: Option<DndHold<W>>,
443+}
444+
445+#[derive(Debug)]
446+struct DndHold<W: LayoutElement> {
447+ /// Time when we started holding on the target.
448+ start_time: Duration,
449+ target: DndHoldTarget<W::Id>,
450+}
451+
452+#[derive(Debug, PartialEq, Eq)]
453+enum DndHoldTarget<WindowId> {
454+ Window(WindowId),
455+ Workspace(WorkspaceId),
441 }456 }
442 457
443 #[derive(Debug, Clone, Copy)]458 #[derive(Debug, Clone, Copy)]
@@ -2755,8 +2770,10 @@ impl<W: LayoutElement> Layout<W> {
2755 let _span = tracy_client::span!("Layout::advance_animations");2770 let _span = tracy_client::span!("Layout::advance_animations");
2756 2771
2757 let mut dnd_scroll = None;2772 let mut dnd_scroll = None;
2773+ let mut is_dnd = false;
2758 if let Some(dnd) = &self.dnd {2774 if let Some(dnd) = &self.dnd {
2759 dnd_scroll = Some((dnd.output.clone(), dnd.pointer_pos_within_output, true));2775 dnd_scroll = Some((dnd.output.clone(), dnd.pointer_pos_within_output, true));
2776+ is_dnd = true;
2760 }2777 }
2761 2778
2762 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {2779 if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
@@ -2771,11 +2788,15 @@ impl<W: LayoutElement> Layout<W> {
2771 }2788 }
2772 }2789 }
2773 2790
2791+ let is_overview_open = self.overview_open;
2792+
2774 // Scroll the view if needed.2793 // Scroll the view if needed.
2775 if let Some((output, pos_within_output, is_scrolling)) = dnd_scroll {2794 if let Some((output, pos_within_output, is_scrolling)) = dnd_scroll {
2776 if let Some(mon) = self.monitor_for_output_mut(&output) {2795 if let Some(mon) = self.monitor_for_output_mut(&output) {
2796+ let mut scrolled = false;
2797+
2777 let zoom = mon.overview_zoom();2798 let zoom = mon.overview_zoom();
2778- mon.dnd_scroll_gesture_scroll(pos_within_output, 1. / zoom);2799+ scrolled |= mon.dnd_scroll_gesture_scroll(pos_within_output, 1. / zoom);
2779 2800
2780 if is_scrolling {2801 if is_scrolling {
2781 if let Some((ws, geo)) = mon.workspace_under(pos_within_output) {2802 if let Some((ws, geo)) = mon.workspace_under(pos_within_output) {
@@ -2788,7 +2809,77 @@ impl<W: LayoutElement> Layout<W> {
2788 // As far as the DnD scroll gesture is concerned, the workspace spans across2809 // As far as the DnD scroll gesture is concerned, the workspace spans across
2789 // the whole monitor horizontally.2810 // the whole monitor horizontally.
2790 let ws_pos = Point::from((0., geo.loc.y));2811 let ws_pos = Point::from((0., geo.loc.y));
2791- ws.dnd_scroll_gesture_scroll(pos_within_output - ws_pos, 1. / zoom);2812+ scrolled |=
2813+ ws.dnd_scroll_gesture_scroll(pos_within_output - ws_pos, 1. / zoom);
2814+ }
2815+ }
2816+
2817+ if scrolled {
2818+ // Don't trigger DnD hold while scrolling.
2819+ if let Some(dnd) = &mut self.dnd {
2820+ dnd.hold = None;
2821+ }
2822+ } else if is_dnd {
2823+ let target = mon
2824+ .window_under(pos_within_output)
2825+ .map(|(win, _)| DndHoldTarget::Window(win.id().clone()))
2826+ .or_else(|| {
2827+ mon.workspace_under_narrow(pos_within_output)
2828+ .map(|ws| DndHoldTarget::Workspace(ws.id()))
2829+ });
2830+
2831+ let dnd = self.dnd.as_mut().unwrap();
2832+ if let Some(target) = target {
2833+ let now = self.clock.now_unadjusted();
2834+ let start_time = if let Some(hold) = &mut dnd.hold {
2835+ if hold.target != target {
2836+ hold.start_time = now;
2837+ }
2838+ hold.target = target;
2839+ hold.start_time
2840+ } else {
2841+ let hold = dnd.hold.insert(DndHold {
2842+ start_time: now,
2843+ target,
2844+ });
2845+ hold.start_time
2846+ };
2847+
2848+ // Delay copied from gnome-shell.
2849+ let delay = Duration::from_millis(750);
2850+ if delay <= now.saturating_sub(start_time) {
2851+ let hold = dnd.hold.take().unwrap();
2852+
2853+ // Synchronize workspace switch to overview close to get a monotonic
2854+ // animation.
2855+ let config = is_overview_open
2856+ .then_some(self.options.animations.overview_open_close.0);
2857+
2858+ let mon = self.monitor_for_output_mut(&output).unwrap();
2859+
2860+ let ws_idx = match hold.target {
2861+ DndHoldTarget::Window(id) => mon
2862+ .workspaces
2863+ .iter_mut()
2864+ .position(|ws| ws.activate_window(&id))
2865+ .unwrap(),
2866+ DndHoldTarget::Workspace(id) => {
2867+ mon.workspaces.iter().position(|ws| ws.id() == id).unwrap()
2868+ }
2869+ };
2870+
2871+ mon.dnd_scroll_gesture_end();
2872+ mon.activate_workspace_with_anim_config(ws_idx, config);
2873+
2874+ self.focus_output(&output);
2875+
2876+ if is_overview_open {
2877+ self.close_overview();
2878+ }
2879+ }
2880+ } else {
2881+ // No target, reset the hold timer.
2882+ dnd.hold = None;
2792 }2883 }
2793 }2884 }
2794 }2885 }
@@ -4459,6 +4550,7 @@ impl<W: LayoutElement> Layout<W> {
4459 self.dnd = Some(DndData {4550 self.dnd = Some(DndData {
4460 output,4551 output,
4461 pointer_pos_within_output,4552 pointer_pos_within_output,
4553+ hold: None,
4462 });4554 });
4463 4555
4464 if begin_gesture {4556 if begin_gesture {
src/layout/scrolling.rsmodified+26 -11
@@ -588,6 +588,11 @@ impl<W: LayoutElement> ScrollingSpace<W> {
588 return self.compute_new_view_offset_for_column_fit(target_x, idx);588 return self.compute_new_view_offset_for_column_fit(target_x, idx);
589 };589 };
590 590
591+ // Activating the same column.
592+ if prev_idx == idx {
593+ return self.compute_new_view_offset_for_column_fit(target_x, idx);
594+ }
595+
591 // Always take the left or right neighbor of the target as the source.596 // Always take the left or right neighbor of the target as the source.
592 let source_idx = if prev_idx > idx {597 let source_idx = if prev_idx > idx {
593 min(idx + 1, self.columns.len() - 1)598 min(idx + 1, self.columns.len() - 1)
@@ -719,7 +724,10 @@ impl<W: LayoutElement> ScrollingSpace<W> {
719 }724 }
720 725
721 fn activate_column_with_anim_config(&mut self, idx: usize, config: niri_config::Animation) {726 fn activate_column_with_anim_config(&mut self, idx: usize, config: niri_config::Animation) {
722- if self.active_column_idx == idx {727+ if self.active_column_idx == idx
728+ // During a DnD scroll, animate even when activating the same window, for DnD hold.
729+ && (self.columns.is_empty() || !self.view_offset.is_dnd_scroll())
730+ {
723 return;731 return;
724 }732 }
725 733
@@ -730,12 +738,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
730 config,738 config,
731 );739 );
732 740
733- self.active_column_idx = idx;741+ if self.active_column_idx != idx {
742+ self.active_column_idx = idx;
734 743
735- // A different column was activated; reset the flag.744+ // A different column was activated; reset the flag.
736- self.activate_prev_column_on_removal = None;745+ self.activate_prev_column_on_removal = None;
737- self.view_offset_before_fullscreen = None;746+ self.view_offset_before_fullscreen = None;
738- self.interactive_resize = None;747+ self.interactive_resize = None;
748+ }
739 }749 }
740 750
741 pub(super) fn insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition {751 pub(super) fn insert_position(&self, pos: Point<f64, Logical>) -> InsertPosition {
@@ -2869,14 +2879,14 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2869 Some(true)2879 Some(true)
2870 }2880 }
2871 2881
2872- pub fn dnd_scroll_gesture_scroll(&mut self, delta: f64) {2882+ pub fn dnd_scroll_gesture_scroll(&mut self, delta: f64) -> bool {
2873 let ViewOffset::Gesture(gesture) = &mut self.view_offset else {2883 let ViewOffset::Gesture(gesture) = &mut self.view_offset else {
2874- return;2884+ return false;
2875 };2885 };
2876 2886
2877 let Some(last_time) = gesture.dnd_last_event_time else {2887 let Some(last_time) = gesture.dnd_last_event_time else {
2878 // Not a DnD scroll.2888 // Not a DnD scroll.
2879- return;2889+ return false;
2880 };2890 };
2881 2891
2882 let config = &self.options.gestures.dnd_edge_view_scroll;2892 let config = &self.options.gestures.dnd_edge_view_scroll;
@@ -2887,7 +2897,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2887 if delta == 0. {2897 if delta == 0. {
2888 // We're outside the scrolling zone.2898 // We're outside the scrolling zone.
2889 gesture.dnd_nonzero_start_time = None;2899 gesture.dnd_nonzero_start_time = None;
2890- return;2900+ return false;
2891 }2901 }
2892 2902
2893 let nonzero_start = *gesture.dnd_nonzero_start_time.get_or_insert(now);2903 let nonzero_start = *gesture.dnd_nonzero_start_time.get_or_insert(now);
@@ -2896,7 +2906,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2896 // monitors.2906 // monitors.
2897 let delay = Duration::from_millis(u64::from(config.delay_ms));2907 let delay = Duration::from_millis(u64::from(config.delay_ms));
2898 if now.saturating_sub(nonzero_start) < delay {2908 if now.saturating_sub(nonzero_start) < delay {
2899- return;2909+ return true;
2900 }2910 }
2901 2911
2902 let time_delta = now.saturating_sub(last_time).as_secs_f64();2912 let time_delta = now.saturating_sub(last_time).as_secs_f64();
@@ -2940,6 +2950,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2940 2950
2941 gesture.delta_from_tracker += clamped_offset - view_offset;2951 gesture.delta_from_tracker += clamped_offset - view_offset;
2942 gesture.current_view_offset = clamped_offset;2952 gesture.current_view_offset = clamped_offset;
2953+ true
2943 }2954 }
2944 2955
2945 pub fn view_offset_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool {2956 pub fn view_offset_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool {
@@ -3560,6 +3571,10 @@ impl ViewOffset {
3560 matches!(self, Self::Gesture(_))3571 matches!(self, Self::Gesture(_))
3561 }3572 }
3562 3573
3574+ pub fn is_dnd_scroll(&self) -> bool {
3575+ matches!(&self, ViewOffset::Gesture(gesture) if gesture.dnd_last_event_time.is_some())
3576+ }
3577+
3563 pub fn is_animation_ongoing(&self) -> bool {3578 pub fn is_animation_ongoing(&self) -> bool {
3564 match self {3579 match self {
3565 ViewOffset::Static(_) => false,3580 ViewOffset::Static(_) => false,
src/layout/workspace.rsmodified+2 -2
@@ -1678,7 +1678,7 @@ impl<W: LayoutElement> Workspace<W> {
1678 self.scrolling.dnd_scroll_gesture_begin();1678 self.scrolling.dnd_scroll_gesture_begin();
1679 }1679 }
1680 1680
1681- pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>, speed: f64) {1681+ pub fn dnd_scroll_gesture_scroll(&mut self, pos: Point<f64, Logical>, speed: f64) -> bool {
1682 let config = &self.options.gestures.dnd_edge_view_scroll;1682 let config = &self.options.gestures.dnd_edge_view_scroll;
1683 let trigger_width = config.trigger_width.0;1683 let trigger_width = config.trigger_width.0;
1684 1684
@@ -1706,7 +1706,7 @@ impl<W: LayoutElement> Workspace<W> {
1706 };1706 };
1707 let delta = delta * speed;1707 let delta = delta * speed;
1708 1708
1709- self.scrolling.dnd_scroll_gesture_scroll(delta);1709+ self.scrolling.dnd_scroll_gesture_scroll(delta)
1710 }1710 }
1711 1711
1712 pub fn dnd_scroll_gesture_end(&mut self) {1712 pub fn dnd_scroll_gesture_end(&mut self) {