1
0
Fork 0

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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3649>
This commit is contained in:
Peter Hutterer 2024-06-10 15:19:24 +10:00 committed by Marge Bot
parent 7ab5a8cf95
commit 7e7a9322fa
2 changed files with 50 additions and 0 deletions

View file

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

View file

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