gtkmm: Gdk::Event Class Reference

gtkmm 4.16.0

Public Types | Public Member Functions | Protected Member Functions | Related Symbols | List of all members
Gdk::Event Class Referencefinal

Functions for handling events from the window system. More...

`#include <gdkmm/event.h>`

## Public Types
enum class | Type { Type::DELETE , Type::MOTION_NOTIFY , Type::BUTTON_PRESS , Type::BUTTON_RELEASE , Type::KEY_PRESS , Type::KEY_RELEASE , Type::ENTER_NOTIFY , Type::LEAVE_NOTIFY , Type::FOCUS_CHANGE , Type::PROXIMITY_IN , Type::PROXIMITY_OUT , Type::DRAG_ENTER , Type::DRAG_LEAVE , Type::DRAG_MOTION , Type::DROP_START , Type::SCROLL , Type::GRAB_BROKEN , Type::TOUCH_BEGIN , Type::TOUCH_UPDATE , Type::TOUCH_END , Type::TOUCH_CANCEL , Type::TOUCHPAD_SWIPE , Type::TOUCHPAD_PINCH , Type::PAD_BUTTON_PRESS , Type::PAD_BUTTON_RELEASE , Type::PAD_RING , Type::PAD_STRIP , Type::PAD_GROUP_MODE , Type::TOUCHPAD_HOLD , Type::EVENT_LAST }
| Specifies the type of the event. More...

## Public Member Functions
void | reference () const
| Increment the reference count for this object.
void | unreference () const
| Decrement the reference count for this object.
GdkEvent * | gobj ()
| Provides access to the underlying C instance.
const GdkEvent * | gobj () const
| Provides access to the underlying C instance.
GdkEvent * | gobj_copy () const
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.
| Event ()=delete
| Event (const Event &)=delete
Event & | operator= (const Event &)=delete
Type | get_event_type () const
| Retrieves the type of the event.
Glib::RefPtr< Surface > | get_surface ()
| Extracts the surface associated with an event.
Glib::RefPtr< const Surface > | get_surface () const
| Extracts the surface associated with an event.
Glib::RefPtr< Seat > | get_seat ()
| Returns the seat that originated the event.
Glib::RefPtr< const Seat > | get_seat () const
| Returns the seat that originated the event.
Glib::RefPtr< Device > | get_device ()
| Returns the device of an event.
Glib::RefPtr< const Device > | get_device () const
| Returns the device of an event.
Glib::RefPtr< DeviceTool > | get_device_tool ()
| Returns a `Gdk::DeviceTool` representing the tool that caused the event.
Glib::RefPtr< const DeviceTool > | get_device_tool () const
| Returns a `Gdk::DeviceTool` representing the tool that caused the event.
guint32 | get_time () const
| Returns the timestamp of event.
Glib::RefPtr< Display > | get_display ()
| Retrieves the display associated to the event.
Glib::RefPtr< const Display > | get_display () const
| Retrieves the display associated to the event.
const EventSequence * | get_event_sequence () const
| Returns the event sequence to which the event belongs.
ModifierType | get_modifier_state () const
| Returns the modifier state field of an event.
bool | get_position (double & x, double & y) const
| Extract the event surface relative x/y coordinates from an event.
std::vector< double > | get_axes () const
| Extracts all axis values from an event.
bool | get_axis (Gdk::AxisUse axis_use, double & value) const
| Extract the axis value for a particular axis use from an event structure.
bool | get_pointer_emulated () const
| Returns whether this event is an 'emulated' pointer event.
guint | get_button () const
| Extract the button number from a button event.
ScrollDirection | get_direction () const
| Extracts the direction of a scroll event.
void | get_deltas (double & delta_x, double & delta_y) const
| Extracts the scroll deltas of a scroll event.
ScrollUnit | get_scroll_unit () const
| Extracts the scroll delta unit of a scroll event.
bool | is_scroll_stop () const
| Check whether a scroll event is a stop scroll event.
guint | get_keyval () const
| Extracts the keyval from a key event.
guint | get_keycode () const
| Extracts the keycode from a key event.
ModifierType | get_consumed_modifiers () const
| Extracts the consumed modifiers from a key event.
guint | get_layout () const
| Extracts the layout from a key event.
guint | get_level () const
| Extracts the shift level from a key event.
bool | is_modifier () const
| Extracts whether the key event is for a modifier key.
bool | get_focus_in () const
| Extracts whether this event is about focus entering or leaving the surface.
bool | get_touch_emulating_pointer () const
| Extracts whether a touch event is emulating a pointer event.
CrossingMode | get_crossing_mode () const
| Extracts the crossing mode from a crossing event.
NotifyType | get_crossing_detail () const
| Extracts the notify detail from a crossing event.
bool | get_crossing_focus () const
| Checks if the event surface is the focus surface.
TouchpadGesturePhase | get_touchpad_gesture_phase () const
| Extracts the touchpad gesture phase from a touchpad event.
guint | get_touchpad_n_fingers () const
| Extracts the number of fingers from a touchpad event.
void | get_touchpad_deltas (double & dx, double & dy) const
| Extracts delta information from a touchpad event.
double | get_touchpad_pinch_angle_delta () const
| Extracts the angle delta from a touchpad pinch event.
double | get_touchpad_pinch_scale () const
| Extracts the scale from a touchpad pinch event.
guint | get_pad_button () const
| Extracts information about the pressed button from a pad event.
void | get_pad_axis_value (guint & index, double & value) const
| Extracts the information from a pad strip or ring event.
void | get_pad_group_mode (guint & group, guint & mode) const
| Extracts group and mode information from a pad event.
Glib::RefPtr< Drop > | get_dnd_drop ()
| Gets the `Gdk::Drop` object from a DND event.
Glib::RefPtr< const Drop > | get_dnd_drop () const
| Gets the `Gdk::Drop` object from a DND event.
Glib::RefPtr< Surface > | get_grab_broken_grab_surface ()
| Extracts the grab surface from a grab broken event.
Glib::RefPtr< const Surface > | get_grab_broken_grab_surface () const
| Extracts the grab surface from a grab broken event.
bool | get_grab_broken_implicit () const
| Checks whether the grab broken event is for an implicit grab.
std::vector< TimeCoord > | get_history () const
| Retrieves the history of the event, as a vector of time and coordinates.
bool | triggers_context_menu () const
| Returns whether a `Gdk::Event` should trigger a context menu, according to platform conventions.
bool | get_distance (const Glib::RefPtr< const Event > & event2, double &distance) const
| Returns the distance between the event locations.
bool | get_angle (const Glib::RefPtr< const Event > & event2, double & angle) const
| Returns the relative angle from event1 to event2.
bool | get_center (const Glib::RefPtr< const Event > & event2, double & x, double & y) const
| Returns the point halfway between the events' positions.
KeyMatch | matches (guint keyval, ModifierType modifiers) const
| Matches a key event against a keyval and modifiers.
bool | get_match (guint & keyval, ModifierType & modifiers) const
| Gets a keyval and modifier combination that will match the event.

## Protected Member Functions
void | operator delete (void *, std::size_t)

## Related Symbols
(Note that these are not member symbols.)
Glib::RefPtr< Gdk::Event > | wrap (GdkEvent * object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Detailed Description

Functions for handling events from the window system.

In GTK applications the events are handled automatically by toplevel widgets and passed on to the event controllers of appropriate widgets, so these functions are rarely needed.

Key values are the codes which are sent whenever a key is pressed or released. The complete list of key values can be found in the gdk/gdkkeysyms.h header file. They are prefixed with `GDK_KEY_`.

## Constructor & Destructor Documentation

## ◆ Event() [1/2]

Gdk::Event::Event | ( |  | ) |
| delete

## ◆ Event() [2/2]

Gdk::Event::Event | ( | const Event & |  | ) |
| delete

## Member Function Documentation

## ◆ get_angle()

bool Gdk::Event::get_angle | ( | const Glib::RefPtr< const Event > & | event2,
|  | double & | angle ) const

Returns the relative angle from event1 to event2.

The relative angle is the angle between the X axis and the line through both events' positions. The rotation direction for positive angles is from the positive X axis towards the positive Y axis.

This assumes that both events have X/Y information. If not, this function returns `false`.

Parameters

  event2 | Second `Gdk::Event`.
  angle | Return location for the relative angle between both events.

Returns
  `true` if the angle could be calculated.

## ◆ get_axes()

std::vector< double > Gdk::Event::get_axes | ( |  | ) | const

Extracts all axis values from an event.

Returns
  A vector of values for all axes. An empty vector in case of failure.

## ◆ get_axis()

bool Gdk::Event::get_axis | ( | Gdk::AxisUse | axis_use,
|  | double & | value ) const

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

To find out which axes are used, use Gdk::DeviceTool::get_axes() on the device tool returned by get_device_tool().

Parameters

  axis_use | The axis use to look for.
  value | Location to store the value found.

Returns
  `true` if the specified axis was found, otherwise `false`.

## ◆ get_button()

guint Gdk::Event::get_button | ( |  | ) | const

Extract the button number from a button event.

Returns
  The button of event.

## ◆ get_center()

bool Gdk::Event::get_center | ( | const Glib::RefPtr< const Event > & | event2,
|  | double & | x,
|  | double & | y ) const

Returns the point halfway between the events' positions.

This assumes that both events have X/Y information. If not, this function returns `false`.

Parameters

  event2 | Second `Gdk::Event`.
  x | Return location for the X coordinate of the center.
  y | Return location for the Y coordinate of the center.

Returns
  `true` if the center could be calculated.

## ◆ get_consumed_modifiers()

ModifierType Gdk::Event::get_consumed_modifiers | ( |  | ) | const

Extracts the consumed modifiers from a key event.

Returns
  The consumed modifiers or event.

## ◆ get_crossing_detail()

NotifyType Gdk::Event::get_crossing_detail | ( |  | ) | const

Extracts the notify detail from a crossing event.

Returns
  The notify detail of event.

## ◆ get_crossing_focus()

bool Gdk::Event::get_crossing_focus | ( |  | ) | const

Checks if the event surface is the focus surface.

Returns
  `true` if the surface is the focus surface.

## ◆ get_crossing_mode()

CrossingMode Gdk::Event::get_crossing_mode | ( |  | ) | const

Extracts the crossing mode from a crossing event.

Returns
  The mode of event.

## ◆ get_deltas()

void Gdk::Event::get_deltas | ( | double & | delta_x,
|  | double & | delta_y ) const

Extracts the scroll deltas of a scroll event.

The deltas will be zero unless the scroll direction is Gdk::ScrollDirection::SMOOTH.

For the representation unit of these deltas, see get_unit().

Parameters

  delta_x | Return location for x scroll delta.
  delta_y | Return location for y scroll delta.

## ◆ get_device() [1/2]

Glib::RefPtr< Device > Gdk::Event::get_device | ( |  | ) |

Returns the device of an event.

Since gtkmm 3.94

Returns
  A `Gdk::Device`.

## ◆ get_device() [2/2]

Glib::RefPtr< const Device > Gdk::Event::get_device | ( |  | ) | const

Returns the device of an event.

Since gtkmm 3.94

Returns
  A `Gdk::Device`.

## ◆ get_device_tool() [1/2]

Glib::RefPtr< DeviceTool > Gdk::Event::get_device_tool | ( |  | ) |

Returns a `Gdk::DeviceTool` representing the tool that caused the event.

If the was not generated by a device that supports different tools (such as a tablet), this function will return `nullptr`.

Note
  the `Gdk::DeviceTool` will be constant during the application lifetime, if settings must be stored persistently across runs, see Gdk::DeviceTool::get_serial().

Returns
  The current device tool.

## ◆ get_device_tool() [2/2]

Glib::RefPtr< const DeviceTool > Gdk::Event::get_device_tool | ( |  | ) | const

Returns a `Gdk::DeviceTool` representing the tool that caused the event.

If the was not generated by a device that supports different tools (such as a tablet), this function will return `nullptr`.

Note
  the `Gdk::DeviceTool` will be constant during the application lifetime, if settings must be stored persistently across runs, see Gdk::DeviceTool::get_serial().

Returns
  The current device tool.

## ◆ get_direction()

ScrollDirection Gdk::Event::get_direction | ( |  | ) | const

Extracts the direction of a scroll event.

Returns
  The scroll direction of event.

## ◆ get_display() [1/2]

Glib::RefPtr< Display > Gdk::Event::get_display | ( |  | ) |

Retrieves the display associated to the event.

Returns
  A `Gdk::Display`.

## ◆ get_display() [2/2]

Glib::RefPtr< const Display > Gdk::Event::get_display | ( |  | ) | const

Retrieves the display associated to the event.

Returns
  A `Gdk::Display`.

## ◆ get_distance()

bool Gdk::Event::get_distance | ( | const Glib::RefPtr< const Event > & | event2,
|  | double & | distance ) const

Returns the distance between the event locations.

This assumes that both events have X/Y information. If not, this function returns `false`.

Parameters

  event2 | Second `Gdk::Event`.
  distance | Return location for the distance.

Returns
  `true` if the distance could be calculated.

## ◆ get_dnd_drop() [1/2]

Glib::RefPtr< Drop > Gdk::Event::get_dnd_drop | ( |  | ) |

Gets the `Gdk::Drop` object from a DND event.

Returns
  The drop.

## ◆ get_dnd_drop() [2/2]

Glib::RefPtr< const Drop > Gdk::Event::get_dnd_drop | ( |  | ) | const

Gets the `Gdk::Drop` object from a DND event.

Returns
  The drop.

## ◆ get_event_sequence()

const EventSequence * Gdk::Event::get_event_sequence | ( |  | ) | const

Returns the event sequence to which the event belongs.

Related touch events are connected in a sequence. Other events typically don't have event sequence information.

Returns
  The event sequence that the event belongs to.

## ◆ get_event_type()

Type Gdk::Event::get_event_type | ( |  | ) | const

Retrieves the type of the event.

Returns
  A `Gdk::Event`Type.

## ◆ get_focus_in()

bool Gdk::Event::get_focus_in | ( |  | ) | const

Extracts whether this event is about focus entering or leaving the surface.

Returns
  `true` of the focus is entering.

## ◆ get_grab_broken_grab_surface() [1/2]

Glib::RefPtr< Surface > Gdk::Event::get_grab_broken_grab_surface | ( |  | ) |

Extracts the grab surface from a grab broken event.

Returns
  The grab surface of event.

## ◆ get_grab_broken_grab_surface() [2/2]

Glib::RefPtr< const Surface > Gdk::Event::get_grab_broken_grab_surface | ( |  | ) | const

Extracts the grab surface from a grab broken event.

Returns
  The grab surface of event.

## ◆ get_grab_broken_implicit()

bool Gdk::Event::get_grab_broken_implicit | ( |  | ) | const

Checks whether the grab broken event is for an implicit grab.

Returns
  `true` if the an implicit grab was broken.

## ◆ get_history()

std::vector< TimeCoord > Gdk::Event::get_history | ( |  | ) | const

Retrieves the history of the event, as a vector of time and coordinates.

The history includes events that are not delivered to the application because they occurred in the same frame as this event.

Note that only motion and scroll events record history, and motion events only if one of the mouse buttons is down.

Returns
  A vector of time and coordinates.

## ◆ get_keycode()

guint Gdk::Event::get_keycode | ( |  | ) | const

Extracts the keycode from a key event.

Returns
  The keycode of event.

## ◆ get_keyval()

guint Gdk::Event::get_keyval | ( |  | ) | const

Extracts the keyval from a key event.

Returns
  The keyval of event.

## ◆ get_layout()

guint Gdk::Event::get_layout | ( |  | ) | const

Extracts the layout from a key event.

Returns
  The layout of event.

## ◆ get_level()

guint Gdk::Event::get_level | ( |  | ) | const

Extracts the shift level from a key event.

Returns
  The shift level of event.

## ◆ get_match()

bool Gdk::Event::get_match | ( | guint & | keyval,
|  | ModifierType & | modifiers ) const

Gets a keyval and modifier combination that will match the event.

See matches().

Parameters

  keyval | Return location for a keyval.
  modifiers | Return location for modifiers.

Returns
  `true` on success.

## ◆ get_modifier_state()

ModifierType Gdk::Event::get_modifier_state | ( |  | ) | const

Returns the modifier state field of an event.

Returns
  The modifier state of event.

## ◆ get_pad_axis_value()

void Gdk::Event::get_pad_axis_value | ( | guint & | index,
|  | double & | value ) const

Extracts the information from a pad strip or ring event.

Parameters

  index | Return location for the axis index.
  value | Return location for the axis value.

## ◆ get_pad_button()

guint Gdk::Event::get_pad_button | ( |  | ) | const

Extracts information about the pressed button from a pad event.

Returns
  The button of event.

## ◆ get_pad_group_mode()

void Gdk::Event::get_pad_group_mode | ( | guint & | group,
|  | guint & | mode ) const

Extracts group and mode information from a pad event.

Parameters

  group | Return location for the group.
  mode | Return location for the mode.

## ◆ get_pointer_emulated()

bool Gdk::Event::get_pointer_emulated | ( |  | ) | const

Returns whether this event is an 'emulated' pointer event.

Emulated pointer events typically originate from a touch events.

Returns
  `true` if this event is emulated.

## ◆ get_position()

bool Gdk::Event::get_position | ( | double & | x,
|  | double & | y ) const

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

This position is in surface coordinates.

Parameters

  x | Location to put event surface x coordinate.
  y | Location to put event surface y coordinate.

Returns
  Whether the positions were set.

## ◆ get_scroll_unit()

ScrollUnit Gdk::Event::get_scroll_unit | ( |  | ) | const

Extracts the scroll delta unit of a scroll event.

The unit will always be Gdk::ScrollUnit::WHEEL if the scroll direction is not Gdk::ScrollDirection::SMOOTH.

Since gtkmm 4.8

Returns
  The scroll unit.

## ◆ get_seat() [1/2]

Glib::RefPtr< Seat > Gdk::Event::get_seat | ( |  | ) |

Returns the seat that originated the event.

Returns
  A `Gdk::Seat`.

## ◆ get_seat() [2/2]

Glib::RefPtr< const Seat > Gdk::Event::get_seat | ( |  | ) | const

Returns the seat that originated the event.

Returns
  A `Gdk::Seat`.

## ◆ get_surface() [1/2]

Glib::RefPtr< Surface > Gdk::Event::get_surface | ( |  | ) |

Extracts the surface associated with an event.

Returns
  The `Gdk::Surface` associated with the event.

## ◆ get_surface() [2/2]

Glib::RefPtr< const Surface > Gdk::Event::get_surface | ( |  | ) | const

Extracts the surface associated with an event.

Returns
  The `Gdk::Surface` associated with the event.

## ◆ get_time()

guint32 Gdk::Event::get_time | ( |  | ) | const

Returns the timestamp of event.

Not all events have timestamps. In that case, this function returns GDK_CURRENT_TIME.

Returns
  Timestamp field from event.

## ◆ get_touch_emulating_pointer()

bool Gdk::Event::get_touch_emulating_pointer | ( |  | ) | const

Extracts whether a touch event is emulating a pointer event.

Returns
  `true` if event is emulating.

## ◆ get_touchpad_deltas()

void Gdk::Event::get_touchpad_deltas | ( | double & | dx,
|  | double & | dy ) const

Extracts delta information from a touchpad event.

Parameters

  dx | Return location for x.
  dy | Return location for y.

## ◆ get_touchpad_gesture_phase()

TouchpadGesturePhase Gdk::Event::get_touchpad_gesture_phase | ( |  | ) | const

Extracts the touchpad gesture phase from a touchpad event.

Returns
  The gesture phase of event.

## ◆ get_touchpad_n_fingers()

guint Gdk::Event::get_touchpad_n_fingers | ( |  | ) | const

Extracts the number of fingers from a touchpad event.

Returns
  The number of fingers for event.

## ◆ get_touchpad_pinch_angle_delta()

double Gdk::Event::get_touchpad_pinch_angle_delta | ( |  | ) | const

Extracts the angle delta from a touchpad pinch event.

Returns
  The angle delta of event.

## ◆ get_touchpad_pinch_scale()

double Gdk::Event::get_touchpad_pinch_scale | ( |  | ) | const

Extracts the scale from a touchpad pinch event.

Returns
  The scale of event.

## ◆ gobj() [1/2]

GdkEvent * Gdk::Event::gobj | ( |  | ) |

Provides access to the underlying C instance.

## ◆ gobj() [2/2]

const GdkEvent * Gdk::Event::gobj | ( |  | ) | const

Provides access to the underlying C instance.

## ◆ gobj_copy()

GdkEvent * Gdk::Event::gobj_copy | ( |  | ) | const

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ is_modifier()

bool Gdk::Event::is_modifier | ( |  | ) | const

Extracts whether the key event is for a modifier key.

Returns
  `true` if the event is for a modifier key.

## ◆ is_scroll_stop()

bool Gdk::Event::is_scroll_stop | ( |  | ) | const

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.

Returns
  `true` if the event is a scroll stop event.

## ◆ matches()

KeyMatch Gdk::Event::matches | ( | guint | keyval,
|  | ModifierType | modifiers ) const

Matches a key event against a keyval and modifiers.

This is typically used to trigger keyboard shortcuts such as Ctrl-C.

Partial matches are possible where the combination matches if the currently active group is ignored.

Note that we ignore Caps Lock for matching.

Parameters

  keyval | The keyval to match.
  modifiers | The modifiers to match.

Returns
  A `Gdk::KeyMatch` value describing whether event matches.

## ◆ operator delete()

void Gdk::Event::operator delete | ( | void * | ,
|  | std::size_t | )
| protected

## ◆ operator=()

Event & Gdk::Event::operator= | ( | const Event & |  | ) |
| delete

## ◆ reference()

void Gdk::Event::reference | ( |  | ) | const

Increment the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## ◆ triggers_context_menu()

bool Gdk::Event::triggers_context_menu | ( |  | ) | const

Returns whether a `Gdk::Event` should trigger a context menu, according to platform conventions.

The right mouse button typically triggers context menus. On macOS, Control+left mouse button also triggers.

This function should always be used instead of simply checking for

[C example ellipted]

Returns
  `true` if the event should trigger a context menu.

## ◆ unreference()

void Gdk::Event::unreference | ( |  | ) | const

Decrement the reference count for this object.

You should never need to do this manually - use the object via a RefPtr instead.

## Friends And Related Symbol Documentation

## ◆ wrap()

Glib::RefPtr< Gdk::Event > wrap | ( | GdkEvent * | object,
|  | bool | take_copy = false )
| related

A Glib::wrap() method for this object.

Parameters

  object | The C instance.
  take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns
  A C++ instance that wraps this C instance.