forked from AuroraMiddleware/gtk
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.
This commit is contained in:
parent
1f264ddb4b
commit
f90c154472
@ -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
|
||||
|
@ -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
|
||||
|
@ -66,6 +66,7 @@ libgdkinclude_HEADERS = \
|
||||
libgdkx11include_HEADERS = \
|
||||
gdkx11applaunchcontext.h \
|
||||
gdkx11cursor.h \
|
||||
gdkx11device.h \
|
||||
gdkx11device-core.h \
|
||||
gdkx11device-xi.h \
|
||||
gdkx11device-xi2.h \
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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>
|
||||
|
35
gdk/x11/gdkx11device.h
Normal file
35
gdk/x11/gdkx11device.h
Normal file
@ -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__ */
|
Loading…
Reference in New Issue
Block a user