1
0
Fork 0
forked from wry/wry

wayland: implement wl_seat v8

This commit is contained in:
Julian Orth 2022-05-27 15:39:48 +02:00
parent 145e4dbc24
commit 50c87d6da7
10 changed files with 111 additions and 80 deletions

View file

@ -3,7 +3,6 @@ use {
backend::{AxisSource, InputEvent, KeyState, ScrollAxis},
backends::metal::MetalBackend,
fixed::Fixed,
ifs::wl_seat::PX_PER_SCROLL,
libinput::{
consts::{
LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_KEY_STATE_PRESSED,
@ -127,7 +126,6 @@ impl MetalBackend {
}
fn handle_pointer_axis(self: &Rc<Self>, event: LibInputEvent, source: AxisSource) {
const ONE_TWENTRY: f64 = 120.0;
let (event, dev) = unpack!(self, event, pointer_event);
let axes = [
(
@ -137,30 +135,28 @@ impl MetalBackend {
(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, ScrollAxis::Vertical),
];
dev.event(InputEvent::AxisSource { source });
for (axis, sa) in axes {
if !event.has_axis(axis) {
for (pointer_axis, axis) in axes {
if !event.has_axis(pointer_axis) {
continue;
}
let mut scroll = match source {
AxisSource::Wheel => event.scroll_value_v120(axis),
_ => event.scroll_value(axis),
let scroll = match source {
AxisSource::Wheel => event.scroll_value_v120(pointer_axis),
_ => event.scroll_value(pointer_axis),
};
if scroll == 0.0 {
dev.event(InputEvent::AxisStop { axis: sa });
} else {
if source == AxisSource::Wheel {
let scroll_discrete = scroll / ONE_TWENTRY;
dev.event(InputEvent::AxisDiscrete {
dist: scroll_discrete as _,
axis: sa,
});
scroll = PX_PER_SCROLL * scroll_discrete;
let ie = if scroll == 0.0 {
InputEvent::AxisStop { axis }
} else if source == AxisSource::Wheel {
InputEvent::Axis120 {
dist: scroll as _,
axis,
}
dev.event(InputEvent::Axis {
} else {
InputEvent::AxisSmooth {
dist: Fixed::from_f64(scroll),
axis: sa,
});
}
axis,
}
};
dev.event(ie);
}
dev.event(InputEvent::AxisFrame {
time_usec: event.time_usec(),

View file

@ -5,11 +5,10 @@ use {
AxisSource, Backend, BackendEvent, Connector, ConnectorEvent, ConnectorId,
ConnectorKernelId, DrmDeviceId, InputDevice, InputDeviceAccelProfile,
InputDeviceCapability, InputDeviceId, InputEvent, KeyState, Mode, MonitorInfo,
ScrollAxis, TransformMatrix,
ScrollAxis, TransformMatrix, AXIS_120,
},
fixed::Fixed,
format::XRGB8888,
ifs::wl_seat::PX_PER_SCROLL,
render::{Framebuffer, RenderContext, RenderError, RenderResult, Texture},
state::State,
time::now_usec,
@ -765,9 +764,8 @@ impl XBackend {
seat.mouse_event(InputEvent::AxisSource {
source: AxisSource::Wheel,
});
seat.mouse_event(InputEvent::AxisDiscrete { dist: val, axis });
seat.mouse_event(InputEvent::Axis {
dist: Fixed::from_f64(val as f64 * PX_PER_SCROLL),
seat.mouse_event(InputEvent::Axis120 {
dist: val * AXIS_120,
axis,
});
seat.mouse_event(InputEvent::AxisFrame {