input: Handle relative pointer motion
Browse files at this commitec1a888386261bf8cd4f5dd9a272d329bb05e110Parent: 00472721 changed file +37 -3
- src/input.rs +37 -3
src/input.rsmodified+37 -3
| @@ -1,9 +1,9 @@ | |||
| 1 | use smithay::backend::input::{ | 1 | use smithay::backend::input::{ |
| 2 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent, | 2 | AbsolutePositionEvent, Axis, AxisSource, ButtonState, Event, InputBackend, InputEvent, |
| 3 | - KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, | 3 | + KeyboardKeyEvent, PointerAxisEvent, PointerButtonEvent, PointerMotionEvent, |
| 4 | }; | 4 | }; |
| 5 | use smithay::input::keyboard::{keysyms, FilterResult}; | 5 | use smithay::input::keyboard::{keysyms, FilterResult}; |
| 6 | -use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent}; | 6 | +use smithay::input::pointer::{AxisFrame, ButtonEvent, MotionEvent, RelativeMotionEvent}; |
| 7 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 7 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 8 | use smithay::utils::SERIAL_COUNTER; | 8 | use smithay::utils::SERIAL_COUNTER; |
| 9 | 9 | ||
| @@ -55,7 +55,41 @@ impl Niri { | |||
| 55 | } | 55 | } |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
| 58 | - InputEvent::PointerMotion { .. } => {} | 58 | + InputEvent::PointerMotion { event, .. } => { |
| 59 | + let serial = SERIAL_COUNTER.next_serial(); | ||
| 60 | + | ||
| 61 | + let pointer = self.seat.get_pointer().unwrap(); | ||
| 62 | + let mut pointer_location = pointer.current_location(); | ||
| 63 | + | ||
| 64 | + pointer_location += event.delta(); | ||
| 65 | + | ||
| 66 | + let output = self.space.outputs().next().unwrap(); | ||
| 67 | + let output_geo = self.space.output_geometry(output).unwrap(); | ||
| 68 | + | ||
| 69 | + pointer_location.x = pointer_location.x.clamp(0., output_geo.size.w as f64); | ||
| 70 | + pointer_location.y = pointer_location.y.clamp(0., output_geo.size.h as f64); | ||
| 71 | + | ||
| 72 | + let under = self.surface_under_pointer(&pointer); | ||
| 73 | + pointer.motion( | ||
| 74 | + self, | ||
| 75 | + under.clone(), | ||
| 76 | + &MotionEvent { | ||
| 77 | + location: pointer_location, | ||
| 78 | + serial, | ||
| 79 | + time: event.time_msec(), | ||
| 80 | + }, | ||
| 81 | + ); | ||
| 82 | + | ||
| 83 | + pointer.relative_motion( | ||
| 84 | + self, | ||
| 85 | + under, | ||
| 86 | + &RelativeMotionEvent { | ||
| 87 | + delta: event.delta(), | ||
| 88 | + delta_unaccel: event.delta_unaccel(), | ||
| 89 | + utime: event.time(), | ||
| 90 | + }, | ||
| 91 | + ); | ||
| 92 | + } | ||
| 59 | InputEvent::PointerMotionAbsolute { event, .. } => { | 93 | InputEvent::PointerMotionAbsolute { event, .. } => { |
| 60 | let output = self.space.outputs().next().unwrap(); | 94 | let output = self.space.outputs().next().unwrap(); |
| 61 | 95 | ||