forge
Explore
Log in

Don't you dare go Hollow

overview: Add two-finger touchpad scroll

Browse files at this commit

59de6918b3c7f3bc8e988046b3fef2cead322f9aIvan MolodetskikhParent: bd3d554
src/input/mod.rsmodified+102 -2
@@ -51,6 +51,7 @@ pub mod move_grab;
51 pub mod pick_color_grab;51 pub mod pick_color_grab;
52 pub mod pick_window_grab;52 pub mod pick_window_grab;
53 pub mod resize_grab;53 pub mod resize_grab;
54+pub mod scroll_swipe_gesture;
54 pub mod scroll_tracker;55 pub mod scroll_tracker;
55 pub mod spatial_movement_grab;56 pub mod spatial_movement_grab;
56 pub mod swipe_tracker;57 pub mod swipe_tracker;
@@ -2568,6 +2569,8 @@ impl State {
2568 self.niri.pointer_hidden = false;2569 self.niri.pointer_hidden = false;
2569 self.niri.tablet_cursor_location = None;2570 self.niri.tablet_cursor_location = None;
2570 2571
2572+ let timestamp = Duration::from_micros(event.time());
2573+
2571 let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal);2574 let horizontal_amount_v120 = event.amount_v120(Axis::Horizontal);
2572 let vertical_amount_v120 = event.amount_v120(Axis::Vertical);2575 let vertical_amount_v120 = event.amount_v120(Axis::Vertical);
2573 2576
@@ -2751,8 +2754,106 @@ impl State {
2751 if source == AxisSource::Finger {2754 if source == AxisSource::Finger {
2752 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();2755 let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
2753 let modifiers = modifiers_from_state(mods);2756 let modifiers = modifiers_from_state(mods);
2757+
2758+ let horizontal = horizontal_amount.unwrap_or(0.);
2759+ let vertical = vertical_amount.unwrap_or(0.);
2760+
2761+ if should_handle_in_overview && modifiers.is_empty() {
2762+ let mut redraw = false;
2763+
2764+ let action = self
2765+ .niri
2766+ .overview_scroll_swipe_gesture
2767+ .update(horizontal, vertical);
2768+ let is_vertical = self.niri.overview_scroll_swipe_gesture.is_vertical();
2769+
2770+ if action.end() {
2771+ if is_vertical {
2772+ redraw |= self
2773+ .niri
2774+ .layout
2775+ .workspace_switch_gesture_end(Some(true))
2776+ .is_some();
2777+ } else {
2778+ redraw |= self
2779+ .niri
2780+ .layout
2781+ .view_offset_gesture_end(Some(true))
2782+ .is_some();
2783+ }
2784+ } else {
2785+ // Maybe begin, then update.
2786+ if is_vertical {
2787+ if action.begin() {
2788+ if let Some(output) = self.niri.output_under_cursor() {
2789+ self.niri
2790+ .layout
2791+ .workspace_switch_gesture_begin(&output, true);
2792+ redraw = true;
2793+ }
2794+ }
2795+
2796+ let res = self
2797+ .niri
2798+ .layout
2799+ .workspace_switch_gesture_update(vertical, timestamp, true);
2800+ if let Some(Some(_)) = res {
2801+ redraw = true;
2802+ }
2803+ } else {
2804+ if action.begin() {
2805+ if let Some((output, ws)) = self.niri.workspace_under_cursor(true) {
2806+ let ws_id = ws.id();
2807+ let ws_idx =
2808+ self.niri.layout.find_workspace_by_id(ws_id).unwrap().0;
2809+
2810+ self.niri.layout.view_offset_gesture_begin(
2811+ &output,
2812+ Some(ws_idx),
2813+ true,
2814+ );
2815+ redraw = true;
2816+ }
2817+ }
2818+
2819+ let res = self
2820+ .niri
2821+ .layout
2822+ .view_offset_gesture_update(horizontal, timestamp, true);
2823+ if let Some(Some(_)) = res {
2824+ redraw = true;
2825+ }
2826+ }
2827+ }
2828+
2829+ if redraw {
2830+ self.niri.queue_redraw_all();
2831+ }
2832+
2833+ return;
2834+ } else {
2835+ let mut redraw = false;
2836+ if self.niri.overview_scroll_swipe_gesture.reset() {
2837+ if self.niri.overview_scroll_swipe_gesture.is_vertical() {
2838+ redraw |= self
2839+ .niri
2840+ .layout
2841+ .workspace_switch_gesture_end(Some(true))
2842+ .is_some();
2843+ } else {
2844+ redraw |= self
2845+ .niri
2846+ .layout
2847+ .view_offset_gesture_end(Some(true))
2848+ .is_some();
2849+ }
2850+ }
2851+ if redraw {
2852+ self.niri.queue_redraw_all();
2853+ }
2854+ }
2855+
2754 if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {2856 if self.niri.mods_with_finger_scroll_binds.contains(&modifiers) {
2755- let horizontal = horizontal_amount.unwrap_or(0.);
2756 let ticks = self2857 let ticks = self
2757 .niri2858 .niri
2758 .horizontal_finger_scroll_tracker2859 .horizontal_finger_scroll_tracker
@@ -2778,7 +2879,6 @@ impl State {
2778 }2879 }
2779 }2880 }
2780 2881
2781- let vertical = vertical_amount.unwrap_or(0.);
2782 let ticks = self2882 let ticks = self
2783 .niri2883 .niri
2784 .vertical_finger_scroll_tracker2884 .vertical_finger_scroll_tracker
src/input/scroll_swipe_gesture.rsadded+69 -0
@@ -0,0 +1,69 @@
1+//! Swipe gesture from scroll events.
2+//!
3+//! Tracks when to begin, update, and end a swipe gesture from pointer axis events, also whether
4+//! the gesture is vertical or horizontal. Necessary because libinput only provides touchpad swipe
5+//! gesture events for 3+ fingers.
6+
7+#[derive(Debug)]
8+pub struct ScrollSwipeGesture {
9+ ongoing: bool,
10+ vertical: bool,
11+}
12+
13+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14+pub enum Action {
15+ BeginUpdate,
16+ Update,
17+ End,
18+}
19+
20+impl ScrollSwipeGesture {
21+ pub const fn new() -> Self {
22+ Self {
23+ ongoing: false,
24+ vertical: false,
25+ }
26+ }
27+
28+ pub fn update(&mut self, dx: f64, dy: f64) -> Action {
29+ if dx == 0. && dy == 0. {
30+ self.ongoing = false;
31+ Action::End
32+ } else if !self.ongoing {
33+ self.ongoing = true;
34+ self.vertical = dy != 0.;
35+ Action::BeginUpdate
36+ } else {
37+ Action::Update
38+ }
39+ }
40+
41+ pub fn reset(&mut self) -> bool {
42+ if self.ongoing {
43+ self.ongoing = false;
44+ true
45+ } else {
46+ false
47+ }
48+ }
49+
50+ pub fn is_vertical(&self) -> bool {
51+ self.vertical
52+ }
53+}
54+
55+impl Default for ScrollSwipeGesture {
56+ fn default() -> Self {
57+ Self::new()
58+ }
59+}
60+
61+impl Action {
62+ pub fn begin(self) -> bool {
63+ self == Action::BeginUpdate
64+ }
65+
66+ pub fn end(self) -> bool {
67+ self == Action::End
68+ }
69+}
src/niri.rsmodified+3 -0
@@ -124,6 +124,7 @@ use crate::dbus::mutter_screen_cast::{self, ScreenCastToNiri};
124 use crate::frame_clock::FrameClock;124 use crate::frame_clock::FrameClock;
125 use crate::handlers::{configure_lock_surface, XDG_ACTIVATION_TOKEN_TIMEOUT};125 use crate::handlers::{configure_lock_surface, XDG_ACTIVATION_TOKEN_TIMEOUT};
126 use crate::input::pick_color_grab::PickColorGrab;126 use crate::input::pick_color_grab::PickColorGrab;
127+use crate::input::scroll_swipe_gesture::ScrollSwipeGesture;
127 use crate::input::scroll_tracker::ScrollTracker;128 use crate::input::scroll_tracker::ScrollTracker;
128 use crate::input::{129 use crate::input::{
129 apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_mouse_binds,130 apply_libinput_settings, mods_with_finger_scroll_binds, mods_with_mouse_binds,
@@ -348,6 +349,7 @@ pub struct Niri {
348 pub notified_activity_this_iteration: bool,349 pub notified_activity_this_iteration: bool,
349 pub tablet_cursor_location: Option<Point<f64, Logical>>,350 pub tablet_cursor_location: Option<Point<f64, Logical>>,
350 pub gesture_swipe_3f_cumulative: Option<(f64, f64)>,351 pub gesture_swipe_3f_cumulative: Option<(f64, f64)>,
352+ pub overview_scroll_swipe_gesture: ScrollSwipeGesture,
351 pub vertical_wheel_tracker: ScrollTracker,353 pub vertical_wheel_tracker: ScrollTracker,
352 pub horizontal_wheel_tracker: ScrollTracker,354 pub horizontal_wheel_tracker: ScrollTracker,
353 pub mods_with_mouse_binds: HashSet<Modifiers>,355 pub mods_with_mouse_binds: HashSet<Modifiers>,
@@ -2427,6 +2429,7 @@ impl Niri {
2427 notified_activity_this_iteration: false,2429 notified_activity_this_iteration: false,
2428 tablet_cursor_location: None,2430 tablet_cursor_location: None,
2429 gesture_swipe_3f_cumulative: None,2431 gesture_swipe_3f_cumulative: None,
2432+ overview_scroll_swipe_gesture: ScrollSwipeGesture::new(),
2430 vertical_wheel_tracker: ScrollTracker::new(120),2433 vertical_wheel_tracker: ScrollTracker::new(120),
2431 horizontal_wheel_tracker: ScrollTracker::new(120),2434 horizontal_wheel_tracker: ScrollTracker::new(120),
2432 mods_with_mouse_binds,2435 mods_with_mouse_binds,