Skip to content

Commit 0444ee5

Browse files
committed
input: upgrade to libinput 1.27
1 parent 03a9889 commit 0444ee5

File tree

3 files changed

+196
-11
lines changed

3 files changed

+196
-11
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ libinput_1_19 = ["input-sys/libinput_1_19", "libinput_1_15"]
3939
libinput_1_21 = ["input-sys/libinput_1_21", "libinput_1_19"]
4040
libinput_1_23 = ["input-sys/libinput_1_23", "libinput_1_21"]
4141
libinput_1_26 = ["input-sys/libinput_1_26", "libinput_1_23"]
42+
libinput_1_27 = ["input-sys/libinput_1_27", "libinput_1_26"]
4243

4344
[workspace]
4445
members = [

src/device.rs

Lines changed: 187 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ pub enum ClickfingerButtonMap {
158158
LeftMiddleRight,
159159
}
160160

161+
/// Drag lock state
162+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
163+
#[non_exhaustive]
164+
pub enum DragLockState {
165+
/// Drag lock is to be disabled, or is currently disabled
166+
Disabled,
167+
/// Drag lock is to be enabled in timeout mode,
168+
/// or is currently enabled in timeout mode
169+
EnabledTimeout,
170+
/// Drag lock is to be enabled in sticky mode,
171+
/// or is currently enabled in sticky mode
172+
#[cfg(feature = "libinput_1_27")]
173+
EnabledSticky,
174+
}
175+
161176
/// Whenever scroll button lock is enabled or not
162177
#[cfg(feature = "libinput_1_15")]
163178
#[allow(missing_docs)]
@@ -189,6 +204,50 @@ bitflags! {
189204
}
190205
}
191206

207+
/// Describes a rectangle to configure a device’s area, see [`Device::config_area_set_rectangle`].
208+
///
209+
/// This struct describes a rectangle via the upper left points (x1, y1) and the lower right point (x2, y2).
210+
///
211+
/// All arguments are normalized to the range [0.0, 1.0] to represent the corresponding proportion of the device’s width and height, respectively. A rectangle covering the whole device thus comprises of the points (0.0, 0.0) and (1.0, 1.0).
212+
///
213+
/// The conditions x1 < x2 and y1 < y2 must be true.
214+
#[derive(Debug, Copy, Clone, PartialEq)]
215+
#[cfg(feature = "libinput_1_27")]
216+
pub struct AreaRectangle {
217+
/// x1 coordinate
218+
pub x1: f64,
219+
/// y1 coordinate
220+
pub y1: f64,
221+
/// x2 coordinate
222+
pub x2: f64,
223+
/// y2 coordinate
224+
pub y2: f64,
225+
}
226+
227+
#[cfg(feature = "libinput_1_27")]
228+
impl From<AreaRectangle> for ffi::libinput_config_area_rectangle {
229+
fn from(rect: AreaRectangle) -> Self {
230+
input_sys::libinput_config_area_rectangle {
231+
x1: rect.x1,
232+
y1: rect.y1,
233+
x2: rect.x2,
234+
y2: rect.y2,
235+
}
236+
}
237+
}
238+
239+
#[cfg(feature = "libinput_1_27")]
240+
impl From<ffi::libinput_config_area_rectangle> for AreaRectangle {
241+
fn from(rect: ffi::libinput_config_area_rectangle) -> Self {
242+
AreaRectangle {
243+
x1: rect.x1,
244+
y1: rect.y1,
245+
x2: rect.x2,
246+
y2: rect.y2,
247+
}
248+
}
249+
}
250+
192251
ffi_ref_struct!(
193252
/// Device group
194253
///
@@ -783,6 +842,85 @@ impl Device {
783842
/// Check if the device can be calibrated via a calibration matrix.
784843
pub fn config_calibration_has_matrix, ffi::libinput_device_config_calibration_has_matrix, bool);
785844

845+
#[cfg(feature = "libinput_1_27")]
846+
ffi_func!(
847+
/// Check if the device can change its logical input area via a rectangle.
848+
pub fn config_area_has_rectangle, ffi::libinput_device_config_area_has_rectangle, bool);
849+
850+
/// Set the given rectangle as the logical input area of this device.
851+
///
852+
/// Future interactions by a tablet tool on this devices are scaled to only
853+
/// consider events within this logical input area - as if the logical input
854+
/// area were the available physical area.
855+
///
856+
/// The coordinates of the rectangle represent the proportion of the
857+
/// available maximum physical area, normalized to the range [0.0, 1.0].
858+
/// For example, a rectangle with the two points 0.25, 0.5, 0.75, 1.0 adds
859+
/// a 25% dead zone to the left and right and a 50% dead zone on the top:
860+
///
861+
/// ```text
862+
/// +----------------------------------+
863+
/// | |
864+
/// | 50% |
865+
/// | |
866+
/// | +-----------------+ |
867+
/// | | | |
868+
/// | 25% | | 25% |
869+
/// | | | |
870+
/// +--------+-----------------+-------+
871+
/// ```
872+
/// The area applies in the tablet’s current logical rotation, i.e. the
873+
/// above example is always at the bottom of the tablet.
874+
///
875+
/// Once applied, the logical area’s top-left coordinate (in the current
876+
/// logical rotation) becomes the new offset (0/0) and the return values
877+
/// of [`TabletToolEventTrait::x`](crate::event::tablet_tool::TabletToolEventTrait::x) and
878+
/// [`TabletToolEventTrait::y`](crate::event::tablet_tool::TabletToolEventTrait::y)
879+
/// are in relation to this new offset.
880+
///
881+
/// Likewise, [`TabletToolEventTrait::x_transformed`](crate::event::tablet_tool::TabletToolEventTrait::x_transformed)
882+
/// and [`TabletToolEventTrait::y_transformed`](crate::event::tablet_tool::TabletToolEventTrait::y_transformed)
883+
/// represent the value scaled into the configured logical area.
884+
///
885+
/// The return value of libinput_device_get_size() is not affected by the configured area.
886+
///
887+
/// Changing the area may not take effect immediately, the device may wait until it is in a
888+
/// neutral state before applying any changes.
889+
#[cfg(feature = "libinput_1_27")]
890+
pub fn config_area_set_rectangle(&self, area: AreaRectangle) -> DeviceConfigResult {
891+
let area = area.into();
892+
match unsafe {
893+
ffi::libinput_device_config_area_set_rectangle(self.as_raw_mut(), &raw const area)
894+
} {
895+
ffi::libinput_config_status_LIBINPUT_CONFIG_STATUS_SUCCESS => Ok(()),
896+
ffi::libinput_config_status_LIBINPUT_CONFIG_STATUS_UNSUPPORTED => {
897+
Err(DeviceConfigError::Unsupported)
898+
}
899+
ffi::libinput_config_status_LIBINPUT_CONFIG_STATUS_INVALID => {
900+
Err(DeviceConfigError::Invalid)
901+
}
902+
_ => panic!("libinput returned invalid 'libinput_config_status'"),
903+
}
904+
}
905+
906+
/// Return the current area rectangle for this device.
907+
///
908+
/// The return value for a device that does not support area rectangles is
909+
/// a rectangle with the points 0/0 and 1/1.
910+
#[cfg(feature = "libinput_1_27")]
911+
pub fn config_area_get_rectangle(&self) -> AreaRectangle {
912+
unsafe { ffi::libinput_device_config_area_get_rectangle(self.as_raw_mut()) }.into()
913+
}
914+
915+
/// Return the default area rectangle for this device.
916+
///
917+
/// The return value for a device that does not support area rectangles is
918+
/// a rectangle with the points 0/0 and 1/1.
919+
#[cfg(feature = "libinput_1_27")]
920+
pub fn config_area_get_default_rectangle(&self) -> AreaRectangle {
921+
unsafe { ffi::libinput_device_config_area_get_default_rectangle(self.as_raw_mut()) }.into()
922+
}
923+
786924
/// Apply the 3x3 transformation matrix to absolute device
787925
/// coordinates.
788926
///
@@ -1724,11 +1862,24 @@ impl Device {
17241862

17251863
/// Return whether tap-and-drag is enabled or disabled by default
17261864
/// on this device.
1727-
pub fn config_tap_default_drag_enabled(&self) -> bool {
1865+
pub fn config_tap_default_drag_enabled(&self) -> DragLockState {
17281866
match unsafe { ffi::libinput_device_config_tap_get_default_drag_enabled(self.as_raw_mut()) }
17291867
{
1730-
ffi::libinput_config_drag_state_LIBINPUT_CONFIG_DRAG_ENABLED => true,
1731-
ffi::libinput_config_drag_state_LIBINPUT_CONFIG_DRAG_DISABLED => false,
1868+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_DISABLED => {
1869+
DragLockState::Disabled
1870+
}
1871+
#[cfg(not(feature = "libinput_1_27"))]
1872+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED => {
1873+
DragLockState::EnabledTimeout
1874+
}
1875+
#[cfg(feature = "libinput_1_27")]
1876+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT => {
1877+
DragLockState::EnabledTimeout
1878+
}
1879+
#[cfg(feature = "libinput_1_27")]
1880+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY => {
1881+
DragLockState::EnabledSticky
1882+
}
17321883
_ => panic!("libinput returned invalid 'libinput_config_drag_state'"),
17331884
}
17341885
}
@@ -1741,12 +1892,25 @@ impl Device {
17411892
///
17421893
/// Drag lock may be enabled by default even when tapping is
17431894
/// disabled by default.
1744-
pub fn config_tap_default_drag_lock_enabled(&self) -> bool {
1895+
pub fn config_tap_default_drag_lock_enabled(&self) -> DragLockState {
17451896
match unsafe {
17461897
ffi::libinput_device_config_tap_get_default_drag_lock_enabled(self.as_raw_mut())
17471898
} {
1748-
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED => true,
1749-
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_DISABLED => false,
1899+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_DISABLED => {
1900+
DragLockState::Disabled
1901+
}
1902+
#[cfg(not(feature = "libinput_1_27"))]
1903+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED => {
1904+
DragLockState::EnabledTimeout
1905+
}
1906+
#[cfg(feature = "libinput_1_27")]
1907+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT => {
1908+
DragLockState::EnabledTimeout
1909+
}
1910+
#[cfg(feature = "libinput_1_27")]
1911+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY => {
1912+
DragLockState::EnabledSticky
1913+
}
17501914
_ => panic!("libinput returned invalid 'libinput_config_drag_lock_state'"),
17511915
}
17521916
}
@@ -1892,14 +2056,26 @@ impl Device {
18922056
///
18932057
/// Enabling drag lock on a device that has tapping disabled is
18942058
/// permitted, but has no effect until tapping is enabled.
1895-
pub fn config_tap_set_drag_lock_enabled(&mut self, enabled: bool) -> DeviceConfigResult {
2059+
pub fn config_tap_set_drag_lock_enabled(&mut self, state: DragLockState) -> DeviceConfigResult {
18962060
match unsafe {
18972061
ffi::libinput_device_config_tap_set_drag_lock_enabled(
18982062
self.as_raw_mut(),
1899-
if enabled {
1900-
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED
1901-
} else {
1902-
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_DISABLED
2063+
match state {
2064+
DragLockState::Disabled => {
2065+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_DISABLED
2066+
}
2067+
#[cfg(not(feature = "libinput_1_27"))]
2068+
DragLockState::EnabledTimeout => {
2069+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED
2070+
}
2071+
#[cfg(feature = "libinput_1_27")]
2072+
DragLockState::EnabledTimeout => {
2073+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT
2074+
}
2075+
#[cfg(feature = "libinput_1_27")]
2076+
DragLockState::EnabledSticky => {
2077+
ffi::libinput_config_drag_lock_state_LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_STICKY
2078+
}
19032079
},
19042080
)
19052081
} {

src/event/tablet_tool.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ pub trait TabletToolEventTrait: AsRaw<ffi::libinput_event_tablet_tool> + Context
181181
/// Use `x_transformed` for transforming the axis value into a different coordinate
182182
/// space.
183183
///
184+
/// If an area is defined for this device, the coordinate is in mm from the
185+
/// top left corner of the area. See
186+
/// [`Device::config_area_set_rectangle`](crate::Device::config_area_set_rectangle) for details.
187+
///
184188
/// ## Note
185189
///
186190
/// On some devices, returned value may be negative or larger than the width of the
@@ -194,6 +198,10 @@ pub trait TabletToolEventTrait: AsRaw<ffi::libinput_event_tablet_tool> + Context
194198
/// Use `y_transformed` for transforming the axis value into a different coordinate
195199
/// space.
196200
///
201+
/// If an area is defined for this device, the coordinate is in mm from the
202+
/// top left corner of the area. See
203+
/// [`Device::config_area_set_rectangle`](crate::Device::config_area_set_rectangle) for details.
204+
///
197205
/// ## Note
198206
///
199207
/// On some devices, returned value may be negative or larger than the width of the

0 commit comments

Comments
 (0)