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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gdkdevicemanager.h"
25 #include "gdkinternals.h"
29 * SECTION:gdkdevicemanager
30 * @Short_description: Functions for handling input devices
31 * @Long_description: In addition to a single pointer and keyboard for user interface input, GDK
32 * contains support for a variety of input devices, including graphics tablets,
33 * touchscreens and multiple pointers/keyboards interacting simultaneously with
34 * the user interface. Under X, the support for multiple input devices is done
35 * through the <firstterm>XInput 2</firstterm> extension, which also supports
36 * additional features such as sub-pixel positioning information and additional
37 * device-dependent information.
38 * @Title: GdkDeviceManager
39 * @See_also: #GdkDevice, #GdkEvent, gdk_disable_multidevice()
41 * By default, and if the platform supports it, GDK is aware of multiple keyboard/pointer pairs
42 * and multitouch devices, this behavior can be changed by calling gdk_disable_multidevice()
43 * before gdk_display_open(), although there would be rarely a reason to do that. For a widget
44 * or window to be dealt as multipointer aware, gdk_window_set_support_multidevice() or
45 * gtk_widget_set_support_multidevice() must have been called on it.
47 * Conceptually, in multidevice mode there are 2 device types, virtual devices (or master devices)
48 * are represented by the pointer cursors and keyboard foci that are seen on the screen. physical
49 * devices (or slave devices) represent the hardware that is controlling the virtual devices, and
50 * thus has no visible cursor on the screen.
52 * Virtual devices are always paired, there is a keyboard device for every pointer device,
53 * associations between devices may be inspected through gdk_device_get_associated_device().
55 * There may be several virtual devices, and several physical devices could be controlling each of
56 * these virtual devices. Physical devices may also be "floating", which means they are not attached
57 * to any virtual device.
59 * By default, GDK will automatically listen for events coming from all master devices, setting the
60 * #GdkDevice for all events coming from input devices
62 * Events containing device information are #GDK_MOTION_NOTIFY, #GDK_BUTTON_PRESS, #GDK_2BUTTON_PRESS,
63 * #GDK_3BUTTON_PRESS, #GDK_BUTTON_RELEASE, #GDK_SCROLL, #GDK_KEY_PRESS, #GDK_KEY_RELEASE,
64 * #GDK_ENTER_NOTIFY, #GDK_LEAVE_NOTIFY, #GDK_FOCUS_CHANGE, #GDK_PROXIMITY_IN, #GDK_PROXIMITY_OUT,
65 * #GDK_DRAG_ENTER, #GDK_DRAG_LEAVE, #GDK_DRAG_MOTION, #GDK_DRAG_STATUS, #GDK_DROP_START,
66 * #GDK_DROP_FINISHED and #GDK_GRAB_BROKEN.
68 * , although gdk_window_set_support_multidevice() has to be called on #GdkWindow<!-- --> in order to
69 * support additional features of multiple pointer interaction, such as multiple, per-device enter/leave
70 * events. The default setting will emit just one enter/leave event pair for all devices on the window.
71 * See gdk_window_set_support_multidevice() documentation for more information.
73 * In order to listen for events coming from other than a virtual device, gdk_window_set_device_events()
74 * must be called. Generally, this function can be used to modify the event mask for any given device.
76 * Input devices may also provide additional information besides X/Y. For example, graphics tablets may
77 * also provide pressure and X/Y tilt information. This information is device-dependent, and may be
78 * queried through gdk_device_get_axis(). In multidevice mode, virtual devices will change axes in order
79 * to always represent the physical device that is routing events through it. Whenever the physical device
80 * changes, the #GdkDevice:n-axes property will be notified, and gdk_device_list_axes() will return the
83 * Devices may also have associated <firstterm>keys</firstterm> or macro buttons. Such keys can be
84 * globally set to map into normal X keyboard events. The mapping is set using gdk_device_set_key().
86 * In order to query the device hierarchy and be aware of changes in the device hierarchy (such as
87 * virtual devices being created or removed, or physical devices being plugged or unplugged), GDK
88 * provides #GdkDeviceManager. On X11, multidevice support is implemented through XInput 2. If
89 * gdk_enable_multidevice() is called, the XInput 2.x #GdkDeviceManager implementation will be used
90 * as input source, else either the core or XInput 1.x implementations will be used.
93 static void gdk_device_manager_set_property (GObject *object,
97 static void gdk_device_manager_get_property (GObject *object,
103 G_DEFINE_ABSTRACT_TYPE (GdkDeviceManager, gdk_device_manager, G_TYPE_OBJECT)
117 static guint signals [LAST_SIGNAL] = { 0 };
120 struct _GdkDeviceManagerPrivate
127 gdk_device_manager_class_init (GdkDeviceManagerClass *klass)
129 GObjectClass *object_class = G_OBJECT_CLASS (klass);
131 object_class->set_property = gdk_device_manager_set_property;
132 object_class->get_property = gdk_device_manager_get_property;
134 g_object_class_install_property (object_class,
136 g_param_spec_object ("display",
138 P_("Display for the device manager"),
140 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
141 G_PARAM_STATIC_STRINGS));
144 * GdkDeviceManager::device-added:
145 * @device_manager: the object on which the signal is emitted
146 * @device: the newly added #GdkDevice.
148 * The ::device-added signal is emitted either when a new master
149 * pointer is created, or when a slave (Hardware) input device
152 signals [DEVICE_ADDED] =
153 g_signal_new (g_intern_static_string ("device-added"),
154 G_TYPE_FROM_CLASS (klass),
156 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_added),
158 g_cclosure_marshal_VOID__OBJECT,
163 * GdkDeviceManager::device-removed:
164 * @device_manager: the object on which the signal is emitted
165 * @device: the just removed #GdkDevice.
167 * The ::device-removed signal is emitted either when a master
168 * pointer is removed, or when a slave (Hardware) input device
171 signals [DEVICE_REMOVED] =
172 g_signal_new (g_intern_static_string ("device-removed"),
173 G_TYPE_FROM_CLASS (klass),
175 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_removed),
177 g_cclosure_marshal_VOID__OBJECT,
182 * GdkDeviceManager::device-changed:
183 * @device_manager: the object on which the signal is emitted
184 * @device: the #GdkDevice that changed.
186 * The ::device-changed signal is emitted whenever a device
187 * has changed in the hierarchy, either slave devices being
188 * disconnected from their master device or connected to
189 * another one, or master devices being added or removed
192 * If a slave device is detached from all master devices
193 * (gdk_device_get_associated_device() returns %NULL), its
194 * #GdkDeviceType will change to %GDK_DEVICE_TYPE_FLOATING,
195 * if it's attached, it will change to %GDK_DEVICE_TYPE_SLAVE.
197 signals [DEVICE_CHANGED] =
198 g_signal_new (g_intern_static_string ("device-changed"),
199 G_TYPE_FROM_CLASS (klass),
201 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_changed),
203 g_cclosure_marshal_VOID__OBJECT,
207 g_type_class_add_private (object_class, sizeof (GdkDeviceManagerPrivate));
211 gdk_device_manager_init (GdkDeviceManager *device_manager)
213 GdkDeviceManagerPrivate *priv;
215 device_manager->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE (device_manager,
216 GDK_TYPE_DEVICE_MANAGER,
217 GdkDeviceManagerPrivate);
221 gdk_device_manager_set_property (GObject *object,
226 GdkDeviceManagerPrivate *priv;
228 priv = GDK_DEVICE_MANAGER (object)->priv;
233 priv->display = g_value_get_object (value);
236 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
242 gdk_device_manager_get_property (GObject *object,
247 GdkDeviceManagerPrivate *priv;
249 priv = GDK_DEVICE_MANAGER (object)->priv;
254 g_value_set_object (value, priv->display);
257 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
263 * gdk_device_manager_get_display:
264 * @device_manager: a #GdkDeviceManager
266 * Gets the #GdkDisplay associated to @device_manager.
268 * Returns: (transfer none): the #GdkDisplay to which @device_manager is
269 * associated to, or #NULL. This memory is owned by GDK and
270 * must not be freed or unreferenced.
275 gdk_device_manager_get_display (GdkDeviceManager *device_manager)
277 GdkDeviceManagerPrivate *priv;
279 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
281 priv = device_manager->priv;
283 return priv->display;
287 * gdk_device_manager_list_devices:
288 * @device_manager: a #GdkDeviceManager
289 * @type: device type to get.
291 * Returns the list of devices of type @type currently attached to
294 * Returns: (transfer container) (element-type Gdk.Device): a list of
295 * #GdkDevice<!-- -->s. The returned list must be
296 * freed with g_list_free (). The list elements are owned by
297 * GTK+ and must not be freed or unreffed.
302 gdk_device_manager_list_devices (GdkDeviceManager *device_manager,
305 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
307 return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->list_devices (device_manager, type);
311 * gdk_device_manager_get_client_pointer:
312 * @device_manager: a #GdkDeviceManager
314 * Returns the client pointer, that is, the master pointer that acts as the core pointer
315 * for this application. In X11, window managers may change this depending on the interaction
316 * pattern under the presence of several pointers.
318 * You should use this function sheldomly, only in code that isn't triggered by a #GdkEvent
319 * and there aren't other means to get a meaningful #GdkDevice to operate on.
321 * Returns: (transfer none): The client pointer. This memory is
322 * owned by GDK and must not be freed or unreferenced.
327 gdk_device_manager_get_client_pointer (GdkDeviceManager *device_manager)
329 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
331 return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->get_client_pointer (device_manager);