About my projects, examples and tutorials
Gnome::Gtk4::GestureClick

Gnome::Gtk4::GestureClick

Description

Gnome::Gtk4::GestureClick is a Gnome::Gtk4::Gesture implementation for clicks.

It is able to recognize multiple clicks on a nearby zone, which can be listened for through the pressed signal. Whenever time or distance between clicks exceed the GTK defaults, stopped is emitted, and the click counter is reset.

Uml Diagram

No caption

Example

Example use of Gnome::Gtk4::GestureClick. The code below shows a helper class to handle the mouse button presses in method .press(). Double click will show a single button first ($nbr-buttons = 1), then 2 buttons ($nbr-buttons = 2). To process that properly, it is suggested above to also register the stopped event.

Normally only button 1 is set to trigger. To change that for other buttons, .set-button() from Gnome::Gtk4::GestureSingle must be used. To set it to 0, it will trigger any button. .get-button() from Gnome::Gtk4::GestureSingle will only return what is set by .set-button().

class SH {
  has Int $!click-count = 0;

  method stopit ( --> gboolean ) { … }

  method stopped ( ) {
    say "button is pressed $!click-count times";
    $!click-count = 0;
  }

  method press (
    Int $nbr-buttons, Rat() $x, Rat() $y,
    GestureClick() :_native-object($gc)
  ) {
    $!click-count = $nbr-buttons;
    say "$gc.get-current-button() mouse button is pressed";
  }
}

my SH $sh .= new;

with my GestureClick $click-gesture .= new-gestureclick {
  $click-gesture.set-button(0);
  .register-signal( $sh, 'press', 'pressed');
  .register-signal( $sh, 'stopped', 'stopped');
}

with my Window $window .= new-window {
  .register-signal( $sh, 'stopit', 'close-request');
  .add-controller($click-gesture);

  .set-title('My mouse buttons test window');
  .present;
}

Class initialization

new

:native-object

Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.

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

new-gestureclick

Returns a newly created Gnome::Gtk4::Gesture that recognizes single and multiple presses.

method new-gestureclick ( --> Gnome::Gtk4::GestureClick )

Signals

pressed

Emitted whenever a button or touch press happens.

method handler (
  gint $n-press,
  gdouble $x,
  gdouble $y,
  Int :$_handle_id,
  N-GObject :$_native-object,
  *%user-options
)
  • $n-press; how many touch/button presses happened with this one.

  • $x; The X coordinate, in widget allocation coordinates.

  • $y; The Y coordinate, in widget allocation coordinates.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::GestureClick object.

  • %user-options; A list of named arguments provided by .register-signal() in class Object.

released

Emitted when a button or touch is released. $n-press will report the number of press that is paired to this event, note that stopped may have been emitted between the press and its release, $n-press will only start over at the next press.

method handler (
  gint $n-press,
  gdouble $x,
  gdouble $y,
  Int :$_handle_id,
  N-GObject :$_native-object,
  *%user-options
)
  • $n-press; number of press that is paired with this release.

  • $x; The X coordinate, in widget allocation coordinates.

  • $y; The Y coordinate, in widget allocation coordinates.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::GestureClick object.

  • %user-options; A list of named arguments provided by .register-signal() in class Object.

stopped

Emitted whenever any time/distance threshold has been exceeded.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  *%user-options
)
  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::GestureClick object.

  • %user-options; A list of named arguments provided by .register-signal() in class Object.

unpaired-release

Emitted whenever the gesture receives a release event that had no previous corresponding press. Due to implicit grabs, this can only happen on situations where input is grabbed elsewhere mid-press or the pressed widget voluntarily relinquishes its implicit grab.

method handler (
  gdouble $x,
  gdouble $y,
  guint $button,
  N-GObject $sequence,
  Int :$_handle_id,
  N-GObject :$_native-object,
  *%user-options
)
  • $x; X coordinate of the event.

  • $y; Y coordinate of the event.

  • $button; Button being released.

  • $sequence; Sequence being released, a native Gnome::Gdk4::N-EventSequence.

  • $_handle_id; The registered event handler id.

  • $_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::GestureClick object.

  • %user-options; A list of named arguments provided by .register-signal() in class Object.