[gtk+/font-chooser] gdk/x11: Add gdk_x11_device_manager_lookup()
- From: Alberto Ruiz <aruiz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/font-chooser] gdk/x11: Add gdk_x11_device_manager_lookup()
- Date: Wed, 20 Jul 2011 20:17:12 +0000 (UTC)
commit 63269fd57a8526dd9df4caf84fd2898255164c97
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Jul 14 17:49:44 2011 +0200
gdk/x11: Add gdk_x11_device_manager_lookup()
This function can be used to find the GdkDevice wrapping
an XInput2 device ID. For core devices, the Virtual Core
Pointer/Keyboard IDs (2/3) may be used.
docs/reference/gdk/gdk3-sections.txt | 1 +
gdk/gdk.symbols | 1 +
gdk/x11/Makefile.am | 1 +
gdk/x11/gdkdevicemanager-x11.c | 40 ++++++++++++++++++++++++++++++++++
gdk/x11/gdkdevicemanager-xi2.c | 8 ++++++
gdk/x11/gdkprivate-x11.h | 2 +
gdk/x11/gdkx.h | 1 +
gdk/x11/gdkx11devicemanager.h | 39 +++++++++++++++++++++++++++++++++
8 files changed, 93 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gdk/gdk3-sections.txt b/docs/reference/gdk/gdk3-sections.txt
index ab5cf98..6f373f1 100644
--- a/docs/reference/gdk/gdk3-sections.txt
+++ b/docs/reference/gdk/gdk3-sections.txt
@@ -929,6 +929,7 @@ GDK_XID_TO_POINTER
gdk_x11_lookup_xdisplay
gdk_x11_get_server_time
gdk_x11_device_get_id
+gdk_x11_device_manager_lookup
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 8386bb9..04ca455 100644
--- a/gdk/gdk.symbols
+++ b/gdk/gdk.symbols
@@ -515,6 +515,7 @@ 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_lookup
gdk_x11_device_manager_xi2_get_type
gdk_x11_device_manager_xi_get_type
gdk_x11_device_xi2_get_type
diff --git a/gdk/x11/Makefile.am b/gdk/x11/Makefile.am
index bd01d93..3b0d1bd 100644
--- a/gdk/x11/Makefile.am
+++ b/gdk/x11/Makefile.am
@@ -70,6 +70,7 @@ libgdkx11include_HEADERS = \
gdkx11device-core.h \
gdkx11device-xi.h \
gdkx11device-xi2.h \
+ gdkx11devicemanager.h \
gdkx11devicemanager-core.h \
gdkx11devicemanager-xi.h \
gdkx11devicemanager-xi2.h \
diff --git a/gdk/x11/gdkdevicemanager-x11.c b/gdk/x11/gdkdevicemanager-x11.c
index 4d2ebfc..b492304 100644
--- a/gdk/x11/gdkdevicemanager-x11.c
+++ b/gdk/x11/gdkdevicemanager-x11.c
@@ -20,6 +20,7 @@
#include "config.h"
#include "gdkx11devicemanager-core.h"
+#include "gdkdevicemanagerprivate-core.h"
#ifdef XINPUT_XFREE
#include "gdkx11devicemanager-xi.h"
#ifdef XINPUT_2
@@ -91,6 +92,45 @@ _gdk_x11_device_manager_new (GdkDisplay *display)
}
/**
+ * gdk_x11_device_manager_lookup:
+ * @device_manager: a #GdkDeviceManager
+ * @device_id: a device ID, as understood by the XInput2 protocol
+ *
+ * Returns the #GdkDevice that wraps the given device ID.
+ *
+ * Returns: (transfer none): (allow-none): The #GdkDevice wrapping the device ID,
+ * or %NULL if the given ID doesn't currently represent a device.
+ **/
+GdkDevice *
+gdk_x11_device_manager_lookup (GdkDeviceManager *device_manager,
+ gint device_id)
+{
+ GdkDevice *device = NULL;
+
+ g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
+
+#ifdef XINPUT_2
+ if (GDK_IS_X11_DEVICE_MANAGER_XI2 (device_manager))
+ device = _gdk_x11_device_manager_xi2_lookup (GDK_X11_DEVICE_MANAGER_XI2 (device_manager),
+ device_id);
+ else
+#endif /* XINPUT_2 */
+ if (GDK_IS_X11_DEVICE_MANAGER_CORE (device_manager))
+ {
+ /* It is a core/xi1 device manager, we only map
+ * IDs 2 and 3, matching XI2's Virtual Core Pointer
+ * and Keyboard.
+ */
+ if (device_id == VIRTUAL_CORE_POINTER_ID)
+ device = GDK_X11_DEVICE_MANAGER_CORE (device_manager)->core_pointer;
+ else if (device_id == VIRTUAL_CORE_KEYBOARD_ID)
+ device = GDK_X11_DEVICE_MANAGER_CORE (device_manager)->core_keyboard;
+ }
+
+ return device;
+}
+
+/**
* gdk_x11_device_get_id:
* @device: a #GdkDevice
*
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 29d8fa1..5bd5500 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -1392,3 +1392,11 @@ gdk_x11_device_manager_xi2_event_translator_init (GdkEventTranslatorIface *iface
}
#endif /* XINPUT_2 */
+
+GdkDevice *
+_gdk_x11_device_manager_xi2_lookup (GdkX11DeviceManagerXI2 *device_manager_xi2,
+ gint device_id)
+{
+ return g_hash_table_lookup (device_manager_xi2->id_table,
+ GINT_TO_POINTER (device_id));
+}
diff --git a/gdk/x11/gdkprivate-x11.h b/gdk/x11/gdkprivate-x11.h
index cb9b231..0a832f9 100644
--- a/gdk/x11/gdkprivate-x11.h
+++ b/gdk/x11/gdkprivate-x11.h
@@ -254,6 +254,8 @@ guint _gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
XIGroupState *group_state);
gint _gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device);
+GdkDevice * _gdk_x11_device_manager_xi2_lookup (GdkX11DeviceManagerXI2 *device_manager_xi2,
+ gint device_id);
#endif
diff --git a/gdk/x11/gdkx.h b/gdk/x11/gdkx.h
index 66425c9..be0b9a6 100644
--- a/gdk/x11/gdkx.h
+++ b/gdk/x11/gdkx.h
@@ -40,6 +40,7 @@
#include <gdk/x11/gdkx11device-core.h>
#include <gdk/x11/gdkx11device-xi.h>
#include <gdk/x11/gdkx11device-xi2.h>
+#include <gdk/x11/gdkx11devicemanager.h>
#include <gdk/x11/gdkx11devicemanager-core.h>
#include <gdk/x11/gdkx11devicemanager-xi.h>
#include <gdk/x11/gdkx11devicemanager-xi2.h>
diff --git a/gdk/x11/gdkx11devicemanager.h b/gdk/x11/gdkx11devicemanager.h
new file mode 100644
index 0000000..bc5b5c5
--- /dev/null
+++ b/gdk/x11/gdkx11devicemanager.h
@@ -0,0 +1,39 @@
+/* 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_MANAGER_H__
+#define __GDK_X11_DEVICE_MANAGER_H__
+
+#include <gdk/gdk.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+
+G_BEGIN_DECLS
+
+GdkDevice * gdk_x11_device_manager_lookup (GdkDeviceManager *device_manager,
+ gint device_id);
+
+G_END_DECLS
+
+#endif /* __GDK_X11_DEVICE_MANAGER_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]