libxkbcommon  1.13.0
Library implementing the XKB specification for parsing keyboard descriptions and handling keyboard state
Data Structures | Enumerations | Functions
Keyboard State

Data Structures

struct  xkb_state_machine_options
 
struct  xkb_event
 
struct  xkb_event_iterator
 

Enumerations

enum  xkb_state_accessibility_flags {
  XKB_STATE_A11Y_NO_FLAGS = 0 ,
  XKB_STATE_A11Y_LATCH_TO_LOCK = (1 << 0) ,
  XKB_STATE_A11Y_LATCH_SIMULTANEOUS_KEYS = (1 << 1)
}
 
enum  xkb_event_type {
  XKB_EVENT_TYPE_KEY_DOWN = 1 ,
  XKB_EVENT_TYPE_KEY_UP ,
  XKB_EVENT_TYPE_COMPONENTS_CHANGE
}
 
enum  xkb_state_component {
  XKB_STATE_MODS_DEPRESSED = (1 << 0) ,
  XKB_STATE_MODS_LATCHED = (1 << 1) ,
  XKB_STATE_MODS_LOCKED = (1 << 2) ,
  XKB_STATE_MODS_EFFECTIVE = (1 << 3) ,
  XKB_STATE_LAYOUT_DEPRESSED = (1 << 4) ,
  XKB_STATE_LAYOUT_LATCHED = (1 << 5) ,
  XKB_STATE_LAYOUT_LOCKED = (1 << 6) ,
  XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7) ,
  XKB_STATE_LEDS = (1 << 8) ,
  XKB_STATE_CONTROLS = (1 << 9)
}
 
enum  xkb_keyboard_controls {
  XKB_KEYBOARD_CONTROL_NONE = 0 ,
  XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS = (1 << 3)
}
 
enum  xkb_event_iterator_flags { XKB_EVENT_ITERATOR_NO_FLAGS = 0 }
 
enum  xkb_key_direction {
  XKB_KEY_UP ,
  XKB_KEY_DOWN
}
 
enum  xkb_state_match {
  XKB_STATE_MATCH_ANY = (1 << 0) ,
  XKB_STATE_MATCH_ALL = (1 << 1) ,
  XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
}
 
enum  xkb_consumed_mode {
  XKB_CONSUMED_MODE_XKB ,
  XKB_CONSUMED_MODE_GTK
}
 

Functions

XKB_EXPORT struct xkb_state_machine_optionsxkb_state_machine_options::xkb_state_machine_options_new (struct xkb_context *context)
 
XKB_EXPORT void xkb_state_machine_options::xkb_state_machine_options_destroy (struct xkb_state_machine_options *options)
 
XKB_EXPORT int xkb_state_machine_options::xkb_state_machine_options_update_a11y_flags (struct xkb_state_machine_options *options, enum xkb_state_accessibility_flags affect, enum xkb_state_accessibility_flags flags)
 
XKB_EXPORT int xkb_state_machine_options::xkb_state_machine_options_mods_set_mapping (struct xkb_state_machine_options *options, xkb_mod_mask_t source, xkb_mod_mask_t target)
 
XKB_EXPORT int xkb_state_machine_options::xkb_state_machine_options_shortcuts_update_mods (struct xkb_state_machine_options *options, xkb_mod_mask_t affect, xkb_mod_mask_t mask)
 
XKB_EXPORT int xkb_state_machine_options::xkb_state_machine_options_shortcuts_set_mapping (struct xkb_state_machine_options *options, xkb_layout_index_t source, xkb_layout_index_t target)
 
XKB_EXPORT enum xkb_event_type xkb_event::xkb_event_get_type (const struct xkb_event *event)
 
XKB_EXPORT xkb_keycode_t xkb_event::xkb_event_get_keycode (const struct xkb_event *event)
 
XKB_EXPORT enum xkb_state_component xkb_event::xkb_event_get_changed_components (const struct xkb_event *event)
 
XKB_EXPORT enum xkb_keyboard_controls xkb_event::xkb_event_serialize_controls (const struct xkb_event *event, enum xkb_state_component components)
 
XKB_EXPORT xkb_mod_mask_t xkb_event::xkb_event_serialize_mods (const struct xkb_event *event, enum xkb_state_component components)
 
XKB_EXPORT xkb_layout_index_t xkb_event::xkb_event_serialize_layout (const struct xkb_event *event, enum xkb_state_component components)
 
XKB_EXPORT struct xkb_event_iteratorxkb_event_iterator::xkb_event_iterator_new (struct xkb_context *context, enum xkb_event_iterator_flags flags)
 
XKB_EXPORT void xkb_event_iterator::xkb_event_iterator_destroy (struct xkb_event_iterator *events)
 
XKB_EXPORT const struct xkb_eventxkb_event_iterator::xkb_event_iterator_next (struct xkb_event_iterator *events)
 
XKB_EXPORT struct xkb_state_machinexkb_state_machine::xkb_state_machine_new (struct xkb_keymap *keymap, const struct xkb_state_machine_options *options)
 
XKB_EXPORT struct xkb_state_machinexkb_state_machine::xkb_state_machine_ref (struct xkb_state_machine *sm)
 
XKB_EXPORT void xkb_state_machine::xkb_state_machine_unref (struct xkb_state_machine *sm)
 
XKB_EXPORT struct xkb_keymapxkb_state_machine::xkb_state_machine_get_keymap (const struct xkb_state_machine *sm)
 
XKB_EXPORT int xkb_state_machine::xkb_state_machine_update_controls (struct xkb_state_machine *sm, struct xkb_event_iterator *events, enum xkb_keyboard_controls affect, enum xkb_keyboard_controls controls)
 
XKB_EXPORT int xkb_state_machine::xkb_state_machine_update_key (struct xkb_state_machine *sm, struct xkb_event_iterator *events, xkb_keycode_t key, enum xkb_key_direction direction)
 
XKB_EXPORT int xkb_state_machine::xkb_state_machine_update_latched_locked (struct xkb_state_machine *sm, struct xkb_event_iterator *events, xkb_mod_mask_t affect_latched_mods, xkb_mod_mask_t latched_mods, bool affect_latched_layout, int32_t latched_layout, xkb_mod_mask_t affect_locked_mods, xkb_mod_mask_t locked_mods, bool affect_locked_layout, int32_t locked_layout)
 
XKB_EXPORT struct xkb_statexkb_state::xkb_state_new (struct xkb_keymap *keymap)
 
XKB_EXPORT struct xkb_statexkb_state::xkb_state_ref (struct xkb_state *state)
 
XKB_EXPORT void xkb_state::xkb_state_unref (struct xkb_state *state)
 
XKB_EXPORT struct xkb_keymapxkb_state::xkb_state_get_keymap (struct xkb_state *state)
 
XKB_EXPORT enum xkb_state_component xkb_state::xkb_state_update_controls (struct xkb_state *state, enum xkb_keyboard_controls affect, enum xkb_keyboard_controls controls)
 
XKB_EXPORT enum xkb_state_component xkb_state::xkb_state_update_key (struct xkb_state *state, xkb_keycode_t key, enum xkb_key_direction direction)
 
XKB_EXPORT enum xkb_state_component xkb_state::xkb_state_update_from_event (struct xkb_state *state, const struct xkb_event *event)
 
XKB_EXPORT enum xkb_state_component xkb_state::xkb_state_update_latched_locked (struct xkb_state *state, xkb_mod_mask_t affect_latched_mods, xkb_mod_mask_t latched_mods, bool affect_latched_layout, int32_t latched_layout, xkb_mod_mask_t affect_locked_mods, xkb_mod_mask_t locked_mods, bool affect_locked_layout, int32_t locked_layout)
 
XKB_EXPORT enum xkb_state_component xkb_state::xkb_state_update_mask (struct xkb_state *state, 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)
 
XKB_EXPORT int xkb_state::xkb_state_key_get_syms (struct xkb_state *state, xkb_keycode_t key, const xkb_keysym_t **syms_out)
 
XKB_EXPORT int xkb_state::xkb_state_key_get_utf8 (struct xkb_state *state, xkb_keycode_t key, char *buffer, size_t size)
 
XKB_EXPORT uint32_t xkb_state::xkb_state_key_get_utf32 (struct xkb_state *state, xkb_keycode_t key)
 
XKB_EXPORT xkb_keysym_t xkb_state::xkb_state_key_get_one_sym (struct xkb_state *state, xkb_keycode_t key)
 
XKB_EXPORT xkb_layout_index_t xkb_state::xkb_state_key_get_layout (struct xkb_state *state, xkb_keycode_t key)
 
XKB_EXPORT xkb_level_index_t xkb_state::xkb_state_key_get_level (struct xkb_state *state, xkb_keycode_t key, xkb_layout_index_t layout)
 
XKB_EXPORT enum xkb_keyboard_controls xkb_state::xkb_state_serialize_controls (const struct xkb_state *state, enum xkb_state_component components)
 
XKB_EXPORT xkb_mod_mask_t xkb_state::xkb_state_serialize_mods (struct xkb_state *state, enum xkb_state_component components)
 
XKB_EXPORT xkb_layout_index_t xkb_state::xkb_state_serialize_layout (struct xkb_state *state, enum xkb_state_component components)
 
XKB_EXPORT int xkb_state::xkb_state_mod_name_is_active (struct xkb_state *state, const char *name, enum xkb_state_component type)
 
XKB_EXPORT int xkb_state::xkb_state_mod_names_are_active (struct xkb_state *state, enum xkb_state_component type, enum xkb_state_match match,...)
 
XKB_EXPORT int xkb_state::xkb_state_mod_index_is_active (struct xkb_state *state, xkb_mod_index_t idx, enum xkb_state_component type)
 
XKB_EXPORT int xkb_state::xkb_state_mod_indices_are_active (struct xkb_state *state, enum xkb_state_component type, enum xkb_state_match match,...)
 
XKB_EXPORT xkb_mod_mask_t xkb_state::xkb_state_key_get_consumed_mods2 (struct xkb_state *state, xkb_keycode_t key, enum xkb_consumed_mode mode)
 
XKB_EXPORT xkb_mod_mask_t xkb_state::xkb_state_key_get_consumed_mods (struct xkb_state *state, xkb_keycode_t key)
 
XKB_EXPORT int xkb_state::xkb_state_mod_index_is_consumed2 (struct xkb_state *state, xkb_keycode_t key, xkb_mod_index_t idx, enum xkb_consumed_mode mode)
 
XKB_EXPORT int xkb_state::xkb_state_mod_index_is_consumed (struct xkb_state *state, xkb_keycode_t key, xkb_mod_index_t idx)
 
XKB_EXPORT xkb_mod_mask_t xkb_state::xkb_state_mod_mask_remove_consumed (struct xkb_state *state, xkb_keycode_t key, xkb_mod_mask_t mask)
 
XKB_EXPORT int xkb_state::xkb_state_layout_name_is_active (struct xkb_state *state, const char *name, enum xkb_state_component type)
 
XKB_EXPORT int xkb_state::xkb_state_layout_index_is_active (struct xkb_state *state, xkb_layout_index_t idx, enum xkb_state_component type)
 
XKB_EXPORT int xkb_state::xkb_state_led_name_is_active (struct xkb_state *state, const char *name)
 
XKB_EXPORT int xkb_state::xkb_state_led_index_is_active (struct xkb_state *state, xkb_led_index_t idx)
 

Detailed Description

Creating, destroying and manipulating keyboard state objects.

Server State and Client State

There are two distinct actors in most window-system architectures:

Server

For example: a Wayland compositor, an X11 server or an evdev listener.

Servers maintain the XKB state for a device according to input events from the device, such as key presses and releases, and out-of-band events from the user, like UI layout switchers.

Client

For example: a Wayland client or an X11 client.

Clients do not listen to input from the device; instead, whenever the server state changes, the server serializes the state and notifies the clients that the state has changed; the clients then update the state from the serialization.

There are two corresponding APIs:

xkb_state_machine: the server API

This is the recommended API for server applications. It enables the full feature set that libxkbcommon supports.

This API enables to generate a sequence of events corresponding to atomic state changes, contrary to the xkb_state API that cannot generate events. Additionally, the event API supports events other than state components changes, such as keys events, so that it enables to handle most of the XKB key actions.

See the example for a Wayland server in the quick guide.

Since
1.14.0
xkb_state: the client API (and legacy server API)

This is the API for client applications and the legacy API for server applications.

Warning
Some entry points in the xkb_state API are only meant for servers and some are only meant for clients, and the two should generally not be mixed.
Note
Since version 1.14.0, server applications should use the xkb_state_machine API, which supports more features.

See the examples for clients in the quick guide.

Consumed Modifiers

Some functions, like xkb_state::xkb_state_key_get_syms(), look at the state of the modifiers in the keymap and derive from it the correct shift level to use for the key. For example, in a US layout, pressing the key labeled <A> while the Shift modifier is active, generates the keysym A. In this case, the Shift modifier is said to be consumed. However, the Num Lock modifier does not affect this translation at all, even if it is active, so it is not consumed by this translation.

It may be desirable for some application to not reuse consumed modifiers for further processing, e.g. for hotkeys or keyboard shortcuts. To understand why, consider some requirements from a standard shortcut mechanism, and how they are implemented:

  1. The shortcut’s modifiers must match exactly to the state. For example, it is possible to bind separate actions to <Alt><Tab> and to <Alt><Shift><Tab>. Further, if only <Alt><Tab> is bound to an action, pressing <Alt><Shift><Tab> should not trigger the shortcut. Effectively, this means that the modifiers are compared using the equality operator (==).
  2. Only relevant modifiers are considered for the matching. For example, Caps Lock and Num Lock should not generally affect the matching, e.g. when matching <Alt><Tab> against the state, it does not matter whether Num Lock is active or not. These relevant, or significant, modifiers usually include Alt, Control, Shift, Super and similar. Effectively, this means that non-significant modifiers are masked out, before doing the comparison as described above.
  3. The matching must be independent of the layout/keymap. For example, the <Plus> (+) symbol is found on the first level on some layouts, but requires holding Shift on others. If you simply bind the action to the <Plus> keysym, it would work for the unshifted kind, but not for the others, because the match against Shift would fail. If you bind the action to <Shift><Plus>, only the shifted kind would work. So what is needed is to recognize that Shift is used up in the translation of the keysym itself, and therefore should not be included in the matching. Effectively, this means that consumed modifiers (Shift in this example) are masked out as well, before doing the comparison.

In summary, this is approximately how the matching would be performed:

(keysym == shortcut_keysym) &&
((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)

state_mods are the modifiers reported by xkb_state::xkb_state_mod_index_is_active() and similar functions. consumed_mods are the modifiers reported by xkb_state::xkb_state_mod_index_is_consumed() and similar functions. significant_mods are decided upon by the application/toolkit/user; it is up to them to decide whether these are configurable or hard-coded.

Enumeration Type Documentation

◆ xkb_state_accessibility_flags

Flags for xkb_state_machine_options::xkb_state_machine_options_update_a11y_flags().

Since
1.14.0
Enumerator
XKB_STATE_A11Y_NO_FLAGS 

Do not apply any flags.

Since
1.14.0
XKB_STATE_A11Y_LATCH_TO_LOCK 

If both XKB_STATE_A11Y_LATCH_TO_LOCK and XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS are activated, they enable users to lock modifier keys without requiring special locking keys.

The user can press a latch modifier twice in a row to lock it, and then unlock it by pressing it one more time.

See also
XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS
Since
1.14.0
XKB_STATE_A11Y_LATCH_SIMULTANEOUS_KEYS 

Without this option, the latch keys are only triggers if keys are strictly sequentially tapped, e.g.

:

  1. ISO_Level2_Latch
  2. ISO_Level2_Latch
  3. A
  4. A

If one wants multiple active latches, they must be tapped in sequence: e.g.:

  1. ISO_Level2_Latch
  2. ISO_Level2_Latch
  3. ISO_Level3_Latch
  4. ISO_Level3_Latch
  5. A
  6. A

This option relaxes the strict sequence requirement and enable to operate keys that do not break latches simultaneously with a latch key, e.g.:

  1. ISO_Level2_Latch
  2. ISO_Level3_Latch
  3. ISO_Level2_Latch
  4. ISO_Level3_Latch
  5. A
  6. A

This is an extension to the X11 XKB protocol and is enabled by default when using XKB_KEYMAP_FORMAT_TEXT_V2.

Since
1.14.0

◆ xkb_event_type

Denotes the type of a state event.

Since
1.14.0
Enumerator
XKB_EVENT_TYPE_KEY_DOWN 

Key down event

Since
1.14.0
XKB_EVENT_TYPE_KEY_UP 

Key up event

Since
1.14.0
XKB_EVENT_TYPE_COMPONENTS_CHANGE 

Components change event

Since
1.14.0

◆ xkb_state_component

Component types for state objects, which belong to the following categories:

This enum is bitmaskable, e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to exclude locked modifiers.

In XKB, the DEPRESSED components are also known as base.

Enumerator
XKB_STATE_MODS_DEPRESSED Depressed modifiers, i.e. a key is physically holding them.
XKB_STATE_MODS_LATCHED Latched modifiers, i.e. will be unset after the next non-modifier key press.
XKB_STATE_MODS_LOCKED Locked modifiers, i.e. will be unset after the key provoking the lock has been pressed again.
XKB_STATE_MODS_EFFECTIVE Effective modifiers, i.e. currently active and affect key processing (derived from the other state components).

Use this unless you explicitly care how the state came about.

XKB_STATE_LAYOUT_DEPRESSED Depressed layout, i.e. a key is physically holding it.
XKB_STATE_LAYOUT_LATCHED Latched layout, i.e. will be unset after the next non-modifier key press.
XKB_STATE_LAYOUT_LOCKED Locked layout, i.e. will be unset after the key provoking the lock has been pressed again.
XKB_STATE_LAYOUT_EFFECTIVE Effective layout, i.e. currently active and affects key processing (derived from the other state components).

Use this unless you explicitly care how the state came about.

XKB_STATE_LEDS 

LEDs (derived from the other state components).

XKB_STATE_CONTROLS 

Effective keyboard controls.

◆ xkb_keyboard_controls

Global keyboard controls, which affect the way libxkbcommon handles the keyboard as a whole.

This enumeration is bit-maskable.

Since
1.14.0
Enumerator
XKB_KEYBOARD_CONTROL_NONE 

Do not apply any control.

Since
1.14.0
XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS 

Sticky keys is an accessibility feature primarily aimed at helping people that find it difficult or impossible to press two keys at once.

The XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS control makes it easier for them to type by changing the behavior of the modifier and group switch keys. When sticky keys are enabled, set modifiers/group switch are transformed into their corresponding latch version: e.g. the user can first press a modifier, release it, then press another key.

See also
XKB_STATE_A11Y_LATCH_TO_LOCK
Since
1.14.0

◆ xkb_event_iterator_flags

◆ xkb_key_direction

Specifies the direction of the key (press / release).

Enumerator
XKB_KEY_UP 

The key was released.

XKB_KEY_DOWN 

The key was pressed.

◆ xkb_state_match

Match flags for xkb_state::xkb_state_mod_indices_are_active() and xkb_state::xkb_state_mod_names_are_active(), specifying the conditions for a successful match.

XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with the other modes.

Enumerator
XKB_STATE_MATCH_ANY 

Returns true if any of the modifiers are active.

XKB_STATE_MATCH_ALL 

Returns true if all of the modifiers are active.

XKB_STATE_MATCH_NON_EXCLUSIVE Makes matching non-exclusive, i.e. will not return false if a modifier not specified in the arguments is active.

◆ xkb_consumed_mode

Consumed modifiers mode.

There are several possible methods for deciding which modifiers are consumed and which are not, each applicable for different systems or situations. The mode selects the method to use.

Keep in mind that in all methods, the keymap may decide to preserve a modifier, meaning it is not reported as consumed even if it would have otherwise.

Enumerator
XKB_CONSUMED_MODE_XKB 

This is the mode defined in the XKB specification and used by libX11.

A modifier is consumed if and only if it may affect key translation.

For example, if Control+Alt+<Backspace> produces some assigned keysym, then when pressing just <Backspace>, Control and Alt are consumed, even though they are not active, since if they were active they would have affected key translation.

XKB_CONSUMED_MODE_GTK 

This is the mode used by the GTK+ toolkit.

The mode consists of the following two independent heuristics:

  • The currently active set of modifiers, excluding modifiers which do not affect the key (as described for XKB_CONSUMED_MODE_XKB), are considered consumed, if the keysyms produced when all of them are active are different from the keysyms produced when no modifiers are active.
  • A single modifier is considered consumed if the keysyms produced for the key when it is the only active modifier are different from the keysyms produced when no modifiers are active.

Function Documentation

◆ xkb_state_machine_options_new()

XKB_EXPORT struct xkb_state_machine_options * xkb_state_machine_options_new ( struct xkb_context context)

Create a new keyboard state machine options object.

Parameters
contextThe context in which to create the options.
Returns
A new keyboard state machine options object, or NULL on failure.
Since
1.14.0

◆ xkb_state_machine_options_destroy()

XKB_EXPORT void xkb_state_machine_options_destroy ( struct xkb_state_machine_options options)

Free a keyboard state machine options object.

Parameters
optionsThe state machine options. If it is NULL, this function does nothing.
Since
1.14.0

◆ xkb_state_machine_options_update_a11y_flags()

XKB_EXPORT int xkb_state_machine_options_update_a11y_flags ( struct xkb_state_machine_options options,
enum xkb_state_accessibility_flags  affect,
enum xkb_state_accessibility_flags  flags 
)

Update the accessibility flags of a state options object.

Parameters
optionsThe state options object to modify.
affectAccessibility flags to modify.
flagsAccessibility flags to set or unset. Only the flags in affect are considered.
Returns
0 on success, otherwise an error code.
Since
1.14.0

◆ xkb_state_machine_options_mods_set_mapping()

XKB_EXPORT int xkb_state_machine_options_mods_set_mapping ( struct xkb_state_machine_options options,
xkb_mod_mask_t  source,
xkb_mod_mask_t  target 
)

Remap a modifier combination, e.g.

to make Control+Alt act as LevelThree (AltGr). This help improving compatibility across platforms.

The remapping takes effect only using xkb_state_machine::xkb_state_machine_update_key() and under certain conditions:

  • The corresponding effective modifiers are active.
  • The key being processed has a type that does not use any of the source modifiers.
  • There is no other remapping entry with the source modifiers being a superset of this entry. E.g. Control+Alt has priority over Control.
Parameters
optionsThe state options object to modify.
sourceModifiers combination to remap, using its encoding.
targetModifiers combination target, using their encoding. Use 0 to remove a previous entry of source.

Example:

// Remap Control+Alt to LevelThree (AltGr)
const xkb_mod_mask_t ctrl = xkb_keymap_mod_get_mask(keymap, XKB_MOD_NAME_CTRL);
const xkb_mod_mask_t alt = xkb_keymap_mod_get_mask(keymap, XKB_VMOD_NAME_ALT);
const xkb_mod_mask_t level3 = xkb_keymap_mod_get_mask(keymap, XKB_VMOD_NAME_LEVEL3);
if (xkb_state_machine_options_mods_set_mapping(options, ctrl | alt, level3)) {
// handle error
XKB_EXPORT int xkb_state_machine_options_mods_set_mapping(struct xkb_state_machine_options *options, xkb_mod_mask_t source, xkb_mod_mask_t target)
Remap a modifier combination, e.g.
#define XKB_VMOD_NAME_LEVEL3
Definition: xkbcommon-names.h:60
#define XKB_VMOD_NAME_ALT
Definition: xkbcommon-names.h:56
uint32_t xkb_mod_mask_t
Definition: xkbcommon.h:268

Using 0 for both source and target removes all the entries.

Since
1.14.0

◆ xkb_state_machine_options_shortcuts_update_mods()

XKB_EXPORT int xkb_state_machine_options_shortcuts_update_mods ( struct xkb_state_machine_options options,
xkb_mod_mask_t  affect,
xkb_mod_mask_t  mask 
)

Set the modifiers that trigger keyboard shortcuts tweak.

Parameters
optionsThe state options object to modify.
affectSee mask.
maskModifiers to set, using their encoding. Only the modifiers in affect are considered.
See also
xkb_state_machine_options_shortcuts_set_mapping()
xkb_keymap::xkb_keymap_mod_get_mask2()
Since
1.14.0

◆ xkb_state_machine_options_shortcuts_set_mapping()

XKB_EXPORT int xkb_state_machine_options_shortcuts_set_mapping ( struct xkb_state_machine_options options,
xkb_layout_index_t  source,
xkb_layout_index_t  target 
)

Set layout mapping for keyboard shortcuts tweak.

Enable tweaking keyboard shortcuts by switching the effective layout when any modifier set by xkb_state_machine_options_shortcuts_update_mods() is active.

Parameters
optionsThe state options object to modify.
sourceSource layout.
targetTarget layout.
See also
xkb_state_machine_options_shortcuts_update_mods()
Since
1.14.0

◆ xkb_event_get_type()

XKB_EXPORT enum xkb_event_type xkb_event_get_type ( const struct xkb_event event)

Get the type of an event.

Since
1.14.0

◆ xkb_event_get_keycode()

XKB_EXPORT xkb_keycode_t xkb_event_get_keycode ( const struct xkb_event event)

Get the keycode associated to a state event of type XKB_EVENT_TYPE_KEY_DOWN or XKB_EVENT_TYPE_KEY_UP.

Parameters
eventThe event to process.
Returns
For an event of type XKB_EVENT_TYPE_KEY_DOWN or XKB_EVENT_TYPE_KEY_UP, returns the corresponding keycode.
The result is undefined if the given event has another type.
Since
1.14.0

◆ xkb_event_get_changed_components()

XKB_EXPORT enum xkb_state_component xkb_event_get_changed_components ( const struct xkb_event event)

Get the state components changes corresponding to a state event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE .

Parameters
eventThe event to process.
Returns
For an event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE, returns the corresponding mask of state components that have changed as a result of the event. If nothing in the state has changed, returns 0.
The result is undefined if the given event has another type.
Since
1.14.0

◆ xkb_event_serialize_controls()

XKB_EXPORT enum xkb_keyboard_controls xkb_event_serialize_controls ( const struct xkb_event event,
enum xkb_state_component  components 
)

Serialization of the global keyboard controls corresponding to a state event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE .

Parameters
eventThe state event.
componentsA mask of the keyboard control state components to serialize. State components other than XKB_STATE_CONTROLS are ignored.
Returns
For an event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE returns the corresponding xkb_keyboard_controls mask.
The result is undefined if the given event has another type.
Since
1.14.0

◆ xkb_event_serialize_mods()

XKB_EXPORT xkb_mod_mask_t xkb_event_serialize_mods ( const struct xkb_event event,
enum xkb_state_component  components 
)

Serialization of the modifiers corresponding to a state event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE .

Parameters
eventThe state event.
componentsA mask of the modifier state components to serialize. State components other than XKB_STATE_MODS_* are ignored. If XKB_STATE_MODS_EFFECTIVE is included, all other state components are ignored.
Returns
For an event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE returns the corresponding xkb_mod_mask_t mask representing the given components of the modifier state.
The result is undefined if the given event has another type.
Since
1.14.0

◆ xkb_event_serialize_layout()

XKB_EXPORT xkb_layout_index_t xkb_event_serialize_layout ( const struct xkb_event event,
enum xkb_state_component  components 
)

Serialization of the layout corresponding to a state event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE .

Parameters
eventThe state event.
componentsA mask of the layout state components to serialize. State components other than XKB_STATE_LAYOUT_* are ignored. If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are ignored.
Returns
For an event of type XKB_EVENT_TYPE_COMPONENTS_CHANGE returns the corresponding layout index representing the given components of the layout state.
The result is undefined if the given event has another type.
Since
1.14.0

◆ xkb_event_iterator_new()

XKB_EXPORT struct xkb_event_iterator * xkb_event_iterator_new ( struct xkb_context context,
enum xkb_event_iterator_flags  flags 
)

Create an event iterator object.

Parameters
contextThe context in which to create the iterator.
flagsOptional flags for the iterator, or 0.
Returns
A new event iterator object, or NULL on failure.
Since
1.14.0
See also
xkb_event_iterator_destroy()

◆ xkb_event_iterator_destroy()

XKB_EXPORT void xkb_event_iterator_destroy ( struct xkb_event_iterator events)

Free an event iterator object.

Parameters
eventsThe event iterator to free. If it is NULL, this function does nothing.
Since
1.14.0
See also
xkb_event_iterator_new()

◆ xkb_event_iterator_next()

XKB_EXPORT const struct xkb_event * xkb_event_iterator_next ( struct xkb_event_iterator events)

Get the next event queued in an event iterator object.

Parameters
eventsThe event iterator.
Returns
The next event, or NULL if the queue is empty.
Since
1.14.0

◆ xkb_state_machine_new()

XKB_EXPORT struct xkb_state_machine * xkb_state_machine_new ( struct xkb_keymap keymap,
const struct xkb_state_machine_options options 
)

Create a new keyboard state machine object.

This entry point is intended for server applications; client applications should use xkb_state_new() instead.

Parameters
keymapThe keymap which the state will use.
optionsThe options to configure the state machine, or NULL to use the defaults.
Returns
A new keyboard state machine object, or NULL on failure.
Since
1.14.0

◆ xkb_state_machine_ref()

XKB_EXPORT struct xkb_state_machine * xkb_state_machine_ref ( struct xkb_state_machine sm)

Take a new reference on a keyboard state machine object.

Parameters
smThe state machine.
Returns
The passed in object.
Since
1.14.0

◆ xkb_state_machine_unref()

XKB_EXPORT void xkb_state_machine_unref ( struct xkb_state_machine sm)

Release a reference on a keyboard state machine object, and possibly free it.

Parameters
smThe state machine. If it is NULL, this function does nothing.
Since
1.14.0

◆ xkb_state_machine_get_keymap()

XKB_EXPORT struct xkb_keymap * xkb_state_machine_get_keymap ( const struct xkb_state_machine sm)

Get the keymap which a keyboard state machine object is using.

Parameters
smThe state machine.
Returns
The keymap which was passed to xkb_state_machine_new() when creating this state machine object.
Warning
This function does not take a new reference on the keymap; you must explicitly reference it yourself if you plan to use it beyond the lifetime of the state machine.
Since
1.14.0

◆ xkb_state_machine_update_controls()

XKB_EXPORT int xkb_state_machine_update_controls ( struct xkb_state_machine sm,
struct xkb_event_iterator events,
enum xkb_keyboard_controls  affect,
enum xkb_keyboard_controls  controls 
)

Update the keyboard state machine to change the global keyboard controls.

Parameters
smThe keyboard state machine object.
eventsThe event iterator to store the events. It will be resetted.
affectGlobal keyboard controls to modify. controls contains the actual values.
controlsGlobal keyboard controls to lock or unlock. Only modifiers in affect are considered.
Returns
0 on success, otherwise an error code.
Since
1.14.0

◆ xkb_state_machine_update_key()

XKB_EXPORT int xkb_state_machine_update_key ( struct xkb_state_machine sm,
struct xkb_event_iterator events,
xkb_keycode_t  key,
enum xkb_key_direction  direction 
)

Generate the series of event corresponding to a given key being pressed or released and update the keyboard state.

A series of calls to this function should be consistent; that is, a call with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key is pressed twice, it should be released twice; etc. Otherwise (e.g. due to missed input events), situations like “stuck modifiers” may occur.

Parameters
smThe keyboard state machine object.
eventsThe event iterator to store the events. It will be resetted.
keyThe key being operated.
directionThe direction of the key operation.
Returns
0 on success, otherwise an error code.
Since
1.14.0

◆ xkb_state_machine_update_latched_locked()

XKB_EXPORT int xkb_state_machine_update_latched_locked ( struct xkb_state_machine sm,
struct xkb_event_iterator events,
xkb_mod_mask_t  affect_latched_mods,
xkb_mod_mask_t  latched_mods,
bool  affect_latched_layout,
int32_t  latched_layout,
xkb_mod_mask_t  affect_locked_mods,
xkb_mod_mask_t  locked_mods,
bool  affect_locked_layout,
int32_t  locked_layout 
)

Update the keyboard state machine to change the latched and locked state of the modifiers and layout.

Use this function to update the latched and locked state according to “out of band” (non-device) inputs, such as UI layout switchers.

Layout out of range

If the effective layout, after taking into account the depressed, latched and locked layout, is out of range (negative or greater than the maximum layout), it is brought into range. Currently, the layout is wrapped using integer modulus (with negative values wrapping from the end). The wrapping behavior may be made configurable in the future.

Parameters
smThe keyboard state machine object.
eventsThe event iterator to store the events. It will be resetted.
affect_latched_modsSee latched_mods.
latched_modsModifiers to set as latched or unlatched. Only modifiers in affect_latched_mods are considered.
affect_latched_layoutSee latched_layout.
latched_layoutLayout to latch. Only considered if affect_latched_layout is true. Maybe be out of range (including negative) – see note above.
affect_locked_modsSee locked_mods.
locked_modsModifiers to set as locked or unlocked. Only modifiers in affect_locked_mods are considered.
affect_locked_layoutSee locked_layout.
locked_layoutLayout to lock. Only considered if affect_locked_layout is true. Maybe be out of range (including negative) – see note above.
Returns
0 on success, otherwise an error code.
Since
1.14.0

◆ xkb_state_new()

XKB_EXPORT struct xkb_state * xkb_state_new ( struct xkb_keymap keymap)

Create a new keyboard state object.

This entry point is intended for both server and client applications.

Parameters
keymapThe keymap which the state will use.
Returns
A new keyboard state object, or NULL on failure.

◆ xkb_state_ref()

XKB_EXPORT struct xkb_state * xkb_state_ref ( struct xkb_state state)

Take a new reference on a keyboard state object.

Returns
The passed in object.

◆ xkb_state_unref()

XKB_EXPORT void xkb_state_unref ( struct xkb_state state)

Release a reference on a keyboard state object, and possibly free it.

Parameters
stateThe state. If it is NULL, this function does nothing.

◆ xkb_state_get_keymap()

XKB_EXPORT struct xkb_keymap * xkb_state_get_keymap ( struct xkb_state state)

Get the keymap which a keyboard state object is using.

Returns
The keymap which was passed to xkb_state_new() when creating this state object.
Warning
This function does not take a new reference on the keymap; you must explicitly reference it yourself if you plan to use it beyond the lifetime of the state.

◆ xkb_state_update_controls()

XKB_EXPORT enum xkb_state_component xkb_state_update_controls ( struct xkb_state state,
enum xkb_keyboard_controls  affect,
enum xkb_keyboard_controls  controls 
)

Update the keyboard state to change the global keyboard controls.

This entry point is intended for server applications and should not be used by client applications; see Server State and Client State for details.

Parameters
stateThe keyboard state object.
affectSee controls.
controlsGlobal keyboard controls to lock or unlock. Only modifiers in affect are considered.
Returns
A mask of state components that have changed as a result of the update. If nothing in the state has changed, returns 0.
Since
1.14.0

◆ xkb_state_update_key()

XKB_EXPORT enum xkb_state_component xkb_state_update_key ( struct xkb_state state,
xkb_keycode_t  key,
enum xkb_key_direction  direction 
)

Update the keyboard state to reflect a given key being pressed or released.

This entry point is intended for server applications and should not be used by client applications; see Server State and Client State for details.

A series of calls to this function should be consistent; that is, a call with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key is pressed twice, it should be released twice; etc. Otherwise (e.g. due to missed input events), situations like “stuck modifiers” may occur.

This function is often used in conjunction with the function xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example, when handling a key event. In this case, you should prefer to get the keysyms before updating the key, such that the keysyms reported for the key event are not affected by the event itself. This is the conventional behavior.

Note
This entry point only support a restricted set of libxkbcommon features. See the xkb_state_machine to enable the full feature set.
Parameters
stateThe keyboard state object.
keyThe key being operated.
directionThe direction of the key operation.
Returns
A mask of state components that have changed as a result of the update. If nothing in the state has changed, returns 0.
See also
xkb_state_update_mask()

◆ xkb_state_update_from_event()

XKB_EXPORT enum xkb_state_component xkb_state_update_from_event ( struct xkb_state state,
const struct xkb_event event 
)

Update the keyboard state components from an event.

This entry point is intended for server applications and should not be used by client applications; see Server State and Client State for details.

Warning
The given state object should not be updated by other means than events, i.e. do not use xkb_state_update_key().
Parameters
stateThe keyboard state object.
eventThe state event to update from.
Returns
A mask of state components that have changed as a result of the update. If nothing in the state has changed, returns 0.
Since
1.14.0

◆ xkb_state_update_latched_locked()

XKB_EXPORT enum xkb_state_component xkb_state_update_latched_locked ( struct xkb_state state,
xkb_mod_mask_t  affect_latched_mods,
xkb_mod_mask_t  latched_mods,
bool  affect_latched_layout,
int32_t  latched_layout,
xkb_mod_mask_t  affect_locked_mods,
xkb_mod_mask_t  locked_mods,
bool  affect_locked_layout,
int32_t  locked_layout 
)

Update the keyboard state to change the latched and locked state of the modifiers and layout.

This entry point is intended for server applications and should not be used by client applications; see Server State and Client State for details.

Use this function to update the latched and locked state according to “out of band” (non-device) inputs, such as UI layout switchers.

Layout out of range

If the effective layout, after taking into account the depressed, latched and locked layout, is out of range (negative or greater than the maximum layout), it is brought into range. Currently, the layout is wrapped using integer modulus (with negative values wrapping from the end). The wrapping behavior may be made configurable in the future.

Parameters
stateThe keyboard state object.
affect_latched_modsSee latched_mods.
latched_modsModifiers to set as latched or unlatched. Only modifiers in affect_latched_mods are considered.
affect_latched_layoutSee latched_layout.
latched_layoutLayout to latch. Only considered if affect_latched_layout is true. Maybe be out of range (including negative) – see note above.
affect_locked_modsSee locked_mods.
locked_modsModifiers to set as locked or unlocked. Only modifiers in affect_locked_mods are considered.
affect_locked_layoutSee locked_layout.
locked_layoutLayout to lock. Only considered if affect_locked_layout is true. Maybe be out of range (including negative) – see note above.
Returns
A mask of state components that have changed as a result of the update. If nothing in the state has changed, returns 0.
See also
xkb_state_update_mask()

◆ xkb_state_update_mask()

XKB_EXPORT enum xkb_state_component xkb_state_update_mask ( struct xkb_state state,
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 
)

Update a keyboard state from a set of explicit masks.

This entry point is intended for client applications; see Server State and Client State for details. Server applications should use xkb_state_update_key() instead.

All parameters must always be passed, or the resulting state may be incoherent.

Warning
The serialization is lossy and will not survive round trips; it must only be used to feed client state objects, and must not be used to update the server state.
Returns
A mask of state components that have changed as a result of the update. If nothing in the state has changed, returns 0.
See also
xkb_state_component
xkb_state_update_key()

◆ xkb_state_key_get_syms()

XKB_EXPORT int xkb_state_key_get_syms ( struct xkb_state state,
xkb_keycode_t  key,
const xkb_keysym_t **  syms_out 
)

Get the keysyms obtained from pressing a particular key in a given keyboard state.

Get the keysyms for a key according to the current active layout, modifiers and shift level for the key, as determined by a keyboard state.

Parameters
[in]stateThe keyboard state object.
[in]keyThe keycode of the key.
[out]syms_outAn immutable array of keysyms corresponding the key in the given keyboard state.

As an extension to XKB, this function can return more than one keysym. If you do not want to handle this case, you can use xkb_state_key_get_one_sym() for a simpler interface.

Returns
The number of keysyms in the syms_out array. If no keysyms are produced by the key in the given keyboard state, returns 0 and sets syms_out to NULL.

This function performs Capitalization Keysym Transformations.

Since
1.9.0 This function now performs Keysym Transformations.

◆ xkb_state_key_get_utf8()

XKB_EXPORT int xkb_state_key_get_utf8 ( struct xkb_state state,
xkb_keycode_t  key,
char *  buffer,
size_t  size 
)

Get the Unicode/UTF-8 string obtained from pressing a particular key in a given keyboard state.

Parameters
[in]stateThe keyboard state object.
[in]keyThe keycode of the key.
[out]bufferA buffer to write the string into.
[in]sizeSize of the buffer.
Warning
If the buffer passed is too small, the string is truncated (though still NULL-terminated).
Returns
The number of bytes required for the string, excluding the NULL byte. If there is nothing to write, returns 0.

You may check if truncation has occurred by comparing the return value with the size of buffer, similarly to the snprintf(3) function. You may safely pass NULL and 0 to buffer and size to find the required size (without the NULL-byte).

This function performs Capitalization and Control Keysym Transformations.

Since
0.4.1

◆ xkb_state_key_get_utf32()

XKB_EXPORT uint32_t xkb_state_key_get_utf32 ( struct xkb_state state,
xkb_keycode_t  key 
)

Get the Unicode/UTF-32 codepoint obtained from pressing a particular key in a a given keyboard state.

Returns
The UTF-32 representation for the key, if it consists of only a single codepoint. Otherwise, returns 0.

This function performs Capitalization and Control Keysym Transformations.

Since
0.4.1

◆ xkb_state_key_get_one_sym()

XKB_EXPORT xkb_keysym_t xkb_state_key_get_one_sym ( struct xkb_state state,
xkb_keycode_t  key 
)

Get the single keysym obtained from pressing a particular key in a given keyboard state.

This function is similar to xkb_state_key_get_syms(), but intended for users which cannot or do not want to handle the case where multiple keysyms are returned (in which case this function is preferred).

Returns
The keysym. If the key does not have exactly one keysym, returns XKB_KEY_NoSymbol.

This function performs Capitalization Keysym Transformations.

See also
xkb_state_key_get_syms()

◆ xkb_state_key_get_layout()

XKB_EXPORT xkb_layout_index_t xkb_state_key_get_layout ( struct xkb_state state,
xkb_keycode_t  key 
)

Get the effective layout index for a key in a given keyboard state.

Returns
The layout index for the key in the given keyboard state. If the given keycode is invalid, or if the key is not included in any layout at all, returns XKB_LAYOUT_INVALID.
Invariant
If the returned layout is valid, the following always holds:
xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
XKB_EXPORT xkb_layout_index_t xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key)
Get the effective layout index for a key in a given keyboard state.

◆ xkb_state_key_get_level()

XKB_EXPORT xkb_level_index_t xkb_state_key_get_level ( struct xkb_state state,
xkb_keycode_t  key,
xkb_layout_index_t  layout 
)

Get the effective shift level for a key in a given keyboard state and layout.

Parameters
stateThe keyboard state.
keyThe keycode of the key.
layoutThe layout for which to get the shift level. This must be smaller than:
xkb_keymap_num_layouts_for_key(keymap, key)
usually it would be:
Returns
The shift level index. If the key or layout are invalid, returns XKB_LEVEL_INVALID.
Invariant
If the returned level is valid, the following always holds:
xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
XKB_EXPORT xkb_level_index_t xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key, xkb_layout_index_t layout)
Get the effective shift level for a key in a given keyboard state and layout.

◆ xkb_state_serialize_controls()

XKB_EXPORT enum xkb_keyboard_controls xkb_state_serialize_controls ( const struct xkb_state state,
enum xkb_state_component  components 
)

Serialization of the global keyboard controls, to be used on the server side of serialization.

This entry point is intended for server applications; see Server State and Client State for details.

Parameters
stateThe keyboard state.
componentsA mask of the keyboard control state components to serialize. State components other than XKB_STATE_CONTROLS are ignored.
Returns
A xkb_keyboard_controls mask representing the given components of the keyboard controls state.
Since
1.14.0

◆ xkb_state_serialize_mods()

XKB_EXPORT xkb_mod_mask_t xkb_state_serialize_mods ( struct xkb_state state,
enum xkb_state_component  components 
)

The counterpart to xkb_state::xkb_state_update_mask() for modifiers, to be used on the server side of serialization.

This entry point is intended for server applications; see Server State and Client State for details. Client applications should use the xkb_state_mod_*_is_active API.

Parameters
stateThe keyboard state.
componentsA mask of the modifier state components to serialize. State components other than XKB_STATE_MODS_* are ignored. If XKB_STATE_MODS_EFFECTIVE is included, all other state components are ignored.
Returns
A xkb_mod_mask_t representing the given components of the modifier state.

◆ xkb_state_serialize_layout()

XKB_EXPORT xkb_layout_index_t xkb_state_serialize_layout ( struct xkb_state state,
enum xkb_state_component  components 
)

The counterpart to xkb_state::xkb_state_update_mask() for layouts, to be used on the server side of serialization.

This entry point is intended for server applications; see Server State and Client State for details. Client applications should use the xkb_state_layout_*_is_active API.

Parameters
stateThe keyboard state.
componentsA mask of the layout state components to serialize. State components other than XKB_STATE_LAYOUT_* are ignored. If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are ignored.
Returns
A layout index representing the given components of the layout state.

◆ xkb_state_mod_name_is_active()

XKB_EXPORT int xkb_state_mod_name_is_active ( struct xkb_state state,
const char *  name,
enum xkb_state_component  type 
)

Test whether a modifier is active in a given keyboard state by name.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Returns
1 if the modifier is active, 0 if it is not. If the modifier name does not exist in the keymap, returns -1.
Since
0.1.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers

◆ xkb_state_mod_names_are_active()

XKB_EXPORT int xkb_state_mod_names_are_active ( struct xkb_state state,
enum xkb_state_component  type,
enum xkb_state_match  match,
  ... 
)

Test whether a set of modifiers are active in a given keyboard state by name.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Parameters
stateThe keyboard state.
typeThe component of the state against which to match the given modifiers.
matchThe manner by which to match the state against the given modifiers.
...The set of of modifier names to test, terminated by a NULL argument (sentinel).
Returns
1 if the modifiers are active, 0 if they are not. If any of the modifier names do not exist in the keymap, returns -1. If match contains invalid flags, returns -2.
Since
0.1.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers
1.14.0: Reject invalid match flags

◆ xkb_state_mod_index_is_active()

XKB_EXPORT int xkb_state_mod_index_is_active ( struct xkb_state state,
xkb_mod_index_t  idx,
enum xkb_state_component  type 
)

Test whether a modifier is active in a given keyboard state by index.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Returns
1 if the modifier is active, 0 if it is not. If the modifier index is invalid in the keymap, returns -1.
Since
0.1.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers

◆ xkb_state_mod_indices_are_active()

XKB_EXPORT int xkb_state_mod_indices_are_active ( struct xkb_state state,
enum xkb_state_component  type,
enum xkb_state_match  match,
  ... 
)

Test whether a set of modifiers are active in a given keyboard state by index.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Parameters
stateThe keyboard state.
typeThe component of the state against which to match the given modifiers.
matchThe manner by which to match the state against the given modifiers.
...The set of of modifier indices to test, terminated by a XKB_MOD_INVALID argument (sentinel).
Returns
1 if the modifiers are active, 0 if they are not. If any of the modifier indices are invalid in the keymap, returns -1. If match contains invalid flags, returns -2.
Since
0.1.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers
1.14.0: Reject invalid match flags

◆ xkb_state_key_get_consumed_mods2()

XKB_EXPORT xkb_mod_mask_t xkb_state_key_get_consumed_mods2 ( struct xkb_state state,
xkb_keycode_t  key,
enum xkb_consumed_mode  mode 
)

Get the mask of modifiers consumed by translating a given key.

Parameters
stateThe keyboard state.
keyThe keycode of the key.
modeThe consumed modifiers mode to use; see enum description.
Returns
a mask of the consumed real modifiers modifiers.
Since
0.7.0

◆ xkb_state_key_get_consumed_mods()

XKB_EXPORT xkb_mod_mask_t xkb_state_key_get_consumed_mods ( struct xkb_state state,
xkb_keycode_t  key 
)

◆ xkb_state_mod_index_is_consumed2()

XKB_EXPORT int xkb_state_mod_index_is_consumed2 ( struct xkb_state state,
xkb_keycode_t  key,
xkb_mod_index_t  idx,
enum xkb_consumed_mode  mode 
)

Test whether a modifier is consumed by keyboard state translation for a key.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Parameters
stateThe keyboard state.
keyThe keycode of the key.
idxThe index of the modifier to check.
modeThe consumed modifiers mode to use; see enum description.
Returns
1 if the modifier is consumed, 0 if it is not. If the modifier index is not valid in the keymap, returns -1.
See also
xkb_state_mod_mask_remove_consumed()
xkb_state_key_get_consumed_mods()
Since
0.7.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers

◆ xkb_state_mod_index_is_consumed()

XKB_EXPORT int xkb_state_mod_index_is_consumed ( struct xkb_state state,
xkb_keycode_t  key,
xkb_mod_index_t  idx 
)

Same as xkb_state_mod_index_is_consumed2() with mode ::XKB_CONSUMED_MOD_XKB.

Warning
For virtual modifiers, this function may overmatch in case there are virtual modifiers with overlapping mappings to real modifiers.
Since
0.4.1: Works only with real modifiers
1.8.0: Works also with virtual modifiers

◆ xkb_state_mod_mask_remove_consumed()

XKB_EXPORT xkb_mod_mask_t xkb_state_mod_mask_remove_consumed ( struct xkb_state state,
xkb_keycode_t  key,
xkb_mod_mask_t  mask 
)

Remove consumed modifiers from a modifier mask for a key.

Deprecated:
Use xkb_state_key_get_consumed_mods2() instead.

Takes the given modifier mask, and removes all modifiers which are consumed for that particular key (as in xkb_state_mod_index_is_consumed()).

Returns
a mask of real modifiers modifiers.
See also
xkb_state_mod_index_is_consumed()
Since
0.5.0: Works only with real modifiers
1.8.0: Works also with virtual modifiers

◆ xkb_state_layout_name_is_active()

XKB_EXPORT int xkb_state_layout_name_is_active ( struct xkb_state state,
const char *  name,
enum xkb_state_component  type 
)

Test whether a layout is active in a given keyboard state by name.

Returns
1 if the layout is active, 0 if it is not. If no layout with this name exists in the keymap, return -1.

If multiple layouts in the keymap have this name, the one with the lowest index is tested.

See also
xkb_layout_index_t

◆ xkb_state_layout_index_is_active()

XKB_EXPORT int xkb_state_layout_index_is_active ( struct xkb_state state,
xkb_layout_index_t  idx,
enum xkb_state_component  type 
)

Test whether a layout is active in a given keyboard state by index.

Returns
1 if the layout is active, 0 if it is not. If the layout index is not valid in the keymap, returns -1.
See also
xkb_layout_index_t

◆ xkb_state_led_name_is_active()

XKB_EXPORT int xkb_state_led_name_is_active ( struct xkb_state state,
const char *  name 
)

Test whether a LED is active in a given keyboard state by name.

Returns
1 if the LED is active, 0 if it not. If no LED with this name exists in the keymap, returns -1.
See also
xkb_led_index_t

◆ xkb_state_led_index_is_active()

XKB_EXPORT int xkb_state_led_index_is_active ( struct xkb_state state,
xkb_led_index_t  idx 
)

Test whether a LED is active in a given keyboard state by index.

Returns
1 if the LED is active, 0 if it not. If the LED index is not valid in the keymap, returns -1.
See also
xkb_led_index_t