[gtk+/xi2-playground: 8/12] GdkDeviceManager: Add gdk_device_manager_get_client_pointer().



commit 2d40e49f90529566681311125439186664bb692d
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Jun 8 15:16:59 2010 +0200

    GdkDeviceManager: Add gdk_device_manager_get_client_pointer().
    
    This function makes a better replacement for
    gdk_display_get_core_pointer(), wherever it might yet be needed, for
    XI2 resorts to XIGetClientPointer(), for the others return the only
    core pointer.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=621685

 docs/reference/gdk/gdk3-sections.txt |    1 +
 gdk/gdk.symbols                      |    1 +
 gdk/gdkdevicemanager.c               |   24 ++++++++++++++++++++++++
 gdk/gdkdevicemanager.h               |    2 ++
 gdk/gdkdisplay.c                     |    4 ++--
 gdk/quartz/gdkdevicemanager-core.c   |   11 +++++++++++
 gdk/win32/gdkdevicemanager-win32.c   |   11 +++++++++++
 gdk/x11/gdkdevicemanager-core.c      |   11 +++++++++++
 gdk/x11/gdkdevicemanager-xi2.c       |   19 +++++++++++++++++++
 gdk/x11/gdkdevicemanager-xi2.h       |    2 ++
 10 files changed, 84 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index 76e4a2c..2bc1dc5 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -1052,6 +1052,7 @@ GdkGrabOwnership
 gdk_enable_multidevice
 gdk_device_manager_get_display
 gdk_device_manager_list_devices
+gdk_device_manager_get_client_pointer
 
 <SUBSECTION>
 gdk_device_get_name
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols
index b83b3f6..8718d63 100644
--- a/gdk/gdk.symbols
+++ b/gdk/gdk.symbols
@@ -415,6 +415,7 @@ gdk_cursor_get_image
 gdk_device_manager_get_display
 gdk_device_manager_get_type G_GNUC_CONST
 gdk_device_manager_list_devices
+gdk_device_manager_get_client_pointer
 #endif
 #endif
 
diff --git a/gdk/gdkdevicemanager.c b/gdk/gdkdevicemanager.c
index 6fa8960..c9395f2 100644
--- a/gdk/gdkdevicemanager.c
+++ b/gdk/gdkdevicemanager.c
@@ -299,5 +299,29 @@ gdk_device_manager_list_devices (GdkDeviceManager *device_manager,
   return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->list_devices (device_manager, type);
 }
 
+/**
+ * gdk_device_manager_get_client_pointer:
+ * @device_manager: a #GdkDeviceManager
+ *
+ * Returns the client pointer, that is, the master pointer that acts as the core pointer
+ * for this application. In X11, window managers may change this depending on the interaction
+ * pattern under the presence of several pointers.
+ *
+ * You should use this function sheldomly, only in code that isn't triggered by a #GdkEvent
+ * and there aren't other means to get a meaningful #GdkDevice to operate on.
+ *
+ * Returns: The client pointer.
+ *
+ * Since: 3.0
+ **/
+GdkDevice *
+gdk_device_manager_get_client_pointer (GdkDeviceManager *device_manager)
+{
+  g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
+
+  return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->get_client_pointer (device_manager);
+}
+
+
 #define __GDK_DEVICE_MANAGER_C__
 #include "gdkaliasdef.c"
diff --git a/gdk/gdkdevicemanager.h b/gdk/gdkdevicemanager.h
index 32ac376..bed2bbb 100644
--- a/gdk/gdkdevicemanager.h
+++ b/gdk/gdkdevicemanager.h
@@ -63,6 +63,7 @@ struct _GdkDeviceManagerClass
   /* VMethods */
   GList * (* list_devices) (GdkDeviceManager *device_manager,
                             GdkDeviceType     type);
+  GdkDevice * (* get_client_pointer) (GdkDeviceManager *device_manager);
 };
 
 GType gdk_device_manager_get_type (void) G_GNUC_CONST;
@@ -70,6 +71,7 @@ GType gdk_device_manager_get_type (void) G_GNUC_CONST;
 GdkDisplay *             gdk_device_manager_get_display      (GdkDeviceManager *device_manager);
 GList *                  gdk_device_manager_list_devices     (GdkDeviceManager *device_manager,
                                                               GdkDeviceType     type);
+GdkDevice *              gdk_device_manager_get_client_pointer (GdkDeviceManager *device_manager);
 
 G_END_DECLS
 
diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c
index d1f6a47..366fcfd 100644
--- a/gdk/gdkdisplay.c
+++ b/gdk/gdkdisplay.c
@@ -605,7 +605,7 @@ gdk_event_send_clientmessage_toall (GdkEvent *event)
  * Return value: the core pointer device; this is owned by the
  *   display and should not be freed.
  *
- * Deprecated: 3.0: Use gdk_display_get_device_manager() instead, or
+ * Deprecated: 3.0: Use gdk_display_get_client_pointer() instead, or
  *             gdk_event_get_device() if a #GdkEvent with pointer device
  *             information is available.
  **/
@@ -626,7 +626,7 @@ gdk_device_get_core_pointer (void)
  *
  * Since: 2.2
  *
- * Deprecated: 3.0: Use gdk_display_get_device_manager() instead, or
+ * Deprecated: 3.0: Use gdk_display_get_client_pointer() instead, or
  *             gdk_event_get_device() if a #GdkEvent with device
  *             information is available.
  **/
diff --git a/gdk/quartz/gdkdevicemanager-core.c b/gdk/quartz/gdkdevicemanager-core.c
index d4765c1..e96e9a9 100644
--- a/gdk/quartz/gdkdevicemanager-core.c
+++ b/gdk/quartz/gdkdevicemanager-core.c
@@ -34,6 +34,7 @@ static void    gdk_device_manager_core_constructed (GObject *object);
 
 static GList * gdk_device_manager_core_list_devices (GdkDeviceManager *device_manager,
                                                      GdkDeviceType     type);
+static GdkDevice * gdk_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager);
 
 
 G_DEFINE_TYPE (GdkDeviceManagerCore, gdk_device_manager_core, GDK_TYPE_DEVICE_MANAGER)
@@ -47,6 +48,7 @@ gdk_device_manager_core_class_init (GdkDeviceManagerCoreClass *klass)
   object_class->finalize = gdk_device_manager_core_finalize;
   object_class->constructed = gdk_device_manager_core_constructed;
   device_manager_class->list_devices = gdk_device_manager_core_list_devices;
+  device_manager_class->get_client_pointer = gdk_device_manager_core_get_client_pointer;
 }
 
 static GdkDevice *
@@ -128,3 +130,12 @@ gdk_device_manager_core_list_devices (GdkDeviceManager *device_manager,
 
   return devices;
 }
+
+static GdkDevice *
+gdk_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager)
+{
+  GdkDeviceManagerCore *device_manager_core;
+
+  device_manager_core = (GdkDeviceManagerCore *) device_manager;
+  return device_manager_core->core_pointer;
+}
diff --git a/gdk/win32/gdkdevicemanager-win32.c b/gdk/win32/gdkdevicemanager-win32.c
index eea8142..e3696bb 100644
--- a/gdk/win32/gdkdevicemanager-win32.c
+++ b/gdk/win32/gdkdevicemanager-win32.c
@@ -69,6 +69,7 @@ static void    gdk_device_manager_win32_constructed (GObject *object);
 
 static GList * gdk_device_manager_win32_list_devices (GdkDeviceManager *device_manager,
                                                       GdkDeviceType     type);
+static GdkDevice * gdk_device_manager_win32_get_client_pointer (GdkDeviceManager *device_manager);
 
 
 G_DEFINE_TYPE (GdkDeviceManagerWin32, gdk_device_manager_win32, GDK_TYPE_DEVICE_MANAGER)
@@ -82,6 +83,7 @@ gdk_device_manager_win32_class_init (GdkDeviceManagerWin32Class *klass)
   object_class->finalize = gdk_device_manager_win32_finalize;
   object_class->constructed = gdk_device_manager_win32_constructed;
   device_manager_class->list_devices = gdk_device_manager_win32_list_devices;
+  device_manager_class->get_client_pointer = gdk_device_manager_win32_get_client_pointer;
 }
 
 static GdkDevice *
@@ -690,6 +692,15 @@ gdk_device_manager_win32_list_devices (GdkDeviceManager *device_manager,
   return devices;
 }
 
+static GdkDevice *
+gdk_device_manager_win32_get_client_pointer (GdkDeviceManager *device_manager)
+{
+  GdkDeviceManagerWin32 *device_manager_win32;
+
+  device_manager_win32 = (GdkDeviceManagerWin32 *) device_manager;
+  return device_manager_win32->core_pointer;
+}
+
 void
 _gdk_input_set_tablet_active (void)
 {
diff --git a/gdk/x11/gdkdevicemanager-core.c b/gdk/x11/gdkdevicemanager-core.c
index 7d2e9e4..5fb6f2e 100644
--- a/gdk/x11/gdkdevicemanager-core.c
+++ b/gdk/x11/gdkdevicemanager-core.c
@@ -42,6 +42,7 @@ static void    gdk_device_manager_core_constructed (GObject *object);
 
 static GList * gdk_device_manager_core_list_devices (GdkDeviceManager *device_manager,
                                                      GdkDeviceType     type);
+static GdkDevice * gdk_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager);
 
 static void     gdk_device_manager_event_translator_init (GdkEventTranslatorIface *iface);
 
@@ -64,6 +65,7 @@ gdk_device_manager_core_class_init (GdkDeviceManagerCoreClass *klass)
   object_class->finalize = gdk_device_manager_core_finalize;
   object_class->constructed = gdk_device_manager_core_constructed;
   device_manager_class->list_devices = gdk_device_manager_core_list_devices;
+  device_manager_class->get_client_pointer = gdk_device_manager_core_get_client_pointer;
 }
 
 static void
@@ -900,5 +902,14 @@ gdk_device_manager_core_list_devices (GdkDeviceManager *device_manager,
   return devices;
 }
 
+static GdkDevice *
+gdk_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager)
+{
+  GdkDeviceManagerCore *device_manager_core;
+
+  device_manager_core = (GdkDeviceManagerCore *) device_manager;
+  return device_manager_core->core_pointer;
+}
+
 #define __GDK_DEVICE_MANAGER_CORE_C__
 #include "gdkaliasdef.c"
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 48d7c18..e519cfa 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -38,6 +38,7 @@ static void    gdk_device_manager_xi2_finalize    (GObject *object);
 
 static GList * gdk_device_manager_xi2_list_devices (GdkDeviceManager *device_manager,
                                                     GdkDeviceType     type);
+static GdkDevice * gdk_device_manager_xi2_get_client_pointer (GdkDeviceManager *device_manager);
 
 static void     gdk_device_manager_xi2_event_translator_init (GdkEventTranslatorIface *iface);
 
@@ -66,6 +67,7 @@ gdk_device_manager_xi2_class_init (GdkDeviceManagerXI2Class *klass)
   object_class->finalize = gdk_device_manager_xi2_finalize;
 
   device_manager_class->list_devices = gdk_device_manager_xi2_list_devices;
+  device_manager_class->get_client_pointer = gdk_device_manager_xi2_get_client_pointer;
 }
 
 static void
@@ -422,6 +424,23 @@ gdk_device_manager_xi2_list_devices (GdkDeviceManager *device_manager,
   return g_list_copy (list);
 }
 
+static GdkDevice *
+gdk_device_manager_xi2_get_client_pointer (GdkDeviceManager *device_manager)
+{
+  GdkDeviceManagerXI2 *device_manager_xi2;
+  GdkDisplay *display;
+  int device_id;
+
+  device_manager_xi2 = (GdkDeviceManagerXI2 *) device_manager;
+  display = gdk_device_manager_get_display (device_manager);
+
+  XIGetClientPointer (GDK_DISPLAY_XDISPLAY (display),
+                      None, &device_id);
+
+  return g_hash_table_lookup (device_manager_xi2->id_table,
+                              GINT_TO_POINTER (device_id));
+}
+
 static void
 gdk_device_manager_xi2_event_translator_init (GdkEventTranslatorIface *iface)
 {
diff --git a/gdk/x11/gdkdevicemanager-xi2.h b/gdk/x11/gdkdevicemanager-xi2.h
index 828aec3..20054c1 100644
--- a/gdk/x11/gdkdevicemanager-xi2.h
+++ b/gdk/x11/gdkdevicemanager-xi2.h
@@ -45,6 +45,8 @@ struct _GdkDeviceManagerXI2
   GList *slave_devices;
   GList *floating_devices;
 
+  GdkDevice *client_pointer;
+
   int opcode;
 };
 



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