autocommit 2022-03-30 22:27:19 CEST
This commit is contained in:
parent
a8136ed88c
commit
ab4ac883ee
19 changed files with 434 additions and 76 deletions
|
|
@ -3,11 +3,19 @@ mod monitor;
|
|||
mod video;
|
||||
|
||||
use crate::async_engine::{AsyncError, AsyncFd};
|
||||
use crate::backend::{Backend, InputDevice, InputDeviceCapability, InputDeviceId, InputEvent};
|
||||
use crate::backend::{
|
||||
Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId, InputEvent,
|
||||
};
|
||||
use crate::backends::metal::video::{MetalDrmDevice, PendingDrmDevice};
|
||||
use crate::dbus::DbusError;
|
||||
use crate::drm::drm::DrmError;
|
||||
use crate::drm::gbm::GbmError;
|
||||
use crate::libinput::consts::{
|
||||
AccelProfile, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE, LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT,
|
||||
LIBINPUT_DEVICE_CAP_GESTURE, LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER,
|
||||
LIBINPUT_DEVICE_CAP_SWITCH, LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_TABLET_TOOL,
|
||||
LIBINPUT_DEVICE_CAP_TOUCH,
|
||||
};
|
||||
use crate::libinput::device::RegisteredDevice;
|
||||
use crate::libinput::{LibInput, LibInputAdapter, LibInputError};
|
||||
use crate::logind::{LogindError, Session};
|
||||
|
|
@ -25,7 +33,6 @@ use std::future::pending;
|
|||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::{c, OwnedFd};
|
||||
use crate::libinput::consts::{LIBINPUT_DEVICE_CAP_GESTURE, LIBINPUT_DEVICE_CAP_KEYBOARD, LIBINPUT_DEVICE_CAP_POINTER, LIBINPUT_DEVICE_CAP_SWITCH, LIBINPUT_DEVICE_CAP_TABLET_PAD, LIBINPUT_DEVICE_CAP_TABLET_TOOL, LIBINPUT_DEVICE_CAP_TOUCH};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum MetalError {
|
||||
|
|
@ -189,6 +196,12 @@ struct MetalInputDevice {
|
|||
cb: CloneCell<Option<Rc<dyn Fn()>>>,
|
||||
hscroll: Cell<f64>,
|
||||
vscroll: Cell<f64>,
|
||||
|
||||
// config
|
||||
left_handed: Cell<Option<bool>>,
|
||||
accel_profile: Cell<Option<AccelProfile>>,
|
||||
accel_speed: Cell<Option<f64>>,
|
||||
transform_matrix: Cell<Option<[[f64; 2]; 2]>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -223,6 +236,24 @@ impl LibInputAdapter for DeviceHolder {
|
|||
}
|
||||
}
|
||||
|
||||
impl MetalInputDevice {
|
||||
fn apply_config(&self) {
|
||||
let dev = match self.inputdev.get() {
|
||||
Some(dev) => dev,
|
||||
_ => return,
|
||||
};
|
||||
if let Some(lh) = self.left_handed.get() {
|
||||
dev.device().set_left_handed(lh);
|
||||
}
|
||||
if let Some(profile) = self.accel_profile.get() {
|
||||
dev.device().set_accel_profile(profile);
|
||||
}
|
||||
if let Some(speed) = self.accel_speed.get() {
|
||||
dev.device().set_accel_speed(speed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InputDevice for MetalInputDevice {
|
||||
fn id(&self) -> InputDeviceId {
|
||||
self.id
|
||||
|
|
@ -259,6 +290,35 @@ impl InputDevice for MetalInputDevice {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_left_handed(&self, left_handed: bool) {
|
||||
self.left_handed.set(Some(left_handed));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_left_handed(left_handed);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_accel_profile(&self, profile: InputDeviceAccelProfile) {
|
||||
let profile = match profile {
|
||||
InputDeviceAccelProfile::Flat => LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT,
|
||||
InputDeviceAccelProfile::Adaptive => LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE,
|
||||
};
|
||||
self.accel_profile.set(Some(profile));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_accel_profile(profile);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_accel_speed(&self, speed: f64) {
|
||||
self.accel_speed.set(Some(speed));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_accel_speed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_transform_matrix(&self, matrix: [[f64; 2]; 2]) {
|
||||
self.transform_matrix.set(Some(matrix));
|
||||
}
|
||||
}
|
||||
|
||||
impl MetalInputDevice {
|
||||
|
|
|
|||
|
|
@ -104,26 +104,28 @@ impl MetalBackend {
|
|||
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,
|
||||
let axes = [
|
||||
(
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
|
||||
&dev.hscroll,
|
||||
ScrollAxis::Horizontal,
|
||||
));
|
||||
}
|
||||
if vscroll_used != 0.0 {
|
||||
dev.event(InputEvent::Scroll(
|
||||
vscroll_used as i32,
|
||||
),
|
||||
(
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
|
||||
&dev.vscroll,
|
||||
ScrollAxis::Vertical,
|
||||
));
|
||||
),
|
||||
];
|
||||
for (axis, val, 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -139,6 +141,12 @@ impl MetalBackend {
|
|||
|
||||
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()));
|
||||
let mut dx = event.dx();
|
||||
let mut dy = event.dy();
|
||||
if let Some(matrix) = dev.transform_matrix.get() {
|
||||
dx = matrix[0][0] * dx + matrix[0][1] * dy;
|
||||
dy = matrix[1][0] * dx + matrix[1][1] * dy;
|
||||
}
|
||||
dev.event(InputEvent::Motion(dx.into(), dy.into()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ impl MetalBackend {
|
|||
};
|
||||
inputdev.device().set_slot(dev.slot);
|
||||
dev.inputdev.set(Some(inputdev));
|
||||
dev.apply_config();
|
||||
}
|
||||
|
||||
fn handle_device_removed(self: &Rc<Self>, dev: c::dev_t) {
|
||||
|
|
@ -280,6 +281,10 @@ impl MetalBackend {
|
|||
cb: Default::default(),
|
||||
hscroll: Cell::new(0.0),
|
||||
vscroll: Cell::new(0.0),
|
||||
left_handed: Default::default(),
|
||||
accel_profile: Default::default(),
|
||||
accel_speed: Default::default(),
|
||||
transform_matrix: Default::default(),
|
||||
});
|
||||
slots[slot] = Some(dev.clone());
|
||||
self.device_holder
|
||||
|
|
@ -319,6 +324,7 @@ impl MetalBackend {
|
|||
};
|
||||
inputdev.device().set_slot(slot);
|
||||
dev.inputdev.set(Some(inputdev));
|
||||
dev.apply_config();
|
||||
slf.state
|
||||
.backend_events
|
||||
.push(BackendEvent::NewInputDevice(dev.clone()));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
use crate::async_engine::{Phase, SpawnedFuture};
|
||||
use crate::backend::{Backend, BackendEvent, InputDevice, InputDeviceCapability, InputDeviceId, InputEvent, KeyState, Output, OutputId, ScrollAxis};
|
||||
use crate::backend::{
|
||||
Backend, BackendEvent, InputDevice, InputDeviceAccelProfile, InputDeviceCapability,
|
||||
InputDeviceId, InputEvent, KeyState, Output, OutputId, ScrollAxis,
|
||||
};
|
||||
use crate::drm::drm::{Drm, DrmError};
|
||||
use crate::drm::gbm::{GbmDevice, GbmError, GBM_BO_USE_RENDERING};
|
||||
use crate::drm::{ModifiedFormat, INVALID_MODIFIER};
|
||||
|
|
@ -963,6 +966,22 @@ impl InputDevice for XSeatKeyboard {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_left_handed(&self, left_handed: bool) {
|
||||
let _ = left_handed;
|
||||
}
|
||||
|
||||
fn set_accel_profile(&self, profile: InputDeviceAccelProfile) {
|
||||
let _ = profile;
|
||||
}
|
||||
|
||||
fn set_accel_speed(&self, speed: f64) {
|
||||
let _ = speed;
|
||||
}
|
||||
|
||||
fn set_transform_matrix(&self, matrix: [[f64; 2]; 2]) {
|
||||
let _ = matrix;
|
||||
}
|
||||
}
|
||||
|
||||
impl InputDevice for XSeatMouse {
|
||||
|
|
@ -992,4 +1011,20 @@ impl InputDevice for XSeatMouse {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn set_left_handed(&self, left_handed: bool) {
|
||||
let _ = left_handed;
|
||||
}
|
||||
|
||||
fn set_accel_profile(&self, profile: InputDeviceAccelProfile) {
|
||||
let _ = profile;
|
||||
}
|
||||
|
||||
fn set_accel_speed(&self, speed: f64) {
|
||||
let _ = speed;
|
||||
}
|
||||
|
||||
fn set_transform_matrix(&self, matrix: [[f64; 2]; 2]) {
|
||||
let _ = matrix;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue