diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-19 21:54:46 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-06-19 21:55:39 +0300 |
| commit | db89d4d3dd1440e18193d4ce98d207531c7720e0 (patch) | |
| tree | 9c4974f68ad38928d4bb0b53f219cc607cf9ea59 /src/input | |
| parent | 226273f6607ae83b17c06e0e094ace64ed7a4f7c (diff) | |
| download | niri-db89d4d3dd1440e18193d4ce98d207531c7720e0.tar.gz niri-db89d4d3dd1440e18193d4ce98d207531c7720e0.tar.bz2 niri-db89d4d3dd1440e18193d4ce98d207531c7720e0.zip | |
Implement vertical middle mouse gesture
Diffstat (limited to 'src/input')
| -rw-r--r-- | src/input/mod.rs | 16 | ||||
| -rw-r--r-- | src/input/spatial_movement_grab.rs (renamed from src/input/view_offset_grab.rs) | 65 |
2 files changed, 61 insertions, 20 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs index d0e1c55b..d5b0cd0e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -29,7 +29,7 @@ use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerCons use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; use self::resize_grab::ResizeGrab; -use self::view_offset_grab::ViewOffsetGrab; +use self::spatial_movement_grab::SpatialMovementGrab; use crate::niri::State; use crate::ui::screenshot_ui::ScreenshotUi; use crate::utils::spawning::spawn; @@ -37,8 +37,8 @@ use crate::utils::{center, get_monotonic_time, ResizeEdge}; pub mod resize_grab; pub mod scroll_tracker; +pub mod spatial_movement_grab; pub mod swipe_tracker; -pub mod view_offset_grab; pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); @@ -1252,15 +1252,13 @@ impl State { }; if mod_down { if let Some(output) = self.niri.output_under_cursor() { - self.niri.layout.view_offset_gesture_begin(&output, false); - let location = pointer.current_location(); let start_data = PointerGrabStartData { focus: None, button: event.button_code(), location, }; - let grab = ViewOffsetGrab::new(start_data); + let grab = SpatialMovementGrab::new(start_data, output); pointer.set_grab(self, grab, serial, Focus::Clear); self.niri.pointer_grab_ongoing = true; self.niri @@ -1699,7 +1697,9 @@ impl State { if cx.abs() > cy.abs() { self.niri.layout.view_offset_gesture_begin(&output, true); } else { - self.niri.layout.workspace_switch_gesture_begin(&output); + self.niri + .layout + .workspace_switch_gesture_begin(&output, true); } } } @@ -1711,7 +1711,7 @@ impl State { let res = self .niri .layout - .workspace_switch_gesture_update(delta_y, timestamp); + .workspace_switch_gesture_update(delta_y, timestamp, true); if let Some(output) = res { if let Some(output) = output { self.niri.queue_redraw(&output); @@ -1757,7 +1757,7 @@ impl State { let res = self .niri .layout - .workspace_switch_gesture_end(event.cancelled()); + .workspace_switch_gesture_end(event.cancelled(), Some(true)); if let Some(output) = res { self.niri.queue_redraw(&output); handled = true; diff --git a/src/input/view_offset_grab.rs b/src/input/spatial_movement_grab.rs index b4f9f96c..5a0e6a8a 100644 --- a/src/input/view_offset_grab.rs +++ b/src/input/spatial_movement_grab.rs @@ -7,28 +7,45 @@ use smithay::input::pointer::{ MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, }; use smithay::input::SeatHandler; +use smithay::output::Output; use smithay::utils::{Logical, Point}; use crate::niri::State; -pub struct ViewOffsetGrab { +pub struct SpatialMovementGrab { start_data: PointerGrabStartData<State>, last_location: Point<f64, Logical>, + output: Output, + gesture: GestureState, } -impl ViewOffsetGrab { - pub fn new(start_data: PointerGrabStartData<State>) -> Self { +#[derive(Debug, Clone, Copy)] +enum GestureState { + Recognizing, + ViewOffset, + WorkspaceSwitch, +} + +impl SpatialMovementGrab { + pub fn new(start_data: PointerGrabStartData<State>, output: Output) -> Self { Self { last_location: start_data.location, start_data, + output, + gesture: GestureState::Recognizing, } } fn on_ungrab(&mut self, state: &mut State) { - let res = state - .niri - .layout - .view_offset_gesture_end(false, Some(false)); + let layout = &mut state.niri.layout; + let res = match self.gesture { + GestureState::Recognizing => None, + GestureState::ViewOffset => layout.view_offset_gesture_end(false, Some(false)), + GestureState::WorkspaceSwitch => { + layout.workspace_switch_gesture_end(false, Some(false)) + } + }; + if let Some(output) = res { state.niri.queue_redraw(&output); } @@ -41,7 +58,7 @@ impl ViewOffsetGrab { } } -impl PointerGrab<State> for ViewOffsetGrab { +impl PointerGrab<State> for SpatialMovementGrab { fn motion( &mut self, data: &mut State, @@ -56,10 +73,34 @@ impl PointerGrab<State> for ViewOffsetGrab { let delta = event.location - self.last_location; self.last_location = event.location; - let res = data - .niri - .layout - .view_offset_gesture_update(-delta.x, timestamp, false); + let layout = &mut data.niri.layout; + let res = match self.gesture { + GestureState::Recognizing => { + let c = event.location - self.start_data.location; + + // Check if the gesture moved far enough to decide. Threshold copied from GTK 4. + if c.x * c.x + c.y * c.y >= 8. * 8. { + if c.x.abs() > c.y.abs() { + self.gesture = GestureState::ViewOffset; + layout.view_offset_gesture_begin(&self.output, false); + layout.view_offset_gesture_update(-c.x, timestamp, false) + } else { + self.gesture = GestureState::WorkspaceSwitch; + layout.workspace_switch_gesture_begin(&self.output, false); + layout.workspace_switch_gesture_update(-c.y, timestamp, false) + } + } else { + Some(None) + } + } + GestureState::ViewOffset => { + layout.view_offset_gesture_update(-delta.x, timestamp, false) + } + GestureState::WorkspaceSwitch => { + layout.workspace_switch_gesture_update(-delta.y, timestamp, false) + } + }; + if let Some(output) = res { if let Some(output) = output { data.niri.queue_redraw(&output); |
