Events

G-Golf Events interfaces.
Handling events from the window system.


_ SPECIAL NOTE _

Most of the numerous, important and sometimes radical changes in between Gtk-3.0/Gdk-3.0 and Gtk-4.0/Gdk-4.0/Gsk-4.0 have had no impact on G-Golf. And by most, we actually mean all but one: the GdkEvent and its API.

For this reason, this section is split/organized in two subheading, namely ‘In Gdk-3.0’ and ‘In Gdk-4.0’, how creative :), that expose their respective G-Golf interfaces.


  _ In Gdk-3.0

In Gdk-3.0, a GdkEvent contains a union of all of the event types. Data fields may be accessed either directly, direct access to GdkEvent structs, or using accessors (but not all data fields have an accessor).

In G-Golf however GdkEvent is a class, with an event slot - holding a pointer the Gdk event - all other slots are virtual and define an accessor, which is the only way users may retrieve data fields.

When G-Golf detects it is leading with GdkEvent from Gdk-3.0, while dynamically implementing the above, in addition, when applicable, it will also add some of the upstream GdkEvent accessor name to the GI Strip Boolean Result list. This is further detailed below, at the end of the section.

Class

<gdk-event>

Accessors

!event
!axis
!button
!click-count
!coords
!device
!device-tool
!event-sequence
!event-type
!keycode
!keyval
!pointer-emulated
!root-coords
!scancode
!screen
!scroll-deltas
!scroll-direction
!seat
!source-device
!state
!time
!window
!keyname
!x
!y
!root-x
!root-y

Class

Class: <gdk-event>

It is an instance of <class>.

Superclasses are:

<object>

Class Precedence List:

<gdk-event>
<object>
<top>

Direct slots are:

event

#:accessor !event
#:init-keyword #:event

A pointer to a GdkEvent.

axis

#:accessor !axis
#:allocation #:virtual

button

#:accessor !button
#:allocation #:virtual

click-count

#:accessor !click-count
#:allocation #:virtual

coords

#:accessor !coords
#:allocation #:virtual

device

#:accessor !device
#:allocation #:virtual

device-tool

#:accessor !device-tool
#:allocation #:virtual

event-sequence

#:accessor !event-sequence
#:allocation #:virtual

event-type

#:accessor !event-type
#:allocation #:virtual

keycode

#:accessor !keycode
#:allocation #:virtual

keyval

#:accessor !keyval
#:allocation #:virtual

pointer-emulated

#:accessor !pointer-emulated
#:allocation #:virtual

root-coords

#:accessor !root-coords
#:allocation #:virtual

scancode

#:accessor !scancode
#:allocation #:virtual

screen

#:accessor !screen
#:allocation #:virtual

scroll-deltas

#:accessor !scroll-deltas
#:allocation #:virtual

scroll-direction

#:accessor !scroll-direction
#:allocation #:virtual

seat

#:accessor !seat
#:allocation #:virtual

source-device

#:accessor !source-device
#:allocation #:virtual

state

#:accessor !state
#:allocation #:virtual

time

#:accessor !time
#:allocation #:virtual

window

#:accessor !window
#:allocation #:virtual

keyname

#:accessor !keyname
#:allocation #:virtual

x

#:accessor !x
#:allocation #:virtual

y

#:accessor !y
#:allocation #:virtual

root-x

#:accessor !root-x
#:allocation #:virtual

root-y

#:accessor !root-y
#:allocation #:virtual

Accessor: !event (inst <gdk-event>)

Returns the content of the event slot for inst, a pointer to a GdkEvent.

Accessor: !axis (inst <gdk-event>)
Accessor: !button (inst <gdk-event>)
Accessor: !click-count (inst <gdk-event>)
Accessor: !coords (inst <gdk-event>)
Accessor: !device (inst <gdk-event>)
Accessor: !device-tool (inst <gdk-event>)
Accessor: !event-sequence (inst <gdk-event>)
Accessor: !event-type (inst <gdk-event>)
Accessor: !keycode (inst <gdk-event>)
Accessor: !keyval (inst <gdk-event>)
Accessor: !pointer-emulated (inst <gdk-event>)
Accessor: !root-coords (inst <gdk-event>)
Accessor: !scancode (inst <gdk-event>)
Accessor: !screen (inst <gdk-event>)
Accessor: !scroll-deltas (inst <gdk-event>)
Accessor: !scroll-direction (inst <gdk-event>)
Accessor: !seat (inst <gdk-event>)
Accessor: !source-device (inst <gdk-event>)
Accessor: !state (inst <gdk-event>)
Accessor: !time (inst <gdk-event>)
Accessor: !window (inst <gdk-event>)

Respectively returns the scheme representation of the content of the inst event (struct) element - refered to by its name. It is an error to call an accessor on a inst for which the event (struct) does not deliver the element.

Internally, each of the above <gdk-event> accessor calls the corresponding GdkEvent accessor, passing the content of the event slot. For example, lets see what happens when a user performs a left button (single) click upon a widget that tracks the 'button-press-event signal callback:

(!button inst)
→ (gdk-event-get-button (!event inst))
⇒ 1

(!click-count inst)
→ (gdk-event-get-click-count (!event inst))
⇒ 1

Please refer to the Gdk Events documentation for a description of the event (struct) element accessor returned value.

To complete the above listed <gdk-event> virtual slots and accessors automatically provided by introspecting GdkEvent, G-Golf also defines a few additional rather convinient virtual slots and accessors:

Accessor: !keyname (inst <gdk-event>)

Returns the key (symbol) name that was pressed or released.

Note that there is actually no such element in any (gdk) event. This accessor calls gdk-keyval-name on the keyval of the event). Here is what happens if a user press the ’a’ keyboard key in a widget that tracks the 'key-press-event signal callback:

(!keyname inst)
→ (gdk-keyval-name (!keyval inst))
→ (gdk-keyval-name (gdk-event-get-keyval inst))
⇒ a
Accessor: !x (inst <gdk-event>)
Accessor: !y (inst <gdk-event>)
Accessor: !root-x (inst <gdk-event>)
Accessor: !root-y (inst <gdk-event>)

Respectively returns the x, y, root-x and root-y coordinate for inst.

The result is simply obtained by destructuring and selecting one of the !coords and !root-coords list values, respectively.

Strip Boolean Result

If you are not (yet) familiar with the concept we are dealing with here, make sure you visit and read the Customization Square - GI Strip Boolean Result section of the manual.

When G-Golf detects it is leading with GdkEvent from Gdk-3.0, while dynamically implementing the <gdk-event> class and its accessors, it will add the following names to the GI Strip Boolean Result list:

gdk-event-get-axis
gdk-event-get-button
gdk-event-get-click-count
gdk-event-get-coords
gdk-event-get-keycode
gdk-event-get-keyval
gdk-event-get-root-coords
gdk-event-get-scroll-deltas
gdk-event-get-scroll-direction
gdk-event-get-state

  _ In Gdk-4.0

In Gdk-4.0, GdkEvent is a class16. GdkEvent structs are opaque and immutable. Direct access to GdkEvent structs is no longer possible in GTK 4. All event fields have accessors.

In G-Golf - as in Gdk-4.0 GdkEvent is a class - no special treatment is performed anymore. In particular, no virtual slot is defined and users must access the GdkEvent structs data fields using the accesors provided by Gdk-4.0.


Footnotes

(16)

From a GI point of view - internally, it is a C struct.