autocommit 2022-04-02 00:31:30 CEST
This commit is contained in:
parent
2dd433aa04
commit
6ad6d83b7e
34 changed files with 446 additions and 161 deletions
|
|
@ -3,9 +3,7 @@ mod monitor;
|
|||
mod video;
|
||||
|
||||
use crate::async_engine::{AsyncError, AsyncFd};
|
||||
use crate::backend::{
|
||||
Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId, InputEvent,
|
||||
};
|
||||
use crate::backend::{Backend, InputDevice, InputDeviceAccelProfile, InputDeviceCapability, InputDeviceId, InputEvent, KeyState};
|
||||
use crate::backends::metal::video::{MetalDrmDevice, PendingDrmDevice};
|
||||
use crate::dbus::DbusError;
|
||||
use crate::drm::drm::DrmError;
|
||||
|
|
@ -30,9 +28,11 @@ use crate::utils::syncqueue::SyncQueue;
|
|||
use std::cell::{Cell, RefCell};
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::future::pending;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use thiserror::Error;
|
||||
use uapi::{c, OwnedFd};
|
||||
use crate::utils::smallmap::SmallMap;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum MetalError {
|
||||
|
|
@ -198,6 +198,10 @@ struct MetalInputDevice {
|
|||
vscroll: Cell<f64>,
|
||||
name: CloneCell<Rc<String>>,
|
||||
|
||||
// state
|
||||
pressed_keys: SmallMap<u32, (), 5>,
|
||||
pressed_buttons: SmallMap<u32, (), 2>,
|
||||
|
||||
// config
|
||||
left_handed: Cell<Option<bool>>,
|
||||
accel_profile: Cell<Option<AccelProfile>>,
|
||||
|
|
@ -205,6 +209,14 @@ struct MetalInputDevice {
|
|||
transform_matrix: Cell<Option<[[f64; 2]; 2]>>,
|
||||
}
|
||||
|
||||
impl Drop for MetalInputDevice {
|
||||
fn drop(&mut self) {
|
||||
if let Some(fd) = self.fd.take() {
|
||||
mem::forget(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
enum MetalDevice {
|
||||
Input(Rc<MetalInputDevice>),
|
||||
|
|
@ -250,6 +262,15 @@ impl MetalInputDevice {
|
|||
dev.device().set_accel_speed(speed);
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_pause(&self) {
|
||||
for (key, _) in self.pressed_keys.take() {
|
||||
self.event(InputEvent::Key(key, KeyState::Released));
|
||||
}
|
||||
for (button, _) in self.pressed_buttons.take() {
|
||||
self.event(InputEvent::Button(button, KeyState::Released));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InputDevice for MetalInputDevice {
|
||||
|
|
|
|||
|
|
@ -93,8 +93,14 @@ impl MetalBackend {
|
|||
fn handle_keyboard_key(self: &Rc<Self>, event: LibInputEvent) {
|
||||
let (event, dev) = unpack!(self, event, keyboard_event);
|
||||
let state = if event.key_state() == LIBINPUT_KEY_STATE_PRESSED {
|
||||
if dev.pressed_keys.insert(event.key(), ()).is_some() {
|
||||
return;
|
||||
}
|
||||
KeyState::Pressed
|
||||
} else {
|
||||
if dev.pressed_keys.remove(&event.key()).is_none() {
|
||||
return;
|
||||
}
|
||||
KeyState::Released
|
||||
};
|
||||
dev.event(InputEvent::Key(event.key(), state));
|
||||
|
|
@ -132,8 +138,14 @@ impl MetalBackend {
|
|||
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 {
|
||||
if dev.pressed_buttons.insert(event.button(), ()).is_some() {
|
||||
return;
|
||||
}
|
||||
KeyState::Pressed
|
||||
} else {
|
||||
if dev.pressed_buttons.remove(&event.button()).is_none() {
|
||||
return;
|
||||
}
|
||||
KeyState::Released
|
||||
};
|
||||
dev.event(InputEvent::Button(event.button(), state));
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ impl MetalBackend {
|
|||
}
|
||||
|
||||
fn handle_input_device_removed(self: &Rc<Self>, dev: &Rc<MetalInputDevice>) {
|
||||
dev.pre_pause();
|
||||
log::info!("Device removed: {}", dev.devnode.to_bytes().as_bstr());
|
||||
self.device_holder.input_devices.borrow_mut()[dev.slot] = None;
|
||||
dev.fd.set(None);
|
||||
|
|
@ -148,6 +149,7 @@ impl MetalBackend {
|
|||
|
||||
fn handle_input_device_paused(self: &Rc<Self>, dev: &Rc<MetalInputDevice>) {
|
||||
log::info!("Device paused: {}", dev.devnode.to_bytes().as_bstr());
|
||||
dev.pre_pause();
|
||||
if let Some(rd) = dev.inputdev.take() {
|
||||
rd.device().unset_slot();
|
||||
}
|
||||
|
|
@ -282,6 +284,8 @@ impl MetalBackend {
|
|||
hscroll: Cell::new(0.0),
|
||||
vscroll: Cell::new(0.0),
|
||||
name: Default::default(),
|
||||
pressed_keys: Default::default(),
|
||||
pressed_buttons: Default::default(),
|
||||
left_handed: Default::default(),
|
||||
accel_profile: Default::default(),
|
||||
accel_speed: Default::default(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue