From f92a388c7aefa8fc5f8b065dd6e291f04fc4c036 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 14 Apr 2021 16:18:21 +1000 Subject: [PATCH] touchpad: factor out clickpad assignment to a helper No functional changes Signed-off-by: Peter Hutterer --- src/evdev-mt-touchpad-buttons.c | 38 +++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c index 4591270e..7d8933fe 100644 --- a/src/evdev-mt-touchpad-buttons.c +++ b/src/evdev-mt-touchpad-buttons.c @@ -935,6 +935,28 @@ tp_init_middlebutton_emulation(struct tp_dispatch *tp, want_config_option); } +static bool +tp_guess_clickpad(const struct tp_dispatch *tp, struct evdev_device *device) +{ + bool is_clickpad; + + is_clickpad = libevdev_has_property(device->evdev, INPUT_PROP_BUTTONPAD); + + if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || + libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { + if (is_clickpad) + evdev_log_bug_kernel(device, + "clickpad advertising right button\n"); + } else if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) && + !is_clickpad && + libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) { + evdev_log_bug_kernel(device, + "non clickpad without right button?\n"); + } + + return is_clickpad; +} + void tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device) @@ -943,23 +965,11 @@ tp_init_buttons(struct tp_dispatch *tp, const struct input_absinfo *absinfo_x, *absinfo_y; int i; - tp->buttons.is_clickpad = libevdev_has_property(device->evdev, - INPUT_PROP_BUTTONPAD); + tp->buttons.is_clickpad = tp_guess_clickpad(tp, device); + tp->buttons.has_topbuttons = libevdev_has_property(device->evdev, INPUT_PROP_TOPBUTTONPAD); - if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE) || - libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) { - if (tp->buttons.is_clickpad) - evdev_log_bug_kernel(device, - "clickpad advertising right button\n"); - } else if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) && - !tp->buttons.is_clickpad && - libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) { - evdev_log_bug_kernel(device, - "non clickpad without right button?\n"); - } - absinfo_x = device->abs.absinfo_x; absinfo_y = device->abs.absinfo_y;