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.
This commit is contained in:
Carlos Garnacho 2011-07-14 17:49:44 +02:00
parent f90c154472
commit 6aab48ead0
8 changed files with 93 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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 \

View File

@ -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
@ -90,6 +91,45 @@ _gdk_x11_device_manager_new (GdkDisplay *display)
NULL);
}
/**
* 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

View File

@ -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));
}

View File

@ -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

View File

@ -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>

View File

@ -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__ */