1
0
Fork 0
forked from wry/wry

autocommit 2022-04-10 01:35:15 CEST

This commit is contained in:
Julian Orth 2022-04-10 01:35:15 +02:00
parent 21e2216ce5
commit befd5e99b2
22 changed files with 280 additions and 114 deletions

View file

@ -207,8 +207,6 @@ struct MetalInputDevice {
removed: Cell<bool>,
events: SyncQueue<InputEvent>,
cb: CloneCell<Option<Rc<dyn Fn()>>>,
hscroll: Cell<f64>,
vscroll: Cell<f64>,
name: CloneCell<Rc<String>>,
// state

View file

@ -1,7 +1,7 @@
use {
crate::{
async_engine::FdStatus,
backend::{InputEvent, KeyState, ScrollAxis},
backend::{AxisSource, InputEvent, KeyState, ScrollAxis},
backends::metal::MetalBackend,
libinput::{
consts::{
@ -81,7 +81,15 @@ impl MetalBackend {
c::LIBINPUT_EVENT_KEYBOARD_KEY => self.handle_keyboard_key(event),
c::LIBINPUT_EVENT_POINTER_MOTION => self.handle_pointer_motion(event),
c::LIBINPUT_EVENT_POINTER_BUTTON => self.handle_pointer_button(event),
c::LIBINPUT_EVENT_POINTER_SCROLL_WHEEL => self.handle_pointer_scroll_wheel(event),
c::LIBINPUT_EVENT_POINTER_SCROLL_WHEEL => {
self.handle_pointer_axis(event, AxisSource::Wheel)
}
c::LIBINPUT_EVENT_POINTER_SCROLL_FINGER => {
self.handle_pointer_axis(event, AxisSource::Finger)
}
c::LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS => {
self.handle_pointer_axis(event, AxisSource::Continuous)
}
_ => {}
}
}
@ -112,33 +120,38 @@ impl MetalBackend {
dev.event(InputEvent::Key(event.key(), state));
}
fn handle_pointer_scroll_wheel(self: &Rc<Self>, event: LibInputEvent) {
fn handle_pointer_axis(self: &Rc<Self>, event: LibInputEvent, source: AxisSource) {
const PX_PER_SCROLL: f64 = 15.0;
const ONE_TWENTRY: f64 = 120.0;
let (event, dev) = unpack!(self, event, pointer_event);
let axes = [
(
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
&dev.hscroll,
ScrollAxis::Horizontal,
),
(
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
&dev.vscroll,
ScrollAxis::Vertical,
),
(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, ScrollAxis::Vertical),
];
for (axis, val, sa) in axes {
dev.event(InputEvent::AxisSource(source));
for (axis, sa) in axes {
if !event.has_axis(axis) {
continue;
}
let scroll = event.scroll_value_v120(axis) / ONE_TWENTRY + val.get();
let scroll_used = (PX_PER_SCROLL * scroll).round();
val.set(scroll - scroll_used / PX_PER_SCROLL);
if scroll_used != 0.0 {
dev.event(InputEvent::Scroll(scroll_used as i32, sa));
let mut scroll = match source {
AxisSource::Wheel => event.scroll_value_v120(axis),
_ => event.scroll_value(axis),
};
if scroll == 0.0 {
dev.event(InputEvent::AxisStop(sa));
} else {
if source == AxisSource::Wheel {
let scroll_discrete = scroll / ONE_TWENTRY;
dev.event(InputEvent::AxisDiscrete(scroll_discrete as _, sa));
scroll = PX_PER_SCROLL * scroll_discrete;
}
dev.event(InputEvent::Axis(scroll.into(), sa));
}
}
dev.event(InputEvent::Frame);
}
fn handle_pointer_button(self: &Rc<Self>, event: LibInputEvent) {

View file

@ -286,8 +286,6 @@ impl MetalBackend {
removed: Cell::new(false),
events: Default::default(),
cb: Default::default(),
hscroll: Cell::new(0.0),
vscroll: Cell::new(0.0),
name: Default::default(),
pressed_keys: Default::default(),
pressed_buttons: Default::default(),

View file

@ -2,9 +2,9 @@ use {
crate::{
async_engine::{Phase, SpawnedFuture},
backend::{
Backend, BackendEvent, Connector, ConnectorEvent, ConnectorId, ConnectorKernelId,
InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId, InputEvent,
KeyState, Mode, MonitorInfo, ScrollAxis,
AxisSource, Backend, BackendEvent, Connector, ConnectorEvent, ConnectorId,
ConnectorKernelId, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
InputDeviceId, InputEvent, KeyState, Mode, MonitorInfo, ScrollAxis,
},
fixed::Fixed,
format::XRGB8888,
@ -721,13 +721,16 @@ impl XBackendData {
if matches!(button, 4..=7) {
if state == KeyState::Pressed {
let (axis, val) = match button {
4 => (ScrollAxis::Vertical, -15),
5 => (ScrollAxis::Vertical, 15),
6 => (ScrollAxis::Horizontal, -15),
7 => (ScrollAxis::Horizontal, 15),
4 => (ScrollAxis::Vertical, -1),
5 => (ScrollAxis::Vertical, 1),
6 => (ScrollAxis::Horizontal, -1),
7 => (ScrollAxis::Horizontal, 1),
_ => unreachable!(),
};
seat.mouse_event(InputEvent::Scroll(val, axis));
seat.mouse_event(InputEvent::AxisSource(AxisSource::Wheel));
seat.mouse_event(InputEvent::AxisDiscrete(val, axis));
seat.mouse_event(InputEvent::Axis(Fixed::from_int(val * 15), axis));
seat.mouse_event(InputEvent::Frame);
}
} else {
const BTN_LEFT: u32 = 0x110;