GTK::V3::Gdk::GdkEventTypes

Event Structures — Data structures specific to each type of event

Synopsis

my GTK::V3::Gtk::GtkWindow $top-window .= new(:empty);
$top-window.set-title('Hello GTK!');
# ... etcetera ...

# Register a signal handler for a window event
$top-window.register-signal( self, 'handle-keypress', 'key-press-event');

method handle-keypress ( :$widget, GdkEvent :$event ) {
  if $event.event-any.type ~~ GDK_KEY_PRESS and
     $event.event-key.keyval eq 's' {

    # key 's' pressed, stop process ...
  }
}

The handler signature can also be defined as

method handle-keypress ( :$widget, GdkEventKey :$event ) {
  if $event.type ~~ GDK_KEY_PRESS and $event.keyval eq 's' {

    # key 's' pressed, stop process ...
  }
}

class GTK::V3::Gdk::GdkEventTypes

Enums, Structs and Unions

Enum GdkEventType Specifies the type of the event.

Do not confuse these events with the signals that GTK+ widgets emit. Although many of these events result in corresponding signals being emitted, the events are often transformed or filtered along the way.

In some language bindings, the values GDK_2BUTTON_PRESS and GDK_3BUTTON_PRESS would translate into something syntactically invalid (eg Gdk.EventType.2ButtonPress, where a symbol is not allowed to start with a number). In that case, the aliases GDK_DOUBLE_BUTTON_PRESS and GDK_TRIPLE_BUTTON_PRESS can be used instead.

class GdkEventAny

Contains the fields which are common to all event classes. This comes in handy to check its type for instance.

class GdkEventKey

Describes a key press or key release event. The type of the event will be one of GDK_KEY_PRESS or GDK_KEY_RELEASE.

class GdkEventButton

Used for mouse button press and button release events. The type will be one of GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_3BUTTON_PRESS or GDK_BUTTON_RELEASE,

Double and triple-clicks result in a sequence of events being received. For double-clicks the order of events will be: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS and GDK_BUTTON_RELEASE.

Note that the first click is received just like a normal button press, while the second click results in a GDK_2BUTTON_PRESS being received just after the GDK_BUTTON_PRESS.

Triple-clicks are very similar to double-clicks, except that GDK_3BUTTON_PRESS is inserted after the third click. The order of the events is: GDK_BUTTON_PRESS, GDK_BUTTON_RELEASE, GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS, GDK_BUTTON_RELEASE, GDK_BUTTON_PRESS, GDK_3BUTTON_PRESS and GDK_BUTTON_RELEASE.

For a double click to occur, the second button press must occur within 1/4 of a second of the first. For a triple click to occur, the third button press must also occur within 1/2 second of the first button press.

To handle e.g. a triple mouse button presses, all events can be ignored except GDK_3BUTTON_PRESS

method handle-keypress ( :$widget, GdkEventButton :$event ) {
  # check if left mouse button was pressed three times
  if $event.type ~~ GDK_3BUTTON_PRESS and $event.button == 1 {
    ...
  }
}

class GdkEventTouch Used for touch events. type field will be one of GDK_TOUCH_BEGIN, GDK_TOUCH_UPDATE, GDK_TOUCH_END or GDK_TOUCH_CANCEL.

Touch events are grouped into sequences by means of the sequence field, which can also be obtained with gdk_event_get_event_sequence(). Each sequence begins with a GDK_TOUCH_BEGIN event, followed by any number of GDK_TOUCH_UPDATE events, and ends with a GDK_TOUCH_END (or GDK_TOUCH_CANCEL) event. With multitouch devices, there may be several active sequences at the same time.

GdkEvent

The event structures contain data specific to each type of event in GDK. The type is a union of all structures explained above.