[gimp/gtk3-port: 33/233] app: port device management to GdkDeviceManager



commit 287f3e8c580b8dc54f80e02d081a41a6ca9baa94
Author: Michael Natterer <mitch gimp org>
Date:   Mon Oct 18 17:58:48 2010 +0200

    app: port device management to GdkDeviceManager

 app/widgets/gimpdevicemanager.c |   93 +++++++++++++++++++++++++++++++--------
 1 files changed, 75 insertions(+), 18 deletions(-)
---
diff --git a/app/widgets/gimpdevicemanager.c b/app/widgets/gimpdevicemanager.c
index 4135db1..805f62d 100644
--- a/app/widgets/gimpdevicemanager.c
+++ b/app/widgets/gimpdevicemanager.c
@@ -75,10 +75,10 @@ static void   gimp_device_manager_display_closed (GdkDisplay        *display,
                                                   gboolean           is_error,
                                                   GimpDeviceManager *manager);
 
-static void   gimp_device_manager_device_added   (GdkDisplay        *gdk_display,
+static void   gimp_device_manager_device_added   (GdkDeviceManager  *gdk_manager,
                                                   GdkDevice         *device,
                                                   GimpDeviceManager *manager);
-static void   gimp_device_manager_device_removed (GdkDisplay        *gdk_display,
+static void   gimp_device_manager_device_removed (GdkDeviceManager  *gdk_manager,
                                                   GdkDevice         *device,
                                                   GimpDeviceManager *manager);
 
@@ -131,6 +131,8 @@ gimp_device_manager_constructed (GObject *object)
   GSList                   *displays;
   GSList                   *list;
   GdkDisplay               *display;
+  GdkDeviceManager         *gdk_manager;
+  GdkDevice                *client_pointer;
 
   G_OBJECT_CLASS (parent_class)->constructed (object);
 
@@ -154,10 +156,12 @@ gimp_device_manager_constructed (GObject *object)
                     G_CALLBACK (gimp_device_manager_display_opened),
                     manager);
 
-  display = gdk_display_get_default ();
+  display     = gdk_display_get_default ();
+  gdk_manager = gdk_display_get_device_manager (display);
 
-  private->current_device =
-    gimp_device_info_get_by_device (gdk_display_get_core_pointer (display));
+  client_pointer = gdk_device_manager_get_client_pointer (gdk_manager);
+
+  private->current_device = gimp_device_info_get_by_device (client_pointer);
 }
 
 static void
@@ -279,16 +283,45 @@ gimp_device_manager_display_opened (GdkDisplayManager *disp_manager,
                                     GdkDisplay        *gdk_display,
                                     GimpDeviceManager *manager)
 {
-  GList *list;
+  GdkDeviceManager *gdk_manager;
+  GList            *devices;
+  GList            *list;
+
+  gdk_manager = gdk_display_get_device_manager (gdk_display);
+
+  devices = gdk_device_manager_list_devices (gdk_manager,
+                                             GDK_DEVICE_TYPE_MASTER);
+
+  /*  create device info structures for present devices */
+  for (list = devices; list; list = g_list_next (list))
+    {
+      GdkDevice *device = list->data;
+
+      gimp_device_manager_device_added (gdk_manager, device, manager);
+    }
+
+  g_list_free (devices);
+
+  devices = gdk_device_manager_list_devices (gdk_manager,
+                                             GDK_DEVICE_TYPE_FLOATING);
 
   /*  create device info structures for present devices */
-  for (list = gdk_display_list_devices (gdk_display); list; list = list->next)
+  for (list = devices; list; list = g_list_next (list))
     {
       GdkDevice *device = list->data;
 
-      gimp_device_manager_device_added (gdk_display, device, manager);
+      gimp_device_manager_device_added (gdk_manager, device, manager);
     }
 
+  g_list_free (devices);
+
+  g_signal_connect (gdk_manager, "device-added",
+                    G_CALLBACK (gimp_device_manager_device_added),
+                    manager);
+  g_signal_connect (gdk_manager, "device-removed",
+                    G_CALLBACK (gimp_device_manager_device_removed),
+                    manager);
+
   g_signal_connect (gdk_display, "closed",
                     G_CALLBACK (gimp_device_manager_display_closed),
                     manager);
@@ -299,35 +332,59 @@ gimp_device_manager_display_closed (GdkDisplay        *gdk_display,
                                     gboolean           is_error,
                                     GimpDeviceManager *manager)
 {
-  GList *list;
+  GdkDeviceManager *gdk_manager;
+  GList            *devices;
+  GList            *list;
+
+  gdk_manager = gdk_display_get_device_manager (gdk_display);
 
-  for (list = gdk_display_list_devices (gdk_display); list; list = list->next)
+  devices = gdk_device_manager_list_devices (gdk_manager,
+                                             GDK_DEVICE_TYPE_MASTER);
+
+  for (list = devices; list; list = list->next)
     {
       GdkDevice *device = list->data;
 
-      gimp_device_manager_device_removed (gdk_display, device, manager);
+      gimp_device_manager_device_removed (gdk_manager, device, manager);
     }
+
+  g_list_free (devices);
+
+  devices = gdk_device_manager_list_devices (gdk_manager,
+                                             GDK_DEVICE_TYPE_FLOATING);
+
+  for (list = devices; list; list = list->next)
+    {
+      GdkDevice *device = list->data;
+
+      gimp_device_manager_device_removed (gdk_manager, device, manager);
+    }
+
+  g_list_free (devices);
 }
 
 static void
-gimp_device_manager_device_added (GdkDisplay        *gdk_display,
+gimp_device_manager_device_added (GdkDeviceManager  *gdk_manager,
                                   GdkDevice         *device,
                                   GimpDeviceManager *manager)
 {
   GimpDeviceManagerPrivate *private = GET_PRIVATE (manager);
+  GdkDisplay               *display;
   GimpDeviceInfo           *device_info;
 
+  display = gdk_device_manager_get_display (gdk_manager);
+
   device_info =
     GIMP_DEVICE_INFO (gimp_container_get_child_by_name (GIMP_CONTAINER (manager),
-                                                        device->name));
+                                                        gdk_device_get_name (device)));
 
   if (device_info)
     {
-      gimp_device_info_set_device (device_info, device, gdk_display);
+      gimp_device_info_set_device (device_info, device, display);
     }
   else
     {
-      device_info = gimp_device_info_new (private->gimp, device, gdk_display);
+      device_info = gimp_device_info_new (private->gimp, device, display);
 
       gimp_device_info_set_default_tool (device_info);
 
@@ -337,7 +394,7 @@ gimp_device_manager_device_added (GdkDisplay        *gdk_display,
 }
 
 static void
-gimp_device_manager_device_removed (GdkDisplay        *gdk_display,
+gimp_device_manager_device_removed (GdkDeviceManager  *gdk_manager,
                                     GdkDevice         *device,
                                     GimpDeviceManager *manager)
 {
@@ -346,7 +403,7 @@ gimp_device_manager_device_removed (GdkDisplay        *gdk_display,
 
   device_info =
     GIMP_DEVICE_INFO (gimp_container_get_child_by_name (GIMP_CONTAINER (manager),
-                                                        device->name));
+                                                        gdk_device_get_name (device)));
 
   if (device_info)
     {
@@ -354,7 +411,7 @@ gimp_device_manager_device_removed (GdkDisplay        *gdk_display,
 
       if (device_info == private->current_device)
         {
-          device      = gdk_display_get_core_pointer (gdk_display);
+          device      = gdk_device_manager_get_client_pointer (gdk_manager);
           device_info = gimp_device_info_get_by_device (device);
 
           gimp_device_manager_set_current_device (manager, device_info);


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