Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High res scrolling support #1246

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ drm-ffi = { version = "0.7.0", optional = true }
errno = "0.3.5"
gbm = { version = "0.14.0", optional = true, default-features = false, features = ["drm-support"] }
glow = { version = "0.12", optional = true }
input = { version = "0.8.2", default-features = false, features=["libinput_1_14"], optional = true }
input = { version = "0.8.2", default-features = false, features=["libinput_1_19"], optional = true }
indexmap = "2.0"
lazy_static = "1"
libc = "0.2.103"
Expand Down Expand Up @@ -94,7 +94,6 @@ backend_udev = ["udev", "input/udev"]
backend_vulkan = ["ash", "scopeguard"]
backend_session_libseat = ["backend_session", "libseat"]
desktop = []
libinput_1_19 = ["input/libinput_1_19"]
renderer_gl = ["gl_generator", "backend_egl"]
renderer_glow = ["renderer_gl", "glow"]
renderer_multi = ["backend_drm"]
Expand All @@ -104,7 +103,7 @@ use_bindgen = ["drm-ffi/use_bindgen", "gbm/use_bindgen", "input/gen"]
wayland_frontend = ["wayland-server", "wayland-protocols", "wayland-protocols-wlr", "wayland-protocols-misc", "tempfile"]
x11rb_event_source = ["x11rb"]
xwayland = ["encoding_rs", "wayland_frontend", "x11rb/composite", "x11rb/xfixes", "x11rb_event_source", "scopeguard"]
test_all_features = ["default", "use_system_lib", "renderer_glow", "libinput_1_19", "renderer_test"]
test_all_features = ["default", "use_system_lib", "renderer_glow", "renderer_test"]

[[example]]
name = "minimal"
Expand Down
12 changes: 6 additions & 6 deletions anvil/src/input_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,25 +384,25 @@ impl<BackendData: Backend> AnvilState<BackendData> {
fn on_pointer_axis<B: InputBackend>(&mut self, _dh: &DisplayHandle, evt: B::PointerAxisEvent) {
let horizontal_amount = evt
.amount(input::Axis::Horizontal)
.unwrap_or_else(|| evt.amount_discrete(input::Axis::Horizontal).unwrap_or(0.0) * 3.0);
.unwrap_or_else(|| evt.amount_v120(input::Axis::Horizontal).unwrap_or(0.0) * 3.0 / 120.);
let vertical_amount = evt
.amount(input::Axis::Vertical)
.unwrap_or_else(|| evt.amount_discrete(input::Axis::Vertical).unwrap_or(0.0) * 3.0);
let horizontal_amount_discrete = evt.amount_discrete(input::Axis::Horizontal);
let vertical_amount_discrete = evt.amount_discrete(input::Axis::Vertical);
.unwrap_or_else(|| evt.amount_v120(input::Axis::Vertical).unwrap_or(0.0) * 3.0 / 120.);
let horizontal_amount_discrete = evt.amount_v120(input::Axis::Horizontal);
let vertical_amount_discrete = evt.amount_v120(input::Axis::Vertical);

{
let mut frame = AxisFrame::new(evt.time_msec()).source(evt.source());
if horizontal_amount != 0.0 {
frame = frame.value(Axis::Horizontal, horizontal_amount);
if let Some(discrete) = horizontal_amount_discrete {
frame = frame.discrete(Axis::Horizontal, discrete as i32);
frame = frame.v120(Axis::Horizontal, discrete as i32);
}
}
if vertical_amount != 0.0 {
frame = frame.value(Axis::Vertical, vertical_amount);
if let Some(discrete) = vertical_amount_discrete {
frame = frame.discrete(Axis::Vertical, discrete as i32);
frame = frame.v120(Axis::Vertical, discrete as i32);
}
}
if evt.source() == AxisSource::Finger {
Expand Down
12 changes: 6 additions & 6 deletions smallvil/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,24 @@ impl Smallvil {

let horizontal_amount = event
.amount(Axis::Horizontal)
.unwrap_or_else(|| event.amount_discrete(Axis::Horizontal).unwrap_or(0.0) * 3.0);
.unwrap_or_else(|| event.amount_v120(Axis::Horizontal).unwrap_or(0.0) * 3.0 / 120.);
let vertical_amount = event
.amount(Axis::Vertical)
.unwrap_or_else(|| event.amount_discrete(Axis::Vertical).unwrap_or(0.0) * 3.0);
let horizontal_amount_discrete = event.amount_discrete(Axis::Horizontal);
let vertical_amount_discrete = event.amount_discrete(Axis::Vertical);
.unwrap_or_else(|| event.amount_v120(Axis::Vertical).unwrap_or(0.0) * 3.0 / 120.);
let horizontal_amount_discrete = event.amount_v120(Axis::Horizontal);
let vertical_amount_discrete = event.amount_v120(Axis::Vertical);

let mut frame = AxisFrame::new(event.time_msec()).source(source);
if horizontal_amount != 0.0 {
frame = frame.value(Axis::Horizontal, horizontal_amount);
if let Some(discrete) = horizontal_amount_discrete {
frame = frame.discrete(Axis::Horizontal, discrete as i32);
frame = frame.v120(Axis::Horizontal, discrete as i32);
}
}
if vertical_amount != 0.0 {
frame = frame.value(Axis::Vertical, vertical_amount);
if let Some(discrete) = vertical_amount_discrete {
frame = frame.discrete(Axis::Vertical, discrete as i32);
frame = frame.v120(Axis::Vertical, discrete as i32);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/backend/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ pub trait PointerAxisEvent<B: InputBackend>: Event<B> {
/// Amount of scrolling in discrete steps on the given [`Axis`].
///
/// Guaranteed to be `Some` when source returns either [`AxisSource::Wheel`] or [`AxisSource::WheelTilt`].
fn amount_discrete(&self, axis: Axis) -> Option<f64>;
fn amount_v120(&self, axis: Axis) -> Option<f64>;

/// Source of the scroll event.
fn source(&self) -> AxisSource;
Expand All @@ -364,7 +364,7 @@ impl<B: InputBackend> PointerAxisEvent<B> for UnusedEvent {
match *self {}
}

fn amount_discrete(&self, _axis: Axis) -> Option<f64> {
fn amount_v120(&self, _axis: Axis) -> Option<f64> {
match *self {}
}

Expand Down
113 changes: 75 additions & 38 deletions src/backend/libinput/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// TODO: Update to use new `Scroll*` events instead of now deprecated
// `PointerAxis*`.
#![cfg_attr(feature = "libinput_1_19", allow(deprecated))]

//! Implementation of input backend trait for types provided by `libinput`

use crate::backend::input::{self as backend, Axis, InputBackend, InputEvent};
Expand Down Expand Up @@ -127,37 +123,80 @@ impl backend::KeyboardKeyEvent<LibinputInputBackend> for event::keyboard::Keyboa
}
}

impl backend::Event<LibinputInputBackend> for event::pointer::PointerAxisEvent {
/// Generic pointer scroll event from libinput
#[derive(Debug, PartialEq, Eq, Hash)]
pub enum PointerScrollAxis {
/// Scroll event from pointer wheel
Wheel(event::pointer::PointerScrollWheelEvent),
/// Scroll event from pointer finger
Finger(event::pointer::PointerScrollFingerEvent),
/// Continuous scroll event
Continuous(event::pointer::PointerScrollContinuousEvent),
}

impl PointerScrollAxis {
fn has_axis(&self, axis: event::pointer::Axis) -> bool {
use input::event::pointer::PointerScrollEvent;
match self {
Self::Wheel(evt) => evt.has_axis(axis),
Self::Finger(evt) => evt.has_axis(axis),
Self::Continuous(evt) => evt.has_axis(axis),
}
}
}

impl backend::Event<LibinputInputBackend> for PointerScrollAxis {
fn time(&self) -> u64 {
event::pointer::PointerEventTrait::time_usec(self)
match self {
Self::Wheel(evt) => event::pointer::PointerEventTrait::time_usec(evt),
Self::Finger(evt) => event::pointer::PointerEventTrait::time_usec(evt),
Self::Continuous(evt) => event::pointer::PointerEventTrait::time_usec(evt),
}
}

fn device(&self) -> libinput::Device {
event::EventTrait::device(self)
match self {
Self::Wheel(evt) => event::EventTrait::device(evt),
Self::Finger(evt) => event::EventTrait::device(evt),
Self::Continuous(evt) => event::EventTrait::device(evt),
}
}
}

impl backend::PointerAxisEvent<LibinputInputBackend> for event::pointer::PointerAxisEvent {
impl backend::PointerAxisEvent<LibinputInputBackend> for PointerScrollAxis {
fn amount(&self, axis: Axis) -> Option<f64> {
use input::event::pointer::PointerScrollEvent;
let axis = axis.into();
if self.has_axis(axis) {
Some(self.axis_value(axis))
Some(match self {
Self::Wheel(evt) => evt.scroll_value(axis),
Self::Finger(evt) => evt.scroll_value(axis),
Self::Continuous(evt) => evt.scroll_value(axis),
})
} else {
None
}
}

fn amount_discrete(&self, axis: Axis) -> Option<f64> {
fn amount_v120(&self, axis: Axis) -> Option<f64> {
let axis = axis.into();
if self.has_axis(axis) {
self.axis_value_discrete(axis)
match self {
Self::Wheel(evt) => Some(evt.scroll_value_v120(axis)),
Self::Finger(_evt) => None,
Self::Continuous(_evt) => None,
}
} else {
None
}
}

fn source(&self) -> backend::AxisSource {
self.axis_source().into()
match self {
Self::Wheel(_) => backend::AxisSource::Wheel,
Self::Finger(_) => backend::AxisSource::Finger,
Self::Continuous(_) => backend::AxisSource::Continuous,
}
}
}

Expand Down Expand Up @@ -356,7 +395,6 @@ impl backend::Event<LibinputInputBackend> for event::gesture::GesturePinchEndEve

impl backend::GesturePinchEndEvent<LibinputInputBackend> for event::gesture::GesturePinchEndEvent {}

#[cfg(feature = "libinput_1_19")]
impl backend::Event<LibinputInputBackend> for event::gesture::GestureHoldBeginEvent {
fn time(&self) -> u64 {
event::gesture::GestureEventTrait::time_usec(self)
Expand All @@ -367,10 +405,8 @@ impl backend::Event<LibinputInputBackend> for event::gesture::GestureHoldBeginEv
}
}

#[cfg(feature = "libinput_1_19")]
impl backend::GestureHoldBeginEvent<LibinputInputBackend> for event::gesture::GestureHoldBeginEvent {}

#[cfg(feature = "libinput_1_19")]
impl backend::Event<LibinputInputBackend> for event::gesture::GestureHoldEndEvent {
fn time(&self) -> u64 {
event::gesture::GestureEventTrait::time_usec(self)
Expand All @@ -381,7 +417,6 @@ impl backend::Event<LibinputInputBackend> for event::gesture::GestureHoldEndEven
}
}

#[cfg(feature = "libinput_1_19")]
impl backend::GestureHoldEndEvent<LibinputInputBackend> for event::gesture::GestureHoldEndEvent {}

impl backend::Event<LibinputInputBackend> for event::touch::TouchDownEvent {
Expand Down Expand Up @@ -507,7 +542,7 @@ impl backend::TouchFrameEvent<LibinputInputBackend> for event::touch::TouchFrame
impl InputBackend for LibinputInputBackend {
type Device = libinput::Device;
type KeyboardKeyEvent = event::keyboard::KeyboardKeyEvent;
type PointerAxisEvent = event::pointer::PointerAxisEvent;
type PointerAxisEvent = PointerScrollAxis;
type PointerButtonEvent = event::pointer::PointerButtonEvent;
type PointerMotionEvent = event::pointer::PointerMotionEvent;
type PointerMotionAbsoluteEvent = event::pointer::PointerMotionAbsoluteEvent;
Expand All @@ -518,13 +553,7 @@ impl InputBackend for LibinputInputBackend {
type GesturePinchBeginEvent = event::gesture::GesturePinchBeginEvent;
type GesturePinchUpdateEvent = event::gesture::GesturePinchUpdateEvent;
type GesturePinchEndEvent = event::gesture::GesturePinchEndEvent;
#[cfg(not(feature = "libinput_1_19"))]
type GestureHoldBeginEvent = backend::UnusedEvent;
#[cfg(not(feature = "libinput_1_19"))]
type GestureHoldEndEvent = backend::UnusedEvent;
#[cfg(feature = "libinput_1_19")]
type GestureHoldBeginEvent = event::gesture::GestureHoldBeginEvent;
#[cfg(feature = "libinput_1_19")]
type GestureHoldEndEvent = event::gesture::GestureHoldEndEvent;

type TouchDownEvent = event::touch::TouchDownEvent;
Expand Down Expand Up @@ -567,17 +596,6 @@ impl From<backend::Axis> for event::pointer::Axis {
}
}

impl From<event::pointer::AxisSource> for backend::AxisSource {
fn from(libinput: event::pointer::AxisSource) -> Self {
match libinput {
event::pointer::AxisSource::Finger => backend::AxisSource::Finger,
event::pointer::AxisSource::Continuous => backend::AxisSource::Continuous,
event::pointer::AxisSource::Wheel => backend::AxisSource::Wheel,
event::pointer::AxisSource::WheelTilt => backend::AxisSource::WheelTilt,
}
}
}

impl From<event::pointer::ButtonState> for backend::ButtonState {
fn from(libinput: event::pointer::ButtonState) -> Self {
match libinput {
Expand Down Expand Up @@ -696,8 +714,29 @@ impl EventSource for LibinputInputBackend {
&mut (),
);
}
event::PointerEvent::Axis(axis_event) => {
callback(InputEvent::PointerAxis { event: axis_event }, &mut ());
event::PointerEvent::ScrollWheel(scroll_event) => {
callback(
InputEvent::PointerAxis {
event: PointerScrollAxis::Wheel(scroll_event),
},
&mut (),
);
}
event::PointerEvent::ScrollFinger(scroll_event) => {
callback(
InputEvent::PointerAxis {
event: PointerScrollAxis::Finger(scroll_event),
},
&mut (),
);
}
event::PointerEvent::ScrollContinuous(scroll_event) => {
callback(
InputEvent::PointerAxis {
event: PointerScrollAxis::Continuous(scroll_event),
},
&mut (),
);
}
event::PointerEvent::Button(button_event) => {
callback(InputEvent::PointerButton { event: button_event }, &mut ());
Expand Down Expand Up @@ -725,11 +764,9 @@ impl EventSource for LibinputInputBackend {
event::GestureEvent::Pinch(event::gesture::GesturePinchEvent::End(event)) => {
callback(InputEvent::GesturePinchEnd { event }, &mut ());
}
#[cfg(feature = "libinput_1_19")]
event::GestureEvent::Hold(event::gesture::GestureHoldEvent::Begin(event)) => {
callback(InputEvent::GestureHoldBegin { event }, &mut ());
}
#[cfg(feature = "libinput_1_19")]
event::GestureEvent::Hold(event::gesture::GestureHoldEvent::End(event)) => {
callback(InputEvent::GestureHoldEnd { event }, &mut ());
}
Expand Down
7 changes: 4 additions & 3 deletions src/backend/winit/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,11 @@ impl PointerAxisEvent<WinitInput> for WinitMouseWheelEvent {
}
}

fn amount_discrete(&self, axis: Axis) -> Option<f64> {
// TODO: Use high-res scroll where backend supports it
fn amount_v120(&self, axis: Axis) -> Option<f64> {
match (axis, self.delta) {
(Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64),
(Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64),
(Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64 * 120.),
(Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64 * 120.),
(_, MouseScrollDelta::PixelDelta(_)) => None,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/x11/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl PointerAxisEvent<X11Input> for X11MouseWheelEvent {
None
}

fn amount_discrete(&self, axis: Axis) -> Option<f64> {
fn amount_v120(&self, axis: Axis) -> Option<f64> {
if self.axis == axis {
Some(self.amount)
Some(self.amount * 120.)
} else {
Some(0.0)
}
Expand Down
12 changes: 6 additions & 6 deletions src/input/pointer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ pub struct AxisFrame {
/// Raw scroll value per axis of the event
pub axis: (f64, f64),
/// Discrete representation of scroll value per axis, if available
pub discrete: Option<(i32, i32)>,
pub v120: Option<(i32, i32)>,
/// If the axis is considered having stoped movement
///
/// Only useful in conjunction of AxisSource::Finger events
Expand Down Expand Up @@ -1021,7 +1021,7 @@ impl AxisFrame {
source: None,
time,
axis: (0.0, 0.0),
discrete: None,
v120: None,
stop: (false, false),
}
}
Expand All @@ -1043,14 +1043,14 @@ impl AxisFrame {
/// 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: Axis, steps: i32) -> Self {
let discrete = self.discrete.get_or_insert_with(Default::default);
pub fn v120(mut self, axis: Axis, steps: i32) -> Self {
let v120 = self.v120.get_or_insert_with(Default::default);
match axis {
Axis::Horizontal => {
discrete.0 = steps;
v120.0 = steps;
}
Axis::Vertical => {
discrete.1 = steps;
v120.1 = steps;
}
};
self
Expand Down
2 changes: 1 addition & 1 deletion src/wayland/seat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<D: SeatHandler + 'static> SeatState<D> {
{
let Seat { arc } = self.new_seat(name);

let global_id = display.create_global::<D, _, _>(7, SeatGlobalData { arc: arc.clone() });
let global_id = display.create_global::<D, _, _>(8, SeatGlobalData { arc: arc.clone() });
arc.inner.lock().unwrap().global = Some(global_id);

Seat { arc }
Expand Down
Loading
Loading