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



commit 780a63eedb974db6d6fa4421ad0777d3898d60dc
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 b952bae..dd9fbda 100644
--- a/app/widgets/gimpdevicemanager.c
+++ b/app/widgets/gimpdevicemanager.c
@@ -77,10 +77,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);
 
@@ -137,6 +137,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);
 
@@ -160,10 +162,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);
 
   g_signal_connect_object (private->gimp->config, "notify::devices-share-tool",
                            G_CALLBACK (gimp_device_manager_config_notify),
@@ -297,16 +301,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);
@@ -317,35 +350,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);
 
@@ -355,7 +412,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)
 {
@@ -364,7 +421,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)
     {
@@ -372,7 +429,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]