1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gdk.DeviceManager; 26 27 private import gdk.Device; 28 private import gdk.Display; 29 private import glib.ListG; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtkc.gdk; 33 public import gtkc.gdktypes; 34 private import std.algorithm; 35 36 37 /** 38 * In addition to a single pointer and keyboard for user interface input, 39 * GDK contains support for a variety of input devices, including graphics 40 * tablets, touchscreens and multiple pointers/keyboards interacting 41 * simultaneously with the user interface. Such input devices often have 42 * additional features, such as sub-pixel positioning information and 43 * additional device-dependent information. 44 * 45 * In order to query the device hierarchy and be aware of changes in the 46 * device hierarchy (such as virtual devices being created or removed, or 47 * physical devices being plugged or unplugged), GDK provides 48 * #GdkDeviceManager. 49 * 50 * By default, and if the platform supports it, GDK is aware of multiple 51 * keyboard/pointer pairs and multitouch devices. This behavior can be 52 * changed by calling gdk_disable_multidevice() before gdk_display_open(). 53 * There should rarely be a need to do that though, since GDK defaults 54 * to a compatibility mode in which it will emit just one enter/leave 55 * event pair for all devices on a window. To enable per-device 56 * enter/leave events and other multi-pointer interaction features, 57 * gdk_window_set_support_multidevice() must be called on 58 * #GdkWindows (or gtk_widget_set_support_multidevice() on widgets). 59 * window. See the gdk_window_set_support_multidevice() documentation 60 * for more information. 61 * 62 * On X11, multi-device support is implemented through XInput 2. 63 * Unless gdk_disable_multidevice() is called, the XInput 2 64 * #GdkDeviceManager implementation will be used as the input source. 65 * Otherwise either the core or XInput 1 implementations will be used. 66 * 67 * For simple applications that don’t have any special interest in 68 * input devices, the so-called “client pointer” 69 * provides a reasonable approximation to a simple setup with a single 70 * pointer and keyboard. The device that has been set as the client 71 * pointer can be accessed via gdk_device_manager_get_client_pointer(). 72 * 73 * Conceptually, in multidevice mode there are 2 device types. Virtual 74 * devices (or master devices) are represented by the pointer cursors 75 * and keyboard foci that are seen on the screen. Physical devices (or 76 * slave devices) represent the hardware that is controlling the virtual 77 * devices, and thus have no visible cursor on the screen. 78 * 79 * Virtual devices are always paired, so there is a keyboard device for every 80 * pointer device. Associations between devices may be inspected through 81 * gdk_device_get_associated_device(). 82 * 83 * There may be several virtual devices, and several physical devices could 84 * be controlling each of these virtual devices. Physical devices may also 85 * be “floating”, which means they are not attached to any virtual device. 86 * 87 * # Master and slave devices 88 * 89 * |[ 90 * carlos@sacarino:~$ xinput list 91 * ⎡ Virtual core pointer id=2 [master pointer (3)] 92 * ⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] 93 * ⎜ ↳ Wacom ISDv4 E6 Pen stylus id=10 [slave pointer (2)] 94 * ⎜ ↳ Wacom ISDv4 E6 Finger touch id=11 [slave pointer (2)] 95 * ⎜ ↳ SynPS/2 Synaptics TouchPad id=13 [slave pointer (2)] 96 * ⎜ ↳ TPPS/2 IBM TrackPoint id=14 [slave pointer (2)] 97 * ⎜ ↳ Wacom ISDv4 E6 Pen eraser id=16 [slave pointer (2)] 98 * ⎣ Virtual core keyboard id=3 [master keyboard (2)] 99 * ↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] 100 * ↳ Power Button id=6 [slave keyboard (3)] 101 * ↳ Video Bus id=7 [slave keyboard (3)] 102 * ↳ Sleep Button id=8 [slave keyboard (3)] 103 * ↳ Integrated Camera id=9 [slave keyboard (3)] 104 * ↳ AT Translated Set 2 keyboard id=12 [slave keyboard (3)] 105 * ↳ ThinkPad Extra Buttons id=15 [slave keyboard (3)] 106 * ]| 107 * 108 * By default, GDK will automatically listen for events coming from all 109 * master devices, setting the #GdkDevice for all events coming from input 110 * devices. Events containing device information are #GDK_MOTION_NOTIFY, 111 * #GDK_BUTTON_PRESS, #GDK_2BUTTON_PRESS, #GDK_3BUTTON_PRESS, 112 * #GDK_BUTTON_RELEASE, #GDK_SCROLL, #GDK_KEY_PRESS, #GDK_KEY_RELEASE, 113 * #GDK_ENTER_NOTIFY, #GDK_LEAVE_NOTIFY, #GDK_FOCUS_CHANGE, 114 * #GDK_PROXIMITY_IN, #GDK_PROXIMITY_OUT, #GDK_DRAG_ENTER, #GDK_DRAG_LEAVE, 115 * #GDK_DRAG_MOTION, #GDK_DRAG_STATUS, #GDK_DROP_START, #GDK_DROP_FINISHED 116 * and #GDK_GRAB_BROKEN. When dealing with an event on a master device, 117 * it is possible to get the source (slave) device that the event originated 118 * from via gdk_event_get_source_device(). 119 * 120 * On a standard session, all physical devices are connected by default to 121 * the "Virtual Core Pointer/Keyboard" master devices, hence routing all events 122 * through these. This behavior is only modified by device grabs, where the 123 * slave device is temporarily detached for as long as the grab is held, and 124 * more permanently by user modifications to the device hierarchy. 125 * 126 * On certain application specific setups, it may make sense 127 * to detach a physical device from its master pointer, and mapping it to 128 * an specific window. This can be achieved by the combination of 129 * gdk_device_grab() and gdk_device_set_mode(). 130 * 131 * In order to listen for events coming from devices 132 * other than a virtual device, gdk_window_set_device_events() must be 133 * called. Generally, this function can be used to modify the event mask 134 * for any given device. 135 * 136 * Input devices may also provide additional information besides X/Y. 137 * For example, graphics tablets may also provide pressure and X/Y tilt 138 * information. This information is device-dependent, and may be 139 * queried through gdk_device_get_axis(). In multidevice mode, virtual 140 * devices will change axes in order to always represent the physical 141 * device that is routing events through it. Whenever the physical device 142 * changes, the #GdkDevice:n-axes property will be notified, and 143 * gdk_device_list_axes() will return the new device axes. 144 * 145 * Devices may also have associated “keys” or 146 * macro buttons. Such keys can be globally set to map into normal X 147 * keyboard events. The mapping is set using gdk_device_set_key(). 148 * 149 * In GTK+ 3.20, a new #GdkSeat object has been introduced that 150 * supersedes #GdkDeviceManager and should be preferred in newly 151 * written code. 152 */ 153 public class DeviceManager : ObjectG 154 { 155 /** the main Gtk struct */ 156 protected GdkDeviceManager* gdkDeviceManager; 157 158 /** Get the main Gtk struct */ 159 public GdkDeviceManager* getDeviceManagerStruct(bool transferOwnership = false) 160 { 161 if (transferOwnership) 162 ownedRef = false; 163 return gdkDeviceManager; 164 } 165 166 /** the main Gtk struct as a void* */ 167 protected override void* getStruct() 168 { 169 return cast(void*)gdkDeviceManager; 170 } 171 172 protected override void setStruct(GObject* obj) 173 { 174 gdkDeviceManager = cast(GdkDeviceManager*)obj; 175 super.setStruct(obj); 176 } 177 178 /** 179 * Sets our main struct and passes it to the parent class. 180 */ 181 public this (GdkDeviceManager* gdkDeviceManager, bool ownedRef = false) 182 { 183 this.gdkDeviceManager = gdkDeviceManager; 184 super(cast(GObject*)gdkDeviceManager, ownedRef); 185 } 186 187 188 /** */ 189 public static GType getType() 190 { 191 return gdk_device_manager_get_type(); 192 } 193 194 /** 195 * Returns the client pointer, that is, the master pointer that acts as the core pointer 196 * for this application. In X11, window managers may change this depending on the interaction 197 * pattern under the presence of several pointers. 198 * 199 * You should use this function seldomly, only in code that isn’t triggered by a #GdkEvent 200 * and there aren’t other means to get a meaningful #GdkDevice to operate on. 201 * 202 * Deprecated: Use gdk_seat_get_pointer() instead. 203 * 204 * Returns: The client pointer. This memory is 205 * owned by GDK and must not be freed or unreferenced. 206 * 207 * Since: 3.0 208 */ 209 public Device getClientPointer() 210 { 211 auto p = gdk_device_manager_get_client_pointer(gdkDeviceManager); 212 213 if(p is null) 214 { 215 return null; 216 } 217 218 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 219 } 220 221 /** 222 * Gets the #GdkDisplay associated to @device_manager. 223 * 224 * Returns: the #GdkDisplay to which 225 * @device_manager is associated to, or #NULL. This memory is 226 * owned by GDK and must not be freed or unreferenced. 227 * 228 * Since: 3.0 229 */ 230 public Display getDisplay() 231 { 232 auto p = gdk_device_manager_get_display(gdkDeviceManager); 233 234 if(p is null) 235 { 236 return null; 237 } 238 239 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 240 } 241 242 /** 243 * Returns the list of devices of type @type currently attached to 244 * @device_manager. 245 * 246 * Deprecated: , use gdk_seat_get_pointer(), gdk_seat_get_keyboard() 247 * and gdk_seat_get_slaves() instead. 248 * 249 * Params: 250 * type = device type to get. 251 * 252 * Returns: a list of 253 * #GdkDevices. The returned list must be 254 * freed with g_list_free (). The list elements are owned by 255 * GTK+ and must not be freed or unreffed. 256 * 257 * Since: 3.0 258 */ 259 public ListG listDevices(GdkDeviceType type) 260 { 261 auto p = gdk_device_manager_list_devices(gdkDeviceManager, type); 262 263 if(p is null) 264 { 265 return null; 266 } 267 268 return new ListG(cast(GList*) p); 269 } 270 271 protected class OnDeviceAddedDelegateWrapper 272 { 273 static OnDeviceAddedDelegateWrapper[] listeners; 274 void delegate(Device, DeviceManager) dlg; 275 gulong handlerId; 276 277 this(void delegate(Device, DeviceManager) dlg) 278 { 279 this.dlg = dlg; 280 this.listeners ~= this; 281 } 282 283 void remove(OnDeviceAddedDelegateWrapper source) 284 { 285 foreach(index, wrapper; listeners) 286 { 287 if (wrapper.handlerId == source.handlerId) 288 { 289 listeners[index] = null; 290 listeners = std.algorithm.remove(listeners, index); 291 break; 292 } 293 } 294 } 295 } 296 297 /** 298 * The ::device-added signal is emitted either when a new master 299 * pointer is created, or when a slave (Hardware) input device 300 * is plugged in. 301 * 302 * Params: 303 * device = the newly added #GdkDevice. 304 */ 305 gulong addOnDeviceAdded(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 306 { 307 auto wrapper = new OnDeviceAddedDelegateWrapper(dlg); 308 wrapper.handlerId = Signals.connectData( 309 this, 310 "device-added", 311 cast(GCallback)&callBackDeviceAdded, 312 cast(void*)wrapper, 313 cast(GClosureNotify)&callBackDeviceAddedDestroy, 314 connectFlags); 315 return wrapper.handlerId; 316 } 317 318 extern(C) static void callBackDeviceAdded(GdkDeviceManager* devicemanagerStruct, GdkDevice* device, OnDeviceAddedDelegateWrapper wrapper) 319 { 320 wrapper.dlg(ObjectG.getDObject!(Device)(device), wrapper.outer); 321 } 322 323 extern(C) static void callBackDeviceAddedDestroy(OnDeviceAddedDelegateWrapper wrapper, GClosure* closure) 324 { 325 wrapper.remove(wrapper); 326 } 327 328 protected class OnDeviceChangedDelegateWrapper 329 { 330 static OnDeviceChangedDelegateWrapper[] listeners; 331 void delegate(Device, DeviceManager) dlg; 332 gulong handlerId; 333 334 this(void delegate(Device, DeviceManager) dlg) 335 { 336 this.dlg = dlg; 337 this.listeners ~= this; 338 } 339 340 void remove(OnDeviceChangedDelegateWrapper source) 341 { 342 foreach(index, wrapper; listeners) 343 { 344 if (wrapper.handlerId == source.handlerId) 345 { 346 listeners[index] = null; 347 listeners = std.algorithm.remove(listeners, index); 348 break; 349 } 350 } 351 } 352 } 353 354 /** 355 * The ::device-changed signal is emitted whenever a device 356 * has changed in the hierarchy, either slave devices being 357 * disconnected from their master device or connected to 358 * another one, or master devices being added or removed 359 * a slave device. 360 * 361 * If a slave device is detached from all master devices 362 * (gdk_device_get_associated_device() returns %NULL), its 363 * #GdkDeviceType will change to %GDK_DEVICE_TYPE_FLOATING, 364 * if it's attached, it will change to %GDK_DEVICE_TYPE_SLAVE. 365 * 366 * Params: 367 * device = the #GdkDevice that changed. 368 */ 369 gulong addOnDeviceChanged(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 370 { 371 auto wrapper = new OnDeviceChangedDelegateWrapper(dlg); 372 wrapper.handlerId = Signals.connectData( 373 this, 374 "device-changed", 375 cast(GCallback)&callBackDeviceChanged, 376 cast(void*)wrapper, 377 cast(GClosureNotify)&callBackDeviceChangedDestroy, 378 connectFlags); 379 return wrapper.handlerId; 380 } 381 382 extern(C) static void callBackDeviceChanged(GdkDeviceManager* devicemanagerStruct, GdkDevice* device, OnDeviceChangedDelegateWrapper wrapper) 383 { 384 wrapper.dlg(ObjectG.getDObject!(Device)(device), wrapper.outer); 385 } 386 387 extern(C) static void callBackDeviceChangedDestroy(OnDeviceChangedDelegateWrapper wrapper, GClosure* closure) 388 { 389 wrapper.remove(wrapper); 390 } 391 392 protected class OnDeviceRemovedDelegateWrapper 393 { 394 static OnDeviceRemovedDelegateWrapper[] listeners; 395 void delegate(Device, DeviceManager) dlg; 396 gulong handlerId; 397 398 this(void delegate(Device, DeviceManager) dlg) 399 { 400 this.dlg = dlg; 401 this.listeners ~= this; 402 } 403 404 void remove(OnDeviceRemovedDelegateWrapper source) 405 { 406 foreach(index, wrapper; listeners) 407 { 408 if (wrapper.handlerId == source.handlerId) 409 { 410 listeners[index] = null; 411 listeners = std.algorithm.remove(listeners, index); 412 break; 413 } 414 } 415 } 416 } 417 418 /** 419 * The ::device-removed signal is emitted either when a master 420 * pointer is removed, or when a slave (Hardware) input device 421 * is unplugged. 422 * 423 * Params: 424 * device = the just removed #GdkDevice. 425 */ 426 gulong addOnDeviceRemoved(void delegate(Device, DeviceManager) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 427 { 428 auto wrapper = new OnDeviceRemovedDelegateWrapper(dlg); 429 wrapper.handlerId = Signals.connectData( 430 this, 431 "device-removed", 432 cast(GCallback)&callBackDeviceRemoved, 433 cast(void*)wrapper, 434 cast(GClosureNotify)&callBackDeviceRemovedDestroy, 435 connectFlags); 436 return wrapper.handlerId; 437 } 438 439 extern(C) static void callBackDeviceRemoved(GdkDeviceManager* devicemanagerStruct, GdkDevice* device, OnDeviceRemovedDelegateWrapper wrapper) 440 { 441 wrapper.dlg(ObjectG.getDObject!(Device)(device), wrapper.outer); 442 } 443 444 extern(C) static void callBackDeviceRemovedDestroy(OnDeviceRemovedDelegateWrapper wrapper, GClosure* closure) 445 { 446 wrapper.remove(wrapper); 447 } 448 449 /** 450 * Disables multidevice support in GDK. This call must happen prior 451 * to gdk_display_open(), gtk_init(), gtk_init_with_args() or 452 * gtk_init_check() in order to take effect. 453 * 454 * Most common GTK+ applications won’t ever need to call this. Only 455 * applications that do mixed GDK/Xlib calls could want to disable 456 * multidevice support if such Xlib code deals with input devices in 457 * any way and doesn’t observe the presence of XInput 2. 458 * 459 * Since: 3.0 460 */ 461 public static void disableMultidevice() 462 { 463 gdk_disable_multidevice(); 464 } 465 }