### ----------------------------------------------------
### -- Gnome::Gdk3
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: lib/Gnome/Gdk3/Events.rakumod
### ----------------------------------------------------
### -- Chunk 3 of 4
 = '';
  GDK_OWNER_CHANGE = '';
  GDK_GRAB_BROKEN = '';
  GDK_DAMAGE = '';
  GDK_TOUCH_BEGIN = '';
  GDK_TOUCH_UPDATE = '';
  GDK_TOUCH_END = '';
  GDK_TOUCH_CANCEL = '';
  GDK_TOUCHPAD_SWIPE = 'touchpad_swipe',
  GDK_TOUCHPAD_PINCH = 'touchpad_pinch',
  GDK_PAD_BUTTON_PRESS = 'pad_button',
  GDK_PAD_BUTTON_RELEASE = 'pad_button',
  GDK_PAD_RING = '';
  GDK_PAD_STRIP = '';
  GDK_PAD_GROUP_MODE = 'pad_group_mode',
  GDK_EVENT_LAST = '';
);
}}

#-------------------------------------------------------------------------------
=begin pod
=head1 Methods
=head2 new

=head3 :type

Creates a new event of the given type. All fields are set to 0.

  multi method new ( GdkEventType :$type!, *%options )

=item $type; a B<Gnome::Gdk3::EventType>
=item %options: Any options to set fields in a N-GdkEvent object wrapped in this event object.


=head3 :get

When C<:get> is given (no value needed) it checks all open displays for a an event to process, to be processed on, fetching events from the windowing system if necessary. See C<Gnome::Gdk3::Display.get-event()>.

Gets the next B<Gnome::Gdk3::Event> to be processed, or, if no events are pending, the object becomes invalid. As always, this object should be freed with C<clear-object()>.

  multi method get ( :get! )


=head3 :native-object

  multi method new ( Gnome::GObject::Object :$native-object! )

Create an object using a native object from elsewhere. See also C<Gnome::GObject::Object>.

=end pod

submethod BUILD ( *%options ) {
  # prevent creating wrong native-objects
  if self.^name eq 'Gnome::Gdk3::Events' {

    # check if native object is set by a parent class
    if self.is-valid { }

    # check if common options are handled by some parent
    elsif %options<native-object>:exists { }

    # process all other options
    else {
      my $no;
      if %options<type>:exists {
#        $no = _gdk_event_new(%options<type>);

##`{{
        my $type = %options<type>;

        given $type {
          when any( GDK_MOTION_NOTIFY, GDK_BUTTON_PRESS, GDK_2BUTTON_PRESS,
            GDK_DOUBLE_BUTTON_PRESS, GDK_3BUTTON_PRESS,
            GDK_TRIPLE_BUTTON_PRESS, GDK_BUTTON_RELEASE
          ) {
            $no = N-GdkEventButton.new(|%options);
#note "event $type: $no.gist()";
          }

          when any( GDK_KEY_PRESS, GDK_KEY_RELEASE) {
            $no = N-GdkEventKey.new(|%options);
          }

          when any( GDK_MOTION_NOTIFY) {
            $no = N-GdkEventMotion.new(|%options);
          }

          when any( GDK_SCROLL ) {
            $no = N-GdkEventScroll.new(|%options);
          }

          default {
            $no = _gdk_event_new(%options<type>);
#            die X::Gnome.new(:message("Type $type not supported"));
          }
        }
#}}
      }

      elsif %options<get>:exists {
        $no = _gdk_event_get;
      }

      ##`{{ use this when the module is not made inheritable
      # check if there are unknown options
      elsif %options.elems {
        die X::Gnome.new(
          :message(
            'Unsupported, undefined, incomplete or wrongly typed options for ' ~
            self.^name ~ ': ' ~ %options.keys.join(', ')
          )
        );
      }
      #}}

      ##`{{ when there are no defaults use this
      # check if there are any options
      elsif %options.elems == 0 {
        die X::Gnome.new(:message('No options specified ' ~ self.^name));
      }
      #}}

      #`{{ when there are defaults use this instead
      # create default object
      else {
        $no = _gdk_events_new();
      }
      }}

      self.set-native-object($no);
    }

    # only after creating the native-object, the gtype is known
    self._set-class-info('GdkEvents');
  }
}

#-------------------------------------------------------------------------------
# no pod. user does not have to know about it.
method _fallback ( $native-sub is copy --> Callable ) {

  my Callable $s;
  try { $s = &::("gdk_events_$native-sub"); };
  try { $s = &::("gdk_$native-sub"); } unless ?$s;
  try { $s = &::($native-sub); } if !$s and $native-sub ~~ m/^ 'gdk_' /;

  $s = callsame unless ?$s;

  $s;
}

#-------------------------------------------------------------------------------
# ? no ref/unref for a variant type
method native-object-ref ( $n-native-object --> Any ) {
  $n-native-object
}

#-------------------------------------------------------------------------------
method native-object-unref ( $n-native-object ) {
#  _g_object_free($n-native-object)
  _gdk_event_free($n-native-object)
}

#`{{
#-------------------------------------------------------------------------------
# TM:0:copy:
=begin pod
=head2 copy

Copies a B<Gnome::Gdk3::Event>, copying or incrementing the reference count of the resources associated with it (e.g. B<Gnome::Gdk3::Window>’s and strings).

Returns: a copy of I<event>. The returned B<Gnome::Gdk3::Event> should be freed with C<gdk_event_free()>.

  method copy ( N-GdkEvent $event --> N-GdkEvent )

=item $event; a B<Gnome::Gdk3::Event>
=end pod

method copy ( N-GdkEvent $event --> N-GdkEvent ) {

  gdk_event_copy(
    self._get-native-object-no-reffing, $event
  )
}

sub gdk_event_copy (
  N-GdkEvent $event --> N-GdkEvent
) is native(&gdk-lib)
  { * }
}}

#`{{
#-------------------------------------------------------------------------------
#TM:0:_gdk_event_free:
=begin pod
=head2 free

Frees a B<Gnome::Gdk3::Event>, freeing or decrementing any resources associated with it. Note that this function should only be called with events returned from functions such as C<gdk_event_peek()>, C<gdk_event_get()>, C<gdk_event_copy()> and C<gdk_event_new()>.

  method free ( N-GdkEvent $event )

=item $event; a B<Gnome::Gdk3::Event>.
=end pod

method free ( N-GdkEvent $event ) {
  gdk_event_free(
    self._get-native-object-no-reffing, $event
  );
}
}}

sub _gdk_event_free (
  N-GdkEvent $event
) is native(&gdk-lib)
  is symbol('gdk_event_free')
  { * }

#-------------------------------------------------------------------------------
#TM:0:_gdk_event_get:
#`{{
=begin pod
=head2 get

Checks all open displays for a B<Gnome::Gdk3::Event> to process,to be processed on, fetching events from the windowing system if necessary. See C<Gnome::Gdk3::Display.get-event()>.

Returns: the next B<Gnome::Gdk3::Event> to be processed, or C<undefined> if no events are pending. The returned B<Gnome::Gdk3::Event> should be freed with C<gdk_event_free()>.

  method get ( --> N-GdkEvent )

=end pod

method get ( --> N-GdkEvent ) {
  gdk_event_get()
}
}}

sub _gdk_event_get (
   --> N-GdkEvent
) is native(&gdk-lib)
  is symbol('gdk_event_get')
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-angle:
=begin pod
=head2 get-angle

If this and the provided event contain X/Y information, this function will return a defined angle, the relative angle from this event to I<$event>. The rotation direction for positive angles is from the positive X axis towards the positive Y axis.

  method get-angle ( N-GdkEvent $event --> Num )

=item $event; the second B<Gnome::Gdk3::Event>
=end pod

method get-angle ( N-GdkEvent $event --> Num ) {
  my gdouble $angle;
  my Bool() $r = gdk_events_get_angle(
    self._get-native-object-no-reffing, $event, $angle
  );

  $r ?? $angle.Num !! Num
}

sub gdk_events_get_angle (
  N-GdkEvent $event1, N-GdkEvent $event2, gdouble $angle is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-center:
=begin pod
=head2 get-center

If this and the provided event contain X/Y information, the center of both coordinates will be returned in a List. An empty list is returned otherwise.

  method get-center ( N-GdkEvent $event2 --> List )

=item $event; the second B<Gnome::Gdk3::Event>

List returns
=item Num; the X coordinate of the center
=item Num; the Y coordinate of the center
=end pod

method get-center ( N-GdkEvent $event, List ) {
  my gdouble $x;
  my gdouble $y;

  my Bool() $r = gdk_events_get_center(
    self._get-native-object-no-reffing, $event, $x, $y
  );

  $r ?? ( $x, $y) !! ( )
}

sub gdk_events_get_center (
  N-GdkEvent $event1, N-GdkEvent $event2, gdouble $x is rw, gdouble $y is rw
  --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-axis:
=begin pod
=head2 get-axis

Extract the axis value for a particular axis use from an event structure.

Returns: the axis value if the specified axis was found, otherwise an undefined C<Num>.

  method get-axis ( GdkAxisUse $axis_use --> Num )

=item $axis_use; the axis use to look for
=end pod

method get-axis ( GdkAxisUse $axis_use --> Num ) {
  my gdouble $value;
  my Bool() $r = gdk_event_get_axis(
    self._get-native-object-no-reffing, $axis_use.value, $value
  );

  $r ?? $value.Num !! Num
}

sub gdk_event_get_axis (
  N-GdkEvent $event, GEnum $axis_use, gdouble $value is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-button:
=begin pod
=head2 get-button

Extract the button number from an event.

Returns: a defined C<Int> if the event delivered a button number.

  method get-button ( --> Int )

=end pod

method get-button ( --> Int ) {
  my guint $button;
  my Bool() $r = gdk_event_get_button(
    self._get-native-object-no-reffing, $button
  );

  $r ?? $button !! Int
}

sub gdk_event_get_button (
  N-GdkEvent $event, guint $button is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-click-count:
=begin pod
=head2 get-click-count

Extracts the click count from an event.

Returns: a defined C<Int> if the event delivered a click count

  method get-click-count ( --> Int )

=end pod

method get-click-count ( --> Int ) {
  my guint $click_count;
  my Bool() $r = gdk_event_get_click_count(
    self._get-native-object-no-reffing, $click_count
  );

  $r ?? $click_count !! Int
}

sub gdk_event_get_click_count (
  N-GdkEvent $event, guint $click_count is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-coords:
=begin pod
=head2 get-coords

Extract the event window relative x/y coordinates from an event.

Returns: C<True> if the event delivered event window coordinates

  method get-coords ( --> List )

List returns;
=item Num; event window x coordinate
=item Num; event window y coordinate
=end pod

method get-coords ( --> List ) {
  my gdouble $x_win;
  my gdouble $y_win;

  my Bool $r = gdk_event_get_coords(
    self._get-native-object-no-reffing, $x_win, $y_win
  ).Bool;

  ( $x_win, $y_win)
}

sub gdk_event_get_coords (
  N-GdkEvent $event, gdouble $x_win is rw, gdouble $y_win is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:get-device:
=begin pod
=head2 get-device

If the event contains a “device” field, this function will return it, else it will return C<undefined> or an invalid object in the case of C<get-device-rk()>.

Returns: a B<Gnome::Gdk3::Device>, or C<undefined>.

  method get-device ( --> N-GObject )

=end pod

method get-device ( --> N-GObject ) {
  gdk_event_get_device(
    nativecast( N-GdkEvent, self._get-native-object-no-reffing)
  )
}

method get-device-rk ( --> Any ) {
  Gnome::N::deprecate(
    'get-device-rk', 'coercing from get-device',
    '0.19.2', '0.21.0'
  );

  self._wrap-native-type(
    'Gnome::Gdk3::Device',
    gdk_event_get_device(self._get-native-object-no-reffing)
  )
}

sub gdk_event_get_device (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:get-device-tool:
=begin pod
=head2 get-device-tool

If the event was generated by a device that supports different tools (eg. a tablet), this function will return a B<Gnome::Gdk3::DeviceTool> representing the tool that caused the event. Otherwise, C<undefined> will be returned or an invalid object in the case of C<get-device-tool-rk()>.

Note: the B<Gnome::Gdk3::DeviceTool><!-- -->s will be constant during the application lifetime, if settings must be stored persistently across runs, see C<gdk_device_tool_get_serial()>

Returns: The current device tool, or C<undefined>

  method get-device-tool ( --> N-GObject )

=end pod

method get-device-tool ( --> N-GObject ) {
  gdk_event_get_device_tool(self._get-native-object-no-reffing)
}

sub gdk_event_get_device_tool (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:get-distance:
=begin pod
=head2 get-distance

If this and the provided event  have X/Y information, the distance between both coordinates (as in a straight line going from this event to I<$event>) will be returned. Otherwise returned value is undefined.

  method get-distance ( N-GdkEvent $event --> Num )

=item $event; second B<Gnome::Gdk3::Event>
=end pod

method get-distance ( N-GdkEvent $event --> Num ) {
  my gdouble $distance;
  my Bool() $r = gdk_events_get_distance(
    self._get-native-object-no-reffing, $event, $distance
  );

  $r ?? $distance.Num !! Num
}

sub gdk_events_get_distance (
  N-GdkEvent $event1, N-GdkEvent $event2, gdouble $distance is rw --> gboolean
) is native(&gdk-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:get-event-sequence:
=begin pod
=head2 get-event-sequence

If I<event> is of type C<GDK_TOUCH_BEGIN>, C<GDK_TOUCH_UPDATE>, C<GDK_TOUCH_END> or C<GDK_TOUCH_CANCEL>, returns the B<Gnome::Gdk3::EventSequence> to which the event belongs. Otherwise, return C<undefined>.

Returns: the event sequence that the event belongs to

  method get-event-sequence ( --> GdkEventSequence )

=end pod

method get-event-sequence ( --> GdkEventSequence ) {
  gdk_event_get_event_sequence(self._get-native-object-no-reffing)
}

sub gdk_event_get_event_sequence (
  N-GdkEvent $event --> GdkEventSequence
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:get-event-type:
=begin pod
=head2 get-event-type

Retrieves the type of the event.

Returns: a B<Gnome::Gdk3::EventType>

  method get-event-type ( --> GdkEventType )

=end pod

method get-event-type ( --> GdkEventType ) {
  GdkEventType(
    gdk_event_get_event_type(self._get-native-object-no-reffing)
  )
}

sub gdk_event_get_event_type (
  N-GdkEvent $event --> GEnum
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-keycode:
=begin pod
=head2 get-keycode

Extracts the hardware keycode from an event.

Also see C<get-scancode()>.

Returns: a defined keycode if the event delivered a hardware keycode, undefined otherwise.

  method get-keycode ( --> UInt )

=end pod

method get-keycode ( --> UInt ) {
  my guint16 $keycode;
  my Bool() $r = gdk_event_get_keycode(
    self._get-native-object-no-reffing, $keycode
  );

  $r ?? $keycode !! UInt
}

sub gdk_event_get_keycode (
  N-GdkEvent $event, guint16 $keycode is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-keyval:
=begin pod
=head2 get-keyval

Extracts the keyval from an event.

Returns: a defined key symbol if the event delivered a key symbol, undefined otherwise.

  method get-keyval ( --> UInt )

=end pod

method get-keyval ( --> UInt ) {
  my guint $keyval;
  my Bool() $r = gdk_event_get_keyval(
    self._get-native-object-no-reffing, $keyval
  );

  $r ?? $keyval !! UInt
}

sub gdk_event_get_keyval (
  N-GdkEvent $event, guint $keyval is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-pointer-emulated:
=begin pod
=head2 get-pointer-emulated

Returns whether this event is an 'emulated' pointer event (typically from a touch event), as opposed to a real one.

Returns: C<True> if this event is emulated

  method get-pointer-emulated ( --> Bool )

=end pod

method get-pointer-emulated ( --> Bool ) {
  gdk_event_get_pointer_emulated(self._get-native-object-no-reffing).Bool
}

sub gdk_event_get_pointer_emulated (
  N-GdkEvent $event --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-root-coords:
=begin pod
=head2 get-root-coords

Extract the root window relative x/y coordinates from an event.

Returns: a list if the event delivered root window coordinates. The list is empty if not.

  method get-root-coords ( --> List )

The List returns
=item Num; root window x coordinate
=item Num; root window y coordinate
=end pod

method get-root-coords (--> List ) {

  my gdouble $x_root;
  my gdouble $y_root;

  my Bool() $r = gdk_event_get_root_coords(
    self._get-native-object-no-reffing, $x_root, $y_root
  );

  $r ?? ( $x_root, $y_root) !! ()
}

sub gdk_event_get_root_coords (
  N-GdkEvent $event, gdouble $x_root is rw, gdouble $y_root is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-scancode:
=begin pod
=head2 get-scancode

Gets the keyboard low-level scancode of a key event.

This is usually hardware_keycode. On Windows this is the high word of WM_KEY{DOWN,UP} lParam which contains the scancode and some extended flags.

Returns: The associated keyboard scancode or 0

  method get-scancode ( --> Int )

=end pod

method get-scancode ( --> Int ) {
  gdk_event_get_scancode(self._get-native-object-no-reffing)
}

sub gdk_event_get_scancode (
  N-GdkEvent $event --> gint
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-screen:
=begin pod
=head2 get-screen

Returns the screen for the event. The screen is typically the screen in any C<$event.any.window>`, but for events such as mouse events, it is the screen where the pointer was when the event occurs - that is, the screen which has the root window to which C<$event.motion.x_root> and C<$event.motion.y_root> are relative.

Returns: the screen for the event

  method get-screen ( --> N-GObject )

=item $event; a B<Gnome::Gdk3::Event>
=end pod

method get-screen ( --> N-GObject ) {
  gdk_event_get_screen(self._get-native-object-no-reffing)
}

method get-screen-rk ( --> Any ) {
  Gnome::N::deprecate(
    'get-screen-rk', 'coercing from get-screen',
    '0.19.2', '0.21.0'
  );

  self._wrap-native-type(
    'Gnome::Gdk3::Screen',
    gdk_event_get_screen(self._get-native-object-no-reffing)
  )
}

sub gdk_event_get_screen (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-scroll-deltas:
=begin pod
=head2 get-scroll-deltas

Retrieves the scroll deltas from this event

See also: C<gdk_event_get_scroll_direction()>

Returns: A List holding the values if the event contains smooth scroll information and an empty List otherwise.

  method get-scroll-deltas ( --> List )

The List returns;
=item Num; X delta
=item Num; Y delta
=end pod

method get-scroll-deltas ( --> List ) {
  my gdouble $delta_x;
  my gdouble $delta_y;
  my Bool() $r = gdk_event_get_scroll_deltas(
    self._get-native-object-no-reffing, $delta_x, $delta_y
  );

  $r ?? ( $delta_x, $delta_y) !! ()
}

sub gdk_event_get_scroll_deltas (
  N-GdkEvent $event, gdouble $delta_x is rw, gdouble $delta_y is rw --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-scroll-direction:
=begin pod
=head2 get-scroll-direction

Extracts the scroll direction from an event.

If I<event> is not of type C<GDK_SCROLL>, the contents of I<direction> are undefined.

If you wish to handle both discrete and smooth scrolling, you should check the return value of this function, or of C<get-scroll-deltas()>; for instance:

  # Handle discrete scrolling with a known constant delta;
  constant Num $delta = 12e0;

  my GdkScrollDirection $direction;
  my Num $vscroll_factor = 0e0;
  my Num ( $x_scroll, $y_scroll);

  if ?( $direction = $event.get-scroll-direction ) {
    with $direction {
      when GDK_SCROLL_UP {
        $vscroll_factor = -$delta;
      }

      when GDK_SCROLL_DOWN {
        $vscroll_factor = $delta;
      }

      default {
        # no scrolling
      }
    }
  }

  elsif my List $deltas = $event.get-scroll-deltas {
    # Handle smooth scrolling directly
    $vscroll_factor = $deltas[1];
  }


Returns: a defined GdkScrollDirection value if the event delivered a scroll direction and undefined otherwise

  method get-scroll-direction ( --> GdkScrollDirection )

=end pod

method get-scroll-direction ( --> GdkScrollDirection ) {
  my GEnum $direction;
  my Bool() $r = gdk_event_get_scroll_direction(
    self._get-native-object-no-reffing, $direction
  );

  %$r ?? GdkScrollDirection($direction) !! GdkScrollDirection
}

sub gdk_event_get_scroll_direction (
  N-GdkEvent $event, GEnum $direction --> gboolean
) is native(&gdk-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:get-seat:
=begin pod
=head2 get-seat

Returns the B<Gnome::Gdk3::Seat> this event was generated for.

  method get-seat ( --> N-GObject )

=end pod

method get-seat ( --> N-GObject ) {
  gdk_event_get_seat(self._get-native-object-no-reffing)
}

sub gdk_event_get_seat (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:get-show-events:
=begin pod
=head2 get-show-events

Gets whether event debugging output is enabled.

Returns: C<True> if event debugging output is enabled.

  method get-show-events ( --> Bool )

=end pod

method get-show-events ( --> Bool ) {
  gdk_get_show_events.Bool
}

sub gdk_get_show_events (
   --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-source-device:
=begin pod
=head2 get-source-device

This function returns the hardware secondary B<Gnome::Gdk3::Device> that has triggered the event, falling back to the virtual primary device (as in C<get-device()>) if the event wasn’t caused by interaction with a hardware device.

This may happen for example in synthesized crossing events after a B<Gnome::Gdk3::Window> updates its geometry or a grab is acquired/released.

If the event does not contain a device field, this function will return C<undefined> or an invalid object in the case of C<get-source-device-rk()>.

Returns: a B<Gnome::Gdk3::Device>, or C<undefined>.

  method get-source-device ( --> N-GObject )

=item $event; a B<Gnome::Gdk3::Event>
=end pod

method get-source-device ( --> N-GObject ) {
  gdk_event_get_source_device(self._get-native-object-no-reffing)
}

method get-source-device-rk ( --> Any ) {
  Gnome::N::deprecate(
    'get-source-device-rk', 'coercing from get-source-device',
    '0.19.2', '0.21.0'
  );

  self._wrap-native-type(
    'Gnome::Gdk3::Device',
    gdk_event_get_source_device(self._get-native-object-no-reffing)
  )
}

sub gdk_event_get_source_device (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-state:
=begin pod
=head2 get-state

If the event contains a “state” field, returns that field.

Returns a defined state value if there was a state field in the event. Undefined otherwise.

=comment I<event> may be C<undefined>, in which case it’s treated as if the event had no state field.

  method get-state ( --> GdkModifierType )

=end pod

method get-state ( --> GdkModifierType ) {
  my GEnum $state;
  my Bool() $r = gdk_event_get_state(
    self._get-native-object-no-reffing, $state
  );

  $r ?? GdkModifierType($state) !! GdkModifierType
}

sub gdk_event_get_state (
  N-GdkEvent $event, GEnum $state --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:get-time:
=begin pod
=head2 get-time

Returns the time stamp from I<event>, if there is one; otherwise returns the current time.

Returns: time stamp field from this event

  method get-time ( --> UInt )

=end pod

method get-time ( --> UInt ) {
  gdk_event_get_time(self._get-native-object-no-reffing)
}

sub gdk_event_get_time (
  N-GdkEvent $event --> guint32
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:get-window:
=begin pod
=head2 get-window

Extracts the B<Gnome::Gdk3::Window> associated with an event.

  method get-window ( --> N-GObject )

=end pod

method get-window ( --> N-GObject ) {
  gdk_event_get_window(
    nativecast( N-GdkEvent, self._get-native-object-no-reffing)
  )
}

method get-window-rk ( --> Any ) {
  Gnome::N::deprecate(
    'get-window-rk', 'coercing from get-window',
    '0.19.2', '0.21.0'
  );

  self._wrap-native-type(
    'Gnome::Gdk3::Window',
    gdk_event_get_window( self._get-native-object-no-reffing)
  )
}

sub gdk_event_get_window (
  N-GdkEvent $event --> N-GObject
) is native(&gdk-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:handler-set:
=begin pod
=head2 handler-set

Sets the function to call to handle all events from GDK.

Note that GTK+ uses this to install its own event handler, so it is usually not useful for GTK+ applications. (Although an application can call this function then call C<gtk_main_do_event()> to pass events to GTK+.)

  method handler-set ( GdkEventFunc $func, Pointer $data, GDestroyNotify $notify )

=item $func; the function to call to handle events from GDK.
=item $data; user data to pass to the function.
=item $notify; the function to call when the handler function is removed, i.e. when C<gdk_event_handler_set()> is called with another event handler.
=end pod

method handler-set ( GdkEventFunc $func, Pointer $data, GDestroyNotify $notify ) {

  gdk_event_handler_set(
    $func, $data, $notify
  );
}

sub gdk_event_handler_set (
  GdkEventFunc $func, gpointer $data, GDestroyNotify $notify
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:is-scroll-stop-event:
=begin pod
=head2 is-scroll-stop-event

Check whether a scroll event is a stop scroll event. Scroll sequences with smooth scroll information may provide a stop scroll event once the interaction with the device finishes, e.g. by lifting a finger. This stop scroll event is the signal that a widget may trigger kinetic scrolling based on the current velocity.

Stop scroll events always have a delta of 0/0.

  method is-scroll-stop-event ( --> Bool )

=end pod

method is-scroll-stop-event ( --> Bool ) {
  gdk_event_is_scroll_stop_event(self._get-native-object-no-reffing).Bool
}

sub gdk_event_is_scroll_stop_event (
  N-GdkEvent $event --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:_gdk_event_new:
#`{{
=begin pod
=head2 gdk-event-new

Creates a new event of the given type. All fields are set to 0.

Returns: a newly-allocated B<Gnome::Gdk3::Event>. The returned B<Gnome::Gdk3::Event> should be freed with C<gdk_event_free()>.

  method gdk-event-new ( GdkEventType $type --> N-GdkEvent )

=item $type; a B<Gnome::Gdk3::EventType>
=end pod

method gdk-event-new ( --> N-GdkEvent ) {
  gdk_event_new($type)
}
}}
sub _gdk_event_new (
  GEnum $type --> N-GdkEvent
) is native(&gdk-lib)
  is symbol('gdk_event_new')
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:peek:
=begin pod
=head2 peek

If there is an event waiting in the event queue of some open display, returns a copy of it. See C<Gnome::Gdk3::Display.peek-event()>.

Returns: a copy of the first B<Gnome::Gdk3::Event> on some event queue, or C<undefined> if no events are in any queues. The returned B<Gnome::Gdk3::Event> should be freed with C<gdk_event_free()>.

  method peek ( --> N-GdkEvent )

=end pod

method peek ( --> N-GdkEvent ) {
  gdk_event_peek(self._get-native-object-no-reffing)
}

sub gdk_event_peek (
   --> N-GdkEvent
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:pending:
=begin pod
=head2 pending

Checks if any events are ready to be processed for any display.

Returns: C<True> if any events are pending.

  method pending ( --> Bool )

=end pod

method pending ( --> Bool ) {
  gdk_events_pending.Bool
}

sub gdk_events_pending (
   --> gboolean
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:put:
=begin pod
=head2 put

Appends a copy of this event onto the front of the event queue for C<$event.any.window>’s display, or the default event queue if C<$event.any.window> is C<undefined>. See C<Gnome::Gdk3::Display.put-event()>.

  method put ( )

=end pod

method put ( N-GdkEvent $event ) {
  gdk_event_put( self._get-native-object-no-reffing);
}

sub gdk_event_put (
  N-GdkEvent $event
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:request-motions:
=begin pod
=head2 request-motions

Request more motion notifies if this event is a motion notify hint event.

This function should be used instead of C<Gnome::Gdk3::Window.get-pointer()> to request further motion notifies, because it also works for extension events where motion notifies are provided for devices other than the core pointer. Coordinate extraction, processing and requesting more motion events from a C<GDK_MOTION_NOTIFY> event usually works like this:

=begin comment

==>> TODO A POD Bug???
= begin code
  my Gnome::Gdk3::Event $e .= new(:type(GDK_MOTION_NOTIFY));
  …

  # Motion_event handler
  my $x = $e.x;
  my $y = $e.y;

  # Handle (x,y) motion. Handles .is-hint() events
  $event.request-motions;
= end code

=end comment

  method request-motions ( )

=end pod

method request-motions ( ) {
  gdk_event_request_motions(self._get-native-object-no-reffing);
}

sub gdk_event_request_motions (
  N-GdkEventMotion $event
) is native(&gdk-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:set-device:
=begin pod
=head2 set-device

Sets the device for I<event> to I<device>. The event must have been allocated by GTK+, for instance, by C<copy()>.

  method set-device ( N-GObject() $device )

=item $device; a B<Gnome::Gdk3::Device>
=end pod

method set-device ( N-GObject() $device ) {
  gdk_event_set_device( self._get-native-object-no-reffing, $device);
}

sub gdk_event_set_device (
  N-GdkEvent $event, N-GObject $device
) is native(&gdk-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
#TM:0:set-device-tool:
=begin pod
=head2 set-device-tool

Sets the device tool for this event, should be rarely used.

  method set-device-tool ( N-GObject() $tool )

=item $tool; tool to set on the event, or C<undefined>
=end pod

method set-device-tool ( N-GObject() $tool ) {
  gdk_event_set_device_tool( self._get-native-object-no-reffing, $tool);
}

sub gdk_event_set_device_tool (
  N-GdkEvent $event, N-GObject $tool
) is native(&gdk-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:set-screen:
=begin pod
=head2 set-screen

Sets the screen for I<event> to I<screen>. The event must have been allocated by GTK+, for instance, by C<gdk_event_copy()>.

  method set-screen ( N-GObject() $screen )

=item $screen; a B<Gnome::Gdk3::Screen>
=end pod

method set-screen ( N-GObject() $screen ) {
  gdk_event_set_screen( self._get-native-object-no-reffing, $screen);
}

sub gdk_event_set_screen (
  N-GdkEvent $event, N-GObject $screen