1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20 #include "gdkx11devicemanager-core.h"
21 #include "gdkdevicemanagerprivate-core.h"
23 #include "gdkx11devicemanager-xi2.h"
25 #include "gdkinternals.h"
26 #include "gdkprivate-x11.h"
28 /* Defines for VCP/VCK, to be used too
29 * for the core protocol device manager
31 #define VIRTUAL_CORE_POINTER_ID 2
32 #define VIRTUAL_CORE_KEYBOARD_ID 3
35 _gdk_x11_device_manager_new (GdkDisplay *display)
37 if (!g_getenv ("GDK_CORE_DEVICE_EVENTS"))
40 int opcode, firstevent, firsterror;
43 xdisplay = GDK_DISPLAY_XDISPLAY (display);
45 if (XQueryExtension (xdisplay, "XInputExtension",
46 &opcode, &firstevent, &firsterror))
55 #endif /* XINPUT_2_2 */
57 if (!_gdk_disable_multidevice &&
58 XIQueryVersion (xdisplay, &major, &minor) != BadRequest)
60 GdkX11DeviceManagerXI2 *device_manager_xi2;
62 GDK_NOTE (INPUT, g_print ("Creating XI2 device manager\n"));
64 device_manager_xi2 = g_object_new (GDK_TYPE_X11_DEVICE_MANAGER_XI2,
71 return GDK_DEVICE_MANAGER (device_manager_xi2);
77 GDK_NOTE (INPUT, g_print ("Creating core device manager\n"));
79 return g_object_new (GDK_TYPE_X11_DEVICE_MANAGER_CORE,
85 * gdk_x11_device_manager_lookup:
86 * @device_manager: a #GdkDeviceManager
87 * @device_id: a device ID, as understood by the XInput2 protocol
89 * Returns the #GdkDevice that wraps the given device ID.
91 * Returns: (transfer none): (allow-none): The #GdkDevice wrapping the device ID,
92 * or %NULL if the given ID doesn't currently represent a device.
97 gdk_x11_device_manager_lookup (GdkDeviceManager *device_manager,
100 GdkDevice *device = NULL;
102 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
105 if (GDK_IS_X11_DEVICE_MANAGER_XI2 (device_manager))
106 device = _gdk_x11_device_manager_xi2_lookup (GDK_X11_DEVICE_MANAGER_XI2 (device_manager),
109 #endif /* XINPUT_2 */
110 if (GDK_IS_X11_DEVICE_MANAGER_CORE (device_manager))
112 /* It is a core/xi1 device manager, we only map
113 * IDs 2 and 3, matching XI2's Virtual Core Pointer
116 if (device_id == VIRTUAL_CORE_POINTER_ID)
117 device = GDK_X11_DEVICE_MANAGER_CORE (device_manager)->core_pointer;
118 else if (device_id == VIRTUAL_CORE_KEYBOARD_ID)
119 device = GDK_X11_DEVICE_MANAGER_CORE (device_manager)->core_keyboard;
126 * gdk_x11_device_get_id:
127 * @device: a #GdkDevice
129 * Returns the device ID as seen by XInput2.
132 * If gdk_disable_multidevice() has been called, this function
133 * will respectively return 2/3 for the core pointer and keyboard,
134 * (matching the IDs for the Virtual Core Pointer and Keyboard in
135 * XInput 2), but calling this function on any slave devices (i.e.
136 * those managed via XInput 1.x), will return 0.
139 * Returns: the XInput2 device ID.
144 gdk_x11_device_get_id (GdkDevice *device)
148 g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
151 if (GDK_IS_X11_DEVICE_XI2 (device))
152 device_id = _gdk_x11_device_xi2_get_id (GDK_X11_DEVICE_XI2 (device));
154 #endif /* XINPUT_2 */
155 if (GDK_IS_X11_DEVICE_CORE (device))
157 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
158 device_id = VIRTUAL_CORE_KEYBOARD_ID;
160 device_id = VIRTUAL_CORE_POINTER_ID;