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:
		| @ -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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Carlos Garnacho
					Carlos Garnacho