metal,config: allow enabling tap-to-click
This commit is contained in:
parent
59445dd875
commit
6cc97ee56e
13 changed files with 293 additions and 4 deletions
|
|
@ -119,6 +119,21 @@ pub fn main() -> anyhow::Result<()> {
|
|||
libinput::LIBINPUT_CONFIG_ACCEL_PROFILE,
|
||||
"libinput_config_accel_profile",
|
||||
)?;
|
||||
write_ty(
|
||||
&mut f,
|
||||
libinput::LIBINPUT_CONFIG_TAP_STATE,
|
||||
"libinput_config_tap_state",
|
||||
)?;
|
||||
write_ty(
|
||||
&mut f,
|
||||
libinput::LIBINPUT_CONFIG_DRAG_STATE,
|
||||
"libinput_config_drag_state",
|
||||
)?;
|
||||
write_ty(
|
||||
&mut f,
|
||||
libinput::LIBINPUT_CONFIG_DRAG_LOCK_STATE,
|
||||
"libinput_config_drag_lock_state",
|
||||
)?;
|
||||
|
||||
let mut f = open("pango_tys.rs")?;
|
||||
write_ty(&mut f, pango::CAIRO_FORMATS, "cairo_format_t")?;
|
||||
|
|
|
|||
|
|
@ -556,6 +556,18 @@ impl Client {
|
|||
self.send(&ClientMessage::SetPxPerWheelScroll { device, px })
|
||||
}
|
||||
|
||||
pub fn set_input_tap_enabled(&self, device: InputDevice, enabled: bool) {
|
||||
self.send(&ClientMessage::SetTapEnabled { device, enabled })
|
||||
}
|
||||
|
||||
pub fn set_input_drag_enabled(&self, device: InputDevice, enabled: bool) {
|
||||
self.send(&ClientMessage::SetDragEnabled { device, enabled })
|
||||
}
|
||||
|
||||
pub fn set_input_drag_lock_enabled(&self, device: InputDevice, enabled: bool) {
|
||||
self.send(&ClientMessage::SetDragLockEnabled { device, enabled })
|
||||
}
|
||||
|
||||
pub fn device_name(&self, device: InputDevice) -> String {
|
||||
let res = self.send_with_response(&ClientMessage::GetDeviceName { device });
|
||||
get_response!(res, String::new(), GetDeviceName { name });
|
||||
|
|
|
|||
|
|
@ -288,6 +288,18 @@ pub enum ClientMessage<'a> {
|
|||
seat: Seat,
|
||||
size: i32,
|
||||
},
|
||||
SetTapEnabled {
|
||||
device: InputDevice,
|
||||
enabled: bool,
|
||||
},
|
||||
SetDragEnabled {
|
||||
device: InputDevice,
|
||||
enabled: bool,
|
||||
},
|
||||
SetDragLockEnabled {
|
||||
device: InputDevice,
|
||||
enabled: bool,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Encode, Decode, Debug)]
|
||||
|
|
|
|||
|
|
@ -83,6 +83,27 @@ impl InputDevice {
|
|||
pub fn set_px_per_wheel_scroll(self, px: f64) {
|
||||
get!().set_px_per_wheel_scroll(self, px);
|
||||
}
|
||||
|
||||
/// Sets whether tap-to-click is enabled for this device.
|
||||
///
|
||||
/// See https://wayland.freedesktop.org/libinput/doc/latest/tapping.html
|
||||
pub fn set_tap_enabled(self, enabled: bool) {
|
||||
get!().set_input_tap_enabled(self, enabled);
|
||||
}
|
||||
|
||||
/// Sets whether tap-and-drag is enabled for this device.
|
||||
///
|
||||
/// See https://wayland.freedesktop.org/libinput/doc/latest/tapping.html
|
||||
pub fn set_drag_enabled(self, enabled: bool) {
|
||||
get!().set_input_drag_enabled(self, enabled);
|
||||
}
|
||||
|
||||
/// Sets whether drag lock is enabled for this device.
|
||||
///
|
||||
/// See https://wayland.freedesktop.org/libinput/doc/latest/tapping.html
|
||||
pub fn set_drag_lock_enabled(self, enabled: bool) {
|
||||
get!().set_input_drag_lock_enabled(self, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/// A seat.
|
||||
|
|
|
|||
|
|
@ -104,6 +104,9 @@ pub trait InputDevice {
|
|||
fn set_accel_speed(&self, speed: f64);
|
||||
fn set_transform_matrix(&self, matrix: TransformMatrix);
|
||||
fn name(&self) -> Rc<String>;
|
||||
fn set_tap_enabled(&self, enabled: bool);
|
||||
fn set_drag_enabled(&self, enabled: bool);
|
||||
fn set_drag_lock_enabled(&self, enabled: bool);
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -291,6 +291,9 @@ struct MetalInputDevice {
|
|||
accel_profile: Cell<Option<AccelProfile>>,
|
||||
accel_speed: Cell<Option<f64>>,
|
||||
transform_matrix: Cell<Option<TransformMatrix>>,
|
||||
tap_enabled: Cell<Option<bool>>,
|
||||
drag_enabled: Cell<Option<bool>>,
|
||||
drag_lock_enabled: Cell<Option<bool>>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -339,6 +342,15 @@ impl MetalInputDevice {
|
|||
if let Some(speed) = self.accel_speed.get() {
|
||||
dev.device().set_accel_speed(speed);
|
||||
}
|
||||
if let Some(enabled) = self.tap_enabled.get() {
|
||||
dev.device().set_tap_enabled(enabled);
|
||||
}
|
||||
if let Some(enabled) = self.drag_enabled.get() {
|
||||
dev.device().set_drag_enabled(enabled);
|
||||
}
|
||||
if let Some(enabled) = self.drag_lock_enabled.get() {
|
||||
dev.device().set_drag_lock_enabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
fn pre_pause(&self) {
|
||||
|
|
@ -429,6 +441,27 @@ impl InputDevice for MetalInputDevice {
|
|||
fn name(&self) -> Rc<String> {
|
||||
self.name.get()
|
||||
}
|
||||
|
||||
fn set_tap_enabled(&self, enabled: bool) {
|
||||
self.tap_enabled.set(Some(enabled));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_tap_enabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_drag_enabled(&self, enabled: bool) {
|
||||
self.drag_enabled.set(Some(enabled));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_drag_enabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
self.drag_lock_enabled.set(Some(enabled));
|
||||
if let Some(dev) = self.inputdev.get() {
|
||||
dev.device().set_drag_lock_enabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetalInputDevice {
|
||||
|
|
|
|||
|
|
@ -287,6 +287,9 @@ impl MetalBackend {
|
|||
accel_profile: Default::default(),
|
||||
accel_speed: Default::default(),
|
||||
transform_matrix: Default::default(),
|
||||
tap_enabled: Default::default(),
|
||||
drag_enabled: Default::default(),
|
||||
drag_lock_enabled: Default::default(),
|
||||
});
|
||||
slots[slot] = Some(dev.clone());
|
||||
self.device_holder
|
||||
|
|
|
|||
|
|
@ -1081,6 +1081,18 @@ impl InputDevice for XSeatKeyboard {
|
|||
fn name(&self) -> Rc<String> {
|
||||
self.0.kb_name.clone()
|
||||
}
|
||||
|
||||
fn set_tap_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
impl InputDevice for XSeatMouse {
|
||||
|
|
@ -1130,4 +1142,16 @@ impl InputDevice for XSeatMouse {
|
|||
fn name(&self) -> Rc<String> {
|
||||
self.0.mouse_name.clone()
|
||||
}
|
||||
|
||||
fn set_tap_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -494,6 +494,28 @@ impl ConfigProxyHandler {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_set_tap_enabled(&self, device: InputDevice, enabled: bool) -> Result<(), CphError> {
|
||||
let dev = self.get_device_handler_data(device)?;
|
||||
dev.device.set_tap_enabled(enabled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_set_drag_enabled(&self, device: InputDevice, enabled: bool) -> Result<(), CphError> {
|
||||
let dev = self.get_device_handler_data(device)?;
|
||||
dev.device.set_drag_enabled(enabled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_set_drag_lock_enabled(
|
||||
&self,
|
||||
device: InputDevice,
|
||||
enabled: bool,
|
||||
) -> Result<(), CphError> {
|
||||
let dev = self.get_device_handler_data(device)?;
|
||||
dev.device.set_drag_lock_enabled(enabled);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_set_transform_matrix(
|
||||
&self,
|
||||
device: InputDevice,
|
||||
|
|
@ -1140,6 +1162,15 @@ impl ConfigProxyHandler {
|
|||
ClientMessage::SetCursorSize { seat, size } => self
|
||||
.handle_set_cursor_size(seat, size)
|
||||
.wrn("set_cursor_size")?,
|
||||
ClientMessage::SetTapEnabled { device, enabled } => self
|
||||
.handle_set_tap_enabled(device, enabled)
|
||||
.wrn("set_tap_enabled")?,
|
||||
ClientMessage::SetDragEnabled { device, enabled } => self
|
||||
.handle_set_drag_enabled(device, enabled)
|
||||
.wrn("set_drag_enabled")?,
|
||||
ClientMessage::SetDragLockEnabled { device, enabled } => self
|
||||
.handle_set_drag_lock_enabled(device, enabled)
|
||||
.wrn("set_drag_lock_enabled")?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -427,6 +427,18 @@ trait TestInputDevice: InputDevice {
|
|||
fn set_transform_matrix(&self, matrix: TransformMatrix) {
|
||||
let _ = matrix;
|
||||
}
|
||||
|
||||
fn set_tap_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
|
||||
fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
let _ = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TestInputDevice> InputDevice for T {
|
||||
|
|
@ -473,4 +485,16 @@ impl<T: TestInputDevice> InputDevice for T {
|
|||
fn name(&self) -> Rc<String> {
|
||||
self.common().name.clone()
|
||||
}
|
||||
|
||||
fn set_tap_enabled(&self, enabled: bool) {
|
||||
<Self as TestInputDevice>::set_tap_enabled(self, enabled)
|
||||
}
|
||||
|
||||
fn set_drag_enabled(&self, enabled: bool) {
|
||||
<Self as TestInputDevice>::set_drag_enabled(self, enabled)
|
||||
}
|
||||
|
||||
fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
<Self as TestInputDevice>::set_drag_lock_enabled(self, enabled)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,3 +166,24 @@ cenum! {
|
|||
LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT = 1 << 0,
|
||||
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE = 1 << 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
ConfigTapState, LIBINPUT_CONFIG_TAP_STATE;
|
||||
|
||||
LIBINPUT_CONFIG_TAP_DISABLED = 0,
|
||||
LIBINPUT_CONFIG_TAP_ENABLED = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
ConfigDragState, LIBINPUT_CONFIG_DRAG_STATE;
|
||||
|
||||
LIBINPUT_CONFIG_DRAG_DISABLED = 0,
|
||||
LIBINPUT_CONFIG_DRAG_ENABLED = 1,
|
||||
}
|
||||
|
||||
cenum! {
|
||||
ConfigDragLockState, LIBINPUT_CONFIG_DRAG_LOCK_STATE;
|
||||
|
||||
LIBINPUT_CONFIG_DRAG_LOCK_DISABLED = 0,
|
||||
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED = 1,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,21 @@
|
|||
use {
|
||||
crate::libinput::{
|
||||
consts::{AccelProfile, DeviceCapability},
|
||||
consts::{
|
||||
AccelProfile, ConfigDragLockState, ConfigDragState, ConfigTapState, DeviceCapability,
|
||||
LIBINPUT_CONFIG_DRAG_DISABLED, LIBINPUT_CONFIG_DRAG_ENABLED,
|
||||
LIBINPUT_CONFIG_DRAG_LOCK_DISABLED, LIBINPUT_CONFIG_DRAG_LOCK_ENABLED,
|
||||
LIBINPUT_CONFIG_TAP_DISABLED, LIBINPUT_CONFIG_TAP_ENABLED,
|
||||
},
|
||||
sys::{
|
||||
libinput_device, libinput_device_config_accel_set_profile,
|
||||
libinput_device_config_accel_set_speed, libinput_device_config_left_handed_set,
|
||||
libinput_device_get_name, libinput_device_get_user_data,
|
||||
libinput_device_has_capability, libinput_device_set_user_data, libinput_device_unref,
|
||||
libinput_path_remove_device,
|
||||
libinput_device_config_tap_get_drag_enabled,
|
||||
libinput_device_config_tap_get_drag_lock_enabled,
|
||||
libinput_device_config_tap_get_enabled, libinput_device_config_tap_set_drag_enabled,
|
||||
libinput_device_config_tap_set_drag_lock_enabled,
|
||||
libinput_device_config_tap_set_enabled, libinput_device_get_name,
|
||||
libinput_device_get_user_data, libinput_device_has_capability,
|
||||
libinput_device_set_user_data, libinput_device_unref, libinput_path_remove_device,
|
||||
},
|
||||
LibInput,
|
||||
},
|
||||
|
|
@ -77,6 +86,66 @@ impl<'a> LibInputDevice<'a> {
|
|||
CStr::from_ptr(name).to_bytes().as_bstr().to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_tap_enabled(&self, enabled: bool) {
|
||||
let enabled = match enabled {
|
||||
true => LIBINPUT_CONFIG_TAP_ENABLED,
|
||||
false => LIBINPUT_CONFIG_TAP_DISABLED,
|
||||
};
|
||||
unsafe {
|
||||
libinput_device_config_tap_set_enabled(self.dev, enabled.raw() as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn tap_enabled(&self) -> bool {
|
||||
let enabled = unsafe { ConfigTapState(libinput_device_config_tap_get_enabled(self.dev)) };
|
||||
match enabled {
|
||||
LIBINPUT_CONFIG_TAP_ENABLED => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_drag_enabled(&self, enabled: bool) {
|
||||
let enabled = match enabled {
|
||||
true => LIBINPUT_CONFIG_DRAG_ENABLED,
|
||||
false => LIBINPUT_CONFIG_DRAG_DISABLED,
|
||||
};
|
||||
unsafe {
|
||||
libinput_device_config_tap_set_drag_enabled(self.dev, enabled.raw() as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn drag_enabled(&self) -> bool {
|
||||
let enabled =
|
||||
unsafe { ConfigDragState(libinput_device_config_tap_get_drag_enabled(self.dev)) };
|
||||
match enabled {
|
||||
LIBINPUT_CONFIG_DRAG_ENABLED => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_drag_lock_enabled(&self, enabled: bool) {
|
||||
let enabled = match enabled {
|
||||
true => LIBINPUT_CONFIG_DRAG_LOCK_ENABLED,
|
||||
false => LIBINPUT_CONFIG_DRAG_LOCK_DISABLED,
|
||||
};
|
||||
unsafe {
|
||||
libinput_device_config_tap_set_drag_lock_enabled(self.dev, enabled.raw() as _);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn drag_lock_enabled(&self) -> bool {
|
||||
let enabled = unsafe {
|
||||
ConfigDragLockState(libinput_device_config_tap_get_drag_lock_enabled(self.dev))
|
||||
};
|
||||
match enabled {
|
||||
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RegisteredDevice {
|
||||
|
|
|
|||
|
|
@ -54,6 +54,27 @@ extern "C" {
|
|||
speed: f64,
|
||||
) -> libinput_config_status;
|
||||
pub fn libinput_device_get_name(device: *mut libinput_device) -> *const c::c_char;
|
||||
pub fn libinput_device_config_tap_set_enabled(
|
||||
device: *mut libinput_device,
|
||||
enable: libinput_config_tap_state,
|
||||
) -> libinput_config_status;
|
||||
pub fn libinput_device_config_tap_get_enabled(
|
||||
device: *mut libinput_device,
|
||||
) -> libinput_config_tap_state;
|
||||
pub fn libinput_device_config_tap_set_drag_enabled(
|
||||
device: *mut libinput_device,
|
||||
enable: libinput_config_drag_state,
|
||||
) -> libinput_config_status;
|
||||
pub fn libinput_device_config_tap_get_drag_enabled(
|
||||
device: *mut libinput_device,
|
||||
) -> libinput_config_drag_state;
|
||||
pub fn libinput_device_config_tap_set_drag_lock_enabled(
|
||||
device: *mut libinput_device,
|
||||
enable: libinput_config_drag_lock_state,
|
||||
) -> libinput_config_status;
|
||||
pub fn libinput_device_config_tap_get_drag_lock_enabled(
|
||||
device: *mut libinput_device,
|
||||
) -> libinput_config_drag_lock_state;
|
||||
|
||||
pub fn libinput_event_destroy(event: *mut libinput_event);
|
||||
pub fn libinput_event_get_type(event: *mut libinput_event) -> libinput_event_type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue