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