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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3325>
This commit is contained in:
Jonas Ådahl 2023-10-11 21:30:35 +08:00 committed by Marge Bot
parent 26b4583164
commit ed6c335140
5 changed files with 6 additions and 80 deletions

View File

@ -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;

View File

@ -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)
{

View File

@ -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;
}

View File

@ -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;
}

View File

@ -22,6 +22,7 @@
#include <glib-object.h>
#include <linux/input.h>
#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)
{