Bindings module

Bindings module — xkbcommon-based GUI bindings support

Functions

Types and Values

Description

Functions

nk_bindings_error ()

GQuark
nk_bindings_error (void);

nk_bindings_new ()

NkBindings *
nk_bindings_new (guint64 double_click_delay);

Creates a new NkBindings context.

Any relevant setting will be retrieved from the Desktop Environment when possible, then from GTK settings. If none is available, the application settings passed as parameters will be used, with a fallback if the value is unusable.

Parameters

double_click_delay

the application default double-click delay, 0 for the default

 

Returns

a new NkBindings.

[transfer full]


nk_bindings_free ()

void
nk_bindings_free (NkBindings *bindings);

Frees the NkBindings context and all its seats.

Parameters

bindings

an NkBindings context

 

NkBindingsCallback ()

gboolean
(*NkBindingsCallback) (guint64 scope,
                       gpointer target,
                       gpointer user_data);

This function is called when a binding might be triggered. It is up to the caller to check in scope and target matches a valid situation in the application.

If the binding is valid, the application can do the relevant actions and return NK_BINDINGS_BINDING_TRIGGERED.

If not, returns NK_BINDINGS_BINDING_NOT_TRIGGERED and the next scope is checked in the NkBindings context.

Parameters

scope

the scope this binding was

 

target

the target passed to nk_bindings_seat_handle_key() and others

 

user_data

user_data passed to nk_bindings_add_binding()

 

Returns

NK_BINDINGS_BINDING_TRIGGERED if the binding was valid, NK_BINDINGS_BINDING_NOT_TRIGGERED otherwise


nk_bindings_add_binding ()

gboolean
nk_bindings_add_binding (NkBindings *bindings,
                         guint64 scope,
                         const gchar *string,
                         NkBindingsCallback callback,
                         gpointer user_data,
                         GDestroyNotify notify,
                         GError **error);

Adds a binding to the bindings context.

The scope is fully opaque to NkBindings. Scopes are ordered higher-first and checked in order. See NkBindingsCallback.

Parameters

bindings

an NkBindings context

 

scope

an opaque scope ID

 

string

a binding string

 

callback

the callback to call when the binding might be triggered

 

user_data

user_data for callback

 

notify

function to call to free user_data when freeing the binding.

[nullable]

error

return location for a GError, or NULL

 

Returns

TRUE on success, FALSE on error


nk_bindings_reset_bindings ()

void
nk_bindings_reset_bindings (NkBindings *bindings);

Removes all bindings from the bindings context.

Parameters

bindings

an NkBindings context

 

nk_bindings_seat_new ()

NkBindingsSeat *
nk_bindings_seat_new (NkBindings *bindings,
                      enum xkb_context_flags flags);

Creates a new NkBindingsSeat in the context to handle the state of a set of devices.

You must call nk_bindings_seat_update_keymap() with non-NULL values before any call to nk_bindings_seat_handle_key() and others.

Parameters

bindings

an NkBindings context

 

flags

flags for the xkb_context_t

 

Returns

a new NkBindingsSeat.

[transfer full]


nk_bindings_seat_free ()

void
nk_bindings_seat_free (NkBindingsSeat *seat);

Frees the seat and all its state.

This will not trigger and pending on-release binding.

Parameters

seat

an NkBindingsSeat

 

nk_bindings_seat_update_keymap ()

void
nk_bindings_seat_update_keymap (NkBindingsSeat *seat,
                                struct xkb_keymap *keymap,
                                struct xkb_state *state);

Updates the keymap and state of this seat .

Both keymap and state can either be NULL to clear the state or non-NULL to update/create it.

Parameters

seat

an NkBindingsSeat

 

keymap

an xkb_keymap.

[nullable]

state

an xkb_state.

[nullable]

nk_bindings_seat_get_context ()

struct xkb_context *
nk_bindings_seat_get_context (NkBindingsSeat *seat);

Gets the xkb_context of the seat .

Parameters

seat

an NkBindingsSeat

 

Returns

the xkb_context of the seat.

[transfer none]


nk_bindings_seat_handle_key ()

gchar *
nk_bindings_seat_handle_key (NkBindingsSeat *seat,
                             gpointer target,
                             xkb_keycode_t key,
                             NkBindingsKeyState state);

Handles a key press/release event on target . target is usually the widget the event occured on.

If the event might trigger a binding, the corresponding callback will be called. See NkBindingsCallback and nk_bindings_add_binding().

If no binding was triggered and the event resulted in text, said text is returned.

Parameters

seat

an NkBindingsSeat

 

target

an opaque target pointer

 

key

the key code being modified

 

state

the NkBindingsKeyState

 

Returns

the entered text if relevant, or NULL.

[nullable]


nk_bindings_seat_handle_key_with_modmask ()

gchar *
nk_bindings_seat_handle_key_with_modmask
                               (NkBindingsSeat *seat,
                                gpointer target,
                                xkb_mod_mask_t modmask,
                                xkb_keycode_t key,
                                NkBindingsKeyState state);

A variant of nk_bindings_seat_handle_key() for cases where you get a modmask with the event instead on relying on the current state (i.e. in the X11 world).

Parameters

seat

an NkBindingsSeat

 

modmask

an xkb_mod_mask_t for the event

 

target

an opaque target pointer

 

key

the key code being modified

 

state

the NkBindingsKeyState

 

Returns

the entered text if relevant, or NULL.

[nullable]


nk_bindings_seat_handle_button ()

gboolean
nk_bindings_seat_handle_button (NkBindingsSeat *seat,
                                gpointer target,
                                NkBindingsMouseButton button,
                                NkBindingsButtonState state,
                                guint64 timestamp);

Handles a button press/release event on target . target is usually the widget the event occured on.

If the event might trigger a binding, the corresponding callback will be called. See NkBindingsCallback and nk_bindings_add_binding().

Parameters

seat

an NkBindingsSeat

 

target

an opaque target pointer

 

button

an NkBindingsMouseButton

 

state

the NkBindingsButtonState

 

timestamp

the timestamp for when the evnte occured

 

Returns

NK_BINDINGS_BINDING_TRIGGERED if a binding was triggered, NK_BINDINGS_BINDING_NOT_TRIGGERED otherwise


nk_bindings_seat_handle_scroll ()

gboolean
nk_bindings_seat_handle_scroll (NkBindingsSeat *seat,
                                gpointer target,
                                NkBindingsScrollAxis axis,
                                gint32 steps);

Handles a scroll event on target . target is usually the widget the event occured on.

If the event might trigger a binding, the corresponding callback will be called step times. See NkBindingsCallback and nk_bindings_add_binding().

A negative value of step means up or left scrolling, a positive value means down or right scrolling.

Parameters

seat

an NkBindingsSeat

 

target

an opaque target pointer

 

axis

an NkBindingsScrollAxis

 

steps

the number of steps of the scroll

 

Returns

NK_BINDINGS_BINDING_TRIGGERED if a binding was triggered, NK_BINDINGS_BINDING_NOT_TRIGGERED otherwise


nk_bindings_seat_update_mask ()

void
nk_bindings_seat_update_mask (NkBindingsSeat *seat,
                              gpointer target,
                              xkb_mod_mask_t depressed_mods,
                              xkb_mod_mask_t latched_mods,
                              xkb_mod_mask_t locked_mods,
                              xkb_layout_index_t depressed_layout,
                              xkb_layout_index_t latched_layout,
                              xkb_layout_index_t locked_layout);

Handles a modifiers mask event on target . target is usually the widget the event occured on.

If the event might trigger a binding, the corresponding callback will be called. See NkBindingsCallback and nk_bindings_add_binding().

Only on-release bindings may be triggered by this function.

See xkb_state_update_mask() for more information about depressed_mods , latched_mods , locked_mods , depressed_layout , latched_layout , locked_layout . Most of the time you should just pass the values you got with your event, using 0 for missing values.

Parameters

seat

an NkBindingsSeat

 

target

an opaque target pointer

 

depressed_mods

see description

 

latched_mods

see description

 

locked_mods

see description

 

depressed_layout

see description

 

latched_layout

see description

 

locked_layout

see description

 

nk_bindings_seat_reset ()

void
nk_bindings_seat_reset (NkBindingsSeat *seat);

Reset any pending on-release bindings on the seat .

Parameters

seat

an NkBindingsSeat

 

Types and Values

NkBindings

typedef struct _NkBindings NkBindings;

An opaque structure holding all the bindings and seats.


enum NkBindingsKeyState

An enumeration describing a key state.

NK_BINDINGS_KEY_STATE_PRESSED is to be used for keyboard focus-in-like events when you get a list of already pressed keys that should not trigger on-press bindings. See nk_bindings_seat_handle_key().

Members

NK_BINDINGS_KEY_STATE_PRESS

the key is being pressed

 

NK_BINDINGS_KEY_STATE_PRESSED

the key was already pressed

 

NK_BINDINGS_KEY_STATE_RELEASE

the key is being released

 

enum NkBindingsButtonState

An enumeration describing a mouse button state.

Members

NK_BINDINGS_BUTTON_STATE_PRESS

the button is being pressed

 

NK_BINDINGS_BUTTON_STATE_RELEASE

the button is being released

 

enum NkBindingsMouseButton

An enumeration describing a mouse button.

Mice may have an arbritrary number of extra buttons, which will be mapped to values starting at NK_BINDINGS_MOUSE_BUTTON_EXTRA.

Members

NK_BINDINGS_MOUSE_BUTTON_PRIMARY

the primary mouse button (“left click” for right-handed people)

 

NK_BINDINGS_MOUSE_BUTTON_SECONDARY

the secondary mouse button (“right click” for right-handed people)

 

NK_BINDINGS_MOUSE_BUTTON_MIDDLE

the middle mouse button (“wheel click”)

 

NK_BINDINGS_MOUSE_BUTTON_BACK

the first commonly-available extra button, usually known as “back”

 

NK_BINDINGS_MOUSE_BUTTON_FORWARD

the second commonly-available extra button, usually known as “forward”

 

NK_BINDINGS_MOUSE_BUTTON_EXTRA

the first value for any button after the commonly-available first five

 

enum NkBindingsScrollAxis

An enumeration describing the scroll direction.

Members

NK_BINDINGS_SCROLL_AXIS_VERTICAL

scroll along the vertical axis

 

NK_BINDINGS_SCROLL_AXIS_HORIZONTAL

scroll along the horizontal axis

 

NK_BINDINGS_SCROLL_NUM_AXIS

#define NK_BINDINGS_SCROLL_NUM_AXIS 2

The number of scroll axis currently supported.


enum NkBindingsError

Members

NK_BINDINGS_ERROR_SYNTAX

Error syntax in the binding string

 

NK_BINDINGS_ERROR_UNKNOWN_KEYSYM

Keysym used in the binding string is unknown to xkbcommon

 

NK_BINDINGS_ERROR_ALREADY_REGISTERED

The binding was already registered

 

NK_BINDINGS_ERROR

#define NK_BINDINGS_ERROR (nk_bindings_error())

NK_BINDINGS_BINDING_NOT_TRIGGERED

#define NK_BINDINGS_BINDING_NOT_TRIGGERED FALSE

Return value for NkBindingsCallback if the binding was not valid.


NK_BINDINGS_BINDING_TRIGGERED

#define NK_BINDINGS_BINDING_TRIGGERED TRUE

Return value for NkBindingsCallback if the binding was valid.


NkBindingsSeat

typedef struct _NkBindingsSeat NkBindingsSeat;

An opaque structure holding all the seat state.