From d1dbbb73282babe6b2bd507a5e201a8b67d90a67 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 14 Jul 2025 16:13:16 +1000 Subject: [PATCH] plugin: register plugins for the plugin-specific usages The debounce, wheel/wheel-low-res, double-tool and eraser-button plugins can limit themselves to a specific usage. The mtdev plugin needs to pass each each event to mtdev and the proximity timer plugin needs to get each event's timestamp so they cannot be restricted. The forced-tool could be restricted but effectively any event on the devices it works on will have one of those usages set so there's no point. Part-of: --- src/libinput-plugin-button-debounce.c | 9 +++++++++ src/libinput-plugin-mouse-wheel-lowres.c | 7 +++++++ src/libinput-plugin-mouse-wheel.c | 5 +++++ src/libinput-plugin-tablet-double-tool.c | 2 ++ src/libinput-plugin-tablet-eraser-button.c | 7 +++++++ 5 files changed, 30 insertions(+) diff --git a/src/libinput-plugin-button-debounce.c b/src/libinput-plugin-button-debounce.c index 1062a34c..bcc79c00 100644 --- a/src/libinput-plugin-button-debounce.c +++ b/src/libinput-plugin-button-debounce.c @@ -743,6 +743,15 @@ debounce_plugin_device_added(struct libinput_plugin *libinput_plugin, libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); + /* We don't care about BTN_TRIGGER_HAPPY_* */ + for (unsigned int code = BTN_0; code <= KEY_OK; code++) { + evdev_usage_t usage = evdev_usage_from_code(EV_KEY, code); + if (evdev_usage_is_button(usage)) { + libinput_plugin_enable_evdev_usage(libinput_plugin, + evdev_usage_enum(usage)); + } + } + struct plugin_data *plugin = libinput_plugin_get_user_data(libinput_plugin); struct plugin_device *pd = zalloc(sizeof(*pd)); pd->device = libinput_device_ref(device); diff --git a/src/libinput-plugin-mouse-wheel-lowres.c b/src/libinput-plugin-mouse-wheel-lowres.c index 4302c2be..fb92fa5c 100644 --- a/src/libinput-plugin-mouse-wheel-lowres.c +++ b/src/libinput-plugin-mouse-wheel-lowres.c @@ -54,6 +54,13 @@ wheel_plugin_device_new(struct libinput_plugin *libinput_plugin, libevdev_enable_event_code(libevdev, EV_REL, REL_HWHEEL_HI_RES, NULL); libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_WHEEL); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_HWHEEL); + + /* A device may have those disabled via a quirk but we just re-enabled it + * above. Make sure we get those events too to filter them out */ + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_WHEEL_HI_RES); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_HWHEEL_HI_RES); } static void diff --git a/src/libinput-plugin-mouse-wheel.c b/src/libinput-plugin-mouse-wheel.c index 7620f0bd..8981137a 100644 --- a/src/libinput-plugin-mouse-wheel.c +++ b/src/libinput-plugin-mouse-wheel.c @@ -506,6 +506,11 @@ wheel_plugin_device_new(struct libinput_plugin *libinput_plugin, libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_WHEEL); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_WHEEL_HI_RES); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_HWHEEL); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_REL_HWHEEL_HI_RES); + struct plugin_data *plugin = libinput_plugin_get_user_data(libinput_plugin); struct plugin_device *pd = wheel_plugin_device_create(libinput_plugin, plugin, device); diff --git a/src/libinput-plugin-tablet-double-tool.c b/src/libinput-plugin-tablet-double-tool.c index eacdc632..ea8ef902 100644 --- a/src/libinput-plugin-tablet-double-tool.c +++ b/src/libinput-plugin-tablet-double-tool.c @@ -339,6 +339,8 @@ double_tool_plugin_device_added(struct libinput_plugin *libinput_plugin, return; libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_TOOL_PEN); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_TOOL_RUBBER); struct plugin_data *plugin = libinput_plugin_get_user_data(libinput_plugin); struct plugin_device *pd = zalloc(sizeof(*pd)); diff --git a/src/libinput-plugin-tablet-eraser-button.c b/src/libinput-plugin-tablet-eraser-button.c index 00cf399e..c3741e30 100644 --- a/src/libinput-plugin-tablet-eraser-button.c +++ b/src/libinput-plugin-tablet-eraser-button.c @@ -541,6 +541,13 @@ eraser_button_plugin_device_added(struct libinput_plugin *libinput_plugin, return; libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_TOOL_PEN); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_TOOL_RUBBER); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_TOUCH); + /* These are the only ones we allow setting the eraser button to */ + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_STYLUS); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_STYLUS2); + libinput_plugin_enable_evdev_usage(libinput_plugin, EVDEV_BTN_STYLUS3); struct plugin_data *plugin = libinput_plugin_get_user_data(libinput_plugin); struct plugin_device *pd = zalloc(sizeof(*pd));