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