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 "gdkdevicemanagerprivate.h"
23 #include "gdkdisplay.h"
28 * SECTION:gdkdevicemanager
29 * @Short_description: Functions for handling input devices
30 * @Title: GdkDeviceManager
31 * @See_also: #GdkDevice, #GdkEvent
33 * In addition to a single pointer and keyboard for user interface input,
34 * GDK contains support for a variety of input devices, including graphics
35 * tablets, touchscreens and multiple pointers/keyboards interacting
36 * simultaneously with the user interface. Under X, the support for multiple
37 * input devices is done through the <firstterm>XInput 2</firstterm> extension,
38 * which also supports additional features such as sub-pixel positioning
39 * information and additional device-dependent information.
41 * By default, and if the platform supports it, GDK is aware of multiple
42 * keyboard/pointer pairs and multitouch devices, this behavior can be
43 * changed by calling gdk_disable_multidevice() before gdk_display_open(),
44 * although there would be rarely a reason to do that. For a widget or
45 * window to be dealt as multipointer aware,
46 * gdk_window_set_support_multidevice() or
47 * gtk_widget_set_support_multidevice() must have been called on it.
49 * Conceptually, in multidevice mode there are 2 device types, virtual
50 * devices (or master devices) are represented by the pointer cursors
51 * and keyboard foci that are seen on the screen. Physical devices (or
52 * slave devices) represent the hardware that is controlling the virtual
53 * devices, and thus has no visible cursor on the screen.
55 * Virtual devices are always paired, there is a keyboard device for every
56 * pointer device, associations between devices may be inspected through
57 * gdk_device_get_associated_device().
59 * There may be several virtual devices, and several physical devices could
60 * be controlling each of these virtual devices. Physical devices may also
61 * be "floating", which means they are not attached to any virtual device.
63 * By default, GDK will automatically listen for events coming from all
64 * master devices, setting the #GdkDevice for all events coming from input
67 * Events containing device information are #GDK_MOTION_NOTIFY,
68 * #GDK_BUTTON_PRESS, #GDK_2BUTTON_PRESS, #GDK_3BUTTON_PRESS,
69 * #GDK_BUTTON_RELEASE, #GDK_SCROLL, #GDK_KEY_PRESS, #GDK_KEY_RELEASE,
70 * #GDK_ENTER_NOTIFY, #GDK_LEAVE_NOTIFY, #GDK_FOCUS_CHANGE,
71 * #GDK_PROXIMITY_IN, #GDK_PROXIMITY_OUT, #GDK_DRAG_ENTER, #GDK_DRAG_LEAVE,
72 * #GDK_DRAG_MOTION, #GDK_DRAG_STATUS, #GDK_DROP_START, #GDK_DROP_FINISHED
73 * and #GDK_GRAB_BROKEN.
75 * although gdk_window_set_support_multidevice() has to be called on
76 * #GdkWindows in order to support additional features of multiple pointer
77 * interaction, such as multiple, per-device enter/leave events. The default
78 * setting will emit just one enter/leave event pair for all devices on the
79 * window. See gdk_window_set_support_multidevice() documentation for more
82 * In order to listen for events coming from other than a virtual device,
83 * gdk_window_set_device_events() must be called. Generally, this function
84 * can be used to modify the event mask for any given device.
86 * Input devices may also provide additional information besides X/Y.
87 * For example, graphics tablets may also provide pressure and X/Y tilt
88 * information. This information is device-dependent, and may be
89 * queried through gdk_device_get_axis(). In multidevice mode, virtual
90 * devices will change axes in order to always represent the physical
91 * device that is routing events through it. Whenever the physical device
92 * changes, the #GdkDevice:n-axes property will be notified, and
93 * gdk_device_list_axes() will return the new device axes.
95 * Devices may also have associated <firstterm>keys</firstterm> or
96 * macro buttons. Such keys can be globally set to map into normal X
97 * keyboard events. The mapping is set using gdk_device_set_key().
99 * In order to query the device hierarchy and be aware of changes in the
100 * device hierarchy (such as virtual devices being created or removed, or
101 * physical devices being plugged or unplugged), GDK provides
102 * #GdkDeviceManager. On X11, multidevice support is implemented through
103 * XInput 2. Unless gdk_disable_multidevice() is called, the XInput 2.x
104 * #GdkDeviceManager implementation will be used as input source, else
105 * either the core or XInput 1.x implementations will be used.
108 static void gdk_device_manager_set_property (GObject *object,
112 static void gdk_device_manager_get_property (GObject *object,
118 G_DEFINE_ABSTRACT_TYPE (GdkDeviceManager, gdk_device_manager, G_TYPE_OBJECT)
132 static guint signals [LAST_SIGNAL] = { 0 };
136 gdk_device_manager_class_init (GdkDeviceManagerClass *klass)
138 GObjectClass *object_class = G_OBJECT_CLASS (klass);
140 object_class->set_property = gdk_device_manager_set_property;
141 object_class->get_property = gdk_device_manager_get_property;
143 g_object_class_install_property (object_class,
145 g_param_spec_object ("display",
147 P_("Display for the device manager"),
149 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
150 G_PARAM_STATIC_STRINGS));
153 * GdkDeviceManager::device-added:
154 * @device_manager: the object on which the signal is emitted
155 * @device: the newly added #GdkDevice.
157 * The ::device-added signal is emitted either when a new master
158 * pointer is created, or when a slave (Hardware) input device
161 signals [DEVICE_ADDED] =
162 g_signal_new (g_intern_static_string ("device-added"),
163 G_TYPE_FROM_CLASS (klass),
165 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_added),
167 g_cclosure_marshal_VOID__OBJECT,
172 * GdkDeviceManager::device-removed:
173 * @device_manager: the object on which the signal is emitted
174 * @device: the just removed #GdkDevice.
176 * The ::device-removed signal is emitted either when a master
177 * pointer is removed, or when a slave (Hardware) input device
180 signals [DEVICE_REMOVED] =
181 g_signal_new (g_intern_static_string ("device-removed"),
182 G_TYPE_FROM_CLASS (klass),
184 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_removed),
186 g_cclosure_marshal_VOID__OBJECT,
191 * GdkDeviceManager::device-changed:
192 * @device_manager: the object on which the signal is emitted
193 * @device: the #GdkDevice that changed.
195 * The ::device-changed signal is emitted whenever a device
196 * has changed in the hierarchy, either slave devices being
197 * disconnected from their master device or connected to
198 * another one, or master devices being added or removed
201 * If a slave device is detached from all master devices
202 * (gdk_device_get_associated_device() returns %NULL), its
203 * #GdkDeviceType will change to %GDK_DEVICE_TYPE_FLOATING,
204 * if it's attached, it will change to %GDK_DEVICE_TYPE_SLAVE.
206 signals [DEVICE_CHANGED] =
207 g_signal_new (g_intern_static_string ("device-changed"),
208 G_TYPE_FROM_CLASS (klass),
210 G_STRUCT_OFFSET (GdkDeviceManagerClass, device_changed),
212 g_cclosure_marshal_VOID__OBJECT,
218 gdk_device_manager_init (GdkDeviceManager *device_manager)
223 gdk_device_manager_set_property (GObject *object,
231 GDK_DEVICE_MANAGER (object)->display = g_value_get_object (value);
234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
240 gdk_device_manager_get_property (GObject *object,
249 g_value_set_object (value, GDK_DEVICE_MANAGER (object)->display);
252 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
258 * gdk_device_manager_get_display:
259 * @device_manager: a #GdkDeviceManager
261 * Gets the #GdkDisplay associated to @device_manager.
263 * Returns: (transfer none): the #GdkDisplay to which @device_manager is
264 * associated to, or #NULL. This memory is owned by GDK and
265 * must not be freed or unreferenced.
270 gdk_device_manager_get_display (GdkDeviceManager *device_manager)
272 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
274 return device_manager->display;
278 * gdk_device_manager_list_devices:
279 * @device_manager: a #GdkDeviceManager
280 * @type: device type to get.
282 * Returns the list of devices of type @type currently attached to
285 * Returns: (transfer container) (element-type Gdk.Device): a list of
286 * #GdkDevice<!-- -->s. The returned list must be
287 * freed with g_list_free (). The list elements are owned by
288 * GTK+ and must not be freed or unreffed.
293 gdk_device_manager_list_devices (GdkDeviceManager *device_manager,
296 g_return_val_if_fail (GDK_IS_DEVICE_MANAGER (device_manager), NULL);
298 return GDK_DEVICE_MANAGER_GET_CLASS (device_manager)->list_devices (device_manager, type);
302 * gdk_device_manager_get_client_pointer:
303 * @device_manager: a #GdkDeviceManager
305 * Returns the client pointer, that is, the master pointer that acts as the core pointer
306 * for this application. In X11, window managers may change this depending on the interaction
307 * pattern under the presence of several pointers.
309 * You should use this function sheldomly, only in code that isn't triggered by a #GdkEvent
310 * and there aren't other means to get a meaningful #GdkDevice to operate on.
312 * Returns: (transfer none): The client pointer. This memory is
313 * owned by GDK and must not be freed or unreferenced.
318 gdk_device_manager_get_client_pointer (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)->get_client_pointer (device_manager);