diff options
Diffstat (limited to 'src/input')
| -rw-r--r-- | src/input/mod.rs | 20 | ||||
| -rw-r--r-- | src/input/move_grab.rs | 2 | ||||
| -rw-r--r-- | src/input/touch_move_grab.rs | 136 |
3 files changed, 157 insertions, 1 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs index b3e38892..11612f2f 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -24,7 +24,10 @@ use smithay::input::pointer::{ GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData, MotionEvent, RelativeMotionEvent, }; -use smithay::input::touch::{DownEvent, MotionEvent as TouchMotionEvent, UpEvent}; +use smithay::input::touch::{ + DownEvent, GrabStartData as TouchGrabStartData, MotionEvent as TouchMotionEvent, UpEvent, +}; +use smithay::input::SeatHandler; use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER}; use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint}; use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; @@ -42,6 +45,7 @@ pub mod resize_grab; pub mod scroll_tracker; pub mod spatial_movement_grab; pub mod swipe_tracker; +pub mod touch_move_grab; pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); @@ -56,6 +60,20 @@ pub struct TabletData { pub aspect_ratio: f64, } +pub enum PointerOrTouchStartData<D: SeatHandler> { + Pointer(PointerGrabStartData<D>), + Touch(TouchGrabStartData<D>), +} + +impl<D: SeatHandler> PointerOrTouchStartData<D> { + pub fn location(&self) -> Point<f64, Logical> { + match self { + PointerOrTouchStartData::Pointer(x) => x.location, + PointerOrTouchStartData::Touch(x) => x.location, + } + } +} + impl State { pub fn process_input_event<I: InputBackend + 'static>(&mut self, event: InputEvent<I>) where diff --git a/src/input/move_grab.rs b/src/input/move_grab.rs index 71d115d7..e62a74f8 100644 --- a/src/input/move_grab.rs +++ b/src/input/move_grab.rs @@ -73,6 +73,8 @@ impl PointerGrab<State> for MoveGrab { false, ); } + // FIXME: only redraw the previous and the new output. + data.niri.queue_redraw_all(); return; } } else { diff --git a/src/input/touch_move_grab.rs b/src/input/touch_move_grab.rs new file mode 100644 index 00000000..e69f4c6e --- /dev/null +++ b/src/input/touch_move_grab.rs @@ -0,0 +1,136 @@ +use smithay::desktop::Window; +use smithay::input::touch::{ + DownEvent, GrabStartData as TouchGrabStartData, MotionEvent, OrientationEvent, ShapeEvent, + TouchGrab, TouchInnerHandle, UpEvent, +}; +use smithay::input::SeatHandler; +use smithay::utils::{IsAlive, Logical, Point, Serial}; + +use crate::niri::State; + +pub struct TouchMoveGrab { + start_data: TouchGrabStartData<State>, + last_location: Point<f64, Logical>, + window: Window, +} + +impl TouchMoveGrab { + pub fn new(start_data: TouchGrabStartData<State>, window: Window) -> Self { + Self { + last_location: start_data.location, + start_data, + window, + } + } + + fn on_ungrab(&mut self, state: &mut State) { + state.niri.layout.interactive_move_end(&self.window); + // FIXME: only redraw the window output. + state.niri.queue_redraw_all(); + } +} + +impl TouchGrab<State> for TouchMoveGrab { + fn down( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>, + event: &DownEvent, + seq: Serial, + ) { + handle.down(data, None, event, seq); + } + + fn up( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &UpEvent, + seq: Serial, + ) { + handle.up(data, event, seq); + + if event.slot != self.start_data.slot { + return; + } + + handle.unset_grab(self, data); + } + + fn motion( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + _focus: Option<(<State as SeatHandler>::TouchFocus, Point<f64, Logical>)>, + event: &MotionEvent, + seq: Serial, + ) { + handle.motion(data, None, event, seq); + + if event.slot != self.start_data.slot { + return; + } + + if self.window.alive() { + if let Some((output, pos_within_output)) = data.niri.output_under(event.location) { + let output = output.clone(); + let event_delta = event.location - self.last_location; + self.last_location = event.location; + let ongoing = data.niri.layout.interactive_move_update( + &self.window, + event_delta, + output, + pos_within_output, + ); + if ongoing { + // FIXME: only redraw the previous and the new output. + data.niri.queue_redraw_all(); + return; + } + } else { + return; + } + } + + // The move is no longer ongoing. + handle.unset_grab(self, data); + } + + fn frame(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) { + handle.frame(data, seq); + } + + fn cancel(&mut self, data: &mut State, handle: &mut TouchInnerHandle<'_, State>, seq: Serial) { + handle.cancel(data, seq); + handle.unset_grab(self, data); + } + + fn shape( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &ShapeEvent, + seq: Serial, + ) { + handle.shape(data, event, seq); + } + + fn orientation( + &mut self, + data: &mut State, + handle: &mut TouchInnerHandle<'_, State>, + event: &OrientationEvent, + seq: Serial, + ) { + handle.orientation(data, event, seq); + } + + fn start_data(&self) -> &TouchGrabStartData<State> { + &self.start_data + } + + fn unset(&mut self, data: &mut State) { + self.on_ungrab(data); + } +} |
