[mutter] backends: Add function to retrieve the action mapped to an stylus button
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] backends: Add function to retrieve the action mapped to an stylus button
- Date: Fri, 22 Jul 2016 12:01:22 +0000 (UTC)
commit fbb4c0b8310ddc4ea8e47fd1f7ecdaf644566a53
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Jun 22 15:48:07 2016 +0200
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
src/backends/meta-input-settings-private.h | 4 +
src/backends/meta-input-settings.c | 112 ++++++++++++++++++++++++++++
2 files changed, 116 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 1b3e13f..45ce92f 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_create (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 708d90d..4ae12db 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -40,8 +40,11 @@
#include <meta/util.h>
+static GQuark quark_tool_settings = 0;
+
typedef struct _MetaInputSettingsPrivate MetaInputSettingsPrivate;
typedef struct _DeviceMappingInfo DeviceMappingInfo;
+typedef struct _ToolSettings ToolSettings;
struct _DeviceMappingInfo
{
@@ -53,6 +56,14 @@ struct _DeviceMappingInfo
#endif
};
+struct _ToolSettings
+{
+ GSettings *settings;
+ ClutterInputDeviceTool *tool;
+ GDesktopStylusButtonAction button_action;
+ GDesktopStylusButtonAction secondary_button_action;
+};
+
struct _MetaInputSettingsPrivate
{
ClutterDeviceManager *device_manager;
@@ -911,6 +922,81 @@ lookup_device_settings (ClutterInputDevice *device)
}
static void
+tool_settings_changed_cb (GSettings *settings,
+ const gchar *key,
+ ToolSettings *tool_settings)
+{
+ if (strcmp (key, "button-action") == 0)
+ tool_settings->button_action = g_settings_get_enum (settings, "button-action");
+ else if (strcmp (key, "secondary-button-action") == 0)
+ tool_settings->secondary_button_action = g_settings_get_enum (settings, "secondary-button-action");
+}
+
+static ToolSettings *
+tool_settings_new (ClutterInputDeviceTool *tool,
+ const gchar *schema_path)
+{
+ ToolSettings *tool_settings;
+
+ tool_settings = g_new0 (ToolSettings, 1);
+ tool_settings->tool = tool;
+ tool_settings->settings =
+ g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet.stylus",
+ schema_path);
+
+ g_signal_connect (tool_settings->settings, "changed",
+ G_CALLBACK (tool_settings_changed_cb), tool_settings);
+
+ /* Initialize values */
+ tool_settings->button_action =
+ g_settings_get_enum (tool_settings->settings, "button-action");
+ tool_settings->secondary_button_action =
+ g_settings_get_enum (tool_settings->settings, "secondary-button-action");
+
+ return tool_settings;
+}
+
+static void
+tool_settings_free (ToolSettings *tool_settings)
+{
+ g_object_unref (tool_settings->settings);
+ g_free (tool_settings);
+}
+
+static ToolSettings *
+lookup_tool_settings (ClutterInputDeviceTool *tool,
+ ClutterInputDevice *device)
+{
+ ToolSettings *tool_settings;
+ guint64 serial;
+ gchar *path;
+
+ tool_settings = g_object_get_qdata (G_OBJECT (tool), quark_tool_settings);
+ if (tool_settings)
+ return tool_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);
+ }
+
+ tool_settings = tool_settings_new (tool, path);
+ g_object_set_qdata_full (G_OBJECT (tool), quark_tool_settings, tool_settings,
+ (GDestroyNotify) tool_settings_free);
+ g_free (path);
+
+ return tool_settings;
+}
+
+static void
monitors_changed_cb (MetaMonitorManager *monitor_manager,
MetaInputSettings *input_settings)
{
@@ -1067,6 +1153,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
@@ -1148,6 +1237,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)
+{
+ ToolSettings *tool_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);
+
+ tool_settings = lookup_tool_settings (tool, current_tablet);
+
+ if (button == 2)
+ return tool_settings->button_action;
+ else if (button == 3)
+ return tool_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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]