From af1fca35bb15b8010cd3a12bbafe71b55d9ecf57 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 25 Apr 2025 09:36:50 +0300 Subject: Implement an Overview --- src/input/move_grab.rs | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) (limited to 'src/input/move_grab.rs') diff --git a/src/input/move_grab.rs b/src/input/move_grab.rs index 96362b45..e939696b 100644 --- a/src/input/move_grab.rs +++ b/src/input/move_grab.rs @@ -1,10 +1,11 @@ use smithay::backend::input::ButtonState; use smithay::desktop::Window; use smithay::input::pointer::{ - AxisFrame, ButtonEvent, CursorImageStatus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent, - GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, - MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, + AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, GestureHoldBeginEvent, + GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, + GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, + GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, + RelativeMotionEvent, }; use smithay::input::SeatHandler; use smithay::utils::{IsAlive, Logical, Point}; @@ -15,14 +16,32 @@ pub struct MoveGrab { start_data: PointerGrabStartData, last_location: Point, window: Window, + gesture: GestureState, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum GestureState { + Recognizing, + Move, } impl MoveGrab { - pub fn new(start_data: PointerGrabStartData, window: Window) -> Self { + pub fn new( + start_data: PointerGrabStartData, + window: Window, + use_threshold: bool, + ) -> Self { + let gesture = if use_threshold { + GestureState::Recognizing + } else { + GestureState::Move + }; + Self { last_location: start_data.location, start_data, window, + gesture, } } @@ -53,6 +72,24 @@ impl PointerGrab for MoveGrab { let output = output.clone(); let event_delta = event.location - self.last_location; self.last_location = event.location; + + if self.gesture == GestureState::Recognizing { + let c = event.location - self.start_data.location; + + // Check if the gesture moved far enough to decide. + if c.x * c.x + c.y * c.y >= 8. * 8. { + self.gesture = GestureState::Move; + + data.niri + .cursor_manager + .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move)); + } + } + + if self.gesture != GestureState::Move { + return; + } + let ongoing = data.niri.layout.interactive_move_update( &self.window, event_delta, -- cgit