autocommit 2022-03-11 23:07:09 CET
This commit is contained in:
parent
eb1d500561
commit
21527b3e38
5 changed files with 53 additions and 11 deletions
|
|
@ -172,6 +172,8 @@ struct MetalInputDevice {
|
|||
removed: Cell<bool>,
|
||||
events: SyncQueue<InputEvent>,
|
||||
cb: CloneCell<Option<Rc<dyn Fn()>>>,
|
||||
hscroll: Cell<f64>,
|
||||
vscroll: Cell<f64>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::async_engine::FdStatus;
|
||||
use crate::backend::{InputEvent, KeyState};
|
||||
use crate::libinput::consts::LIBINPUT_KEY_STATE_PRESSED;
|
||||
use crate::backend::{InputEvent, KeyState, ScrollAxis};
|
||||
use crate::libinput::consts::{LIBINPUT_BUTTON_STATE_PRESSED, LIBINPUT_KEY_STATE_PRESSED, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL};
|
||||
use crate::libinput::event::LibInputEvent;
|
||||
use crate::metal::MetalBackend;
|
||||
use crate::ErrorFmt;
|
||||
|
|
@ -71,6 +71,8 @@ impl MetalBackend {
|
|||
c::LIBINPUT_EVENT_DEVICE_REMOVED => self.handle_li_device_removed(event),
|
||||
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),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -95,6 +97,34 @@ impl MetalBackend {
|
|||
dev.event(InputEvent::Key(event.key(), state));
|
||||
}
|
||||
|
||||
fn handle_pointer_scroll_wheel(self: &Rc<Self>, event: LibInputEvent) {
|
||||
const PX_PER_SCROLL: f64 = 15.0;
|
||||
const ONE_TWENTRY: f64 = 120.0;
|
||||
let (event, dev) = unpack!(self, event, pointer_event);
|
||||
let hscroll = event.scroll_value_v120(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) / ONE_TWENTRY + dev.hscroll.get();
|
||||
let vscroll = event.scroll_value_v120(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL) / ONE_TWENTRY + dev.vscroll.get();
|
||||
let hscroll_used = (PX_PER_SCROLL * hscroll).round();
|
||||
let vscroll_used = (PX_PER_SCROLL * vscroll).round();
|
||||
dev.hscroll.set(hscroll - hscroll_used / PX_PER_SCROLL);
|
||||
dev.vscroll.set(vscroll - vscroll_used / PX_PER_SCROLL);
|
||||
if hscroll_used != 0.0 {
|
||||
dev.event(InputEvent::Scroll(hscroll_used as i32, ScrollAxis::Horizontal));
|
||||
}
|
||||
if vscroll_used != 0.0 {
|
||||
dev.event(InputEvent::Scroll(vscroll_used as i32, ScrollAxis::Vertical));
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_pointer_button(self: &Rc<Self>, event: LibInputEvent) {
|
||||
let (event, dev) = unpack!(self, event, pointer_event);
|
||||
let state = if event.button_state() == LIBINPUT_BUTTON_STATE_PRESSED {
|
||||
KeyState::Pressed
|
||||
} else {
|
||||
KeyState::Released
|
||||
};
|
||||
dev.event(InputEvent::Button(event.button(), state));
|
||||
}
|
||||
|
||||
fn handle_pointer_motion(self: &Rc<Self>, event: LibInputEvent) {
|
||||
let (event, dev) = unpack!(self, event, pointer_event);
|
||||
dev.event(InputEvent::Motion(event.dx().into(), event.dy().into()));
|
||||
|
|
|
|||
|
|
@ -274,6 +274,8 @@ impl MetalBackend {
|
|||
removed: Cell::new(false),
|
||||
events: Default::default(),
|
||||
cb: Default::default(),
|
||||
hscroll: Cell::new(0.0),
|
||||
vscroll: Cell::new(0.0),
|
||||
});
|
||||
slots[slot] = Some(dev.clone());
|
||||
self.device_holder
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue