backends: Add helpers to convert from clutter tool button to evcode

This complements the existing clutter->evdev and evdev->clutter helpers,
but this time for buttons we expect from a stylus tool. We also need to
convert left/middle/right for the Wacom puck/lens cursor tools but that
particular conversion is lossy.

Note that these are more restrictive than the normal codes - if we
get "other" buttons from a stylus we don't really know what they could
possibly map to. So we safely map what looks like buttons from a mouse
but otherwise complain and return zero.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3649>
This commit is contained in:
Peter Hutterer
2024-03-06 14:44:23 +10:00
committed by Marge Bot
parent 6c77af1493
commit dfcb160321
3 changed files with 152 additions and 0 deletions

View File

@ -123,6 +123,11 @@ static guint signals[N_SIGNALS];
#define BTN_LEFT 0x110
#define BTN_RIGHT 0x111
#define BTN_MIDDLE 0x112
#define BTN_STYLUS3 0x149
#define BTN_TOUCH 0x14a
#define BTN_STYLUS 0x14b
#define BTN_STYLUS2 0x14c
#define BTN_JOYSTICK 0x120
#endif
struct _MetaBackendPrivate
@ -1853,6 +1858,50 @@ meta_clutter_button_to_evdev (uint32_t clutter_button)
return (clutter_button + (BTN_LEFT - 1)) - 4;
}
uint32_t
meta_clutter_tool_button_to_evdev (uint32_t clutter_button)
{
switch (clutter_button)
{
case CLUTTER_BUTTON_PRIMARY:
return BTN_TOUCH;
case CLUTTER_BUTTON_MIDDLE:
return BTN_STYLUS;
case CLUTTER_BUTTON_SECONDARY:
return BTN_STYLUS2;
case 8:
return BTN_STYLUS3;
}
return (clutter_button + (BTN_LEFT - 1)) - 5;
}
uint32_t
meta_evdev_tool_button_to_clutter (uint32_t evdev_button)
{
switch (evdev_button)
{
case BTN_TOUCH:
case BTN_LEFT:
return CLUTTER_BUTTON_PRIMARY;
case BTN_STYLUS:
case BTN_MIDDLE:
return CLUTTER_BUTTON_MIDDLE;
case BTN_STYLUS2:
case BTN_RIGHT:
return CLUTTER_BUTTON_SECONDARY;
case BTN_STYLUS3:
return 8;
}
g_return_val_if_fail (evdev_button > BTN_LEFT, 0);
g_return_val_if_fail (evdev_button < BTN_JOYSTICK, 0);
/* For compatibility reasons, all additional buttons (i.e. BTN_SIDE and
* higher) go after the old 4-7 scroll ones and 8 for BTN_STYLUS3 */
return (evdev_button - (BTN_LEFT - 1)) + 5;
}
uint32_t
meta_evdev_button_to_clutter (uint32_t evdev_button)
{