Skip to content

Gdk.Event

class

Represents windowing system events.

In GTK applications the events are handled automatically by toplevel widgets and passed on to the event controllers of appropriate widgets, so using GdkEvent and its related API is rarely needed.

GdkEvent structs are immutable.

Methods

_get_angle

def _get_angle(self, event2: Event) -> tuple[bool, float]

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 GdkEvent

_get_center

def _get_center(self, event2: Event) -> tuple[bool, float, float]

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 GdkEvent

_get_distance

def _get_distance(self, event2: Event) -> tuple[bool, float]

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 GdkEvent

get_axes

def get_axes(self) -> tuple[bool, list[float]]

Extracts all axis values from an event.

To find out which axes are used, use DeviceTool.get_axes on the device tool returned by Event.get_device_tool.

get_axis

def get_axis(self, axis_use: AxisUse | int) -> tuple[bool, float]

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

To find out which axes are used, use DeviceTool.get_axes on the device tool returned by Event.get_device_tool.

Parameters:

  • axis_use — the axis use to look for

get_device

def get_device(self) -> Device | None

Returns the device of an event.

get_device_tool

def get_device_tool(self) -> DeviceTool | None

Returns a GdkDeviceTool 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 None.

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

get_display

def get_display(self) -> Display | None

Retrieves the display associated to the event.

get_event_sequence

def get_event_sequence(self) -> EventSequence

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.

get_event_type

def get_event_type(self) -> EventType

Retrieves the type of the event.

get_history

def get_history(self) -> list[TimeCoord] | None

Retrieves the history of the device that event is for, as a list of time and coordinates.

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

Note that only motion and scroll events record history, and motion events do it only if one of the mouse buttons is down, or the device has a tool.

get_modifier_state

def get_modifier_state(self) -> ModifierType

Returns the modifier state field of an event.

get_pointer_emulated

def get_pointer_emulated(self) -> bool

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

Emulated pointer events typically originate from a touch events.

get_position

def get_position(self) -> tuple[bool, float, float]

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

This position is in surface coordinates.

get_seat

def get_seat(self) -> Seat | None

Returns the seat that originated the event.

get_surface

def get_surface(self) -> Surface | None

Extracts the surface associated with an event.

get_time

def get_time(self) -> int

Returns the timestamp of event.

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

ref

def ref(self) -> Event

Increase the ref count of event.

triggers_context_menu

def triggers_context_menu(self) -> bool

Returns whether a GdkEvent 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

event->button == GDK_BUTTON_SECONDARY

unref

def unref(self) -> None

Decrease the ref count of event.

If the last reference is dropped, the structure is freed.