1
0
Fork 0
forked from wry/wry

tablet: implement version 2

This commit is contained in:
Julian Orth 2025-04-22 22:22:31 +02:00
parent 1d017ec2c2
commit dee0066f1a
25 changed files with 426 additions and 31 deletions

View file

@ -140,6 +140,7 @@ cenum! {
LIBINPUT_EVENT_TABLET_PAD_RING = 701,
LIBINPUT_EVENT_TABLET_PAD_STRIP = 702,
LIBINPUT_EVENT_TABLET_PAD_KEY = 703,
LIBINPUT_EVENT_TABLET_PAD_DIAL = 704,
LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN = 800,
LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE = 801,
LIBINPUT_EVENT_GESTURE_SWIPE_END = 802,

View file

@ -25,18 +25,19 @@ use {
libinput_device_config_tap_set_drag_enabled,
libinput_device_config_tap_set_drag_lock_enabled,
libinput_device_config_tap_set_enabled, libinput_device_get_device_group,
libinput_device_get_id_product, libinput_device_get_id_vendor,
libinput_device_get_name, libinput_device_get_user_data, libinput_device_group,
libinput_device_group_get_user_data, libinput_device_group_set_user_data,
libinput_device_has_capability, libinput_device_set_user_data,
libinput_device_tablet_pad_get_mode_group, libinput_device_tablet_pad_get_num_buttons,
libinput_device_get_id_bustype, libinput_device_get_id_product,
libinput_device_get_id_vendor, libinput_device_get_name, libinput_device_get_user_data,
libinput_device_group, libinput_device_group_get_user_data,
libinput_device_group_set_user_data, libinput_device_has_capability,
libinput_device_set_user_data, libinput_device_tablet_pad_get_mode_group,
libinput_device_tablet_pad_get_num_buttons, libinput_device_tablet_pad_get_num_dials,
libinput_device_tablet_pad_get_num_mode_groups,
libinput_device_tablet_pad_get_num_rings, libinput_device_tablet_pad_get_num_strips,
libinput_device_unref, libinput_path_remove_device, libinput_tablet_pad_mode_group,
libinput_tablet_pad_mode_group_get_index, libinput_tablet_pad_mode_group_get_mode,
libinput_tablet_pad_mode_group_get_num_modes,
libinput_tablet_pad_mode_group_has_button, libinput_tablet_pad_mode_group_has_ring,
libinput_tablet_pad_mode_group_has_strip,
libinput_tablet_pad_mode_group_has_button, libinput_tablet_pad_mode_group_has_dial,
libinput_tablet_pad_mode_group_has_ring, libinput_tablet_pad_mode_group_has_strip,
},
},
bstr::ByteSlice,
@ -223,6 +224,10 @@ impl<'a> LibInputDevice<'a> {
unsafe { libinput_device_get_id_vendor(self.dev) as u32 }
}
pub fn bustype(&self) -> Option<u32> {
libinput_device_get_id_bustype.map(|f| unsafe { f(self.dev) as u32 })
}
pub fn pad_num_buttons(&self) -> u32 {
match unsafe { libinput_device_tablet_pad_get_num_buttons(self.dev) } {
-1 => 0,
@ -244,6 +249,17 @@ impl<'a> LibInputDevice<'a> {
}
}
pub fn pad_num_dials(&self) -> u32 {
match unsafe {
libinput_device_tablet_pad_get_num_dials
.map(|f| f(self.dev))
.unwrap_or_default()
} {
-1 => 0,
n => n as u32,
}
}
pub fn pad_num_mode_groups(&self) -> u32 {
match unsafe { libinput_device_tablet_pad_get_num_mode_groups(self.dev) } {
-1 => 0,
@ -316,6 +332,15 @@ impl<'a> LibInputTabletPadModeGroup<'a> {
pub fn has_strip(&self, strip: u32) -> bool {
unsafe { libinput_tablet_pad_mode_group_has_strip(self.group, strip as _) != 0 }
}
pub fn has_dial(&self, dial: u32) -> bool {
unsafe {
libinput_tablet_pad_mode_group_has_dial
.map(|f| f(self.group, dial as _))
.unwrap_or_default()
!= 0
}
}
}
impl RegisteredDevice {

View file

@ -27,7 +27,9 @@ use {
libinput_event_switch, libinput_event_switch_get_switch,
libinput_event_switch_get_switch_state, libinput_event_switch_get_time_usec,
libinput_event_tablet_pad, libinput_event_tablet_pad_get_button_number,
libinput_event_tablet_pad_get_button_state, libinput_event_tablet_pad_get_mode,
libinput_event_tablet_pad_get_button_state,
libinput_event_tablet_pad_get_dial_delta_v120,
libinput_event_tablet_pad_get_dial_number, libinput_event_tablet_pad_get_mode,
libinput_event_tablet_pad_get_mode_group, libinput_event_tablet_pad_get_ring_number,
libinput_event_tablet_pad_get_ring_position, libinput_event_tablet_pad_get_ring_source,
libinput_event_tablet_pad_get_strip_number,
@ -459,6 +461,14 @@ impl<'a> LibInputEventTabletPad<'a> {
unsafe { TabletPadStripAxisSource(libinput_event_tablet_pad_get_strip_source(self.event)) }
}
pub fn dial_number(&self) -> Option<u32> {
libinput_event_tablet_pad_get_dial_number.map(|f| unsafe { f(self.event) as u32 })
}
pub fn dial_delta_v120(&self) -> Option<f64> {
libinput_event_tablet_pad_get_dial_delta_v120.map(|f| unsafe { f(self.event) })
}
pub fn button_number(&self) -> u32 {
unsafe { libinput_event_tablet_pad_get_button_number(self.event) }
}

View file

@ -1,4 +1,4 @@
use uapi::c;
use {libloading::os::unix::Library, std::sync::LazyLock, uapi::c};
include!(concat!(env!("OUT_DIR"), "/libinput_tys.rs"));
@ -393,3 +393,38 @@ pub struct libinput_interface {
) -> c::c_int,
pub close_restricted: unsafe extern "C" fn(fd: c::c_int, user_data: *mut c::c_void),
}
macro_rules! dynload {
(
$(
fn $name:ident($($arg:ident: $ty:ty),* $(,)?) -> $ret:ty;
)*
) => {
$(
#[expect(non_upper_case_globals)]
pub static $name: LazyLock<Option<unsafe extern "C" fn($($arg: $ty),*) -> $ret>> = LazyLock::new(|| {
unsafe {
Library::this()
.get(concat!(stringify!($name), "\0").as_bytes())
.ok()
.map(|sym| *sym)
}
});
)*
};
}
dynload! {
fn libinput_device_get_id_bustype(device: *mut libinput_device) -> c::c_uint;
fn libinput_event_tablet_pad_get_dial_delta_v120(event: *mut libinput_event_tablet_pad) -> f64;
fn libinput_event_tablet_pad_get_dial_number(event: *mut libinput_event_tablet_pad) -> c::c_uint;
fn libinput_device_tablet_pad_get_num_dials(device: *mut libinput_device) -> c::c_int;
fn libinput_tablet_pad_mode_group_has_dial(
group: *mut libinput_tablet_pad_mode_group,
dial: c::c_uint,
) -> c::c_int;
}