[mutter/wip/tablet-protocol-v2: 40/48] backends: Fetch libwacom information for tablets in MetaInputSettings



commit 549c2e26867be3e4e986b874a3486583efba8ca4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri May 13 13:20:07 2016 +0200

    backends: Fetch libwacom information for tablets in MetaInputSettings
    
    Given that information defines largely how such devices are to be
    configured, it makes sense to have that information at hand. A getter
    has been also added for the places where it could be useful, although
    it will require HAVE_LIBWACOM checks in callers too.

 src/backends/meta-input-settings-private.h |    9 ++++
 src/backends/meta-input-settings.c         |   56 ++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 4a8cf68..897ebde 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -26,6 +26,10 @@
 
 #include <clutter/clutter.h>
 
+#ifdef HAVE_LIBWACOM
+#include <libwacom/libwacom.h>
+#endif
+
 #define META_TYPE_INPUT_SETTINGS             (meta_input_settings_get_type ())
 #define META_INPUT_SETTINGS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), META_TYPE_INPUT_SETTINGS, 
MetaInputSettings))
 #define META_INPUT_SETTINGS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass),  META_TYPE_INPUT_SETTINGS, 
MetaInputSettingsClass))
@@ -100,4 +104,9 @@ MetaInputSettings * meta_input_settings_create (void);
 GDesktopTabletMapping meta_input_settings_get_tablet_mapping (MetaInputSettings  *settings,
                                                               ClutterInputDevice *device);
 
+#ifdef HAVE_LIBWACOM
+WacomDevice * meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings,
+                                                           ClutterInputDevice *device);
+#endif
+
 #endif /* META_INPUT_SETTINGS_PRIVATE_H */
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index d7464b8..42d799f 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -48,6 +48,9 @@ struct _DeviceMappingInfo
   MetaInputSettings *input_settings;
   ClutterInputDevice *device;
   GSettings *settings;
+#ifdef HAVE_LIBWACOM
+  WacomDevice *wacom_device;
+#endif
 };
 
 struct _MetaInputSettingsPrivate
@@ -62,6 +65,10 @@ struct _MetaInputSettingsPrivate
   GSettings *keyboard_settings;
 
   GHashTable *mappable_devices;
+
+#ifdef HAVE_LIBWACOM
+  WacomDeviceDatabase *wacom_db;
+#endif
 };
 
 typedef void (*ConfigBoolFunc)   (MetaInputSettings  *input_settings,
@@ -122,6 +129,9 @@ meta_input_settings_dispose (GObject *object)
 
   g_clear_object (&priv->monitor_manager);
 
+  if (priv->wacom_db)
+    libwacom_database_destroy (priv->wacom_db);
+
   G_OBJECT_CLASS (meta_input_settings_parent_class)->dispose (object);
 }
 
@@ -866,6 +876,26 @@ check_add_mappable_device (MetaInputSettings  *input_settings,
   info->device = device;
   info->settings = settings;
 
+#ifdef HAVE_LIBWACOM
+  if (clutter_input_device_get_device_type (device) == CLUTTER_TABLET_DEVICE ||
+      clutter_input_device_get_device_type (device) == CLUTTER_PAD_DEVICE)
+    {
+      WacomError *error = libwacom_error_new ();
+
+      info->wacom_device = libwacom_new_from_path (priv->wacom_db,
+                                                   clutter_input_device_get_device_node (device),
+                                                   WFALLBACK_NONE, error);
+      if (!info->wacom_device)
+        {
+          g_warning ("Could not get tablet information for '%s': %s",
+                     clutter_input_device_get_device_name (device),
+                     libwacom_error_get_message (error));
+        }
+
+      libwacom_error_free (&error);
+    }
+#endif
+
   g_signal_connect (settings, "changed",
                     G_CALLBACK (mapped_device_changed_cb), NULL);
 
@@ -991,6 +1021,13 @@ meta_input_settings_init (MetaInputSettings *settings)
   priv->monitor_manager = g_object_ref (meta_monitor_manager_get ());
   g_signal_connect (priv->monitor_manager, "monitors-changed",
                     G_CALLBACK (monitors_changed_cb), settings);
+
+  priv->wacom_db = libwacom_database_new ();
+  if (!priv->wacom_db)
+    {
+      g_warning ("Could not create database of Wacom devices, "
+                 "expect tablets to misbehave");
+    }
 }
 
 MetaInputSettings *
@@ -1028,3 +1065,22 @@ meta_input_settings_get_tablet_mapping (MetaInputSettings  *settings,
 
   return g_settings_get_enum (info->settings, "mapping");
 }
+
+#ifdef HAVE_LIBWACOM
+WacomDevice *
+meta_input_settings_get_tablet_wacom_device (MetaInputSettings *settings,
+                                             ClutterInputDevice *device)
+{
+  MetaInputSettingsPrivate *priv;
+  DeviceMappingInfo *info;
+
+  g_return_val_if_fail (META_IS_INPUT_SETTINGS (settings), NULL);
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL);
+
+  priv = meta_input_settings_get_instance_private (settings);
+  info = g_hash_table_lookup (priv->mappable_devices, device);
+  g_return_val_if_fail (info != NULL, NULL);
+
+  return info->wacom_device;
+}
+#endif /* HAVE_LIBWACOM */


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