[gimp/gtk3-port: 453/457] app: use GdkDeviceTool properties to GimpDeviceInfo



commit 4de70889714fbdcc4d3b3aa87a7dc6331e368681
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 16 22:42:34 2018 +0200

    app: use GdkDeviceTool properties to GimpDeviceInfo
    
    and display the current tool's info in GimpDeviceInfoEditor.

 app/widgets/gimpdeviceinfo.c       |  149 ++++++++++++++++++++++++++++++++++--
 app/widgets/gimpdeviceinfo.h       |   90 +++++++++++----------
 app/widgets/gimpdeviceinfoeditor.c |   15 ++++
 3 files changed, 205 insertions(+), 49 deletions(-)
---
diff --git a/app/widgets/gimpdeviceinfo.c b/app/widgets/gimpdeviceinfo.c
index cbfdd81..23a1cde 100644
--- a/app/widgets/gimpdeviceinfo.c
+++ b/app/widgets/gimpdeviceinfo.c
@@ -55,6 +55,9 @@ enum
   PROP_SOURCE,
   PROP_VENDOR_ID,
   PROP_PRODUCT_ID,
+  PROP_TOOL_TYPE,
+  PROP_TOOL_SERIAL,
+  PROP_TOOL_HARDWARE_ID,
   PROP_AXES,
   PROP_KEYS,
   PROP_PRESSURE_CURVE
@@ -76,6 +79,10 @@ static void   gimp_device_info_get_property (GObject        *object,
 
 static void   gimp_device_info_guess_icon   (GimpDeviceInfo *info);
 
+static void   gimp_device_info_tool_changed (GdkDevice      *device,
+                                             GdkDeviceTool  *tool,
+                                             GimpDeviceInfo *info);
+
 
 G_DEFINE_TYPE (GimpDeviceInfo, gimp_device_info, GIMP_TYPE_TOOL_PRESET)
 
@@ -142,6 +149,28 @@ gimp_device_info_class_init (GimpDeviceInfoClass *klass)
                                                         GIMP_PARAM_STATIC_STRINGS |
                                                         G_PARAM_READABLE));
 
+  g_object_class_install_property (object_class, PROP_TOOL_TYPE,
+                                   g_param_spec_enum ("tool-type",
+                                                      NULL, NULL,
+                                                      GDK_TYPE_DEVICE_TOOL_TYPE,
+                                                      GDK_DEVICE_TOOL_TYPE_UNKNOWN,
+                                                      GIMP_PARAM_STATIC_STRINGS |
+                                                      G_PARAM_READABLE));
+
+  g_object_class_install_property (object_class, PROP_TOOL_SERIAL,
+                                   g_param_spec_uint64 ("tool-serial",
+                                                        NULL, NULL,
+                                                        0, G_MAXUINT64, 0,
+                                                        GIMP_PARAM_STATIC_STRINGS |
+                                                        G_PARAM_READABLE));
+
+  g_object_class_install_property (object_class, PROP_TOOL_HARDWARE_ID,
+                                   g_param_spec_uint64 ("tool-hardware-id",
+                                                        NULL, NULL,
+                                                        0, G_MAXUINT64, 0,
+                                                        GIMP_PARAM_STATIC_STRINGS |
+                                                        G_PARAM_READABLE));
+
   param_spec = g_param_spec_enum ("axis",
                                   NULL, NULL,
                                   GDK_TYPE_AXIS_USE,
@@ -237,7 +266,15 @@ gimp_device_info_set_property (GObject      *object,
   switch (property_id)
     {
     case PROP_DEVICE:
+      if (info->device)
+        g_signal_handlers_disconnect_by_func (info->device,
+                                              gimp_device_info_tool_changed,
+                                              info);
       info->device = g_value_get_object (value);
+      if (info->device)
+        g_signal_connect_object (info->device, "tool-changed",
+                                 G_CALLBACK (gimp_device_info_tool_changed),
+                                 G_OBJECT (info), 0);
       break;
 
     case PROP_DISPLAY:
@@ -374,6 +411,18 @@ gimp_device_info_get_property (GObject    *object,
       g_value_set_string (value, gimp_device_info_get_product_id (info));
       break;
 
+    case PROP_TOOL_TYPE:
+      g_value_set_enum (value, gimp_device_info_get_tool_type (info));
+      break;
+
+    case PROP_TOOL_SERIAL:
+      g_value_set_uint64 (value, gimp_device_info_get_tool_serial (info));
+      break;
+
+    case PROP_TOOL_HARDWARE_ID:
+      g_value_set_uint64 (value, gimp_device_info_get_tool_hardware_id (info));
+      break;
+
     case PROP_AXES:
       {
         GimpValueArray *array;
@@ -496,6 +545,20 @@ gimp_device_info_guess_icon (GimpDeviceInfo *info)
     }
 }
 
+static void
+gimp_device_info_tool_changed (GdkDevice      *device,
+                               GdkDeviceTool  *tool,
+                               GimpDeviceInfo *info)
+{
+  g_object_freeze_notify (G_OBJECT (info));
+
+  g_object_notify (G_OBJECT (info), "tool-type");
+  g_object_notify (G_OBJECT (info), "tool-serial");
+  g_object_notify (G_OBJECT (info), "tool-hardware-id");
+
+  g_object_thaw_notify (G_OBJECT (info));
+}
+
 
 /*  public functions  */
 
@@ -557,8 +620,10 @@ gimp_device_info_set_device (GimpDeviceInfo *info,
 
   if (device)
     {
-      info->device  = device;
-      info->display = display;
+      g_object_set (info,
+                    "device",  device,
+                    "display", display,
+                    NULL);
 
       g_object_set_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY, info);
 
@@ -588,8 +653,10 @@ gimp_device_info_set_device (GimpDeviceInfo *info,
       device  = info->device;
       display = info->display;
 
-      info->device  = NULL;
-      info->display = NULL;
+      g_object_set (info,
+                    "device",  NULL,
+                    "display", NULL,
+                    NULL);
 
       g_object_set_data (G_OBJECT (device), GIMP_DEVICE_INFO_DATA_KEY, NULL);
 
@@ -620,11 +687,12 @@ gimp_device_info_set_device (GimpDeviceInfo *info,
   /*  sort order depends on device presence  */
   gimp_object_name_changed (GIMP_OBJECT (info));
 
-  g_object_notify (G_OBJECT (info), "device");
-  g_object_notify (G_OBJECT (info), "display");
   g_object_notify (G_OBJECT (info), "source");
   g_object_notify (G_OBJECT (info), "vendor-id");
   g_object_notify (G_OBJECT (info), "product-id");
+  g_object_notify (G_OBJECT (info), "tool-type");
+  g_object_notify (G_OBJECT (info), "tool-serial");
+  g_object_notify (G_OBJECT (info), "tool-hardware-id");
 
   g_object_thaw_notify (G_OBJECT (info));
 }
@@ -826,6 +894,75 @@ gimp_device_info_get_product_id (GimpDeviceInfo  *info)
   return id;
 }
 
+GdkDeviceToolType
+gimp_device_info_get_tool_type (GimpDeviceInfo *info)
+{
+  GdkDeviceToolType type = GDK_DEVICE_TOOL_TYPE_UNKNOWN;
+
+  g_return_val_if_fail (GIMP_IS_DEVICE_INFO (info), type);
+
+  if (info->device)
+    {
+      GdkDeviceTool *tool;
+
+      g_object_get (info->device, "tool", &tool, NULL);
+
+      if (tool)
+        {
+          type = gdk_device_tool_get_tool_type (tool);
+          g_object_unref (tool);
+        }
+    }
+
+  return type;
+}
+
+guint64
+gimp_device_info_get_tool_serial (GimpDeviceInfo *info)
+{
+  guint64 serial = 0;
+
+  g_return_val_if_fail (GIMP_IS_DEVICE_INFO (info), serial);
+
+  if (info->device)
+    {
+      GdkDeviceTool *tool;
+
+      g_object_get (info->device, "tool", &tool, NULL);
+
+      if (tool)
+        {
+          serial = gdk_device_tool_get_serial (tool);
+          g_object_unref (tool);
+        }
+    }
+
+  return serial;
+}
+
+guint64
+gimp_device_info_get_tool_hardware_id (GimpDeviceInfo *info)
+{
+  guint64 id = 0;
+
+  g_return_val_if_fail (GIMP_IS_DEVICE_INFO (info), id);
+
+  if (info->device)
+    {
+      GdkDeviceTool *tool;
+
+      g_object_get (info->device, "tool", &tool, NULL);
+
+      if (tool)
+        {
+          id = gdk_device_tool_get_hardware_id (tool);
+          g_object_unref (tool);
+        }
+    }
+
+  return id;
+}
+
 gint
 gimp_device_info_get_n_axes (GimpDeviceInfo *info)
 {
diff --git a/app/widgets/gimpdeviceinfo.h b/app/widgets/gimpdeviceinfo.h
index 583428a..9ba6f7f 100644
--- a/app/widgets/gimpdeviceinfo.h
+++ b/app/widgets/gimpdeviceinfo.h
@@ -70,63 +70,67 @@ struct _GimpDeviceInfoClass
 };
 
 
-GType            gimp_device_info_get_type          (void) G_GNUC_CONST;
+GType             gimp_device_info_get_type             (void) G_GNUC_CONST;
 
-GimpDeviceInfo * gimp_device_info_new               (Gimp            *gimp,
-                                                     GdkDevice       *device,
-                                                     GdkDisplay      *display);
+GimpDeviceInfo  * gimp_device_info_new                  (Gimp            *gimp,
+                                                         GdkDevice       *device,
+                                                         GdkDisplay      *display);
 
-GdkDevice      * gimp_device_info_get_device        (GimpDeviceInfo  *info,
-                                                     GdkDisplay     **display);
-void             gimp_device_info_set_device        (GimpDeviceInfo  *info,
-                                                     GdkDevice       *device,
-                                                     GdkDisplay      *display);
+GdkDevice       * gimp_device_info_get_device           (GimpDeviceInfo  *info,
+                                                         GdkDisplay     **display);
+void              gimp_device_info_set_device           (GimpDeviceInfo  *info,
+                                                         GdkDevice       *device,
+                                                         GdkDisplay      *display);
 
-void             gimp_device_info_set_default_tool  (GimpDeviceInfo  *info);
+void              gimp_device_info_set_default_tool     (GimpDeviceInfo  *info);
 
-void             gimp_device_info_save_tool         (GimpDeviceInfo  *info);
-void             gimp_device_info_restore_tool      (GimpDeviceInfo  *info);
+void              gimp_device_info_save_tool            (GimpDeviceInfo  *info);
+void              gimp_device_info_restore_tool         (GimpDeviceInfo  *info);
 
-GdkInputMode     gimp_device_info_get_mode          (GimpDeviceInfo  *info);
-void             gimp_device_info_set_mode          (GimpDeviceInfo  *info,
-                                                     GdkInputMode     mode);
+GdkInputMode      gimp_device_info_get_mode             (GimpDeviceInfo  *info);
+void              gimp_device_info_set_mode             (GimpDeviceInfo  *info,
+                                                         GdkInputMode     mode);
 
-gboolean         gimp_device_info_has_cursor        (GimpDeviceInfo  *info);
+gboolean          gimp_device_info_has_cursor           (GimpDeviceInfo  *info);
 
-GdkInputSource   gimp_device_info_get_source        (GimpDeviceInfo  *info);
+GdkInputSource    gimp_device_info_get_source           (GimpDeviceInfo  *info);
 
-const gchar    * gimp_device_info_get_vendor_id     (GimpDeviceInfo  *info);
-const gchar    * gimp_device_info_get_product_id    (GimpDeviceInfo  *info);
+const gchar     * gimp_device_info_get_vendor_id        (GimpDeviceInfo  *info);
+const gchar     * gimp_device_info_get_product_id       (GimpDeviceInfo  *info);
 
-gint             gimp_device_info_get_n_axes        (GimpDeviceInfo  *info);
-GdkAxisUse       gimp_device_info_get_axis_use      (GimpDeviceInfo  *info,
-                                                     gint             axis);
-void             gimp_device_info_set_axis_use      (GimpDeviceInfo  *info,
-                                                     gint             axis,
-                                                     GdkAxisUse       use);
+GdkDeviceToolType gimp_device_info_get_tool_type        (GimpDeviceInfo  *info);
+guint64           gimp_device_info_get_tool_serial      (GimpDeviceInfo  *info);
+guint64           gimp_device_info_get_tool_hardware_id (GimpDeviceInfo  *info);
 
-gint             gimp_device_info_get_n_keys        (GimpDeviceInfo  *info);
-void             gimp_device_info_get_key           (GimpDeviceInfo  *info,
-                                                     gint             key,
-                                                     guint           *keyval,
-                                                     GdkModifierType *modifiers);
-void             gimp_device_info_set_key           (GimpDeviceInfo  *info,
-                                                     gint             key,
-                                                     guint            keyval,
-                                                     GdkModifierType  modifiers);
+gint             gimp_device_info_get_n_axes            (GimpDeviceInfo  *info);
+GdkAxisUse       gimp_device_info_get_axis_use          (GimpDeviceInfo  *info,
+                                                         gint             axis);
+void             gimp_device_info_set_axis_use          (GimpDeviceInfo  *info,
+                                                         gint             axis,
+                                                         GdkAxisUse       use);
 
-GimpCurve      * gimp_device_info_get_curve         (GimpDeviceInfo  *info,
-                                                     GdkAxisUse       use);
-gdouble          gimp_device_info_map_axis          (GimpDeviceInfo  *info,
-                                                     GdkAxisUse       use,
-                                                     gdouble          value);
+gint             gimp_device_info_get_n_keys            (GimpDeviceInfo  *info);
+void             gimp_device_info_get_key               (GimpDeviceInfo  *info,
+                                                         gint             key,
+                                                         guint           *keyval,
+                                                         GdkModifierType *modifiers);
+void             gimp_device_info_set_key               (GimpDeviceInfo  *info,
+                                                         gint             key,
+                                                         guint            keyval,
+                                                         GdkModifierType  modifiers);
 
-void             gimp_device_info_changed           (GimpDeviceInfo  *info);
+GimpCurve      * gimp_device_info_get_curve             (GimpDeviceInfo  *info,
+                                                         GdkAxisUse       use);
+gdouble          gimp_device_info_map_axis              (GimpDeviceInfo  *info,
+                                                         GdkAxisUse       use,
+                                                         gdouble          value);
 
-GimpDeviceInfo * gimp_device_info_get_by_device     (GdkDevice       *device);
+void             gimp_device_info_changed               (GimpDeviceInfo  *info);
 
-gint             gimp_device_info_compare           (GimpDeviceInfo  *a,
-                                                     GimpDeviceInfo  *b);
+GimpDeviceInfo * gimp_device_info_get_by_device         (GdkDevice       *device);
+
+gint             gimp_device_info_compare               (GimpDeviceInfo  *a,
+                                                         GimpDeviceInfo  *b);
 
 
 G_END_DECLS
diff --git a/app/widgets/gimpdeviceinfoeditor.c b/app/widgets/gimpdeviceinfoeditor.c
index 85e9452..5577d65 100644
--- a/app/widgets/gimpdeviceinfoeditor.c
+++ b/app/widgets/gimpdeviceinfoeditor.c
@@ -380,6 +380,21 @@ gimp_device_info_editor_constructed (GObject *object)
                             _("Product ID:"), 0.0, 0.5,
                             label, 1);
 
+  label = gimp_prop_enum_label_new (G_OBJECT (private->info), "tool-type");
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, 4,
+                            _("Tool type:"), 0.0, 0.5,
+                            label, 1);
+
+  label = gimp_prop_label_new (G_OBJECT (private->info), "tool-serial");
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, 5,
+                            _("Tool serial:"), 0.0, 0.5,
+                            label, 1);
+
+  label = gimp_prop_label_new (G_OBJECT (private->info), "tool-hardware-id");
+  gimp_grid_attach_aligned (GTK_GRID (grid), 0, 6,
+                            _("Tool hardware ID:"), 0.0, 0.5,
+                            label, 1);
+
   /*  the axes  */
 
   n_axes = gimp_device_info_get_n_axes (private->info);


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