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.Device; 26 27 private import gdk.Cursor; 28 private import gdk.Display; 29 private import gdk.Screen; 30 private import gdk.Window; 31 private import glib.ListG; 32 private import glib.Str; 33 private import gobject.ObjectG; 34 private import gobject.Signals; 35 private import gtkc.gdk; 36 public import gtkc.gdktypes; 37 38 39 /** 40 * The #GdkDevice object represents a single input device, such 41 * as a keyboard, a mouse, a touchpad, etc. 42 * 43 * See the #GdkDeviceManager documentation for more information 44 * about the various kinds of master and slave devices, and their 45 * relationships. 46 */ 47 public class Device : ObjectG 48 { 49 /** the main Gtk struct */ 50 protected GdkDevice* gdkDevice; 51 52 /** Get the main Gtk struct */ 53 public GdkDevice* getDeviceStruct() 54 { 55 return gdkDevice; 56 } 57 58 /** the main Gtk struct as a void* */ 59 protected override void* getStruct() 60 { 61 return cast(void*)gdkDevice; 62 } 63 64 protected override void setStruct(GObject* obj) 65 { 66 gdkDevice = cast(GdkDevice*)obj; 67 super.setStruct(obj); 68 } 69 70 /** 71 * Sets our main struct and passes it to the parent class. 72 */ 73 public this (GdkDevice* gdkDevice, bool ownedRef = false) 74 { 75 this.gdkDevice = gdkDevice; 76 super(cast(GObject*)gdkDevice, ownedRef); 77 } 78 79 /** 80 */ 81 82 public static GType getType() 83 { 84 return gdk_device_get_type(); 85 } 86 87 /** 88 * Frees an array of #GdkTimeCoord that was returned by gdk_device_get_history(). 89 * 90 * Params: 91 * events = an array of #GdkTimeCoord. 92 * nEvents = the length of the array. 93 */ 94 public static void freeHistory(GdkTimeCoord*[] events) 95 { 96 gdk_device_free_history(events.ptr, cast(int)events.length); 97 } 98 99 /** 100 * Determines information about the current keyboard grab. 101 * This is not public API and must not be used by applications. 102 * 103 * Params: 104 * display = the display for which to get the grab information 105 * device = device to get the grab information from 106 * grabWindow = location to store current grab window 107 * ownerEvents = location to store boolean indicating whether 108 * the @owner_events flag to gdk_keyboard_grab() or 109 * gdk_pointer_grab() was %TRUE. 110 * 111 * Return: %TRUE if this application currently has the 112 * keyboard grabbed. 113 */ 114 public static bool grabInfoLibgtkOnly(Display display, Device device, out Window grabWindow, out bool ownerEvents) 115 { 116 GdkWindow* outgrabWindow = null; 117 int outownerEvents; 118 119 auto p = gdk_device_grab_info_libgtk_only((display is null) ? null : display.getDisplayStruct(), (device is null) ? null : device.getDeviceStruct(), &outgrabWindow, &outownerEvents) != 0; 120 121 grabWindow = ObjectG.getDObject!(Window)(outgrabWindow); 122 ownerEvents = (outownerEvents == 1); 123 124 return p; 125 } 126 127 /** 128 * Returns the associated device to @device, if @device is of type 129 * %GDK_DEVICE_TYPE_MASTER, it will return the paired pointer or 130 * keyboard. 131 * 132 * If @device is of type %GDK_DEVICE_TYPE_SLAVE, it will return 133 * the master device to which @device is attached to. 134 * 135 * If @device is of type %GDK_DEVICE_TYPE_FLOATING, %NULL will be 136 * returned, as there is no associated device. 137 * 138 * Return: The associated device, or 139 * %NULL 140 * 141 * Since: 3.0 142 */ 143 public Device getAssociatedDevice() 144 { 145 auto p = gdk_device_get_associated_device(gdkDevice); 146 147 if(p is null) 148 { 149 return null; 150 } 151 152 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 153 } 154 155 /** 156 * Interprets an array of double as axis values for a given device, 157 * and locates the value in the array for a given axis use. 158 * 159 * Params: 160 * axes = pointer to an array of axes 161 * use = the use to look for 162 * value = location to store the found value. 163 * 164 * Return: %TRUE if the given axis use was found, otherwise %FALSE 165 */ 166 public bool getAxis(double[] axes, GdkAxisUse use, out double value) 167 { 168 return gdk_device_get_axis(gdkDevice, axes.ptr, use, &value) != 0; 169 } 170 171 /** 172 * Returns the axis use for @index_. 173 * 174 * Params: 175 * index = the index of the axis. 176 * 177 * Return: a #GdkAxisUse specifying how the axis is used. 178 * 179 * Since: 2.20 180 */ 181 public GdkAxisUse getAxisUse(uint index) 182 { 183 return gdk_device_get_axis_use(gdkDevice, index); 184 } 185 186 /** 187 * Interprets an array of double as axis values for a given device, 188 * and locates the value in the array for a given axis label, as returned 189 * by gdk_device_list_axes() 190 * 191 * Params: 192 * axes = pointer to an array of axes 193 * axisLabel = #GdkAtom with the axis label. 194 * value = location to store the found value. 195 * 196 * Return: %TRUE if the given axis use was found, otherwise %FALSE. 197 * 198 * Since: 3.0 199 */ 200 public bool getAxisValue(double[] axes, GdkAtom axisLabel, out double value) 201 { 202 return gdk_device_get_axis_value(gdkDevice, axes.ptr, axisLabel, &value) != 0; 203 } 204 205 /** 206 * Returns the device type for @device. 207 * 208 * Return: the #GdkDeviceType for @device. 209 * 210 * Since: 3.0 211 */ 212 public GdkDeviceType getDeviceType() 213 { 214 return gdk_device_get_device_type(gdkDevice); 215 } 216 217 /** 218 * Returns the #GdkDisplay to which @device pertains. 219 * 220 * Return: a #GdkDisplay. This memory is owned 221 * by GTK+, and must not be freed or unreffed. 222 * 223 * Since: 3.0 224 */ 225 public Display getDisplay() 226 { 227 auto p = gdk_device_get_display(gdkDevice); 228 229 if(p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(Display)(cast(GdkDisplay*) p); 235 } 236 237 /** 238 * Determines whether the pointer follows device motion. 239 * 240 * Return: %TRUE if the pointer follows device motion 241 * 242 * Since: 2.20 243 */ 244 public bool getHasCursor() 245 { 246 return gdk_device_get_has_cursor(gdkDevice) != 0; 247 } 248 249 /** 250 * Obtains the motion history for a pointer device; given a starting and 251 * ending timestamp, return all events in the motion history for 252 * the device in the given range of time. Some windowing systems 253 * do not support motion history, in which case, %FALSE will 254 * be returned. (This is not distinguishable from the case where 255 * motion history is supported and no events were found.) 256 * 257 * Note that there is also gdk_window_set_event_compression() to get 258 * more motion events delivered directly, independent of the windowing 259 * system. 260 * 261 * Params: 262 * window = the window with respect to which which the event coordinates will be reported 263 * start = starting timestamp for range of events to return 264 * stop = ending timestamp for the range of events to return 265 * events = location to store a newly-allocated array of #GdkTimeCoord, or 266 * %NULL 267 * nEvents = location to store the length of 268 * @events, or %NULL 269 * 270 * Return: %TRUE if the windowing system supports motion history and 271 * at least one event was found. 272 */ 273 public bool getHistory(Window window, uint start, uint stop, out GdkTimeCoord*[] events) 274 { 275 GdkTimeCoord** outevents = null; 276 int nEvents; 277 278 auto p = gdk_device_get_history(gdkDevice, (window is null) ? null : window.getWindowStruct(), start, stop, &outevents, &nEvents) != 0; 279 280 events = outevents[0 .. nEvents]; 281 282 return p; 283 } 284 285 /** 286 * If @index_ has a valid keyval, this function will return %TRUE 287 * and fill in @keyval and @modifiers with the keyval settings. 288 * 289 * Params: 290 * index = the index of the macro button to get. 291 * keyval = return value for the keyval. 292 * modifiers = return value for modifiers. 293 * 294 * Return: %TRUE if keyval is set for @index. 295 * 296 * Since: 2.20 297 */ 298 public bool getKey(uint index, out uint keyval, out GdkModifierType modifiers) 299 { 300 return gdk_device_get_key(gdkDevice, index, &keyval, &modifiers) != 0; 301 } 302 303 /** 304 * Gets information about which window the given pointer device is in, based on 305 * that have been received so far from the display server. If another application 306 * has a pointer grab, or this application has a grab with owner_events = %FALSE, 307 * %NULL may be returned even if the pointer is physically over one of this 308 * application's windows. 309 * 310 * Return: the last window the device 311 * 312 * Since: 3.12 313 */ 314 public Window getLastEventWindow() 315 { 316 auto p = gdk_device_get_last_event_window(gdkDevice); 317 318 if(p is null) 319 { 320 return null; 321 } 322 323 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 324 } 325 326 /** 327 * Determines the mode of the device. 328 * 329 * Return: a #GdkInputSource 330 * 331 * Since: 2.20 332 */ 333 public GdkInputMode getMode() 334 { 335 return gdk_device_get_mode(gdkDevice); 336 } 337 338 /** 339 * Returns the number of axes the device currently has. 340 * 341 * Return: the number of axes. 342 * 343 * Since: 3.0 344 */ 345 public int getNAxes() 346 { 347 return gdk_device_get_n_axes(gdkDevice); 348 } 349 350 /** 351 * Returns the number of keys the device currently has. 352 * 353 * Return: the number of keys. 354 * 355 * Since: 2.24 356 */ 357 public int getNKeys() 358 { 359 return gdk_device_get_n_keys(gdkDevice); 360 } 361 362 /** 363 * Determines the name of the device. 364 * 365 * Return: a name 366 * 367 * Since: 2.20 368 */ 369 public string getName() 370 { 371 return Str.toString(gdk_device_get_name(gdkDevice)); 372 } 373 374 /** 375 * Gets the current location of @device. As a slave device 376 * coordinates are those of its master pointer, This function 377 * may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE, 378 * unless there is an ongoing grab on them, see gdk_device_grab(). 379 * 380 * Params: 381 * screen = location to store the #GdkScreen 382 * the @device is on, or %NULL. 383 * x = location to store root window X coordinate of @device, or %NULL. 384 * y = location to store root window Y coordinate of @device, or %NULL. 385 * 386 * Since: 3.0 387 */ 388 public void getPosition(out Screen screen, out int x, out int y) 389 { 390 GdkScreen* outscreen = null; 391 392 gdk_device_get_position(gdkDevice, &outscreen, &x, &y); 393 394 screen = ObjectG.getDObject!(Screen)(outscreen); 395 } 396 397 /** 398 * Gets the current location of @device in double precision. As a slave device's 399 * coordinates are those of its master pointer, this function 400 * may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE, 401 * unless there is an ongoing grab on them. See gdk_device_grab(). 402 * 403 * Params: 404 * screen = location to store the #GdkScreen 405 * the @device is on, or %NULL. 406 * x = location to store root window X coordinate of @device, or %NULL. 407 * y = location to store root window Y coordinate of @device, or %NULL. 408 * 409 * Since: 3.10 410 */ 411 public void getPositionDouble(out Screen screen, out double x, out double y) 412 { 413 GdkScreen* outscreen = null; 414 415 gdk_device_get_position_double(gdkDevice, &outscreen, &x, &y); 416 417 screen = ObjectG.getDObject!(Screen)(outscreen); 418 } 419 420 /** 421 * Determines the type of the device. 422 * 423 * Return: a #GdkInputSource 424 * 425 * Since: 2.20 426 */ 427 public GdkInputSource getSource() 428 { 429 return gdk_device_get_source(gdkDevice); 430 } 431 432 /** 433 * Gets the current state of a pointer device relative to @window. As a slave 434 * device’s coordinates are those of its master pointer, this 435 * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE, 436 * unless there is an ongoing grab on them. See gdk_device_grab(). 437 * 438 * Params: 439 * window = a #GdkWindow. 440 * axes = an array of doubles to store the values of 441 * the axes of @device in, or %NULL. 442 * mask = location to store the modifiers, or %NULL. 443 */ 444 public void getState(Window window, double[] axes, out GdkModifierType mask) 445 { 446 gdk_device_get_state(gdkDevice, (window is null) ? null : window.getWindowStruct(), axes.ptr, &mask); 447 } 448 449 /** 450 * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y. Returns 451 * %NULL if the window tree under @device is not known to GDK (for example, belongs to another application). 452 * 453 * As a slave device coordinates are those of its master pointer, This 454 * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE, 455 * unless there is an ongoing grab on them, see gdk_device_grab(). 456 * 457 * Params: 458 * winX = return location for the X coordinate of the device location, 459 * relative to the window origin, or %NULL. 460 * winY = return location for the Y coordinate of the device location, 461 * relative to the window origin, or %NULL. 462 * 463 * Return: the #GdkWindow under the 464 * device position, or %NULL. 465 * 466 * Since: 3.0 467 */ 468 public Window getWindowAtPosition(out int winX, out int winY) 469 { 470 auto p = gdk_device_get_window_at_position(gdkDevice, &winX, &winY); 471 472 if(p is null) 473 { 474 return null; 475 } 476 477 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 478 } 479 480 /** 481 * Obtains the window underneath @device, returning the location of the device in @win_x and @win_y in 482 * double precision. Returns %NULL if the window tree under @device is not known to GDK (for example, 483 * belongs to another application). 484 * 485 * As a slave device coordinates are those of its master pointer, This 486 * function may not be called on devices of type %GDK_DEVICE_TYPE_SLAVE, 487 * unless there is an ongoing grab on them, see gdk_device_grab(). 488 * 489 * Params: 490 * winX = return location for the X coordinate of the device location, 491 * relative to the window origin, or %NULL. 492 * winY = return location for the Y coordinate of the device location, 493 * relative to the window origin, or %NULL. 494 * 495 * Return: the #GdkWindow under the 496 * device position, or %NULL. 497 * 498 * Since: 3.0 499 */ 500 public Window getWindowAtPositionDouble(out double winX, out double winY) 501 { 502 auto p = gdk_device_get_window_at_position_double(gdkDevice, &winX, &winY); 503 504 if(p is null) 505 { 506 return null; 507 } 508 509 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 510 } 511 512 /** 513 * Grabs the device so that all events coming from this device are passed to 514 * this application until the device is ungrabbed with gdk_device_ungrab(), 515 * or the window becomes unviewable. This overrides any previous grab on the device 516 * by this client. 517 * 518 * Device grabs are used for operations which need complete control over the 519 * given device events (either pointer or keyboard). For example in GTK+ this 520 * is used for Drag and Drop operations, popup menus and such. 521 * 522 * Note that if the event mask of an X window has selected both button press 523 * and button release events, then a button press event will cause an automatic 524 * pointer grab until the button is released. X does this automatically since 525 * most applications expect to receive button press and release events in pairs. 526 * It is equivalent to a pointer grab on the window with @owner_events set to 527 * %TRUE. 528 * 529 * If you set up anything at the time you take the grab that needs to be 530 * cleaned up when the grab ends, you should handle the #GdkEventGrabBroken 531 * events that are emitted when the grab ends unvoluntarily. 532 * 533 * Params: 534 * window = the #GdkWindow which will own the grab (the grab window) 535 * grabOwnership = specifies the grab ownership. 536 * ownerEvents = if %FALSE then all device events are reported with respect to 537 * @window and are only reported if selected by @event_mask. If 538 * %TRUE then pointer events for this application are reported 539 * as normal, but pointer events outside this application are 540 * reported with respect to @window and only if selected by 541 * @event_mask. In either mode, unreported events are discarded. 542 * eventMask = specifies the event mask, which is used in accordance with 543 * @owner_events. 544 * cursor = the cursor to display while the grab is active if the device is 545 * a pointer. If this is %NULL then the normal cursors are used for 546 * @window and its descendants, and the cursor for @window is used 547 * elsewhere. 548 * time = the timestamp of the event which led to this pointer grab. This 549 * usually comes from the #GdkEvent struct, though %GDK_CURRENT_TIME 550 * can be used if the time isn’t known. 551 * 552 * Return: %GDK_GRAB_SUCCESS if the grab was successful. 553 * 554 * Since: 3.0 555 */ 556 public GdkGrabStatus grab(Window window, GdkGrabOwnership grabOwnership, bool ownerEvents, GdkEventMask eventMask, Cursor cursor, uint time) 557 { 558 return gdk_device_grab(gdkDevice, (window is null) ? null : window.getWindowStruct(), grabOwnership, ownerEvents, eventMask, (cursor is null) ? null : cursor.getCursorStruct(), time); 559 } 560 561 /** 562 * Returns a #GList of #GdkAtoms, containing the labels for 563 * the axes that @device currently has. 564 * 565 * Return: A #GList of #GdkAtoms, free with g_list_free(). 566 * 567 * Since: 3.0 568 */ 569 public ListG listAxes() 570 { 571 auto p = gdk_device_list_axes(gdkDevice); 572 573 if(p is null) 574 { 575 return null; 576 } 577 578 return new ListG(cast(GList*) p); 579 } 580 581 /** 582 * If the device if of type %GDK_DEVICE_TYPE_MASTER, it will return 583 * the list of slave devices attached to it, otherwise it will return 584 * %NULL 585 * 586 * Return: the list of slave devices, or %NULL. The list must be 587 * freed with g_list_free(), the contents of the list are 588 * owned by GTK+ and should not be freed. 589 */ 590 public ListG listSlaveDevices() 591 { 592 auto p = gdk_device_list_slave_devices(gdkDevice); 593 594 if(p is null) 595 { 596 return null; 597 } 598 599 return new ListG(cast(GList*) p); 600 } 601 602 /** 603 * Specifies how an axis of a device is used. 604 * 605 * Params: 606 * index = the index of the axis 607 * use = specifies how the axis is used 608 */ 609 public void setAxisUse(uint index, GdkAxisUse use) 610 { 611 gdk_device_set_axis_use(gdkDevice, index, use); 612 } 613 614 /** 615 * Specifies the X key event to generate when a macro button of a device 616 * is pressed. 617 * 618 * Params: 619 * index = the index of the macro button to set 620 * keyval = the keyval to generate 621 * modifiers = the modifiers to set 622 */ 623 public void setKey(uint index, uint keyval, GdkModifierType modifiers) 624 { 625 gdk_device_set_key(gdkDevice, index, keyval, modifiers); 626 } 627 628 /** 629 * Sets a the mode of an input device. The mode controls if the 630 * device is active and whether the device’s range is mapped to the 631 * entire screen or to a single window. 632 * 633 * Note: This is only meaningful for floating devices, master devices (and 634 * slaves connected to these) drive the pointer cursor, which is not limited 635 * by the input mode. 636 * 637 * Params: 638 * mode = the input mode. 639 * 640 * Return: %TRUE if the mode was successfully changed. 641 */ 642 public bool setMode(GdkInputMode mode) 643 { 644 return gdk_device_set_mode(gdkDevice, mode) != 0; 645 } 646 647 /** 648 * Release any grab on @device. 649 * 650 * Params: 651 * time = a timestap (e.g. %GDK_CURRENT_TIME). 652 * 653 * Since: 3.0 654 */ 655 public void ungrab(uint time) 656 { 657 gdk_device_ungrab(gdkDevice, time); 658 } 659 660 /** 661 * Warps @device in @display to the point @x,@y on 662 * the screen @screen, unless the device is confined 663 * to a window by a grab, in which case it will be moved 664 * as far as allowed by the grab. Warping the pointer 665 * creates events as if the user had moved the mouse 666 * instantaneously to the destination. 667 * 668 * Note that the pointer should normally be under the 669 * control of the user. This function was added to cover 670 * some rare use cases like keyboard navigation support 671 * for the color picker in the #GtkColorSelectionDialog. 672 * 673 * Params: 674 * screen = the screen to warp @device to. 675 * x = the X coordinate of the destination. 676 * y = the Y coordinate of the destination. 677 * 678 * Since: 3.0 679 */ 680 public void warp(Screen screen, int x, int y) 681 { 682 gdk_device_warp(gdkDevice, (screen is null) ? null : screen.getScreenStruct(), x, y); 683 } 684 685 int[string] connectedSignals; 686 687 void delegate(Device)[] onChangedListeners; 688 /** 689 * The ::changed signal is emitted either when the #GdkDevice 690 * has changed the number of either axes or keys. For example 691 * In X this will normally happen when the slave device routing 692 * events through the master device changes (for example, user 693 * switches from the USB mouse to a tablet), in that case the 694 * master device will change to reflect the new slave device 695 * axes and keys. 696 */ 697 void addOnChanged(void delegate(Device) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 698 { 699 if ( "changed" !in connectedSignals ) 700 { 701 Signals.connectData( 702 this, 703 "changed", 704 cast(GCallback)&callBackChanged, 705 cast(void*)this, 706 null, 707 connectFlags); 708 connectedSignals["changed"] = 1; 709 } 710 onChangedListeners ~= dlg; 711 } 712 extern(C) static void callBackChanged(GdkDevice* deviceStruct, Device _device) 713 { 714 foreach ( void delegate(Device) dlg; _device.onChangedListeners ) 715 { 716 dlg(_device); 717 } 718 } 719 }