diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2023-11-10 08:17:46 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2023-11-10 08:17:46 +1000 |
commit | b254d491e204f09226aa17f249e1bec7282c0fa5 (patch) | |
tree | 7fcfa826136afe8f9c1fa9e14d75737474ddd40e | |
parent | 0dc42f0e4ec8b006d589c0351cee0fc53cf02375 (diff) |
Add a property for the tablet tool serial and hw ID
The driver encodes the serial in the device name but that's not reliable
enough. Expose both serial and tool id (optional) as a property so
clients can read them and adjust their behavior accordingly.
Fixes #16
-rw-r--r-- | include/libinput-properties.h | 15 | ||||
-rw-r--r-- | src/xf86libinput.c | 35 |
2 files changed, 50 insertions, 0 deletions
diff --git a/include/libinput-properties.h b/include/libinput-properties.h index 71e6208..d5b5197 100644 --- a/include/libinput-properties.h +++ b/include/libinput-properties.h @@ -229,4 +229,19 @@ * If disabled, high-resolution wheel scroll events are discarded */ #define LIBINPUT_PROP_HIRES_WHEEL_SCROLL_ENABLED "libinput High Resolution Wheel Scroll Enabled" +/* The tablet tool unique serial number: CARD32, 1 value, constant for the + * lifetime of the device. + * + * If this property exists and is zero, the tool does not have a unique serial + * number. + */ +#define LIBINPUT_PROP_TABLET_TOOL_SERIAL "libinput Tablet Tool Serial" + +/* The tablet tool hardware ID: CARD32, 1 value, constant for the lifetime of the device. + * + * This property only exists if the device has a known tool ID. + * See libinput_tablet_tool_get_tool_id() in the libinput documentation for details. + */ +#define LIBINPUT_PROP_TABLET_TOOL_ID "libinput Tablet Tool ID" + #endif /* _LIBINPUT_PROPERTIES_H_ */ diff --git a/src/xf86libinput.c b/src/xf86libinput.c index 48169e2..5f46ad6 100644 --- a/src/xf86libinput.c +++ b/src/xf86libinput.c @@ -4100,6 +4100,8 @@ static Atom prop_draglock; static Atom prop_horiz_scroll; static Atom prop_pressurecurve; static Atom prop_area_ratio; +static Atom prop_serial; +static Atom prop_tool_id; static Atom prop_hires_scroll; /* general properties */ @@ -5275,10 +5277,12 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, atom == prop_scroll_pixel_distance_default || atom == prop_sendevents_available || atom == prop_sendevents_default || + atom == prop_serial || atom == prop_tap_buttonmap_default || atom == prop_tap_default || atom == prop_tap_drag_default || atom == prop_tap_drag_lock_default || + atom == prop_tool_id || atom == prop_device) return BadAccess; /* read-only */ else @@ -6269,6 +6273,36 @@ LibinputInitTabletAreaRatioProperty(DeviceIntPtr dev, } static void +LibinputInitTabletSerialProperty(DeviceIntPtr dev, + struct xf86libinput *driver_data) +{ + struct libinput_tablet_tool *tool = driver_data->tablet_tool; + uint32_t serial, tool_id; + + if ((driver_data->capabilities & CAP_TABLET_TOOL) == 0) + return; + + if (!tool) + return; + + /* Serial prop is always created to indicate when we don't have a serial */ + serial = libinput_tablet_tool_get_serial(tool); + prop_serial = LibinputMakeProperty(dev, + LIBINPUT_PROP_TABLET_TOOL_SERIAL, + XA_CARDINAL, 32, + 1, &serial); + + /* The tool ID prop is only created if we have a known tool id */ + tool_id = libinput_tablet_tool_get_tool_id(tool); + if (tool_id) { + prop_tool_id = LibinputMakeProperty(dev, + LIBINPUT_PROP_TABLET_TOOL_ID, + XA_CARDINAL, 32, + 1, &tool_id); + } +} + +static void LibinputInitHighResolutionScrollProperty(DeviceIntPtr dev, struct xf86libinput *driver_data, struct libinput_device *device) @@ -6343,5 +6377,6 @@ LibinputInitProperty(DeviceIntPtr dev) LibinputInitScrollPixelDistanceProperty(dev, driver_data, device); LibinputInitPressureCurveProperty(dev, driver_data); LibinputInitTabletAreaRatioProperty(dev, driver_data); + LibinputInitTabletSerialProperty(dev, driver_data); LibinputInitHighResolutionScrollProperty(dev, driver_data, device); } |