From daccddf9b6bf021013b71d56bf323a96c230bcfa Mon Sep 17 00:00:00 2001 From: Drakulix Date: Tue, 20 Mar 2018 17:35:02 +0100 Subject: [PATCH] Reintroduce wl_seat 4 support --- examples/udev.rs | 2 +- examples/winit.rs | 2 +- src/wayland/seat/pointer.rs | 54 +++++++++++++++++++++++-------------- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/examples/udev.rs b/examples/udev.rs index 64c9255..fe68aff 100644 --- a/examples/udev.rs +++ b/examples/udev.rs @@ -209,7 +209,7 @@ impl InputHandler for LibinputInputHandler { if let input::AxisSource::Wheel = evt.source() { event.discrete(axis, evt.amount() as i32); } - // drop and submit the axis event + event.done(); } } fn on_touch_down( diff --git a/examples/winit.rs b/examples/winit.rs index 1ad24b7..b1a0d6f 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -130,7 +130,7 @@ impl InputHandler for WinitInputHandler { if let input::AxisSource::Wheel = evt.source() { event.discrete(axis, evt.amount() as i32); } - // drop and submit the axis event + event.done(); } } fn on_touch_down( diff --git a/src/wayland/seat/pointer.rs b/src/wayland/seat/pointer.rs index 5fde17a..8c8b1c5 100644 --- a/src/wayland/seat/pointer.rs +++ b/src/wayland/seat/pointer.rs @@ -73,7 +73,9 @@ impl PointerHandle { if leave { guard.with_focused_pointers(|pointer, surface| { pointer.leave(serial, surface); - pointer.frame(); + if pointer.version() >= 5 { + pointer.frame(); + } }); guard.focus = None; } @@ -84,13 +86,17 @@ impl PointerHandle { guard.focus = surface.clone(); guard.with_focused_pointers(|pointer, surface| { pointer.enter(serial, surface, x, y); - pointer.frame(); + if pointer.version() >= 5 { + pointer.frame(); + } }) } else { // we were on top of a surface and remained on it guard.with_focused_pointers(|pointer, _| { pointer.motion(time, x, y); - pointer.frame(); + if pointer.version() >= 5 { + pointer.frame(); + } }) } } @@ -104,15 +110,17 @@ impl PointerHandle { let guard = self.inner.lock().unwrap(); guard.with_focused_pointers(|pointer, _| { pointer.button(serial, time, button, state); - pointer.frame(); + if pointer.version() >= 5 { + pointer.frame(); + } }) } /// Start an axis frame - /// + /// /// A single frame will group multiple scroll events as if they happended in the same instance. /// Dropping the returned `PointerAxisHandle` will group the events together. - pub fn axis<'a>(&'a self) -> PointerAxisHandle<'a> { + pub fn axis<'a>(&'a self) -> PointerAxisHandle<'a> { PointerAxisHandle { inner: self.inner.lock().unwrap(), } @@ -127,7 +135,7 @@ impl PointerHandle { } /// A frame of pointer axis events. -/// +/// /// Can be used with the builder pattern, e.g.: /// ```ignore /// pointer.axis() @@ -137,32 +145,36 @@ impl PointerHandle { /// .stop(Axis::Vertical); /// ``` pub struct PointerAxisHandle<'a> { - inner: MutexGuard<'a, PointerInternal> + inner: MutexGuard<'a, PointerInternal>, } impl<'a> PointerAxisHandle<'a> { /// Specify the source of the axis events - /// + /// /// This event is optional, if no source is known, you can ignore this call. /// Only one source event is allowed per frame. - /// + /// /// Using the `AxisSource::Finger` requires a stop event to be send, /// when the user lifts off the finger (not necessarily in the same frame). pub fn source(&mut self, source: wl_pointer::AxisSource) -> &mut Self { self.inner.with_focused_pointers(|pointer, _| { - pointer.axis_source(source); + if pointer.version() >= 5 { + pointer.axis_source(source); + } }); self } - + /// Specify discrete scrolling steps additionally to the computed value. - /// + /// /// This event is optional and gives the client additional information about /// the nature of the axis event. E.g. a scroll wheel might issue separate steps, /// while a touchpad may never issue this event as it has no steps. pub fn discrete(&mut self, axis: wl_pointer::Axis, steps: i32) -> &mut Self { self.inner.with_focused_pointers(|pointer, _| { - pointer.axis_discrete(axis, steps); + if pointer.version() >= 5 { + pointer.axis_discrete(axis, steps); + } }); self } @@ -177,21 +189,23 @@ impl<'a> PointerAxisHandle<'a> { } /// Notification of stop of scrolling on an axis. - /// + /// /// This event is required for sources of the `AxisSource::Finger` type /// and otherwise optional. pub fn stop(&mut self, axis: wl_pointer::Axis, time: u32) -> &mut Self { self.inner.with_focused_pointers(|pointer, _| { - pointer.axis_stop(time, axis); + if pointer.version() >= 5 { + pointer.axis_stop(time, axis); + } }); self } -} -impl<'a> Drop for PointerAxisHandle<'a> { - fn drop(&mut self) { + pub fn done(&mut self) { self.inner.with_focused_pointers(|pointer, _| { - pointer.frame(); + if pointer.version() >= 5 { + pointer.frame(); + } }) } }