From 31854a829a21f66c5ebd7a5913a2e2631ca5d747 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 26 Jun 2025 14:21:52 +1000 Subject: [PATCH] plugin: only register the wheel plugin on devices that have a wheel Touchpad devices are pointers too in libinput but they don't usually have wheels. Let's check for REL_WHEEL in device_new *and* then again for the actual pointer capability in device_added. Fixes: d1800a76fec9 ("evdev: Handle scroll wheel with a plugin") Part-of: --- src/libinput-plugin-mouse-wheel.c | 34 ++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/libinput-plugin-mouse-wheel.c b/src/libinput-plugin-mouse-wheel.c index 12f526f7..584b00fa 100644 --- a/src/libinput-plugin-mouse-wheel.c +++ b/src/libinput-plugin-mouse-wheel.c @@ -463,10 +463,13 @@ wheel_plugin_destroy(struct libinput_plugin *libinput_plugin) } static void -wheel_plugin_device_added(struct libinput_plugin *libinput_plugin, - struct libinput_device *device) +wheel_plugin_device_new(struct libinput_plugin *libinput_plugin, + struct libinput_device *device, + struct libevdev *libevdev, + struct udev_device *udev_device) { - if (!libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) + if (!libevdev_has_event_code(libevdev, EV_REL, REL_WHEEL_HI_RES) && + !libevdev_has_event_code(libevdev, EV_REL, REL_HWHEEL_HI_RES)) return; libinput_plugin_enable_device_event_frame(libinput_plugin, device, true); @@ -477,6 +480,27 @@ wheel_plugin_device_added(struct libinput_plugin *libinput_plugin, list_take_append(&plugin->devices, pd, link); } +static void +wheel_plugin_device_added(struct libinput_plugin *libinput_plugin, + struct libinput_device *device) +{ + if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER)) + return; + + /* For any non-pointer device: check if we happened to have added + * it during device_new and if so, remove it. We only want to enable + * this on devices that have a wheel *and* are a pointer device */ + struct plugin_data *plugin = libinput_plugin_get_user_data(libinput_plugin); + struct plugin_device *pd; + + list_for_each_safe(pd, &plugin->devices, link) { + if (pd->device == device) { + wheel_plugin_device_destroy(pd); + return; + } + } +} + static void wheel_plugin_device_removed(struct libinput_plugin *libinput_plugin, struct libinput_device *device) @@ -533,8 +557,8 @@ wheel_plugin_evdev_frame(struct libinput_plugin *libinput_plugin, static const struct libinput_plugin_interface interface = { .run = NULL, .destroy = wheel_plugin_destroy, - .device_new = NULL, - .device_ignored = NULL, + .device_new = wheel_plugin_device_new, + .device_ignored = wheel_plugin_device_removed, .device_added = wheel_plugin_device_added, .device_removed = wheel_plugin_device_removed, .evdev_frame = wheel_plugin_evdev_frame,