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 "gdkdevicemanagerprivate.h"
21 #include "gdkdisplay.h"
26 * SECTION:gdkdevicemanager
27 * @Short_description: Functions for handling input devices
28 * @Title: GdkDeviceManager
29 * @See_also: #GdkDevice, #GdkEvent
31 * In addition to a single pointer and keyboard for user interface input,
32 * GDK contains support for a variety of input devices, including graphics
33 * tablets, touchscreens and multiple pointers/keyboards interacting
34 * simultaneously with the user interface. Such input devices often have
35 * additional features, such as sub-pixel positioning information and
36 * additional device-dependent information.
38 * In order to query the device hierarchy and be aware of changes in the
39 * device hierarchy (such as virtual devices being created or removed, or
40 * physical devices being plugged or unplugged), GDK provides
43 * By default, and if the platform supports it, GDK is aware of multiple
44 * keyboard/pointer pairs and multitouch devices. This behavior can be
45 * changed by calling gdk_disable_multidevice() before gdk_display_open().
46 * There should rarely be a need to do that though, since GDK defaults
47 * to a compatibility mode in which it will emit just one enter/leave
48 * event pair for all devices on a window. To enable per-device
49 * enter/leave events and other multi-pointer interaction features,
50 * gdk_window_set_support_multidevice() must be called on
51 * #GdkWindows (or gtk_widget_set_support_multidevice() on widgets).
52 * window. See the gdk_window_set_support_multidevice() documentation
53 * for more information.
55 * On X11, multi-device support is implemented through XInput 2.
56 * Unless gdk_disable_multidevice() is called, the XInput 2
57 * #GdkDeviceManager implementation will be used as the input source.
58 * Otherwise either the core or XInput 1 implementations will be used.
60 * For simple applications that don't have any special interest in
61 * input devices, the so-called <firstterm>client pointer</firstterm>
62 * provides a reasonable approximation to a simple setup with a single
63 * pointer and keyboard. The device that has been set as the client
64 * pointer can be accessed via gdk_device_manager_get_client_pointer().
66 * Conceptually, in multidevice mode there are 2 device types. Virtual
67 * devices (or master devices) are represented by the pointer cursors
68 * and keyboard foci that are seen on the screen. Physical devices (or
69 * slave devices) represent the hardware that is controlling the virtual
70 * devices, and thus have no visible cursor on the screen.
72 * Virtual devices are always paired, so there is a keyboard device for every
73 * pointer device. Associations between devices may be inspected through
74 * gdk_device_get_associated_device().
76 * There may be several virtual devices, and several physical devices could
77 * be controlling each of these virtual devices. Physical devices may also
78 * be "floating", which means they are not attached to any virtual device.
80 * <example><title>Master and slave devices</title>
82 * carlos@sacarino:~$ xinput list
83 * ⎡ Virtual core pointer id=2 [master pointer (3)]
84 * ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
85 * ⎜ ↳ Wacom ISDv4 E6 Pen stylus id=10 [slave pointer (2)]
86 * ⎜ ↳ Wacom ISDv4 E6 Finger touch id=11 [slave pointer (2)]
87 * ⎜ ↳ SynPS/2 Synaptics TouchPad id=13 [slave pointer (2)]
88 * ⎜ ↳ TPPS/2 IBM TrackPoint id=14 [slave pointer (2)]
89 * ⎜ ↳ Wacom ISDv4 E6 Pen eraser id=16 [slave pointer (2)]
90 * ⎣ Virtual core keyboard id=3 [master keyboard (2)]
91 * ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
92 * ↳ Power Button id=6 [slave keyboard (3)]
93 * ↳ Video Bus id=7 [slave keyboard (3)]
94 * ↳ Sleep Button id=8 [slave keyboard (3)]
95 * ↳ Integrated Camera id=9 [slave keyboard (3)]
96 * ↳ AT Translated Set 2 keyboard id=12 [slave keyboard (3)]
97 * ↳ ThinkPad Extra Buttons id=15 [slave keyboard (3)]
101 * By default, GDK will automatically listen for events coming from all
102 * master devices, setting the #GdkDevice for all events coming from input
103 * devices. Events containing device information are #GDK_MOTION_NOTIFY,
104 * #GDK_BUTTON_PRESS, #GDK_2BUTTON_PRESS, #GDK_3BUTTON_PRESS,
105 * #GDK_BUTTON_RELEASE, #GDK_SCROLL, #GDK_KEY_PRESS, #GDK_KEY_RELEASE,
106 * #GDK_ENTER_NOTIFY, #GDK_LEAVE_NOTIFY, #GDK_FOCUS_CHANGE,
107 * #GDK_PROXIMITY_IN, #GDK_PROXIMITY_OUT, #GDK_DRAG_ENTER, #GDK_DRAG_LEAVE,
108 * #GDK_DRAG_MOTION, #GDK_DRAG_STATUS, #GDK_DROP_START, #GDK_DROP_FINISHED
109 * and #GDK_GRAB_BROKEN. When dealing with an event on a master device,
110 * it is possible to get the source (slave) device that the event originated
111 * from via gdk_event_get_source_device().
113 * In order to listen for events coming from devices
114 * other than a virtual device, gdk_window_set_device_events() must be
115 * called. Generally, this function can be used to modify the event mask
116 * for any given device.
118 * Input devices may also provide additional information besides X/Y.
119 * For example, graphics tablets may also provide pressure and X/Y tilt
120 * information. This information is device-dependent, and may be
121 * queried through gdk_device_get_axis(). In multidevice mode, virtual
122 * devices will change axes in order to always represent the physical
123 * device that is routing events through it. Whenever the physical device
124 * changes, the #GdkDevice:n-axes property will be notified, and
125 * gdk_device_list_axes() will return the new device axes.
127 * Devices may also have associated <firstterm>keys</firstterm> or
128 * macro buttons. Such keys can be globally set to map into normal X
129 * keyboard events. The mapping is set using gdk_device_set_key().
132 static void gdk_device_manager_set_property (GObject *object,
136 static void gdk_device_manager_get_property (GObject *object,
142 G_DEFINE_ABSTRACT_TYPE (GdkDeviceManager, gdk_device_manager, G_TYPE_OBJECT)
156 static guint signals [LAST_SIGNAL] = { 0 };
160 gdk_device_manager_class_init (GdkDeviceManagerClass *klass)
162 GObjectClass *object_class = G_OBJECT_CLASS (klass);
164 object_class->set_property = gdk_device_manager_set_property;
165 object_class->get_property = gdk_device_manager_get_property;
167 g_object_class_install_property (object_class,
169 g_param_spec_object ("display",
171 P_("Display for the device manager"),
173 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
174 G_PARAM_STATIC_STRINGS));
177 * GdkDeviceManager::device-added:
178 * @device_manager: the object on which the signal is emitted
179 * @device: the newly added #GdkDevice.
181 * The ::device-added signal is emitted either when a new master
182 * pointer is created, or when a slave (Hardware) input device
185 signals [DEVICE_ADDED] =
186 g_signal_new (g_intern_static_string ("device-added"),
187 G_TYPE_FROM_CLASS (klass),
189 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_added),
191 g_cclosure_marshal_VOID__OBJECT,
196 * GdkDeviceManager::device-removed:
197 * @device_manager: the object on which the signal is emitted
198 * @device: the just removed #GdkDevice.
200 * The ::device-removed signal is emitted either when a master
201 * pointer is removed, or when a slave (Hardware) input device
204 signals [DEVICE_REMOVED] =
205 g_signal_new (g_intern_static_string ("device-removed"),
206 G_TYPE_FROM_CLASS (klass),
208 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_removed),
210 g_cclosure_marshal_VOID__OBJECT,
215 * GdkDeviceManager::device-changed:
216 * @device_manager: the object on which the signal is emitted
217 * @device: the #GdkDevice that changed.
219 * The ::device-changed signal is emitted whenever a device
220 * has changed in the hierarchy, either slave devices being
221 * disconnected from their master device or connected to
222 * another one, or master devices being added or removed
225 * If a slave device is detached from all master devices
226 * (gdk_device_get_associated_device() returns %NULL), its
227 * #GdkDeviceType will change to %GDK_DEVICE_TYPE_FLOATING,
228 * if it's attached, it will change to %GDK_DEVICE_TYPE_SLAVE.
230 signals [DEVICE_CHANGED] =
231 g_signal_new (g_intern_static_string ("device-changed"),
232 G_TYPE_FROM_CLASS (klass),
234 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_changed),
236 g_cclosure_marshal_VOID__OBJECT,
242 gdk_device_manager_init (GdkDeviceManager *device_manager)
247 gdk_device_manager_set_property (GObject *object,
255 GDK_DEVICE_MANAGER (object)->display = g_value_get_object (value);
258 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
264 gdk_device_manager_get_property (GObject *object,
273 g_value_set_object (value, GDK_DEVICE_MANAGER (object)->display);
276 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
282 * gdk_device_manager_get_display:
283 * @device_manager: a #GdkDeviceManager
285 * Gets the #GdkDisplay associated to @device_manager.
287 * Returns: (transfer none): the #GdkDisplay to which @device_manager is
288 * associated to, or #NULL. This memory is owned by GDK and
289 * must not be freed or unreferenced.
294 gdk_device_manager_get_display (GdkDeviceManager *device_manager)
296 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
298 return device_manager->display;
302 * gdk_device_manager_list_devices:
303 * @device_manager: a #GdkDeviceManager
304 * @type: device type to get.
306 * Returns the list of devices of type @type currently attached to
309 * Returns: (transfer container) (element-type Gdk.Device): a list of
310 * #GdkDevice<!-- -->s. The returned list must be
311 * freed with g_list_free (). The list elements are owned by
312 * GTK+ and must not be freed or unreffed.
317 gdk_device_manager_list_devices (GdkDeviceManager *device_manager,
320 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
322 return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->list_devices (device_manager, type);
326 * gdk_device_manager_get_client_pointer:
327 * @device_manager: a #GdkDeviceManager
329 * Returns the client pointer, that is, the master pointer that acts as the core pointer
330 * for this application. In X11, window managers may change this depending on the interaction
331 * pattern under the presence of several pointers.
333 * You should use this function sheldomly, only in code that isn't triggered by a #GdkEvent
334 * and there aren't other means to get a meaningful #GdkDevice to operate on.
336 * Returns: (transfer none): The client pointer. This memory is
337 * owned by GDK and must not be freed or unreferenced.
342 gdk_device_manager_get_client_pointer (GdkDeviceManager *device_manager)
344 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
346 return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->get_client_pointer (device_manager);