Remove cancellation from swipe gestures
Browse files at this commit59a42249a4da4bda44fa08a2e6a460ac1bd2000fParent: 74b01627 changed files +20 -52
- src/input/mod.rs +2 -8
- src/input/spatial_movement_grab.rs +2 -4
- src/layout/mod.rs +8 -16
- src/layout/monitor.rs +1 -11
- src/layout/scrolling.rs +2 -2
- src/layout/tests.rs +3 -8
- src/layout/workspace.rs +2 -3
src/input/mod.rsmodified+2 -8
| @@ -2886,19 +2886,13 @@ impl State { | |||
| 2886 | self.niri.gesture_swipe_3f_cumulative = None; | 2886 | self.niri.gesture_swipe_3f_cumulative = None; |
| 2887 | 2887 | ||
| 2888 | let mut handled = false; | 2888 | let mut handled = false; |
| 2889 | - let res = self | 2889 | + let res = self.niri.layout.workspace_switch_gesture_end(Some(true)); |
| 2890 | - .niri | ||
| 2891 | - .layout | ||
| 2892 | - .workspace_switch_gesture_end(event.cancelled(), Some(true)); | ||
| 2893 | if let Some(output) = res { | 2890 | if let Some(output) = res { |
| 2894 | self.niri.queue_redraw(&output); | 2891 | self.niri.queue_redraw(&output); |
| 2895 | handled = true; | 2892 | handled = true; |
| 2896 | } | 2893 | } |
| 2897 | 2894 | ||
| 2898 | - let res = self | 2895 | + let res = self.niri.layout.view_offset_gesture_end(Some(true)); |
| 2899 | - .niri | ||
| 2900 | - .layout | ||
| 2901 | - .view_offset_gesture_end(event.cancelled(), Some(true)); | ||
| 2902 | if let Some(output) = res { | 2896 | if let Some(output) = res { |
| 2903 | self.niri.queue_redraw(&output); | 2897 | self.niri.queue_redraw(&output); |
| 2904 | handled = true; | 2898 | handled = true; |
src/input/spatial_movement_grab.rsmodified+2 -4
| @@ -40,10 +40,8 @@ impl SpatialMovementGrab { | |||
| 40 | let layout = &mut state.niri.layout; | 40 | let layout = &mut state.niri.layout; |
| 41 | let res = match self.gesture { | 41 | let res = match self.gesture { |
| 42 | GestureState::Recognizing => None, | 42 | GestureState::Recognizing => None, |
| 43 | - GestureState::ViewOffset => layout.view_offset_gesture_end(false, Some(false)), | 43 | + GestureState::ViewOffset => layout.view_offset_gesture_end(Some(false)), |
| 44 | - GestureState::WorkspaceSwitch => { | 44 | + GestureState::WorkspaceSwitch => layout.workspace_switch_gesture_end(Some(false)), |
| 45 | - layout.workspace_switch_gesture_end(false, Some(false)) | ||
| 46 | - } | ||
| 47 | }; | 45 | }; |
| 48 | 46 | ||
| 49 | if let Some(output) = res { | 47 | if let Some(output) = res { |
src/layout/mod.rsmodified+8 -16
| @@ -3534,7 +3534,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3534 | for monitor in monitors { | 3534 | for monitor in monitors { |
| 3535 | // Cancel the gesture on other outputs. | 3535 | // Cancel the gesture on other outputs. |
| 3536 | if &monitor.output != output { | 3536 | if &monitor.output != output { |
| 3537 | - monitor.workspace_switch_gesture_end(true, None); | 3537 | + monitor.workspace_switch_gesture_end(None); |
| 3538 | continue; | 3538 | continue; |
| 3539 | } | 3539 | } |
| 3540 | 3540 | ||
| @@ -3568,18 +3568,14 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3568 | None | 3568 | None |
| 3569 | } | 3569 | } |
| 3570 | 3570 | ||
| 3571 | - pub fn workspace_switch_gesture_end( | 3571 | + pub fn workspace_switch_gesture_end(&mut self, is_touchpad: Option<bool>) -> Option<Output> { |
| 3572 | - &mut self, | ||
| 3573 | - cancelled: bool, | ||
| 3574 | - is_touchpad: Option<bool>, | ||
| 3575 | - ) -> Option<Output> { | ||
| 3576 | let monitors = match &mut self.monitor_set { | 3572 | let monitors = match &mut self.monitor_set { |
| 3577 | MonitorSet::Normal { monitors, .. } => monitors, | 3573 | MonitorSet::Normal { monitors, .. } => monitors, |
| 3578 | MonitorSet::NoOutputs { .. } => return None, | 3574 | MonitorSet::NoOutputs { .. } => return None, |
| 3579 | }; | 3575 | }; |
| 3580 | 3576 | ||
| 3581 | for monitor in monitors { | 3577 | for monitor in monitors { |
| 3582 | - if monitor.workspace_switch_gesture_end(cancelled, is_touchpad) { | 3578 | + if monitor.workspace_switch_gesture_end(is_touchpad) { |
| 3583 | return Some(monitor.output.clone()); | 3579 | return Some(monitor.output.clone()); |
| 3584 | } | 3580 | } |
| 3585 | } | 3581 | } |
| @@ -3597,7 +3593,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3597 | for (idx, ws) in monitor.workspaces.iter_mut().enumerate() { | 3593 | for (idx, ws) in monitor.workspaces.iter_mut().enumerate() { |
| 3598 | // Cancel the gesture on other workspaces. | 3594 | // Cancel the gesture on other workspaces. |
| 3599 | if &monitor.output != output || idx != monitor.active_workspace_idx { | 3595 | if &monitor.output != output || idx != monitor.active_workspace_idx { |
| 3600 | - ws.view_offset_gesture_end(true, None); | 3596 | + ws.view_offset_gesture_end(None); |
| 3601 | continue; | 3597 | continue; |
| 3602 | } | 3598 | } |
| 3603 | 3599 | ||
| @@ -3634,11 +3630,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3634 | None | 3630 | None |
| 3635 | } | 3631 | } |
| 3636 | 3632 | ||
| 3637 | - pub fn view_offset_gesture_end( | 3633 | + pub fn view_offset_gesture_end(&mut self, is_touchpad: Option<bool>) -> Option<Output> { |
| 3638 | - &mut self, | ||
| 3639 | - cancelled: bool, | ||
| 3640 | - is_touchpad: Option<bool>, | ||
| 3641 | - ) -> Option<Output> { | ||
| 3642 | let monitors = match &mut self.monitor_set { | 3634 | let monitors = match &mut self.monitor_set { |
| 3643 | MonitorSet::Normal { monitors, .. } => monitors, | 3635 | MonitorSet::Normal { monitors, .. } => monitors, |
| 3644 | MonitorSet::NoOutputs { .. } => return None, | 3636 | MonitorSet::NoOutputs { .. } => return None, |
| @@ -3646,7 +3638,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3646 | 3638 | ||
| 3647 | for monitor in monitors { | 3639 | for monitor in monitors { |
| 3648 | for ws in &mut monitor.workspaces { | 3640 | for ws in &mut monitor.workspaces { |
| 3649 | - if ws.view_offset_gesture_end(cancelled, is_touchpad) { | 3641 | + if ws.view_offset_gesture_end(is_touchpad) { |
| 3650 | return Some(monitor.output.clone()); | 3642 | return Some(monitor.output.clone()); |
| 3651 | } | 3643 | } |
| 3652 | } | 3644 | } |
| @@ -4560,7 +4552,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4560 | } else { | 4552 | } else { |
| 4561 | // Cancel the view offset gesture after workspace switches, moves, etc. | 4553 | // Cancel the view offset gesture after workspace switches, moves, etc. |
| 4562 | if ws_idx != mon.active_workspace_idx { | 4554 | if ws_idx != mon.active_workspace_idx { |
| 4563 | - ws.view_offset_gesture_end(false, None); | 4555 | + ws.view_offset_gesture_end(None); |
| 4564 | } | 4556 | } |
| 4565 | } | 4557 | } |
| 4566 | } | 4558 | } |
| @@ -4569,7 +4561,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 4569 | MonitorSet::NoOutputs { workspaces, .. } => { | 4561 | MonitorSet::NoOutputs { workspaces, .. } => { |
| 4570 | for ws in workspaces { | 4562 | for ws in workspaces { |
| 4571 | ws.refresh(false); | 4563 | ws.refresh(false); |
| 4572 | - ws.view_offset_gesture_end(false, None); | 4564 | + ws.view_offset_gesture_end(None); |
| 4573 | } | 4565 | } |
| 4574 | } | 4566 | } |
| 4575 | } | 4567 | } |
src/layout/monitor.rsmodified+1 -11
| @@ -1026,11 +1026,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1026 | Some(true) | 1026 | Some(true) |
| 1027 | } | 1027 | } |
| 1028 | 1028 | ||
| 1029 | - pub fn workspace_switch_gesture_end( | 1029 | + pub fn workspace_switch_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { |
| 1030 | - &mut self, | ||
| 1031 | - cancelled: bool, | ||
| 1032 | - is_touchpad: Option<bool>, | ||
| 1033 | - ) -> bool { | ||
| 1034 | let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { | 1030 | let Some(WorkspaceSwitch::Gesture(gesture)) = &mut self.workspace_switch else { |
| 1035 | return false; | 1031 | return false; |
| 1036 | }; | 1032 | }; |
| @@ -1039,12 +1035,6 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1039 | return false; | 1035 | return false; |
| 1040 | } | 1036 | } |
| 1041 | 1037 | ||
| 1042 | - if cancelled { | ||
| 1043 | - self.workspace_switch = None; | ||
| 1044 | - self.clean_up_workspaces(); | ||
| 1045 | - return true; | ||
| 1046 | - } | ||
| 1047 | - | ||
| 1048 | // Take into account any idle time between the last event and now. | 1038 | // Take into account any idle time between the last event and now. |
| 1049 | let now = self.clock.now_unadjusted(); | 1039 | let now = self.clock.now_unadjusted(); |
| 1050 | gesture.tracker.push(0., now); | 1040 | gesture.tracker.push(0., now); |
src/layout/scrolling.rsmodified+2 -2
| @@ -2989,7 +2989,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 2989 | gesture.current_view_offset = clamped_offset; | 2989 | gesture.current_view_offset = clamped_offset; |
| 2990 | } | 2990 | } |
| 2991 | 2991 | ||
| 2992 | - pub fn view_offset_gesture_end(&mut self, _cancelled: bool, is_touchpad: Option<bool>) -> bool { | 2992 | + pub fn view_offset_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { |
| 2993 | let ViewOffset::Gesture(gesture) = &mut self.view_offset else { | 2993 | let ViewOffset::Gesture(gesture) = &mut self.view_offset else { |
| 2994 | return false; | 2994 | return false; |
| 2995 | }; | 2995 | }; |
| @@ -3279,7 +3279,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | |||
| 3279 | return; | 3279 | return; |
| 3280 | } | 3280 | } |
| 3281 | 3281 | ||
| 3282 | - self.view_offset_gesture_end(false, None); | 3282 | + self.view_offset_gesture_end(None); |
| 3283 | } | 3283 | } |
| 3284 | 3284 | ||
| 3285 | pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool { | 3285 | pub fn interactive_resize_begin(&mut self, window: W::Id, edges: ResizeEdge) -> bool { |
src/layout/tests.rsmodified+3 -8
| @@ -599,7 +599,6 @@ enum Op { | |||
| 599 | is_touchpad: bool, | 599 | is_touchpad: bool, |
| 600 | }, | 600 | }, |
| 601 | WorkspaceSwitchGestureEnd { | 601 | WorkspaceSwitchGestureEnd { |
| 602 | - cancelled: bool, | ||
| 603 | is_touchpad: Option<bool>, | 602 | is_touchpad: Option<bool>, |
| 604 | }, | 603 | }, |
| 605 | InteractiveMoveBegin { | 604 | InteractiveMoveBegin { |
| @@ -1362,8 +1361,7 @@ impl Op { | |||
| 1362 | layout.view_offset_gesture_update(delta, timestamp, is_touchpad); | 1361 | layout.view_offset_gesture_update(delta, timestamp, is_touchpad); |
| 1363 | } | 1362 | } |
| 1364 | Op::ViewOffsetGestureEnd { is_touchpad } => { | 1363 | Op::ViewOffsetGestureEnd { is_touchpad } => { |
| 1365 | - // We don't handle cancels in this gesture. | 1364 | + layout.view_offset_gesture_end(is_touchpad); |
| 1366 | - layout.view_offset_gesture_end(false, is_touchpad); | ||
| 1367 | } | 1365 | } |
| 1368 | Op::WorkspaceSwitchGestureBegin { | 1366 | Op::WorkspaceSwitchGestureBegin { |
| 1369 | output_idx: id, | 1367 | output_idx: id, |
| @@ -1383,11 +1381,8 @@ impl Op { | |||
| 1383 | } => { | 1381 | } => { |
| 1384 | layout.workspace_switch_gesture_update(delta, timestamp, is_touchpad); | 1382 | layout.workspace_switch_gesture_update(delta, timestamp, is_touchpad); |
| 1385 | } | 1383 | } |
| 1386 | - Op::WorkspaceSwitchGestureEnd { | 1384 | + Op::WorkspaceSwitchGestureEnd { is_touchpad } => { |
| 1387 | - cancelled, | 1385 | + layout.workspace_switch_gesture_end(is_touchpad); |
| 1388 | - is_touchpad, | ||
| 1389 | - } => { | ||
| 1390 | - layout.workspace_switch_gesture_end(cancelled, is_touchpad); | ||
| 1391 | } | 1386 | } |
| 1392 | Op::InteractiveMoveBegin { | 1387 | Op::InteractiveMoveBegin { |
| 1393 | window, | 1388 | window, |
src/layout/workspace.rsmodified+2 -3
| @@ -1619,9 +1619,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1619 | .view_offset_gesture_update(delta_x, timestamp, is_touchpad) | 1619 | .view_offset_gesture_update(delta_x, timestamp, is_touchpad) |
| 1620 | } | 1620 | } |
| 1621 | 1621 | ||
| 1622 | - pub fn view_offset_gesture_end(&mut self, cancelled: bool, is_touchpad: Option<bool>) -> bool { | 1622 | + pub fn view_offset_gesture_end(&mut self, is_touchpad: Option<bool>) -> bool { |
| 1623 | - self.scrolling | 1623 | + self.scrolling.view_offset_gesture_end(is_touchpad) |
| 1624 | - .view_offset_gesture_end(cancelled, is_touchpad) | ||
| 1625 | } | 1624 | } |
| 1626 | 1625 | ||
| 1627 | pub fn dnd_scroll_gesture_begin(&mut self) { | 1626 | pub fn dnd_scroll_gesture_begin(&mut self) { |