1 | /* GDK - The GIMP Drawing Kit |
2 | * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org> |
3 | * |
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. |
8 | * |
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. |
13 | * |
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/>. |
16 | */ |
17 | |
18 | #include "config.h" |
19 | |
20 | #include "gdkx11devicemanager-xi2.h" |
21 | #include "gdkprivate-x11.h" |
22 | #include "gdkdisplay-x11.h" |
23 | |
24 | /* Defines for VCP/VCK, to be used too |
25 | * for the core protocol device manager |
26 | */ |
27 | #define VIRTUAL_CORE_POINTER_ID 2 |
28 | #define VIRTUAL_CORE_KEYBOARD_ID 3 |
29 | |
30 | GdkX11DeviceManagerXI2 * |
31 | _gdk_x11_device_manager_new (GdkDisplay *display) |
32 | { |
33 | int opcode, firstevent, firsterror; |
34 | Display *xdisplay; |
35 | |
36 | xdisplay = GDK_DISPLAY_XDISPLAY (display); |
37 | |
38 | if (XQueryExtension (xdisplay, "XInputExtension" , |
39 | &opcode, &firstevent, &firsterror)) |
40 | { |
41 | int major, minor; |
42 | |
43 | major = 2; |
44 | minor = 4; |
45 | |
46 | if (XIQueryVersion (dpy: xdisplay, major_version_inout: &major, minor_version_inout: &minor) != BadRequest) |
47 | { |
48 | GdkX11DeviceManagerXI2 *device_manager_xi2; |
49 | |
50 | GDK_DISPLAY_NOTE (display, INPUT, |
51 | g_message ("Creating XI2 (version %d.%d) device manager" , |
52 | major, minor)); |
53 | |
54 | device_manager_xi2 = g_object_new (GDK_TYPE_X11_DEVICE_MANAGER_XI2, |
55 | first_property_name: "display" , display, |
56 | "opcode" , opcode, |
57 | "major" , major, |
58 | "minor" , minor, |
59 | NULL); |
60 | |
61 | return device_manager_xi2; |
62 | } |
63 | } |
64 | |
65 | g_error ("XInput2 support not found on display" ); |
66 | } |
67 | |
68 | /** |
69 | * gdk_x11_device_manager_lookup: |
70 | * @device_manager: (type GdkX11DeviceManagerXI2): a `GdkDeviceManager` |
71 | * @device_id: a device ID, as understood by the XInput2 protocol |
72 | * |
73 | * Returns the `GdkDevice` that wraps the given device ID. |
74 | * |
75 | * Returns: (transfer none) (nullable) (type GdkX11DeviceXI2): The |
76 | * `GdkDevice` wrapping the device ID, or %NULL if the given ID |
77 | * doesn’t currently represent a device. |
78 | */ |
79 | GdkDevice * |
80 | gdk_x11_device_manager_lookup (GdkX11DeviceManagerXI2 *device_manager, |
81 | int device_id) |
82 | { |
83 | g_return_val_if_fail (GDK_IS_X11_DEVICE_MANAGER_XI2 (device_manager), NULL); |
84 | |
85 | return _gdk_x11_device_manager_xi2_lookup (GDK_X11_DEVICE_MANAGER_XI2 (device_manager), |
86 | device_id); |
87 | } |
88 | |
89 | /** |
90 | * gdk_x11_device_get_id: |
91 | * @device: (type GdkX11DeviceXI2): a `GdkDevice` |
92 | * |
93 | * Returns the device ID as seen by XInput2. |
94 | * |
95 | * Returns: the XInput2 device ID |
96 | */ |
97 | int |
98 | gdk_x11_device_get_id (GdkDevice *device) |
99 | { |
100 | g_return_val_if_fail (GDK_IS_DEVICE (device), 0); |
101 | |
102 | return _gdk_x11_device_xi2_get_id (GDK_X11_DEVICE_XI2 (device)); |
103 | } |
104 | |