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.Event; 26 27 private import gdk.Device; 28 private import gdk.Screen; 29 private import gdk.Window; 30 private import glib.ConstructionException; 31 private import glib.Str; 32 private import gobject.ObjectG; 33 private import gobject.Value; 34 private import gtkc.gdk; 35 public import gtkc.gdktypes; 36 37 38 /** 39 * A #GdkEvent contains a union of all of the event types, 40 * and allows access to the data fields in a number of ways. 41 * 42 * The event type is always the first field in all of the event types, and 43 * can always be accessed with the following code, no matter what type of 44 * event it is: 45 * |[<!-- language="C" --> 46 * GdkEvent *event; 47 * GdkEventType type; 48 * 49 * type = event->type; 50 * ]| 51 * 52 * To access other fields of the event, the pointer to the event 53 * can be cast to the appropriate event type, or the union member 54 * name can be used. For example if the event type is %GDK_BUTTON_PRESS 55 * then the x coordinate of the button press can be accessed with: 56 * |[<!-- language="C" --> 57 * GdkEvent *event; 58 * gdouble x; 59 * 60 * x = ((GdkEventButton*)event)->x; 61 * ]| 62 * or: 63 * |[<!-- language="C" --> 64 * GdkEvent *event; 65 * gdouble x; 66 * 67 * x = event->button.x; 68 * ]| 69 */ 70 public class Event 71 { 72 /** the main Gtk struct */ 73 protected GdkEvent* gdkEvent; 74 75 /** Get the main Gtk struct */ 76 public GdkEvent* getEventStruct() 77 { 78 return gdkEvent; 79 } 80 81 /** the main Gtk struct as a void* */ 82 protected void* getStruct() 83 { 84 return cast(void*)gdkEvent; 85 } 86 87 /** 88 * Sets our main struct and passes it to the parent class. 89 */ 90 public this (GdkEvent* gdkEvent) 91 { 92 this.gdkEvent = gdkEvent; 93 } 94 95 /** 96 * Specifies the type of the event. 97 */ 98 public EventType type() 99 { 100 return gdkEvent.type; 101 } 102 103 /** Get a specific event. */ 104 public GdkEventAny* any() 105 { 106 return cast(GdkEventAny*)gdkEvent; 107 } 108 109 /** ditto */ 110 public GdkEventExpose* expose() 111 { 112 return cast(GdkEventExpose*)gdkEvent; 113 } 114 115 /** ditto */ 116 public GdkEventVisibility* visibility() 117 { 118 return cast(GdkEventVisibility*)gdkEvent; 119 } 120 121 /** ditto */ 122 public GdkEventMotion* motion() 123 { 124 return cast(GdkEventMotion*)gdkEvent; 125 } 126 127 /** ditto */ 128 public GdkEventButton* button() 129 { 130 return cast(GdkEventButton*)gdkEvent; 131 } 132 133 /** ditto */ 134 public GdkEventScroll* scroll() 135 { 136 return cast(GdkEventScroll*)gdkEvent; 137 } 138 139 /** ditto */ 140 public GdkEventKey* key() 141 { 142 return cast(GdkEventKey*)gdkEvent; 143 } 144 145 /** ditto */ 146 public GdkEventCrossing* crossing() 147 { 148 return cast(GdkEventCrossing*)gdkEvent; 149 } 150 151 /** ditto */ 152 public GdkEventFocus* focus() 153 { 154 return cast(GdkEventFocus*)gdkEvent; 155 } 156 157 /** ditto */ 158 public GdkEventConfigure* configure() 159 { 160 return cast(GdkEventConfigure*)gdkEvent; 161 } 162 163 /** ditto */ 164 public GdkEventProperty* property() 165 { 166 return cast(GdkEventProperty*)gdkEvent; 167 } 168 169 /** ditto */ 170 public GdkEventSelection* selection() 171 { 172 return cast(GdkEventSelection*)gdkEvent; 173 } 174 175 /** ditto */ 176 public GdkEventOwnerChange* ownerChange() 177 { 178 return cast(GdkEventOwnerChange*)gdkEvent; 179 } 180 181 /** ditto */ 182 public GdkEventProximity* proximity() 183 { 184 return cast(GdkEventProximity*)gdkEvent; 185 } 186 187 /** ditto */ 188 public GdkEventDND* dnd() 189 { 190 return cast(GdkEventDND*)gdkEvent; 191 } 192 193 /** ditto */ 194 public GdkEventWindowState* windowState() 195 { 196 return cast(GdkEventWindowState*)gdkEvent; 197 } 198 199 /** ditto */ 200 public GdkEventSetting* setting() 201 { 202 return cast(GdkEventSetting*)gdkEvent; 203 } 204 205 /** ditto */ 206 public GdkEventGrabBroken* grabBroken() 207 { 208 return cast(GdkEventGrabBroken*)gdkEvent; 209 } 210 211 /** */ 212 public static bool isDoubleClick(GdkEventButton* eventButton, int buttonNumber=1) 213 { 214 return eventButton.button==buttonNumber 215 && eventButton.type == EventType.DOUBLE_BUTTON_PRESS; 216 } 217 218 /** */ 219 public static bool isTripleClick(GdkEventButton* eventButton, int buttonNumber=1) 220 { 221 return eventButton.button==buttonNumber 222 && eventButton.type == EventType.TRIPLE_BUTTON_PRESS; 223 } 224 225 /** 226 */ 227 228 public static GType getType() 229 { 230 return gdk_event_get_type(); 231 } 232 233 /** 234 * Creates a new event of the given type. All fields are set to 0. 235 * 236 * Params: 237 * type = a #GdkEventType 238 * 239 * Return: a newly-allocated #GdkEvent. The returned #GdkEvent 240 * should be freed with gdk_event_free(). 241 * 242 * Since: 2.2 243 * 244 * Throws: ConstructionException GTK+ fails to create the object. 245 */ 246 public this(GdkEventType type) 247 { 248 auto p = gdk_event_new(type); 249 250 if(p is null) 251 { 252 throw new ConstructionException("null returned by new"); 253 } 254 255 this(cast(GdkEvent*) p); 256 } 257 258 /** 259 * If both events contain X/Y information, this function will return %TRUE 260 * and return in @angle the relative angle from @event1 to @event2. The rotation 261 * direction for positive angles is from the positive X axis towards the positive 262 * Y axis. 263 * 264 * Params: 265 * event1 = first #GdkEvent 266 * event2 = second #GdkEvent 267 * angle = return location for the relative angle between both events 268 * 269 * Return: %TRUE if the angle could be calculated. 270 * 271 * Since: 3.0 272 */ 273 public static bool getAngle(Event event1, Event event2, out double angle) 274 { 275 return gdk_events_get_angle((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &angle) != 0; 276 } 277 278 /** 279 * If both events contain X/Y information, the center of both coordinates 280 * will be returned in @x and @y. 281 * 282 * Params: 283 * event1 = first #GdkEvent 284 * event2 = second #GdkEvent 285 * x = return location for the X coordinate of the center 286 * y = return location for the Y coordinate of the center 287 * 288 * Return: %TRUE if the center could be calculated. 289 * 290 * Since: 3.0 291 */ 292 public static bool getCenter(Event event1, Event event2, out double x, out double y) 293 { 294 return gdk_events_get_center((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &x, &y) != 0; 295 } 296 297 /** 298 * If both events have X/Y information, the distance between both coordinates 299 * (as in a straight line going from @event1 to @event2) will be returned. 300 * 301 * Params: 302 * event1 = first #GdkEvent 303 * event2 = second #GdkEvent 304 * distance = return location for the distance 305 * 306 * Return: %TRUE if the distance could be calculated. 307 * 308 * Since: 3.0 309 */ 310 public static bool getDistance(Event event1, Event event2, out double distance) 311 { 312 return gdk_events_get_distance((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &distance) != 0; 313 } 314 315 /** 316 * Copies a #GdkEvent, copying or incrementing the reference count of the 317 * resources associated with it (e.g. #GdkWindow’s and strings). 318 * 319 * Return: a copy of @event. The returned #GdkEvent should be freed with 320 * gdk_event_free(). 321 */ 322 public Event copy() 323 { 324 auto p = gdk_event_copy(gdkEvent); 325 326 if(p is null) 327 { 328 return null; 329 } 330 331 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 332 } 333 334 /** 335 * Frees a #GdkEvent, freeing or decrementing any resources associated with it. 336 * Note that this function should only be called with events returned from 337 * functions such as gdk_event_peek(), gdk_event_get(), gdk_event_copy() 338 * and gdk_event_new(). 339 */ 340 public void free() 341 { 342 gdk_event_free(gdkEvent); 343 } 344 345 /** 346 * Extract the axis value for a particular axis use from 347 * an event structure. 348 * 349 * Params: 350 * axisUse = the axis use to look for 351 * value = location to store the value found 352 * 353 * Return: %TRUE if the specified axis was found, otherwise %FALSE 354 */ 355 public bool getAxis(GdkAxisUse axisUse, out double value) 356 { 357 return gdk_event_get_axis(gdkEvent, axisUse, &value) != 0; 358 } 359 360 /** 361 * Extract the button number from an event. 362 * 363 * Params: 364 * button = location to store mouse button number 365 * 366 * Return: %TRUE if the event delivered a button number 367 * 368 * Since: 3.2 369 */ 370 public bool getButton(out uint button) 371 { 372 return gdk_event_get_button(gdkEvent, &button) != 0; 373 } 374 375 /** 376 * Extracts the click count from an event. 377 * 378 * Params: 379 * clickCount = location to store click count 380 * 381 * Return: %TRUE if the event delivered a click count 382 * 383 * Since: 3.2 384 */ 385 public bool getClickCount(out uint clickCount) 386 { 387 return gdk_event_get_click_count(gdkEvent, &clickCount) != 0; 388 } 389 390 /** 391 * Extract the event window relative x/y coordinates from an event. 392 * 393 * Params: 394 * xWin = location to put event window x coordinate 395 * yWin = location to put event window y coordinate 396 * 397 * Return: %TRUE if the event delivered event window coordinates 398 */ 399 public bool getCoords(out double xWin, out double yWin) 400 { 401 return gdk_event_get_coords(gdkEvent, &xWin, &yWin) != 0; 402 } 403 404 /** 405 * If the event contains a “device” field, this function will return 406 * it, else it will return %NULL. 407 * 408 * Return: a #GdkDevice, or %NULL. 409 * 410 * Since: 3.0 411 */ 412 public Device getDevice() 413 { 414 auto p = gdk_event_get_device(gdkEvent); 415 416 if(p is null) 417 { 418 return null; 419 } 420 421 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 422 } 423 424 /** 425 * If @event if of type %GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE, 426 * %GDK_TOUCH_END or %GDK_TOUCH_CANCEL, returns the #GdkEventSequence 427 * to which the event belongs. Otherwise, return %NULL. 428 * 429 * Return: the event sequence that the event belongs to 430 * 431 * Since: 3.4 432 */ 433 public GdkEventSequence* getEventSequence() 434 { 435 return gdk_event_get_event_sequence(gdkEvent); 436 } 437 438 /** 439 * Retrieves the type of the event. 440 * 441 * Return: a #GdkEventType 442 * 443 * Since: 3.10 444 */ 445 public GdkEventType getEventType() 446 { 447 return gdk_event_get_event_type(gdkEvent); 448 } 449 450 /** 451 * Extracts the hardware keycode from an event. 452 * 453 * Params: 454 * keycode = location to store the keycode 455 * 456 * Return: %TRUE if the event delivered a hardware keycode 457 * 458 * Since: 3.2 459 */ 460 public bool getKeycode(out ushort keycode) 461 { 462 return gdk_event_get_keycode(gdkEvent, &keycode) != 0; 463 } 464 465 /** 466 * Extracts the keyval from an event. 467 * 468 * Params: 469 * keyval = location to store the keyval 470 * 471 * Return: %TRUE if the event delivered a key symbol 472 * 473 * Since: 3.2 474 */ 475 public bool getKeyval(out uint keyval) 476 { 477 return gdk_event_get_keyval(gdkEvent, &keyval) != 0; 478 } 479 480 /** 481 * Extract the root window relative x/y coordinates from an event. 482 * 483 * Params: 484 * xRoot = location to put root window x coordinate 485 * yRoot = location to put root window y coordinate 486 * 487 * Return: %TRUE if the event delivered root window coordinates 488 */ 489 public bool getRootCoords(out double xRoot, out double yRoot) 490 { 491 return gdk_event_get_root_coords(gdkEvent, &xRoot, &yRoot) != 0; 492 } 493 494 /** 495 * Returns the screen for the event. The screen is 496 * typically the screen for `event->any.window`, but 497 * for events such as mouse events, it is the screen 498 * where the pointer was when the event occurs - 499 * that is, the screen which has the root window 500 * to which `event->motion.x_root` and 501 * `event->motion.y_root` are relative. 502 * 503 * Return: the screen for the event 504 * 505 * Since: 2.2 506 */ 507 public Screen getScreen() 508 { 509 auto p = gdk_event_get_screen(gdkEvent); 510 511 if(p is null) 512 { 513 return null; 514 } 515 516 return ObjectG.getDObject!(Screen)(cast(GdkScreen*) p); 517 } 518 519 /** 520 * Retrieves the scroll deltas from a #GdkEvent 521 * 522 * Params: 523 * deltaX = return location for X delta 524 * deltaY = return location for Y delta 525 * 526 * Return: %TRUE if the event contains smooth scroll information 527 * 528 * Since: 3.4 529 */ 530 public bool getScrollDeltas(out double deltaX, out double deltaY) 531 { 532 return gdk_event_get_scroll_deltas(gdkEvent, &deltaX, &deltaY) != 0; 533 } 534 535 /** 536 * Extracts the scroll direction from an event. 537 * 538 * Params: 539 * direction = location to store the scroll direction 540 * 541 * Return: %TRUE if the event delivered a scroll direction 542 * 543 * Since: 3.2 544 */ 545 public bool getScrollDirection(out GdkScrollDirection direction) 546 { 547 return gdk_event_get_scroll_direction(gdkEvent, &direction) != 0; 548 } 549 550 /** 551 * This function returns the hardware (slave) #GdkDevice that has 552 * triggered the event, falling back to the virtual (master) device 553 * (as in gdk_event_get_device()) if the event wasn’t caused by 554 * interaction with a hardware device. This may happen for example 555 * in synthesized crossing events after a #GdkWindow updates its 556 * geometry or a grab is acquired/released. 557 * 558 * If the event does not contain a device field, this function will 559 * return %NULL. 560 * 561 * Return: a #GdkDevice, or %NULL. 562 * 563 * Since: 3.0 564 */ 565 public Device getSourceDevice() 566 { 567 auto p = gdk_event_get_source_device(gdkEvent); 568 569 if(p is null) 570 { 571 return null; 572 } 573 574 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 575 } 576 577 /** 578 * If the event contains a “state” field, puts that field in @state. Otherwise 579 * stores an empty state (0). Returns %TRUE if there was a state field 580 * in the event. @event may be %NULL, in which case it’s treated 581 * as if the event had no state field. 582 * 583 * Params: 584 * state = return location for state 585 * 586 * Return: %TRUE if there was a state field in the event 587 */ 588 public bool getState(out GdkModifierType state) 589 { 590 return gdk_event_get_state(gdkEvent, &state) != 0; 591 } 592 593 /** 594 * Returns the time stamp from @event, if there is one; otherwise 595 * returns #GDK_CURRENT_TIME. If @event is %NULL, returns #GDK_CURRENT_TIME. 596 * 597 * Return: time stamp field from @event 598 */ 599 public uint getTime() 600 { 601 return gdk_event_get_time(gdkEvent); 602 } 603 604 /** 605 * Extracts the #GdkWindow associated with an event. 606 * 607 * Return: The #GdkWindow associated with the event 608 * 609 * Since: 3.10 610 */ 611 public Window getWindow() 612 { 613 auto p = gdk_event_get_window(gdkEvent); 614 615 if(p is null) 616 { 617 return null; 618 } 619 620 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 621 } 622 623 /** 624 * Appends a copy of the given event onto the front of the event 625 * queue for event->any.window’s display, or the default event 626 * queue if event->any.window is %NULL. See gdk_display_put_event(). 627 */ 628 public void put() 629 { 630 gdk_event_put(gdkEvent); 631 } 632 633 /** 634 * Sets the device for @event to @device. The event must 635 * have been allocated by GTK+, for instance, by 636 * gdk_event_copy(). 637 * 638 * Params: 639 * device = a #GdkDevice 640 * 641 * Since: 3.0 642 */ 643 public void setDevice(Device device) 644 { 645 gdk_event_set_device(gdkEvent, (device is null) ? null : device.getDeviceStruct()); 646 } 647 648 /** 649 * Sets the screen for @event to @screen. The event must 650 * have been allocated by GTK+, for instance, by 651 * gdk_event_copy(). 652 * 653 * Params: 654 * screen = a #GdkScreen 655 * 656 * Since: 2.2 657 */ 658 public void setScreen(Screen screen) 659 { 660 gdk_event_set_screen(gdkEvent, (screen is null) ? null : screen.getScreenStruct()); 661 } 662 663 /** 664 * Sets the slave device for @event to @device. 665 * 666 * The event must have been allocated by GTK+, 667 * for instance by gdk_event_copy(). 668 * 669 * Params: 670 * device = a #GdkDevice 671 * 672 * Since: 3.0 673 */ 674 public void setSourceDevice(Device device) 675 { 676 gdk_event_set_source_device(gdkEvent, (device is null) ? null : device.getDeviceStruct()); 677 } 678 679 /** 680 * This function returns whether a #GdkEventButton should trigger a 681 * context menu, according to platform conventions. The right mouse 682 * button always triggers context menus. Additionally, if 683 * gdk_keymap_get_modifier_mask() returns a non-0 mask for 684 * %GDK_MODIFIER_INTENT_CONTEXT_MENU, then the left mouse button will 685 * also trigger a context menu if this modifier is pressed. 686 * 687 * This function should always be used instead of simply checking for 688 * event->button == %GDK_BUTTON_SECONDARY. 689 * 690 * Return: %TRUE if the event should trigger a context menu. 691 * 692 * Since: 3.4 693 */ 694 public bool triggersContextMenu() 695 { 696 return gdk_event_triggers_context_menu(gdkEvent) != 0; 697 } 698 699 /** 700 * Checks all open displays for a #GdkEvent to process,to be processed 701 * on, fetching events from the windowing system if necessary. 702 * See gdk_display_get_event(). 703 * 704 * Return: the next #GdkEvent to be processed, or %NULL 705 * if no events are pending. The returned #GdkEvent should be freed 706 * with gdk_event_free(). 707 */ 708 public static Event get() 709 { 710 auto p = gdk_event_get(); 711 712 if(p is null) 713 { 714 return null; 715 } 716 717 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 718 } 719 720 /** 721 * Sets the function to call to handle all events from GDK. 722 * 723 * Note that GTK+ uses this to install its own event handler, so it is 724 * usually not useful for GTK+ applications. (Although an application 725 * can call this function then call gtk_main_do_event() to pass 726 * events to GTK+.) 727 * 728 * Params: 729 * func = the function to call to handle events from GDK. 730 * data = user data to pass to the function. 731 * notify = the function to call when the handler function is removed, i.e. when 732 * gdk_event_handler_set() is called with another event handler. 733 */ 734 public static void handlerSet(GdkEventFunc func, void* data, GDestroyNotify notify) 735 { 736 gdk_event_handler_set(func, data, notify); 737 } 738 739 /** 740 * If there is an event waiting in the event queue of some open 741 * display, returns a copy of it. See gdk_display_peek_event(). 742 * 743 * Return: a copy of the first #GdkEvent on some event 744 * queue, or %NULL if no events are in any queues. The returned 745 * #GdkEvent should be freed with gdk_event_free(). 746 */ 747 public static Event peek() 748 { 749 auto p = gdk_event_peek(); 750 751 if(p is null) 752 { 753 return null; 754 } 755 756 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 757 } 758 759 /** 760 * Request more motion notifies if @event is a motion notify hint event. 761 * 762 * This function should be used instead of gdk_window_get_pointer() to 763 * request further motion notifies, because it also works for extension 764 * events where motion notifies are provided for devices other than the 765 * core pointer. Coordinate extraction, processing and requesting more 766 * motion events from a %GDK_MOTION_NOTIFY event usually works like this: 767 * 768 * |[<!-- language="C" --> 769 * { 770 * // motion_event handler 771 * x = motion_event->x; 772 * y = motion_event->y; 773 * // handle (x,y) motion 774 * gdk_event_request_motions (motion_event); // handles is_hint events 775 * } 776 * ]| 777 * 778 * Params: 779 * event = a valid #GdkEvent 780 * 781 * Since: 2.12 782 */ 783 public static void requestMotions(GdkEventMotion* event) 784 { 785 gdk_event_request_motions(event); 786 } 787 788 /** 789 * Checks if any events are ready to be processed for any display. 790 * 791 * Return: %TRUE if any events are pending. 792 */ 793 public static bool pending() 794 { 795 return gdk_events_pending() != 0; 796 } 797 798 /** 799 * Gets whether event debugging output is enabled. 800 * 801 * Return: %TRUE if event debugging output is enabled. 802 */ 803 public static bool getShowEvents() 804 { 805 return gdk_get_show_events() != 0; 806 } 807 808 /** 809 * Sets whether a trace of received events is output. 810 * Note that GTK+ must be compiled with debugging (that is, 811 * configured using the `--enable-debug` option) 812 * to use this option. 813 * 814 * Params: 815 * showEvents = %TRUE to output event debugging information. 816 */ 817 public static void setShowEvents(bool showEvents) 818 { 819 gdk_set_show_events(showEvents); 820 } 821 822 /** 823 * Obtains a desktop-wide setting, such as the double-click time, 824 * for the default screen. See gdk_screen_get_setting(). 825 * 826 * Params: 827 * name = the name of the setting. 828 * value = location to store the value of the setting. 829 * 830 * Return: %TRUE if the setting existed and a value was stored 831 * in @value, %FALSE otherwise. 832 */ 833 public static bool settingGet(string name, Value value) 834 { 835 return gdk_setting_get(Str.toStringz(name), (value is null) ? null : value.getValueStruct()) != 0; 836 } 837 }