diff options
author | Carlos Garnacho <carlosg@gnome.org> | 2016-06-22 15:48:07 +0200 |
---|---|---|
committer | Carlos Garnacho <carlosg@gnome.org> | 2016-07-20 19:26:31 +0200 |
commit | ec2ab05d8eb31726353b123fd200b166799e7ec7 (patch) | |
tree | 4c17c8bf8c3cc168049cabbd94c8993f4959eb6d | |
parent | 69955471fc7a3dd6828c78608b681b808949d9d6 (diff) | |
download | mutter-ec2ab05d8eb31726353b123fd200b166799e7ec7.tar.gz |
backends: Add function to retrieve the action mapped to an stylus button
This function will be useful for the wayland implementation, because buttons
are mapped at the time of sending those through the wire.
As x11/wayland implementations differ here, this function will be useful for
the wayland implementation, as the action is handled lat
-rw-r--r-- | src/backends/meta-input-settings-private.h | 4 | ||||
-rw-r--r-- | src/backends/meta-input-settings.c | 63 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h index d8b8976c5..813108648 100644 --- a/src/backends/meta-input-settings-private.h +++ b/src/backends/meta-input-settings-private.h @@ -106,6 +106,10 @@ MetaInputSettings * meta_input_settings_get (void); GDesktopTabletMapping meta_input_settings_get_tablet_mapping (MetaInputSettings *settings, ClutterInputDevice *device); +GDesktopStylusButtonAction meta_input_settings_get_stylus_button_action (MetaInputSettings *settings, + ClutterInputDeviceTool *tool, + ClutterInputDevice *current_device, + guint button); #ifdef HAVE_LIBWACOM WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings, ClutterInputDevice *device); diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c index af46bd9a1..049d1b846 100644 --- a/src/backends/meta-input-settings.c +++ b/src/backends/meta-input-settings.c @@ -40,6 +40,8 @@ #include <meta/util.h> +static GQuark quark_tool_settings = 0; + typedef struct _MetaInputSettingsPrivate MetaInputSettingsPrivate; typedef struct _DeviceMappingInfo DeviceMappingInfo; @@ -910,6 +912,41 @@ lookup_device_settings (ClutterInputDevice *device) return settings; } +static GSettings * +lookup_tool_settings (ClutterInputDeviceTool *tool, + ClutterInputDevice *device) +{ + GSettings *settings; + guint64 serial; + gchar *path; + + settings = g_object_get_qdata (G_OBJECT (tool), quark_tool_settings); + + if (!settings) + { + serial = clutter_input_device_tool_get_serial (tool); + + if (serial == 0) + { + path = g_strdup_printf ("/org/gnome/desktop/peripherals/stylus/default-%s:%s/", + clutter_input_device_get_vendor_id (device), + clutter_input_device_get_product_id (device)); + } + else + { + path = g_strdup_printf ("/org/gnome/desktop/peripherals/stylus/%lx/", serial); + } + + settings = g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet.stylus", + path); + g_object_set_qdata_full (G_OBJECT (tool), quark_tool_settings, settings, + (GDestroyNotify) g_object_unref); + g_free (path); + } + + return settings; +} + static void monitors_changed_cb (MetaMonitorManager *monitor_manager, MetaInputSettings *input_settings) @@ -1067,6 +1104,9 @@ meta_input_settings_class_init (MetaInputSettingsClass *klass) object_class->dispose = meta_input_settings_dispose; object_class->constructed = meta_input_settings_constructed; + + quark_tool_settings = + g_quark_from_static_string ("meta-input-settings-tool-settings"); } static void @@ -1162,6 +1202,29 @@ meta_input_settings_get_tablet_mapping (MetaInputSettings *settings, return g_settings_get_enum (info->settings, "mapping"); } +GDesktopStylusButtonAction +meta_input_settings_get_stylus_button_action (MetaInputSettings *input_settings, + ClutterInputDeviceTool *tool, + ClutterInputDevice *current_tablet, + guint button) +{ + GSettings *settings; + + g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), + G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT); + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), + G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT); + + settings = lookup_tool_settings (tool, current_tablet); + + if (button == 2) + return g_settings_get_enum (settings, "button-action"); + else if (button == 3) + return g_settings_get_enum (settings, "secondary-button-action"); + else + return G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT; +} + #ifdef HAVE_LIBWACOM WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings, |