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 /** */ 229 public static GType getType() 230 { 231 return gdk_event_get_type(); 232 } 233 234 /** 235 * Creates a new event of the given type. All fields are set to 0. 236 * 237 * Params: 238 * type = a #GdkEventType 239 * 240 * Return: a newly-allocated #GdkEvent. The returned #GdkEvent 241 * should be freed with gdk_event_free(). 242 * 243 * Since: 2.2 244 * 245 * Throws: ConstructionException GTK+ fails to create the object. 246 */ 247 public this(GdkEventType type) 248 { 249 auto p = gdk_event_new(type); 250 251 if(p is null) 252 { 253 throw new ConstructionException("null returned by new"); 254 } 255 256 this(cast(GdkEvent*) p); 257 } 258 259 /** 260 * If both events contain X/Y information, this function will return %TRUE 261 * and return in @angle the relative angle from @event1 to @event2. The rotation 262 * direction for positive angles is from the positive X axis towards the positive 263 * Y axis. 264 * 265 * Params: 266 * event1 = first #GdkEvent 267 * event2 = second #GdkEvent 268 * angle = return location for the relative angle between both events 269 * 270 * Return: %TRUE if the angle could be calculated. 271 * 272 * Since: 3.0 273 */ 274 public static bool getAngle(Event event1, Event event2, out double angle) 275 { 276 return gdk_events_get_angle((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &angle) != 0; 277 } 278 279 /** 280 * If both events contain X/Y information, the center of both coordinates 281 * will be returned in @x and @y. 282 * 283 * Params: 284 * event1 = first #GdkEvent 285 * event2 = second #GdkEvent 286 * x = return location for the X coordinate of the center 287 * y = return location for the Y coordinate of the center 288 * 289 * Return: %TRUE if the center could be calculated. 290 * 291 * Since: 3.0 292 */ 293 public static bool getCenter(Event event1, Event event2, out double x, out double y) 294 { 295 return gdk_events_get_center((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &x, &y) != 0; 296 } 297 298 /** 299 * If both events have X/Y information, the distance between both coordinates 300 * (as in a straight line going from @event1 to @event2) will be returned. 301 * 302 * Params: 303 * event1 = first #GdkEvent 304 * event2 = second #GdkEvent 305 * distance = return location for the distance 306 * 307 * Return: %TRUE if the distance could be calculated. 308 * 309 * Since: 3.0 310 */ 311 public static bool getDistance(Event event1, Event event2, out double distance) 312 { 313 return gdk_events_get_distance((event1 is null) ? null : event1.getEventStruct(), (event2 is null) ? null : event2.getEventStruct(), &distance) != 0; 314 } 315 316 /** 317 * Copies a #GdkEvent, copying or incrementing the reference count of the 318 * resources associated with it (e.g. #GdkWindow’s and strings). 319 * 320 * Return: a copy of @event. The returned #GdkEvent should be freed with 321 * gdk_event_free(). 322 */ 323 public Event copy() 324 { 325 auto p = gdk_event_copy(gdkEvent); 326 327 if(p is null) 328 { 329 return null; 330 } 331 332 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 333 } 334 335 /** 336 * Frees a #GdkEvent, freeing or decrementing any resources associated with it. 337 * Note that this function should only be called with events returned from 338 * functions such as gdk_event_peek(), gdk_event_get(), gdk_event_copy() 339 * and gdk_event_new(). 340 */ 341 public void free() 342 { 343 gdk_event_free(gdkEvent); 344 } 345 346 /** 347 * Extract the axis value for a particular axis use from 348 * an event structure. 349 * 350 * Params: 351 * axisUse = the axis use to look for 352 * value = location to store the value found 353 * 354 * Return: %TRUE if the specified axis was found, otherwise %FALSE 355 */ 356 public bool getAxis(GdkAxisUse axisUse, out double value) 357 { 358 return gdk_event_get_axis(gdkEvent, axisUse, &value) != 0; 359 } 360 361 /** 362 * Extract the button number from an event. 363 * 364 * Params: 365 * button = location to store mouse button number 366 * 367 * Return: %TRUE if the event delivered a button number 368 * 369 * Since: 3.2 370 */ 371 public bool getButton(out uint button) 372 { 373 return gdk_event_get_button(gdkEvent, &button) != 0; 374 } 375 376 /** 377 * Extracts the click count from an event. 378 * 379 * Params: 380 * clickCount = location to store click count 381 * 382 * Return: %TRUE if the event delivered a click count 383 * 384 * Since: 3.2 385 */ 386 public bool getClickCount(out uint clickCount) 387 { 388 return gdk_event_get_click_count(gdkEvent, &clickCount) != 0; 389 } 390 391 /** 392 * Extract the event window relative x/y coordinates from an event. 393 * 394 * Params: 395 * xWin = location to put event window x coordinate 396 * yWin = location to put event window y coordinate 397 * 398 * Return: %TRUE if the event delivered event window coordinates 399 */ 400 public bool getCoords(out double xWin, out double yWin) 401 { 402 return gdk_event_get_coords(gdkEvent, &xWin, &yWin) != 0; 403 } 404 405 /** 406 * If the event contains a “device” field, this function will return 407 * it, else it will return %NULL. 408 * 409 * Return: a #GdkDevice, or %NULL. 410 * 411 * Since: 3.0 412 */ 413 public Device getDevice() 414 { 415 auto p = gdk_event_get_device(gdkEvent); 416 417 if(p is null) 418 { 419 return null; 420 } 421 422 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 423 } 424 425 /** 426 * If @event if of type %GDK_TOUCH_BEGIN, %GDK_TOUCH_UPDATE, 427 * %GDK_TOUCH_END or %GDK_TOUCH_CANCEL, returns the #GdkEventSequence 428 * to which the event belongs. Otherwise, return %NULL. 429 * 430 * Return: the event sequence that the event belongs to 431 * 432 * Since: 3.4 433 */ 434 public GdkEventSequence* getEventSequence() 435 { 436 return gdk_event_get_event_sequence(gdkEvent); 437 } 438 439 /** 440 * Retrieves the type of the event. 441 * 442 * Return: a #GdkEventType 443 * 444 * Since: 3.10 445 */ 446 public GdkEventType getEventType() 447 { 448 return gdk_event_get_event_type(gdkEvent); 449 } 450 451 /** 452 * Extracts the hardware keycode from an event. 453 * 454 * Params: 455 * keycode = location to store the keycode 456 * 457 * Return: %TRUE if the event delivered a hardware keycode 458 * 459 * Since: 3.2 460 */ 461 public bool getKeycode(out ushort keycode) 462 { 463 return gdk_event_get_keycode(gdkEvent, &keycode) != 0; 464 } 465 466 /** 467 * Extracts the keyval from an event. 468 * 469 * Params: 470 * keyval = location to store the keyval 471 * 472 * Return: %TRUE if the event delivered a key symbol 473 * 474 * Since: 3.2 475 */ 476 public bool getKeyval(out uint keyval) 477 { 478 return gdk_event_get_keyval(gdkEvent, &keyval) != 0; 479 } 480 481 /** 482 * Extract the root window relative x/y coordinates from an event. 483 * 484 * Params: 485 * xRoot = location to put root window x coordinate 486 * yRoot = location to put root window y coordinate 487 * 488 * Return: %TRUE if the event delivered root window coordinates 489 */ 490 public bool getRootCoords(out double xRoot, out double yRoot) 491 { 492 return gdk_event_get_root_coords(gdkEvent, &xRoot, &yRoot) != 0; 493 } 494 495 /** 496 * Returns the screen for the event. The screen is 497 * typically the screen for `event->any.window`, but 498 * for events such as mouse events, it is the screen 499 * where the pointer was when the event occurs - 500 * that is, the screen which has the root window 501 * to which `event->motion.x_root` and 502 * `event->motion.y_root` are relative. 503 * 504 * Return: the screen for the event 505 * 506 * Since: 2.2 507 */ 508 public Screen getScreen() 509 { 510 auto p = gdk_event_get_screen(gdkEvent); 511 512 if(p is null) 513 { 514 return null; 515 } 516 517 return ObjectG.getDObject!(Screen)(cast(GdkScreen*) p); 518 } 519 520 /** 521 * Retrieves the scroll deltas from a #GdkEvent 522 * 523 * Params: 524 * deltaX = return location for X delta 525 * deltaY = return location for Y delta 526 * 527 * Return: %TRUE if the event contains smooth scroll information 528 * 529 * Since: 3.4 530 */ 531 public bool getScrollDeltas(out double deltaX, out double deltaY) 532 { 533 return gdk_event_get_scroll_deltas(gdkEvent, &deltaX, &deltaY) != 0; 534 } 535 536 /** 537 * Extracts the scroll direction from an event. 538 * 539 * Params: 540 * direction = location to store the scroll direction 541 * 542 * Return: %TRUE if the event delivered a scroll direction 543 * 544 * Since: 3.2 545 */ 546 public bool getScrollDirection(out GdkScrollDirection direction) 547 { 548 return gdk_event_get_scroll_direction(gdkEvent, &direction) != 0; 549 } 550 551 /** 552 * This function returns the hardware (slave) #GdkDevice that has 553 * triggered the event, falling back to the virtual (master) device 554 * (as in gdk_event_get_device()) if the event wasn’t caused by 555 * interaction with a hardware device. This may happen for example 556 * in synthesized crossing events after a #GdkWindow updates its 557 * geometry or a grab is acquired/released. 558 * 559 * If the event does not contain a device field, this function will 560 * return %NULL. 561 * 562 * Return: a #GdkDevice, or %NULL. 563 * 564 * Since: 3.0 565 */ 566 public Device getSourceDevice() 567 { 568 auto p = gdk_event_get_source_device(gdkEvent); 569 570 if(p is null) 571 { 572 return null; 573 } 574 575 return ObjectG.getDObject!(Device)(cast(GdkDevice*) p); 576 } 577 578 /** 579 * If the event contains a “state” field, puts that field in @state. Otherwise 580 * stores an empty state (0). Returns %TRUE if there was a state field 581 * in the event. @event may be %NULL, in which case it’s treated 582 * as if the event had no state field. 583 * 584 * Params: 585 * state = return location for state 586 * 587 * Return: %TRUE if there was a state field in the event 588 */ 589 public bool getState(out GdkModifierType state) 590 { 591 return gdk_event_get_state(gdkEvent, &state) != 0; 592 } 593 594 /** 595 * Returns the time stamp from @event, if there is one; otherwise 596 * returns #GDK_CURRENT_TIME. If @event is %NULL, returns #GDK_CURRENT_TIME. 597 * 598 * Return: time stamp field from @event 599 */ 600 public uint getTime() 601 { 602 return gdk_event_get_time(gdkEvent); 603 } 604 605 /** 606 * Extracts the #GdkWindow associated with an event. 607 * 608 * Return: The #GdkWindow associated with the event 609 * 610 * Since: 3.10 611 */ 612 public Window getWindow() 613 { 614 auto p = gdk_event_get_window(gdkEvent); 615 616 if(p is null) 617 { 618 return null; 619 } 620 621 return ObjectG.getDObject!(Window)(cast(GdkWindow*) p); 622 } 623 624 /** 625 * Appends a copy of the given event onto the front of the event 626 * queue for event->any.window’s display, or the default event 627 * queue if event->any.window is %NULL. See gdk_display_put_event(). 628 */ 629 public void put() 630 { 631 gdk_event_put(gdkEvent); 632 } 633 634 /** 635 * Sets the device for @event to @device. The event must 636 * have been allocated by GTK+, for instance, by 637 * gdk_event_copy(). 638 * 639 * Params: 640 * device = a #GdkDevice 641 * 642 * Since: 3.0 643 */ 644 public void setDevice(Device device) 645 { 646 gdk_event_set_device(gdkEvent, (device is null) ? null : device.getDeviceStruct()); 647 } 648 649 /** 650 * Sets the screen for @event to @screen. The event must 651 * have been allocated by GTK+, for instance, by 652 * gdk_event_copy(). 653 * 654 * Params: 655 * screen = a #GdkScreen 656 * 657 * Since: 2.2 658 */ 659 public void setScreen(Screen screen) 660 { 661 gdk_event_set_screen(gdkEvent, (screen is null) ? null : screen.getScreenStruct()); 662 } 663 664 /** 665 * Sets the slave device for @event to @device. 666 * 667 * The event must have been allocated by GTK+, 668 * for instance by gdk_event_copy(). 669 * 670 * Params: 671 * device = a #GdkDevice 672 * 673 * Since: 3.0 674 */ 675 public void setSourceDevice(Device device) 676 { 677 gdk_event_set_source_device(gdkEvent, (device is null) ? null : device.getDeviceStruct()); 678 } 679 680 /** 681 * This function returns whether a #GdkEventButton should trigger a 682 * context menu, according to platform conventions. The right mouse 683 * button always triggers context menus. Additionally, if 684 * gdk_keymap_get_modifier_mask() returns a non-0 mask for 685 * %GDK_MODIFIER_INTENT_CONTEXT_MENU, then the left mouse button will 686 * also trigger a context menu if this modifier is pressed. 687 * 688 * This function should always be used instead of simply checking for 689 * event->button == %GDK_BUTTON_SECONDARY. 690 * 691 * Return: %TRUE if the event should trigger a context menu. 692 * 693 * Since: 3.4 694 */ 695 public bool triggersContextMenu() 696 { 697 return gdk_event_triggers_context_menu(gdkEvent) != 0; 698 } 699 700 /** 701 * Checks all open displays for a #GdkEvent to process,to be processed 702 * on, fetching events from the windowing system if necessary. 703 * See gdk_display_get_event(). 704 * 705 * Return: the next #GdkEvent to be processed, or %NULL 706 * if no events are pending. The returned #GdkEvent should be freed 707 * with gdk_event_free(). 708 */ 709 public static Event get() 710 { 711 auto p = gdk_event_get(); 712 713 if(p is null) 714 { 715 return null; 716 } 717 718 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 719 } 720 721 /** 722 * Sets the function to call to handle all events from GDK. 723 * 724 * Note that GTK+ uses this to install its own event handler, so it is 725 * usually not useful for GTK+ applications. (Although an application 726 * can call this function then call gtk_main_do_event() to pass 727 * events to GTK+.) 728 * 729 * Params: 730 * func = the function to call to handle events from GDK. 731 * data = user data to pass to the function. 732 * notify = the function to call when the handler function is removed, i.e. when 733 * gdk_event_handler_set() is called with another event handler. 734 */ 735 public static void handlerSet(GdkEventFunc func, void* data, GDestroyNotify notify) 736 { 737 gdk_event_handler_set(func, data, notify); 738 } 739 740 /** 741 * If there is an event waiting in the event queue of some open 742 * display, returns a copy of it. See gdk_display_peek_event(). 743 * 744 * Return: a copy of the first #GdkEvent on some event 745 * queue, or %NULL if no events are in any queues. The returned 746 * #GdkEvent should be freed with gdk_event_free(). 747 */ 748 public static Event peek() 749 { 750 auto p = gdk_event_peek(); 751 752 if(p is null) 753 { 754 return null; 755 } 756 757 return ObjectG.getDObject!(Event)(cast(GdkEvent*) p); 758 } 759 760 /** 761 * Request more motion notifies if @event is a motion notify hint event. 762 * 763 * This function should be used instead of gdk_window_get_pointer() to 764 * request further motion notifies, because it also works for extension 765 * events where motion notifies are provided for devices other than the 766 * core pointer. Coordinate extraction, processing and requesting more 767 * motion events from a %GDK_MOTION_NOTIFY event usually works like this: 768 * 769 * |[<!-- language="C" --> 770 * { 771 * // motion_event handler 772 * x = motion_event->x; 773 * y = motion_event->y; 774 * // handle (x,y) motion 775 * gdk_event_request_motions (motion_event); // handles is_hint events 776 * } 777 * ]| 778 * 779 * Params: 780 * event = a valid #GdkEvent 781 * 782 * Since: 2.12 783 */ 784 public static void requestMotions(GdkEventMotion* event) 785 { 786 gdk_event_request_motions(event); 787 } 788 789 /** 790 * Checks if any events are ready to be processed for any display. 791 * 792 * Return: %TRUE if any events are pending. 793 */ 794 public static bool pending() 795 { 796 return gdk_events_pending() != 0; 797 } 798 799 /** 800 * Gets whether event debugging output is enabled. 801 * 802 * Return: %TRUE if event debugging output is enabled. 803 */ 804 public static bool getShowEvents() 805 { 806 return gdk_get_show_events() != 0; 807 } 808 809 /** 810 * Sets whether a trace of received events is output. 811 * Note that GTK+ must be compiled with debugging (that is, 812 * configured using the `--enable-debug` option) 813 * to use this option. 814 * 815 * Params: 816 * showEvents = %TRUE to output event debugging information. 817 */ 818 public static void setShowEvents(bool showEvents) 819 { 820 gdk_set_show_events(showEvents); 821 } 822 823 /** 824 * Obtains a desktop-wide setting, such as the double-click time, 825 * for the default screen. See gdk_screen_get_setting(). 826 * 827 * Params: 828 * name = the name of the setting. 829 * value = location to store the value of the setting. 830 * 831 * Return: %TRUE if the setting existed and a value was stored 832 * in @value, %FALSE otherwise. 833 */ 834 public static bool settingGet(string name, Value value) 835 { 836 return gdk_setting_get(Str.toStringz(name), (value is null) ? null : value.getValueStruct()) != 0; 837 } 838 }