[gimp/gtk3-port: 56/242] app: port device management to GdkDeviceManager



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

    app: port device management to GdkDeviceManager

 app/widgets/gimpdevices.c |   85 +++++++++++++++++++++++++++++++++++++--------
 1 files changed, 70 insertions(+), 15 deletions(-)
---
diff --git a/app/widgets/gimpdevices.c b/app/widgets/gimpdevices.c
index b09a9ac..8e1c8c4 100644
--- a/app/widgets/gimpdevices.c
+++ b/app/widgets/gimpdevices.c
@@ -78,10 +78,10 @@ static void   gimp_devices_display_closed (GdkDisplay        *display,
                                            gboolean           is_error,
                                            GimpDeviceManager *manager);
 
-static void   gimp_devices_device_added   (GdkDisplay        *gdk_display,
+static void   gimp_devices_device_added   (GdkDeviceManager  *gdk_manager,
                                            GdkDevice         *device,
                                            GimpDeviceManager *manager);
-static void   gimp_devices_device_removed (GdkDisplay        *gdk_display,
+static void   gimp_devices_device_removed (GdkDeviceManager  *gdk_manager,
                                            GdkDevice         *device,
                                            GimpDeviceManager *manager);
 
@@ -100,6 +100,8 @@ gimp_devices_init (Gimp                   *gimp,
   GSList            *displays;
   GSList            *list;
   GdkDisplay        *gdk_display;
+  GdkDeviceManager  *gdk_manager;
+  GdkDevice         *client_pointer;
 
   g_return_if_fail (GIMP_IS_GIMP (gimp));
   g_return_if_fail (gimp_device_manager_get (gimp) == NULL);
@@ -134,9 +136,11 @@ gimp_devices_init (Gimp                   *gimp,
                     manager);
 
   gdk_display = gdk_display_get_default ();
+  gdk_manager = gdk_display_get_device_manager (gdk_display);
 
-  manager->current_device =
-    gimp_device_info_get_by_device (gdk_display_get_core_pointer (gdk_display));
+  client_pointer = gdk_device_manager_get_client_pointer (gdk_manager);
+
+  manager->current_device = gimp_device_info_get_by_device (client_pointer);
 }
 
 void
@@ -424,16 +428,45 @@ gimp_devices_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 = gdk_display_list_devices (gdk_display); list; list = list->next)
+  for (list = devices; list; list = g_list_next (list))
     {
       GdkDevice *device = list->data;
 
-      gimp_devices_device_added (gdk_display, device, manager);
+      gimp_devices_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 = devices; list; list = g_list_next (list))
+    {
+      GdkDevice *device = list->data;
+
+      gimp_devices_device_added (gdk_manager, device, manager);
+    }
+
+  g_list_free (devices);
+
+  g_signal_connect (gdk_manager, "device-added",
+                    G_CALLBACK (gimp_devices_device_added),
+                    manager);
+  g_signal_connect (gdk_manager, "device-removed",
+                    G_CALLBACK (gimp_devices_device_removed),
+                    manager);
+
   g_signal_connect (gdk_display, "closed",
                     G_CALLBACK (gimp_devices_display_closed),
                     manager);
@@ -444,21 +477,43 @@ gimp_devices_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);
+
+  devices = gdk_device_manager_list_devices (gdk_manager,
+                                             GDK_DEVICE_TYPE_MASTER);
+
+  for (list = devices; list; list = list->next)
+    {
+      GdkDevice *device = list->data;
+
+      gimp_devices_device_removed (gdk_manager, device, manager);
+    }
 
-  for (list = gdk_display_list_devices (gdk_display); list; list = list->next)
+  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_devices_device_removed (gdk_display, device, manager);
+      gimp_devices_device_removed (gdk_manager, device, manager);
     }
+
+  g_list_free (devices);
 }
 
 static void
-gimp_devices_device_added (GdkDisplay        *gdk_display,
+gimp_devices_device_added (GdkDeviceManager  *gdk_manager,
                            GdkDevice         *device,
                            GimpDeviceManager *manager)
 {
+  GdkDisplay     *display = gdk_device_manager_get_display (gdk_manager);
   GimpDeviceInfo *device_info;
 
   device_info =
@@ -467,11 +522,11 @@ gimp_devices_device_added (GdkDisplay        *gdk_display,
 
   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 (manager->gimp, device, gdk_display);
+      device_info = gimp_device_info_new (manager->gimp, device, display);
 
       gimp_container_add (manager->device_info_list, GIMP_OBJECT (device_info));
       g_object_unref (device_info);
@@ -479,7 +534,7 @@ gimp_devices_device_added (GdkDisplay        *gdk_display,
 }
 
 static void
-gimp_devices_device_removed (GdkDisplay        *gdk_display,
+gimp_devices_device_removed (GdkDeviceManager  *gdk_manager,
                              GdkDevice         *device,
                              GimpDeviceManager *manager)
 {
@@ -495,7 +550,7 @@ gimp_devices_device_removed (GdkDisplay        *gdk_display,
 
       if (device_info == manager->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_devices_select_device (manager, device_info);



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