[gtk+/font-chooser] gdk/x11: Add gdk_x11_device_get_id()



commit 98a9466819424714ce63b04a1aec94ba7a5e6714
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jul 14 17:43:59 2011 +0200

    gdk/x11: Add gdk_x11_device_get_id()
    
    This function can be used to find out the XInput2 device ID
    behind a GdkDevice, mostly useful when you need to interact
    with say Clutter, or raw libXi calls.

 docs/reference/gdk/gdk3-sections.txt |    1 +
 gdk/gdk.symbols                      |    1 +
 gdk/x11/Makefile.am                  |    1 +
 gdk/x11/gdkdevice-xi2.c              |    8 ++++++
 gdk/x11/gdkdevicemanager-x11.c       |   45 ++++++++++++++++++++++++++++++++++
 gdk/x11/gdkprivate-x11.h             |    3 ++
 gdk/x11/gdkx.h                       |    1 +
 gdk/x11/gdkx11device.h               |   35 ++++++++++++++++++++++++++
 8 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index 287599b..ab5cf98 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -928,6 +928,7 @@ GDK_POINTER_TO_XID
 GDK_XID_TO_POINTER
 gdk_x11_lookup_xdisplay
 gdk_x11_get_server_time
+gdk_x11_device_get_id
 gdk_x11_display_get_user_time
 gdk_x11_display_broadcast_startup_message
 gdk_x11_display_get_startup_notification_id
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols
index 239ca4e..8386bb9 100644
--- a/gdk/gdk.symbols
+++ b/gdk/gdk.symbols
@@ -513,6 +513,7 @@ gdk_x11_cursor_get_type
 gdk_x11_cursor_get_xcursor
 gdk_x11_cursor_get_xdisplay
 gdk_x11_device_core_get_type
+gdk_x11_device_get_id
 gdk_x11_device_manager_core_get_type
 gdk_x11_device_manager_xi2_get_type
 gdk_x11_device_manager_xi_get_type
diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am
index 6e10b49..bd01d93 100644
--- a/gdk/x11/Makefile.am
+++ b/gdk/x11/Makefile.am
@@ -66,6 +66,7 @@ libgdkinclude_HEADERS = 	\
 libgdkx11include_HEADERS = 	\
 	gdkx11applaunchcontext.h \
 	gdkx11cursor.h		\
+	gdkx11device.h		\
 	gdkx11device-core.h	\
 	gdkx11device-xi.h	\
 	gdkx11device-xi2.h	\
diff --git a/gdk/x11/gdkdevice-xi2.c b/gdk/x11/gdkdevice-xi2.c
index d56f8fa..b86d802 100644
--- a/gdk/x11/gdkdevice-xi2.c
+++ b/gdk/x11/gdkdevice-xi2.c
@@ -750,6 +750,14 @@ _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
   return state;
 }
 
+gint
+_gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
+{
+  g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), 0);
+
+  return device->device_id;
+}
+
 #else /* XINPUT_2 */
 
 static void
diff --git a/gdk/x11/gdkdevicemanager-x11.c b/gdk/x11/gdkdevicemanager-x11.c
index a19a05e..4d2ebfc 100644
--- a/gdk/x11/gdkdevicemanager-x11.c
+++ b/gdk/x11/gdkdevicemanager-x11.c
@@ -29,6 +29,12 @@
 #include "gdkinternals.h"
 #include "gdkprivate-x11.h"
 
+/* Defines for VCP/VCK, to be used too
+ * for the core protocol device manager
+ */
+#define VIRTUAL_CORE_POINTER_ID 2
+#define VIRTUAL_CORE_KEYBOARD_ID 3
+
 GdkDeviceManager *
 _gdk_x11_device_manager_new (GdkDisplay *display)
 {
@@ -83,3 +89,42 @@ _gdk_x11_device_manager_new (GdkDisplay *display)
                        "display", display,
                        NULL);
 }
+
+/**
+ * gdk_x11_device_get_id:
+ * @device: a #GdkDevice
+ *
+ * Returns the device ID as seen by XInput2.
+ *
+ * <note>
+ *   If gdk_disable_multidevice() has been called, this function
+ *   will respectively return 2/3 for the core pointer and keyboard,
+ *   (matching the IDs for the Virtual Core Pointer and Keyboard in
+ *   XInput 2), but calling this function on any slave devices (i.e.
+ *   those managed via XInput 1.x), will return 0.
+ * </note>
+ *
+ * Returns: the XInput2 device ID.
+ **/
+gint
+gdk_x11_device_get_id (GdkDevice *device)
+{
+  gint device_id = 0;
+
+  g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
+
+#ifdef XINPUT_2
+  if (GDK_IS_X11_DEVICE_XI2 (device))
+    device_id = _gdk_x11_device_xi2_get_id (GDK_X11_DEVICE_XI2 (device));
+  else
+#endif /* XINPUT_2 */
+    if (GDK_IS_X11_DEVICE_CORE (device))
+      {
+        if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
+          device_id = VIRTUAL_CORE_KEYBOARD_ID;
+        else
+          device_id = VIRTUAL_CORE_POINTER_ID;
+      }
+
+  return device_id;
+}
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index 52ff852..cb9b231 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -252,6 +252,9 @@ guchar * _gdk_x11_device_xi2_translate_event_mask (GdkEventMask     event_mask,
 guint    _gdk_x11_device_xi2_translate_state      (XIModifierState *mods_state,
                                                    XIButtonState   *buttons_state,
                                                    XIGroupState    *group_state);
+gint     _gdk_x11_device_xi2_get_id               (GdkX11DeviceXI2 *device);
+
+
 #endif
 
 void     _gdk_x11_event_translate_keyboard_string (GdkEventKey *event);
diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h
index 48207b5..66425c9 100644
--- a/gdk/x11/gdkx.h
+++ b/gdk/x11/gdkx.h
@@ -36,6 +36,7 @@
 
 #include <gdk/x11/gdkx11applaunchcontext.h>
 #include <gdk/x11/gdkx11cursor.h>
+#include <gdk/x11/gdkx11device.h>
 #include <gdk/x11/gdkx11device-core.h>
 #include <gdk/x11/gdkx11device-xi.h>
 #include <gdk/x11/gdkx11device-xi2.h>
diff --git a/gdk/x11/gdkx11device.h b/gdk/x11/gdkx11device.h
new file mode 100644
index 0000000..4a55540
--- /dev/null
+++ b/gdk/x11/gdkx11device.h
@@ -0,0 +1,35 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2011 Carlos Garnacho
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (__GDKX_H_INSIDE__) && !defined (GDK_COMPILATION)
+#error "Only <gdk/gdkx.h> can be included directly."
+#endif
+
+#ifndef __GDK_X11_DEVICE_H__
+#define __GDK_X11_DEVICE_H__
+
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+gint  gdk_x11_device_get_id  (GdkDevice *device);
+
+G_END_DECLS
+
+#endif /* __GDK_X11_DEVICE_H__ */



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