From 7e7a9322fae0f560a28c2cb962f112046c591afc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Mon, 10 Jun 2024 15:19:24 +1000 Subject: [PATCH] backends: Expose the tool button mapping via InputSettings Unlike most other schemas the path for a tool requires a bit of processing (serial number or tablet vid/pid if there's no serial number). Let's make the tool settings available through the MetaInputSettings instead of having to duplicate that path composition in the caller. Part-of: --- src/backends/meta-input-settings-private.h | 6 +++ src/backends/meta-input-settings.c | 44 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h index 226b195bc..9dcb3816f 100644 --- a/src/backends/meta-input-settings-private.h +++ b/src/backends/meta-input-settings-private.h @@ -192,3 +192,9 @@ void meta_input_settings_notify_kbd_a11y_change (MetaInputSettings *input_se MetaKeyboardA11yFlags what_changed); MetaBackend * meta_input_settings_get_backend (MetaInputSettings *input_settings); + +GDesktopStylusButtonAction meta_input_settings_get_tool_button_action (MetaInputSettings *input_settings, + ClutterInputDevice *device, + ClutterInputDeviceTool *tool, + uint32_t clutter_button, + char **keybinding); diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index 1d98247b1..e3a1ed1f7 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -1970,3 +1970,47 @@ meta_input_settings_get_backend (MetaInputSettings *settings) return priv->backend; } + +GDesktopStylusButtonAction +meta_input_settings_get_tool_button_action (MetaInputSettings *input_settings, + ClutterInputDevice *device, + ClutterInputDeviceTool *tool, + uint32_t clutter_button, + char **keybinding) +{ + GDesktopStylusButtonAction action; + GSettings *settings; + const char *prefix = NULL; + g_autofree char *key = NULL; + + g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT); + + switch (clutter_button) + { + case CLUTTER_BUTTON_MIDDLE: /* BTN_STYLUS */ + prefix = "button"; + break; + case CLUTTER_BUTTON_SECONDARY: /* BTN_STYLUS2 */ + prefix = "secondary-button"; + break; + case 8: /* BTN_STYLUS3 */ + prefix = "tertiary-button"; + break; + + /* BUTTON_PRIMARY is tip down and has no mapping */ + case CLUTTER_BUTTON_PRIMARY: + default: + return G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT; + } + + key = g_strdup_printf ("%s-action", prefix); + settings = lookup_tool_settings (tool, device); + action = g_settings_get_enum (settings, key); + if (keybinding && action == G_DESKTOP_STYLUS_BUTTON_ACTION_KEYBINDING) + { + g_autofree char *binding_key = g_strdup_printf ("%s-keybinding", prefix); + *keybinding = g_settings_get_string (settings, binding_key); + } + + return action; +}