forge
Explore
Log in

Don't you dare go Hollow

layout/scrolling: Support view offset anim during gesture

Browse files at this commit

ce3103949fe07bb656970da30c87accde83852faIvan MolodetskikhParent: ef60dd8
Brings back moving the newly active window into focus upon interactive
move dragging out.
src/layout/scrolling.rsmodified+58 -20
@@ -113,6 +113,10 @@ pub(super) enum ViewOffset {
113 #[derive(Debug)]113 #[derive(Debug)]
114 pub(super) struct ViewGesture {114 pub(super) struct ViewGesture {
115 current_view_offset: f64,115 current_view_offset: f64,
116+ /// Animation for the extra offset to the current position.
117+ ///
118+ /// For example, when we need to activate a specific window during a DnD scroll.
119+ animation: Option<Animation>,
116 tracker: SwipeTracker,120 tracker: SwipeTracker,
117 delta_from_tracker: f64,121 delta_from_tracker: f64,
118 // The view offset we'll use if needed for activate_prev_column_on_removal.122 // The view offset we'll use if needed for activate_prev_column_on_removal.
@@ -321,6 +325,12 @@ impl<W: LayoutElement> ScrollingSpace<W> {
321 gesture.dnd_nonzero_start_time = None;325 gesture.dnd_nonzero_start_time = None;
322 }326 }
323 }327 }
328+
329+ if let Some(anim) = &mut gesture.animation {
330+ if anim.is_done() {
331+ gesture.animation = None;
332+ }
333+ }
324 }334 }
325 335
326 for col in &mut self.columns {336 for col in &mut self.columns {
@@ -334,7 +344,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
334 }344 }
335 345
336 pub fn are_animations_ongoing(&self) -> bool {346 pub fn are_animations_ongoing(&self) -> bool {
337- self.view_offset.is_animation()347+ self.view_offset.is_animation_ongoing()
338 || self.columns.iter().any(Column::are_animations_ongoing)348 || self.columns.iter().any(Column::are_animations_ongoing)
339 || !self.closing_windows.is_empty()349 || !self.closing_windows.is_empty()
340 }350 }
@@ -626,8 +636,6 @@ impl<W: LayoutElement> ScrollingSpace<W> {
626 new_view_offset: f64,636 new_view_offset: f64,
627 config: niri_config::Animation,637 config: niri_config::Animation,
628 ) {638 ) {
629- self.view_offset.cancel_gesture();
630-
631 let new_col_x = self.column_x(idx);639 let new_col_x = self.column_x(idx);
632 let old_col_x = self.column_x(self.active_column_idx);640 let old_col_x = self.column_x(self.active_column_idx);
633 let offset_delta = old_col_x - new_col_x;641 let offset_delta = old_col_x - new_col_x;
@@ -644,14 +652,28 @@ impl<W: LayoutElement> ScrollingSpace<W> {
644 return;652 return;
645 }653 }
646 654
647- // FIXME: also compute and use current velocity.655+ match &mut self.view_offset {
648- self.view_offset = ViewOffset::Animation(Animation::new(656+ ViewOffset::Gesture(gesture) if gesture.dnd_last_event_time.is_some() => {
649- self.clock.clone(),657+ gesture.stationary_view_offset = new_view_offset;
650- self.view_offset.current(),658+
651- new_view_offset,659+ let current_pos = gesture.current_view_offset - gesture.delta_from_tracker;
652- 0.,660+ gesture.delta_from_tracker = new_view_offset - current_pos;
653- config,661+ let offset_delta = new_view_offset - gesture.current_view_offset;
654- ));662+ gesture.current_view_offset = new_view_offset;
663+
664+ gesture.animate_from(-offset_delta, self.clock.clone(), config);
665+ }
666+ _ => {
667+ // FIXME: also compute and use current velocity.
668+ self.view_offset = ViewOffset::Animation(Animation::new(
669+ self.clock.clone(),
670+ self.view_offset.current(),
671+ new_view_offset,
672+ 0.,
673+ config,
674+ ));
675+ }
676+ }
655 }677 }
656 678
657 fn animate_view_offset_to_column_centered(679 fn animate_view_offset_to_column_centered(
@@ -1563,7 +1585,6 @@ impl<W: LayoutElement> ScrollingSpace<W> {
1563 1585
1564 // Preserve the camera position when moving to the left.1586 // Preserve the camera position when moving to the left.
1565 let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x;1587 let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x;
1566- self.view_offset.cancel_gesture();
1567 self.view_offset.offset(view_offset_delta);1588 self.view_offset.offset(view_offset_delta);
1568 1589
1569 // The column we just moved is offset by the difference between its new and old position.1590 // The column we just moved is offset by the difference between its new and old position.
@@ -2784,6 +2805,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2784 2805
2785 let gesture = ViewGesture {2806 let gesture = ViewGesture {
2786 current_view_offset: self.view_offset.current(),2807 current_view_offset: self.view_offset.current(),
2808+ animation: None,
2787 tracker: SwipeTracker::new(),2809 tracker: SwipeTracker::new(),
2788 delta_from_tracker: self.view_offset.current(),2810 delta_from_tracker: self.view_offset.current(),
2789 stationary_view_offset: self.view_offset.stationary(),2811 stationary_view_offset: self.view_offset.stationary(),
@@ -2806,6 +2828,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2806 2828
2807 let gesture = ViewGesture {2829 let gesture = ViewGesture {
2808 current_view_offset: self.view_offset.current(),2830 current_view_offset: self.view_offset.current(),
2831+ animation: None,
2809 tracker: SwipeTracker::new(),2832 tracker: SwipeTracker::new(),
2810 delta_from_tracker: self.view_offset.current(),2833 delta_from_tracker: self.view_offset.current(),
2811 stationary_view_offset: self.view_offset.stationary(),2834 stationary_view_offset: self.view_offset.stationary(),
@@ -3500,7 +3523,10 @@ impl ViewOffset {
3500 match self {3523 match self {
3501 ViewOffset::Static(offset) => *offset,3524 ViewOffset::Static(offset) => *offset,
3502 ViewOffset::Animation(anim) => anim.value(),3525 ViewOffset::Animation(anim) => anim.value(),
3503- ViewOffset::Gesture(gesture) => gesture.current_view_offset,3526+ ViewOffset::Gesture(gesture) => {
3527+ gesture.current_view_offset
3528+ + gesture.animation.as_ref().map_or(0., |anim| anim.value())
3529+ }
3504 }3530 }
3505 }3531 }
3506 3532
@@ -3530,21 +3556,26 @@ impl ViewOffset {
3530 matches!(self, Self::Static(_))3556 matches!(self, Self::Static(_))
3531 }3557 }
3532 3558
3533- pub fn is_animation(&self) -> bool {
3534- matches!(self, Self::Animation(_))
3535- }
3536-
3537 pub fn is_gesture(&self) -> bool {3559 pub fn is_gesture(&self) -> bool {
3538 matches!(self, Self::Gesture(_))3560 matches!(self, Self::Gesture(_))
3539 }3561 }
3540 3562
3563+ pub fn is_animation_ongoing(&self) -> bool {
3564+ match self {
3565+ ViewOffset::Static(_) => false,
3566+ ViewOffset::Animation(_) => true,
3567+ ViewOffset::Gesture(gesture) => gesture.animation.is_some(),
3568+ }
3569+ }
3570+
3541 pub fn offset(&mut self, delta: f64) {3571 pub fn offset(&mut self, delta: f64) {
3542 match self {3572 match self {
3543 ViewOffset::Static(offset) => *offset += delta,3573 ViewOffset::Static(offset) => *offset += delta,
3544 ViewOffset::Animation(anim) => anim.offset(delta),3574 ViewOffset::Animation(anim) => anim.offset(delta),
3545- ViewOffset::Gesture(_gesture) => {3575+ ViewOffset::Gesture(gesture) => {
3546- // Is this needed?3576+ gesture.stationary_view_offset += delta;
3547- error!("cancel gesture before offsetting");3577+ gesture.delta_from_tracker += delta;
3578+ gesture.current_view_offset += delta;
3548 }3579 }
3549 }3580 }
3550 }3581 }
@@ -3560,6 +3591,13 @@ impl ViewOffset {
3560 }3591 }
3561 }3592 }
3562 3593
3594+impl ViewGesture {
3595+ fn animate_from(&mut self, from: f64, clock: Clock, config: niri_config::Animation) {
3596+ let current = self.animation.as_ref().map_or(0., Animation::value);
3597+ self.animation = Some(Animation::new(clock, from + current, 0., 0., config));
3598+ }
3599+}
3600+
3563 impl ColumnData {3601 impl ColumnData {
3564 pub fn new<W: LayoutElement>(column: &Column<W>) -> Self {3602 pub fn new<W: LayoutElement>(column: &Column<W>) -> Self {
3565 let mut rv = Self { width: 0. };3603 let mut rv = Self { width: 0. };