[mutter/wip/tablet-protocol-v2: 61/70] backends: Add API to trigger actions related to pad buttons



commit 016180c2e93d3949faa07bf68875637b06d92129
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 22 18:51:27 2016 +0200

    backends: Add API to trigger actions related to pad buttons
    
    It does nothing at the moment, but can be hooked into MetaWaylandTabletPad
    now. For X11, we need to trigger these for the pad events we receive from
    the passive pad button grabs.

 src/backends/meta-input-settings-private.h |    9 +++
 src/backends/meta-input-settings.c         |   89 ++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 8c8fed6..fe3e2f5 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -115,6 +115,15 @@ gdouble                    meta_input_settings_translate_tablet_tool_pressure (M
                                                                                ClutterInputDevice     
*current_tablet,
                                                                                gdouble                 
pressure);
 
+gboolean                   meta_input_settings_is_pad_button_grabbed     (MetaInputSettings  *input_settings,
+                                                                          ClutterInputDevice *pad,
+                                                                          guint               button);
+
+gboolean                   meta_input_settings_handle_pad_button         (MetaInputSettings  *input_settings,
+                                                                          ClutterInputDevice *pad,
+                                                                          gboolean            is_press,
+                                                                          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 0fec343..95ce0e2 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -947,6 +947,25 @@ lookup_tool_settings (ClutterInputDeviceTool *tool,
   return settings;
 }
 
+static GSettings *
+lookup_pad_button_settings (ClutterInputDevice *device,
+                            guint               button)
+{
+  const gchar *vendor, *product;
+  GSettings *settings;
+  gchar *path;
+
+  vendor = clutter_input_device_get_vendor_id (device);
+  product = clutter_input_device_get_product_id (device);
+  path = g_strdup_printf ("/org/gnome/desktop/peripherals/tablets/%s:%s/button%c/",
+                          vendor, product, 'A' + button);
+  settings = g_settings_new_with_path ("org.gnome.desktop.peripherals.tablet.pad-button",
+                                       path);
+  g_free (path);
+
+  return settings;
+}
+
 static void
 monitors_changed_cb (MetaMonitorManager *monitor_manager,
                      MetaInputSettings  *input_settings)
@@ -1225,6 +1244,26 @@ meta_input_settings_get_stylus_button_action (MetaInputSettings      *input_sett
     return G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT;
 }
 
+static GDesktopPadButtonAction
+meta_input_settings_get_pad_button_action (MetaInputSettings   *input_settings,
+                                           ClutterInputDevice  *pad,
+                                           guint                button)
+{
+  GDesktopPadButtonAction action;
+  GSettings *settings;
+
+  g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings),
+                        G_DESKTOP_PAD_BUTTON_ACTION_NONE);
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (pad),
+                        G_DESKTOP_PAD_BUTTON_ACTION_NONE);
+
+  settings = lookup_pad_button_settings (pad, button);
+  action = g_settings_get_enum (settings, "action");
+  g_object_unref (settings);
+
+  return action;
+}
+
 #ifdef HAVE_LIBWACOM
 WacomDevice *
 meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings,
@@ -1302,3 +1341,53 @@ meta_input_settings_translate_tablet_tool_pressure (MetaInputSettings      *inpu
 
   return pressure;
 }
+
+gboolean
+meta_input_settings_is_pad_button_grabbed (MetaInputSettings  *input_settings,
+                                           ClutterInputDevice *pad,
+                                           guint               button)
+{
+  MetaInputSettingsPrivate *priv;
+
+  g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), FALSE);
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (pad), FALSE);
+  g_return_val_if_fail (clutter_input_device_get_device_type (pad) ==
+                        CLUTTER_PAD_DEVICE, FALSE);
+
+  priv = meta_input_settings_get_instance_private (input_settings);
+
+  if (priv->osd)
+    return FALSE;
+
+  return (meta_input_settings_get_pad_button_action (input_settings, pad, button) !=
+          G_DESKTOP_PAD_BUTTON_ACTION_NONE);
+}
+
+gboolean
+meta_input_settings_handle_pad_button (MetaInputSettings  *input_settings,
+                                       ClutterInputDevice *pad,
+                                       gboolean            is_press,
+                                       guint               button)
+{
+  MetaInputSettingsPrivate *priv;
+  GDesktopPadButtonAction action;
+
+  g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), FALSE);
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (pad), FALSE);
+  g_return_val_if_fail (clutter_input_device_get_device_type (pad) ==
+                        CLUTTER_PAD_DEVICE, FALSE);
+
+  priv = meta_input_settings_get_instance_private (input_settings);
+
+  action = meta_input_settings_get_pad_button_action (input_settings, pad, button);
+
+  switch (action)
+    {
+    case G_DESKTOP_PAD_BUTTON_ACTION_SWITCH_MONITOR:
+    case G_DESKTOP_PAD_BUTTON_ACTION_KEYBINDING:
+    case G_DESKTOP_PAD_BUTTON_ACTION_HELP:
+    case G_DESKTOP_PAD_BUTTON_ACTION_NONE:
+    default:
+      return FALSE;
+    }
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]