Events

Events — Functions for handling events from the window system

Functions

gboolean gdk_events_pending ()
GdkEvent * gdk_event_peek ()
GdkEvent * gdk_event_get ()
void gdk_event_put ()
GdkEvent * gdk_event_new ()
GdkEvent * gdk_event_copy ()
void gdk_event_free ()
gboolean gdk_event_get_axis ()
gboolean gdk_event_get_button ()
gboolean gdk_event_get_click_count ()
gboolean gdk_event_get_coords ()
gboolean gdk_event_get_keycode ()
gboolean gdk_event_get_keyval ()
gboolean gdk_event_get_root_coords ()
gboolean gdk_event_get_scroll_direction ()
gboolean gdk_event_get_scroll_deltas ()
gboolean gdk_event_is_scroll_stop_event ()
gboolean gdk_event_get_state ()
guint32 gdk_event_get_time ()
GdkWindow * gdk_event_get_window ()
GdkEventType gdk_event_get_event_type ()
GdkEventSequence * gdk_event_get_event_sequence ()
void gdk_event_request_motions ()
gboolean gdk_events_get_angle ()
gboolean gdk_events_get_center ()
gboolean gdk_events_get_distance ()
gboolean gdk_event_triggers_context_menu ()
GdkSeat * gdk_event_get_seat ()
int gdk_event_get_scancode ()
gboolean gdk_event_get_pointer_emulated ()
void gdk_event_handler_set ()
void (*GdkEventFunc) ()
gboolean gdk_get_show_events ()
void gdk_set_show_events ()
void gdk_event_set_screen ()
GdkScreen * gdk_event_get_screen ()
GdkDevice * gdk_event_get_device ()
void gdk_event_set_device ()
GdkDevice * gdk_event_get_source_device ()
void gdk_event_set_source_device ()
GdkDeviceTool * gdk_event_get_device_tool ()
void gdk_event_set_device_tool ()
gboolean gdk_setting_get ()

Types and Values

enum GdkEventType
enum GdkEventMask
#define GDK_CURRENT_TIME
#define GDK_PRIORITY_EVENTS
#define GDK_PRIORITY_REDRAW
#define GDK_EVENT_PROPAGATE
#define GDK_EVENT_STOP
#define GDK_BUTTON_PRIMARY
#define GDK_BUTTON_MIDDLE
#define GDK_BUTTON_SECONDARY
  GdkEventSequence

Includes

#include <gdk/gdk.h>

Description

This section describes functions dealing with events from the window system.

In GTK+ applications the events are handled automatically in gtk_main_do_event() and passed on to the appropriate widgets, so these functions are rarely needed. Though some of the fields in the Event Structures are useful.

Functions

gdk_events_pending ()

gboolean
gdk_events_pending (void);

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

Returns

TRUE if any events are pending.


gdk_event_peek ()

GdkEvent *
gdk_event_peek (void);

If there is an event waiting in the event queue of some open display, returns a copy of it. See gdk_display_peek_event().

Returns

a copy of the first GdkEvent on some event queue, or NULL if no events are in any queues. The returned GdkEvent should be freed with gdk_event_free().

[nullable]


gdk_event_get ()

GdkEvent *
gdk_event_get (void);

Checks all open displays for a GdkEvent to process,to be processed on, fetching events from the windowing system if necessary. See gdk_display_get_event().

Returns

the next GdkEvent to be processed, or NULL if no events are pending. The returned GdkEvent should be freed with gdk_event_free().

[nullable]


gdk_event_put ()

void
gdk_event_put (const GdkEvent *event);

Appends a copy of the given event onto the front of the event queue for event->any.window’s display, or the default event queue if event->any.window is NULL. See gdk_display_put_event().

Parameters

event

a GdkEvent.

 

gdk_event_new ()

GdkEvent *
gdk_event_new (GdkEventType type);

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

Parameters

type

a GdkEventType

 

Returns

a newly-allocated GdkEvent. The returned GdkEvent should be freed with gdk_event_free().

Since: 2.2


gdk_event_copy ()

GdkEvent *
gdk_event_copy (const GdkEvent *event);

Copies a GdkEvent, copying or incrementing the reference count of the resources associated with it (e.g. GdkWindow’s and strings).

Parameters

event

a GdkEvent

 

Returns

a copy of event . The returned GdkEvent should be freed with gdk_event_free().


gdk_event_free ()

void
gdk_event_free (GdkEvent *event);

Frees a GdkEvent, freeing or decrementing any resources associated with it. Note that this function should only be called with events returned from functions such as gdk_event_peek(), gdk_event_get(), gdk_event_copy() and gdk_event_new().

Parameters

event

a GdkEvent.

 

gdk_event_get_axis ()

gboolean
gdk_event_get_axis (const GdkEvent *event,
                    GdkAxisUse axis_use,
                    gdouble *value);

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

Parameters

event

a GdkEvent

 

axis_use

the axis use to look for

 

value

location to store the value found.

[out]

Returns

TRUE if the specified axis was found, otherwise FALSE


gdk_event_get_button ()

gboolean
gdk_event_get_button (const GdkEvent *event,
                      guint *button);

Extract the button number from an event.

Parameters

event

a GdkEvent

 

button

location to store mouse button number.

[out]

Returns

TRUE if the event delivered a button number

Since: 3.2


gdk_event_get_click_count ()

gboolean
gdk_event_get_click_count (const GdkEvent *event,
                           guint *click_count);

Extracts the click count from an event.

Parameters

event

a GdkEvent

 

click_count

location to store click count.

[out]

Returns

TRUE if the event delivered a click count

Since: 3.2


gdk_event_get_coords ()

gboolean
gdk_event_get_coords (const GdkEvent *event,
                      gdouble *x_win,
                      gdouble *y_win);

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

Parameters

event

a GdkEvent

 

x_win

location to put event window x coordinate.

[out][optional]

y_win

location to put event window y coordinate.

[out][optional]

Returns

TRUE if the event delivered event window coordinates


gdk_event_get_keycode ()

gboolean
gdk_event_get_keycode (const GdkEvent *event,
                       guint16 *keycode);

Extracts the hardware keycode from an event.

Also see gdk_event_get_scancode().

Parameters

event

a GdkEvent

 

keycode

location to store the keycode.

[out]

Returns

TRUE if the event delivered a hardware keycode

Since: 3.2


gdk_event_get_keyval ()

gboolean
gdk_event_get_keyval (const GdkEvent *event,
                      guint *keyval);

Extracts the keyval from an event.

Parameters

event

a GdkEvent

 

keyval

location to store the keyval.

[out]

Returns

TRUE if the event delivered a key symbol

Since: 3.2


gdk_event_get_root_coords ()

gboolean
gdk_event_get_root_coords (const GdkEvent *event,
                           gdouble *x_root,
                           gdouble *y_root);

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

Parameters

event

a GdkEvent

 

x_root

location to put root window x coordinate.

[out][optional]

y_root

location to put root window y coordinate.

[out][optional]

Returns

TRUE if the event delivered root window coordinates


gdk_event_get_scroll_direction ()

gboolean
gdk_event_get_scroll_direction (const GdkEvent *event,
                                GdkScrollDirection *direction);

Extracts the scroll direction from an event.

If event is not of type GDK_SCROLL, the contents of direction are undefined.

If you wish to handle both discrete and smooth scrolling, you should check the return value of this function, or of gdk_event_get_scroll_deltas(); for instance:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
GdkScrollDirection direction;
double vscroll_factor = 0.0;
double x_scroll, y_scroll;

if (gdk_event_get_scroll_direction (event, &direction))
  {
    // Handle discrete scrolling with a known constant delta;
    const double delta = 12.0;

    switch (direction)
      {
      case GDK_SCROLL_UP:
        vscroll_factor = -delta;
        break;
      case GDK_SCROLL_DOWN:
        vscroll_factor = delta;
        break;
      default:
        // no scrolling
        break;
      }
  }
else if (gdk_event_get_scroll_deltas (event, &x_scroll, &y_scroll))
  {
    // Handle smooth scrolling directly
    vscroll_factor = y_scroll;
  }

Parameters

event

a GdkEvent

 

direction

location to store the scroll direction.

[out]

Returns

TRUE if the event delivered a scroll direction and FALSE otherwise

Since: 3.2


gdk_event_get_scroll_deltas ()

gboolean
gdk_event_get_scroll_deltas (const GdkEvent *event,
                             gdouble *delta_x,
                             gdouble *delta_y);

Retrieves the scroll deltas from a GdkEvent

See also: gdk_event_get_scroll_direction()

Parameters

event

a GdkEvent

 

delta_x

return location for X delta.

[out]

delta_y

return location for Y delta.

[out]

Returns

TRUE if the event contains smooth scroll information and FALSE otherwise

Since: 3.4


gdk_event_is_scroll_stop_event ()

gboolean
gdk_event_is_scroll_stop_event (const GdkEvent *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 a delta of 0/0.

Parameters

event

a GdkEvent

 

Returns

TRUE if the event is a scroll stop event

Since: 3.20


gdk_event_get_state ()

gboolean
gdk_event_get_state (const GdkEvent *event,
                     GdkModifierType *state);

If the event contains a “state” field, puts that field in state . Otherwise stores an empty state (0). Returns TRUE if there was a state field in the event. event may be NULL, in which case it’s treated as if the event had no state field.

Parameters

event

a GdkEvent or NULL.

[allow-none]

state

return location for state.

[out]

Returns

TRUE if there was a state field in the event


gdk_event_get_time ()

guint32
gdk_event_get_time (const GdkEvent *event);

Returns the time stamp from event , if there is one; otherwise returns GDK_CURRENT_TIME. If event is NULL, returns GDK_CURRENT_TIME.

Parameters

event

a GdkEvent

 

Returns

time stamp field from event


gdk_event_get_window ()

GdkWindow *
gdk_event_get_window (const GdkEvent *event);

Extracts the GdkWindow associated with an event.

Parameters

event

a GdkEvent

 

Returns

The GdkWindow associated with the event.

[transfer none]

Since: 3.10


gdk_event_get_event_type ()

GdkEventType
gdk_event_get_event_type (const GdkEvent *event);

Retrieves the type of the event.

Parameters

event

a GdkEvent

 

Returns

a GdkEventType

Since: 3.10


gdk_event_get_event_sequence ()

GdkEventSequence *
gdk_event_get_event_sequence (const GdkEvent *event);

If event if of type GDK_TOUCH_BEGIN, GDK_TOUCH_UPDATE, GDK_TOUCH_END or GDK_TOUCH_CANCEL, returns the GdkEventSequence to which the event belongs. Otherwise, return NULL.

Parameters

event

a GdkEvent

 

Returns

the event sequence that the event belongs to.

[transfer none]

Since: 3.4


gdk_event_request_motions ()

void
gdk_event_request_motions (const GdkEventMotion *event);

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

This function should be used instead of gdk_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 GDK_MOTION_NOTIFY event usually works like this:

1
2
3
4
5
6
7
{
  // motion_event handler
  x = motion_event->x;
  y = motion_event->y;
  // handle (x,y) motion
  gdk_event_request_motions (motion_event); // handles is_hint events
}

Parameters

event

a valid GdkEvent

 

Since: 2.12


gdk_events_get_angle ()

gboolean
gdk_events_get_angle (GdkEvent *event1,
                      GdkEvent *event2,
                      gdouble *angle);

If both events contain X/Y information, this function will return TRUE and return in angle the relative angle from event1 to event2 . The rotation direction for positive angles is from the positive X axis towards the positive Y axis.

Parameters

event1

first GdkEvent

 

event2

second GdkEvent

 

angle

return location for the relative angle between both events.

[out]

Returns

TRUE if the angle could be calculated.

Since: 3.0


gdk_events_get_center ()

gboolean
gdk_events_get_center (GdkEvent *event1,
                       GdkEvent *event2,
                       gdouble *x,
                       gdouble *y);

If both events contain X/Y information, the center of both coordinates will be returned in x and y .

Parameters

event1

first GdkEvent

 

event2

second GdkEvent

 

x

return location for the X coordinate of the center.

[out]

y

return location for the Y coordinate of the center.

[out]

Returns

TRUE if the center could be calculated.

Since: 3.0


gdk_events_get_distance ()

gboolean
gdk_events_get_distance (GdkEvent *event1,
                         GdkEvent *event2,
                         gdouble *distance);

If both events have X/Y information, the distance between both coordinates (as in a straight line going from event1 to event2 ) will be returned.

Parameters

event1

first GdkEvent

 

event2

second GdkEvent

 

distance

return location for the distance.

[out]

Returns

TRUE if the distance could be calculated.

Since: 3.0


gdk_event_triggers_context_menu ()

gboolean
gdk_event_triggers_context_menu (const GdkEvent *event);

This function returns whether a GdkEventButton should trigger a context menu, according to platform conventions. The right mouse button always triggers context menus. Additionally, if gdk_keymap_get_modifier_mask() returns a non-0 mask for GDK_MODIFIER_INTENT_CONTEXT_MENU, then the left mouse button will also trigger a context menu if this modifier is pressed.

This function should always be used instead of simply checking for event->button == GDK_BUTTON_SECONDARY.

Parameters

event

a GdkEvent, currently only button events are meaningful values

 

Returns

TRUE if the event should trigger a context menu.

Since: 3.4


gdk_event_get_seat ()

GdkSeat *
gdk_event_get_seat (const GdkEvent *event);

Returns the GdkSeat this event was generated for.

Parameters

event

a GdkEvent

 

Returns

The GdkSeat of this event.

[transfer none]

Since: 3.20


gdk_event_get_scancode ()

int
gdk_event_get_scancode (GdkEvent *event);

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.

Parameters

event

a GdkEvent

 

Returns

The associated keyboard scancode or 0

Since: 3.22


gdk_event_get_pointer_emulated ()

gboolean
gdk_event_get_pointer_emulated (GdkEvent *event);

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

Returns

TRUE if this event is emulated

Since: 3.22


gdk_event_handler_set ()

void
gdk_event_handler_set (GdkEventFunc func,
                       gpointer data,
                       GDestroyNotify notify);

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 gtk_main_do_event() to pass events to GTK+.)

Parameters

func

the function to call to handle events from GDK.

 

data

user data to pass to the function.

 

notify

the function to call when the handler function is removed, i.e. when gdk_event_handler_set() is called with another event handler.

 

GdkEventFunc ()

void
(*GdkEventFunc) (GdkEvent *event,
                 gpointer data);

Specifies the type of function passed to gdk_event_handler_set() to handle all GDK events.

Parameters

event

the GdkEvent to process.

 

data

user data set when the event handler was installed with gdk_event_handler_set().

[closure]

gdk_get_show_events ()

gboolean
gdk_get_show_events (void);

Gets whether event debugging output is enabled.

Returns

TRUE if event debugging output is enabled.


gdk_set_show_events ()

void
gdk_set_show_events (gboolean show_events);

Sets whether a trace of received events is output. Note that GTK+ must be compiled with debugging (that is, configured using the --enable-debug option) to use this option.

Parameters

show_events

TRUE to output event debugging information.

 

gdk_event_set_screen ()

void
gdk_event_set_screen (GdkEvent *event,
                      GdkScreen *screen);

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

Parameters

event

a GdkEvent

 

screen

a GdkScreen

 

Since: 2.2


gdk_event_get_screen ()

GdkScreen *
gdk_event_get_screen (const GdkEvent *event);

Returns the screen for the event. The screen is typically the screen for 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 event->motion.x_root and event->motion.y_root are relative.

Parameters

event

a GdkEvent

 

Returns

the screen for the event.

[transfer none]

Since: 2.2


gdk_event_get_device ()

GdkDevice *
gdk_event_get_device (const GdkEvent *event);

If the event contains a “device” field, this function will return it, else it will return NULL.

Parameters

event

a GdkEvent.

 

Returns

a GdkDevice, or NULL.

[nullable][transfer none]

Since: 3.0


gdk_event_set_device ()

void
gdk_event_set_device (GdkEvent *event,
                      GdkDevice *device);

Sets the device for event to device . The event must have been allocated by GTK+, for instance, by gdk_event_copy().

Parameters

event

a GdkEvent

 

device

a GdkDevice

 

Since: 3.0


gdk_event_get_source_device ()

GdkDevice *
gdk_event_get_source_device (const GdkEvent *event);

This function returns the hardware (slave) GdkDevice that has triggered the event, falling back to the virtual (master) device (as in gdk_event_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 GdkWindow updates its geometry or a grab is acquired/released.

If the event does not contain a device field, this function will return NULL.

Parameters

event

a GdkEvent

 

Returns

a GdkDevice, or NULL.

[nullable][transfer none]

Since: 3.0


gdk_event_set_source_device ()

void
gdk_event_set_source_device (GdkEvent *event,
                             GdkDevice *device);

Sets the slave device for event to device .

The event must have been allocated by GTK+, for instance by gdk_event_copy().

Parameters

event

a GdkEvent

 

device

a GdkDevice

 

Since: 3.0


gdk_event_get_device_tool ()

GdkDeviceTool *
gdk_event_get_device_tool (const GdkEvent *event);

If the event was generated by a device that supports different tools (eg. a tablet), this function will return a GdkDeviceTool representing the tool that caused the event. Otherwise, NULL will be returned.

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

Parameters

event

a GdkEvent

 

Returns

The current device tool, or NULL.

[transfer none]

Since: 3.22


gdk_event_set_device_tool ()

void
gdk_event_set_device_tool (GdkEvent *event,
                           GdkDeviceTool *tool);

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

Parameters

event

a GdkEvent

 

tool

tool to set on the event, or NULL.

[nullable]

Since: 3.22


gdk_setting_get ()

gboolean
gdk_setting_get (const gchar *name,
                 GValue *value);

Obtains a desktop-wide setting, such as the double-click time, for the default screen. See gdk_screen_get_setting().

Parameters

name

the name of the setting.

 

value

location to store the value of the setting.

 

Returns

TRUE if the setting existed and a value was stored in value , FALSE otherwise.

See Also

Event Structures