From ed6c33514089ca7fba283e9197670c0bbd8f9ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 11 Oct 2023 21:30:35 +0800 Subject: [PATCH] backends: Use helper to translate from/to clutter/evdev button codes This fixes an issue in the MetaEisClient implementation which didn't offset correctly. Part-of: --- src/backends/meta-eis-client.c | 17 +------------- src/backends/meta-remote-desktop-session.c | 23 +------------------ .../native/meta-input-settings-native.c | 21 +---------------- src/backends/native/meta-seat-impl.c | 2 +- .../native/meta-virtual-input-device-native.c | 23 ++----------------- 5 files changed, 6 insertions(+), 80 deletions(-) diff --git a/src/backends/meta-eis-client.c b/src/backends/meta-eis-client.c index 13ea37607..a45928928 100644 --- a/src/backends/meta-eis-client.c +++ b/src/backends/meta-eis-client.c @@ -555,22 +555,7 @@ handle_button (MetaEisClient *client, gboolean is_press = eis_event_button_get_is_press (event); button = eis_event_button_get_button (event); - switch (button) - { - case 0x110: /* BTN_LEFT */ - button = CLUTTER_BUTTON_PRIMARY; - break; - case 0x111: /* BTN_RIGHT */ - button = CLUTTER_BUTTON_SECONDARY; - break; - case 0x112: /* BTN_MIDDLE */ - button = CLUTTER_BUTTON_MIDDLE; - break; - default: - if (button > 0x110) - button -= 0x110; - break; - } + button = meta_evdev_button_to_clutter (button); if (button > MAX_BUTTON) return; diff --git a/src/backends/meta-remote-desktop-session.c b/src/backends/meta-remote-desktop-session.c index 62e927ea2..9605c3c9b 100644 --- a/src/backends/meta-remote-desktop-session.c +++ b/src/backends/meta-remote-desktop-session.c @@ -755,27 +755,6 @@ handle_notify_keyboard_keysym (MetaDBusRemoteDesktopSession *skeleton, return TRUE; } -/* Translation taken from the clutter evdev backend. */ -static int -translate_to_clutter_button (int button) -{ - switch (button) - { - case BTN_LEFT: - return CLUTTER_BUTTON_PRIMARY; - case BTN_RIGHT: - return CLUTTER_BUTTON_SECONDARY; - case BTN_MIDDLE: - return CLUTTER_BUTTON_MIDDLE; - default: - /* - * For compatibility reasons, all additional buttons go after the old - * 4-7 scroll ones. - */ - return button - (BTN_LEFT - 1) + 4; - } -} - static gboolean handle_notify_pointer_button (MetaDBusRemoteDesktopSession *skeleton, GDBusMethodInvocation *invocation, @@ -789,7 +768,7 @@ handle_notify_pointer_button (MetaDBusRemoteDesktopSession *skeleton, if (!meta_remote_desktop_session_check_can_notify (session, invocation)) return TRUE; - button = translate_to_clutter_button (button_code); + button = meta_evdev_button_to_clutter (button_code); if (pressed) { diff --git a/src/backends/native/meta-input-settings-native.c b/src/backends/native/meta-input-settings-native.c index 948c8696e..7e3813fa7 100644 --- a/src/backends/native/meta-input-settings-native.c +++ b/src/backends/native/meta-input-settings-native.c @@ -376,26 +376,7 @@ meta_input_settings_native_set_scroll_button (MetaInputSettings *settings, } else { - switch (button) - { - case 1: - evcode = BTN_LEFT; - break; - case 2: - evcode = BTN_MIDDLE; - break; - case 3: - evcode = BTN_RIGHT; - break; - default: - /* Compensate for X11 scroll buttons */ - if (button > 7) - button -= 4; - - /* Button is 1-indexed */ - evcode = (BTN_LEFT - 1) + button; - } - + evcode = meta_clutter_button_to_evdev (button); method = LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN; } diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c index e87dbdf07..4ce3a0c4e 100644 --- a/src/backends/native/meta-seat-impl.c +++ b/src/backends/native/meta-seat-impl.c @@ -739,7 +739,7 @@ meta_seat_impl_notify_button_in_impl (MetaSeatImpl *seat_impl, if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE) button_nr = button - BTN_TOOL_PEN + 4; else - button_nr = button - (BTN_LEFT - 1) + 4; + button_nr = meta_evdev_button_to_clutter (button); break; } diff --git a/src/backends/native/meta-virtual-input-device-native.c b/src/backends/native/meta-virtual-input-device-native.c index d287aa58f..f02a47d8a 100644 --- a/src/backends/native/meta-virtual-input-device-native.c +++ b/src/backends/native/meta-virtual-input-device-native.c @@ -22,6 +22,7 @@ #include #include +#include "backends/meta-backend-private.h" #include "backends/native/meta-input-thread.h" #include "backends/native/meta-seat-native.h" #include "backends/native/meta-virtual-input-device-native.h" @@ -300,26 +301,6 @@ meta_virtual_input_device_native_notify_absolute_motion (ClutterVirtualInputDevi g_object_unref (task); } -static int -translate_to_evdev_button (int clutter_button) -{ - switch (clutter_button) - { - case CLUTTER_BUTTON_PRIMARY: - return BTN_LEFT; - case CLUTTER_BUTTON_SECONDARY: - return BTN_RIGHT; - case CLUTTER_BUTTON_MIDDLE: - return BTN_MIDDLE; - default: - /* - * For compatibility reasons, all additional buttons go after the old - * 4-7 scroll ones. - */ - return clutter_button + (BTN_LEFT - 1) - 4; - } -} - static gboolean notify_button_in_impl (GTask *task) { @@ -333,7 +314,7 @@ notify_button_in_impl (GTask *task) if (event->time_us == CLUTTER_CURRENT_TIME) event->time_us = g_get_monotonic_time (); - evdev_button = translate_to_evdev_button (event->button); + evdev_button = meta_clutter_button_to_evdev (event->button); if (get_button_type (evdev_button) != EVDEV_BUTTON_TYPE_BUTTON) {