autocommit 2022-03-09 14:01:21 CET
This commit is contained in:
parent
aa0cb94143
commit
4df6b559b7
32 changed files with 1121 additions and 172 deletions
152
src/libinput/consts.rs
Normal file
152
src/libinput/consts.rs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
cenum! {
|
||||
LogPriority, LIBINPUT_LOG_PRIORITY;
|
||||
|
||||
LIBINPUT_LOG_PRIORITY_DEBUG = 10,
|
||||
LIBINPUT_LOG_PRIORITY_INFO = 20,
|
||||
LIBINPUT_LOG_PRIORITY_ERROR = 30,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
DeviceCapability, LIBINPUT_DEVICE_CAPABILITY;
|
||||
|
||||
LIBINPUT_DEVICE_CAP_KEYBOARD = 0,
|
||||
LIBINPUT_DEVICE_CAP_POINTER = 1,
|
||||
LIBINPUT_DEVICE_CAP_TOUCH = 2,
|
||||
LIBINPUT_DEVICE_CAP_TABLET_TOOL = 3,
|
||||
LIBINPUT_DEVICE_CAP_TABLET_PAD = 4,
|
||||
LIBINPUT_DEVICE_CAP_GESTURE = 5,
|
||||
LIBINPUT_DEVICE_CAP_SWITCH = 6,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
KeyState, LIBINPUT_KEY_STATE;
|
||||
|
||||
LIBINPUT_KEY_STATE_RELEASED = 0,
|
||||
LIBINPUT_KEY_STATE_PRESSED = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
Led, LIBINPUT_LED;
|
||||
|
||||
LIBINPUT_LED_NUM_LOCK = 1 << 0,
|
||||
LIBINPUT_LED_CAPS_LOCK = 1 << 1,
|
||||
LIBINPUT_LED_SCROLL_LOCK = 1 << 2,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
ButtonState, LIBINPUT_BUTTON_STATE;
|
||||
|
||||
LIBINPUT_BUTTON_STATE_RELEASED = 0,
|
||||
LIBINPUT_BUTTON_STATE_PRESSED = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
PointerAxis, LIBINPUT_POINTER_AXIS;
|
||||
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL = 0,
|
||||
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
PointerAxisSource, LIBINPUT_POINTER_AXIS_SOURCE;
|
||||
|
||||
LIBINPUT_POINTER_AXIS_SOURCE_WHEEL = 1,
|
||||
LIBINPUT_POINTER_AXIS_SOURCE_FINGER = 2,
|
||||
LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS = 3,
|
||||
LIBINPUT_POINTER_AXIS_SOURCE_WHEEL_TILT = 4,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
TabletPadRingAxisSource, LIBINPUT_TABLET_PAD_RING_AXIS_SOURCE;
|
||||
|
||||
LIBINPUT_TABLET_PAD_RING_SOURCE_UNKNOWN = 1,
|
||||
LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER = 2,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
TabletPadStripAxisSource, LIBINPUT_TABLET_PAD_STRIP_AXIS_SOURCE;
|
||||
|
||||
LIBINPUT_TABLET_PAD_STRIP_SOURCE_UNKNOWN = 1,
|
||||
LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER = 2,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
TabletToolType, LIBINPUT_TABLET_TOOL_TYPE;
|
||||
|
||||
LIBINPUT_TABLET_TOOL_TYPE_PEN = 1,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_ERASER = 2,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_BRUSH = 3,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_PENCIL = 4,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH = 5,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_MOUSE = 6,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_LENS = 7,
|
||||
LIBINPUT_TABLET_TOOL_TYPE_TOTEM = 8,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
TabletToolProximityState, LIBINPUT_TABLET_TOOL_PROXIMITY_STATE;
|
||||
|
||||
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT = 0,
|
||||
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
TabletToolTipState, LIBINPUT_TABLET_TOOL_TIP_STATE;
|
||||
|
||||
LIBINPUT_TABLET_TOOL_TIP_UP = 0,
|
||||
LIBINPUT_TABLET_TOOL_TIP_DOWN = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
SwitchState, LIBINPUT_SWITCH_STATE;
|
||||
|
||||
LIBINPUT_SWITCH_STATE_OFF = 0,
|
||||
LIBINPUT_SWITCH_STATE_ON = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
Switch, LIBINPUT_SWITCH;
|
||||
|
||||
LIBINPUT_SWITCH_LID = 1,
|
||||
LIBINPUT_SWITCH_TABLET_MODE = 2,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
EventType, LIBINPUT_EVENT_TYPE;
|
||||
|
||||
LIBINPUT_EVENT_NONE = 0,
|
||||
LIBINPUT_EVENT_DEVICE_ADDED = 1,
|
||||
LIBINPUT_EVENT_DEVICE_REMOVED = 2,
|
||||
LIBINPUT_EVENT_KEYBOARD_KEY = 300,
|
||||
LIBINPUT_EVENT_POINTER_MOTION = 400,
|
||||
LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE = 401,
|
||||
LIBINPUT_EVENT_POINTER_BUTTON = 402,
|
||||
LIBINPUT_EVENT_POINTER_AXIS = 403,
|
||||
LIBINPUT_EVENT_POINTER_SCROLL_WHEEL = 404,
|
||||
LIBINPUT_EVENT_POINTER_SCROLL_FINGER = 405,
|
||||
LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS = 406,
|
||||
LIBINPUT_EVENT_TOUCH_DOWN = 500,
|
||||
LIBINPUT_EVENT_TOUCH_UP = 501,
|
||||
LIBINPUT_EVENT_TOUCH_MOTION = 502,
|
||||
LIBINPUT_EVENT_TOUCH_CANCEL = 503,
|
||||
LIBINPUT_EVENT_TOUCH_FRAME = 504,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS = 600,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY = 601,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP = 602,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_BUTTON = 603,
|
||||
LIBINPUT_EVENT_TABLET_PAD_BUTTON = 700,
|
||||
LIBINPUT_EVENT_TABLET_PAD_RING = 701,
|
||||
LIBINPUT_EVENT_TABLET_PAD_STRIP = 702,
|
||||
LIBINPUT_EVENT_TABLET_PAD_KEY = 703,
|
||||
LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800,
|
||||
LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE = 801,
|
||||
LIBINPUT_EVENT_GESTURE_SWIPE_END = 802,
|
||||
LIBINPUT_EVENT_GESTURE_PINCH_BEGIN = 803,
|
||||
LIBINPUT_EVENT_GESTURE_PINCH_UPDATE = 804,
|
||||
LIBINPUT_EVENT_GESTURE_PINCH_END = 805,
|
||||
LIBINPUT_EVENT_GESTURE_HOLD_BEGIN = 806,
|
||||
LIBINPUT_EVENT_GESTURE_HOLD_END = 807,
|
||||
LIBINPUT_EVENT_SWITCH_TOGGLE = 900,
|
||||
}
|
||||
51
src/libinput/device.rs
Normal file
51
src/libinput/device.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use crate::libinput::sys::{
|
||||
libinput_device, libinput_device_set_user_data, libinput_device_unref,
|
||||
libinput_path_remove_device,
|
||||
};
|
||||
use crate::libinput::LibInput;
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct LibInputDevice<'a> {
|
||||
pub(super) dev: *mut libinput_device,
|
||||
pub(super) _phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
pub struct RegisteredDevice {
|
||||
pub(super) li: Rc<LibInput>,
|
||||
pub(super) dev: *mut libinput_device,
|
||||
}
|
||||
|
||||
impl<'a> LibInputDevice<'a> {
|
||||
pub fn set_slot(&self, slot: usize) {
|
||||
self.set_slot_(slot + 1)
|
||||
}
|
||||
|
||||
pub fn unset_slot(&self) {
|
||||
self.set_slot_(0)
|
||||
}
|
||||
|
||||
fn set_slot_(&self, slot: usize) {
|
||||
unsafe {
|
||||
libinput_device_set_user_data(self.dev, slot as _);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RegisteredDevice {
|
||||
pub fn device(&self) -> LibInputDevice {
|
||||
LibInputDevice {
|
||||
dev: self.dev,
|
||||
_phantom: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RegisteredDevice {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
libinput_path_remove_device(self.dev);
|
||||
libinput_device_unref(self.dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
src/libinput/event.rs
Normal file
66
src/libinput/event.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
use crate::libinput::consts::{EventType, KeyState};
|
||||
use crate::libinput::device::LibInputDevice;
|
||||
use crate::libinput::sys::{
|
||||
libinput_event, libinput_event_destroy, libinput_event_get_device,
|
||||
libinput_event_get_keyboard_event, libinput_event_get_type, libinput_event_keyboard,
|
||||
libinput_event_keyboard_get_key, libinput_event_keyboard_get_key_state,
|
||||
libinput_event_keyboard_get_time_usec,
|
||||
};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct LibInputEvent<'a> {
|
||||
pub(super) event: *mut libinput_event,
|
||||
pub(super) _phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
pub struct LibInputEventKeyboard<'a> {
|
||||
pub(super) event: *mut libinput_event_keyboard,
|
||||
pub(super) _phantom: PhantomData<&'a ()>,
|
||||
}
|
||||
|
||||
impl<'a> Drop for LibInputEvent<'a> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
libinput_event_destroy(self.event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LibInputEvent<'a> {
|
||||
pub fn ty(&self) -> EventType {
|
||||
unsafe { EventType(libinput_event_get_type(self.event)) }
|
||||
}
|
||||
|
||||
pub fn device(&self) -> LibInputDevice {
|
||||
LibInputDevice {
|
||||
dev: unsafe { libinput_event_get_device(self.event) },
|
||||
_phantom: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn keyboard_event(&self) -> Option<LibInputEventKeyboard> {
|
||||
let res = unsafe { libinput_event_get_keyboard_event(self.event) };
|
||||
if res.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(LibInputEventKeyboard {
|
||||
event: res,
|
||||
_phantom: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> LibInputEventKeyboard<'a> {
|
||||
pub fn key(&self) -> u32 {
|
||||
unsafe { libinput_event_keyboard_get_key(self.event) }
|
||||
}
|
||||
|
||||
pub fn key_state(&self) -> KeyState {
|
||||
unsafe { KeyState(libinput_event_keyboard_get_key_state(self.event)) }
|
||||
}
|
||||
|
||||
pub fn time_usec(&self) -> u64 {
|
||||
unsafe { libinput_event_keyboard_get_time_usec(self.event) }
|
||||
}
|
||||
}
|
||||
64
src/libinput/sys.rs
Normal file
64
src/libinput/sys.rs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
use std::ffi::VaList;
|
||||
use uapi::c;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/libinput_tys.rs"));
|
||||
|
||||
pub type libinput_log_handler = unsafe extern "C" fn(
|
||||
libinput: *mut libinput,
|
||||
priority: libinput_log_priority,
|
||||
format: *const c::c_char,
|
||||
args: VaList,
|
||||
);
|
||||
|
||||
#[link(name = "input")]
|
||||
extern "C" {
|
||||
pub type libinput;
|
||||
pub type libinput_device;
|
||||
pub type libinput_event;
|
||||
pub type libinput_event_keyboard;
|
||||
|
||||
pub fn libinput_log_set_handler(libinput: *mut libinput, log_handler: libinput_log_handler);
|
||||
pub fn libinput_log_set_priority(libinput: *mut libinput, priority: libinput_log_priority);
|
||||
pub fn libinput_path_create_context(
|
||||
interface: *const libinput_interface,
|
||||
user_data: *mut c::c_void,
|
||||
) -> *mut libinput;
|
||||
pub fn libinput_device_set_user_data(device: *mut libinput_device, user_data: *mut c::c_void);
|
||||
pub fn libinput_device_get_user_data(device: *mut libinput_device) -> *mut c::c_void;
|
||||
pub fn libinput_device_ref(device: *mut libinput_device) -> *mut libinput_device;
|
||||
pub fn libinput_device_unref(device: *mut libinput_device) -> *mut libinput_device;
|
||||
pub fn libinput_path_add_device(
|
||||
libinput: *mut libinput,
|
||||
path: *const c::c_char,
|
||||
) -> *mut libinput_device;
|
||||
pub fn libinput_path_remove_device(device: *mut libinput_device);
|
||||
pub fn libinput_unref(libinput: *mut libinput) -> *mut libinput;
|
||||
pub fn libinput_get_fd(libinput: *mut libinput) -> c::c_int;
|
||||
|
||||
pub fn libinput_dispatch(libinput: *mut libinput) -> c::c_int;
|
||||
|
||||
pub fn libinput_get_event(libinput: *mut libinput) -> *mut libinput_event;
|
||||
|
||||
pub fn libinput_event_destroy(event: *mut libinput_event);
|
||||
pub fn libinput_event_get_type(event: *mut libinput_event) -> libinput_event_type;
|
||||
pub fn libinput_event_get_device(event: *mut libinput_event) -> *mut libinput_device;
|
||||
pub fn libinput_event_get_keyboard_event(
|
||||
event: *mut libinput_event,
|
||||
) -> *mut libinput_event_keyboard;
|
||||
|
||||
pub fn libinput_event_keyboard_get_key(event: *mut libinput_event_keyboard) -> u32;
|
||||
pub fn libinput_event_keyboard_get_key_state(
|
||||
event: *mut libinput_event_keyboard,
|
||||
) -> libinput_key_state;
|
||||
pub fn libinput_event_keyboard_get_time_usec(event: *mut libinput_event_keyboard) -> u64;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct libinput_interface {
|
||||
pub open_restricted: unsafe extern "C" fn(
|
||||
path: *const c::c_char,
|
||||
flags: c::c_int,
|
||||
user_data: *mut c::c_void,
|
||||
) -> c::c_int,
|
||||
pub close_restricted: unsafe extern "C" fn(fd: c::c_int, user_data: *mut c::c_void),
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue