libxkbcommon  1.3.0
Data Structures | Macros | Typedefs | Enumerations | Functions
xkbcommon.h File Reference
#include <stdint.h>
#include <stdio.h>
#include <stdarg.h>
#include <xkbcommon/xkbcommon-names.h>
#include <xkbcommon/xkbcommon-keysyms.h>
#include <xkbcommon/xkbcommon-compat.h>

Data Structures

struct  xkb_rule_names


#define XKB_KEYCODE_INVALID   (0xffffffff)
#define XKB_LAYOUT_INVALID   (0xffffffff)
#define XKB_LEVEL_INVALID   (0xffffffff)
#define XKB_MOD_INVALID   (0xffffffff)
#define XKB_LED_INVALID   (0xffffffff)
#define XKB_KEYCODE_MAX   (0xffffffff - 1)
#define xkb_keycode_is_legal_ext(key)   (key <= XKB_KEYCODE_MAX)
#define xkb_keycode_is_legal_x11(key)   (key >= 8 && key <= 255)
#define XKB_KEYMAP_USE_ORIGINAL_FORMAT   ((enum xkb_keymap_format) -1)


typedef uint32_t xkb_keycode_t
typedef uint32_t xkb_keysym_t
typedef uint32_t xkb_layout_index_t
typedef uint32_t xkb_layout_mask_t
typedef uint32_t xkb_level_index_t
typedef uint32_t xkb_mod_index_t
typedef uint32_t xkb_mod_mask_t
typedef uint32_t xkb_led_index_t
typedef uint32_t xkb_led_mask_t


enum  xkb_keysym_flags {
enum  xkb_context_flags {
enum  xkb_log_level {
enum  xkb_keymap_compile_flags { XKB_KEYMAP_COMPILE_NO_FLAGS = 0 }
enum  xkb_keymap_format { XKB_KEYMAP_FORMAT_TEXT_V1 = 1 }
enum  xkb_key_direction {
enum  xkb_state_component {
  XKB_STATE_MODS_LOCKED = (1 << 2) ,
  XKB_STATE_LEDS = (1 << 8)
enum  xkb_state_match {
  XKB_STATE_MATCH_ANY = (1 << 0) ,
  XKB_STATE_MATCH_ALL = (1 << 1) ,
enum  xkb_consumed_mode {


int xkb_keysym_get_name (xkb_keysym_t keysym, char *buffer, size_t size)
xkb_keysym_t xkb_keysym_from_name (const char *name, enum xkb_keysym_flags flags)
int xkb_keysym_to_utf8 (xkb_keysym_t keysym, char *buffer, size_t size)
uint32_t xkb_keysym_to_utf32 (xkb_keysym_t keysym)
xkb_keysym_t xkb_utf32_to_keysym (uint32_t ucs)
xkb_keysym_t xkb_keysym_to_upper (xkb_keysym_t ks)
xkb_keysym_t xkb_keysym_to_lower (xkb_keysym_t ks)

Detailed Description

Main libxkbcommon API.

Macro Definition Documentation

◆ xkb_keycode_is_legal_ext

#define xkb_keycode_is_legal_ext (   key)    (key <= XKB_KEYCODE_MAX)

Test whether a value is a valid extended keycode.

See also

◆ xkb_keycode_is_legal_x11

#define xkb_keycode_is_legal_x11 (   key)    (key >= 8 && key <= 255)

Test whether a value is a valid X11 keycode.

See also

Typedef Documentation

◆ xkb_keycode_t

typedef uint32_t xkb_keycode_t

A number used to represent a physical key on a keyboard.

A standard PC-compatible keyboard might have 102 keys. An appropriate keymap would assign each of them a keycode, by which the user should refer to the key throughout the library.

Historically, the X11 protocol, and consequentially the XKB protocol, assign only 8 bits for keycodes. This limits the number of different keys that can be used simultaneously in a single keymap to 256 (disregarding other limitations). This library does not share this limit; keycodes beyond 255 ('extended keycodes') are not treated specially. Keymaps and applications which are compatible with X11 should not use these keycodes.

The values of specific keycodes are determined by the keymap and the underlying input system. For example, with an X11-compatible keymap and Linux evdev scan codes (see linux/input.h), a fixed offset is used:

The keymap defines a canonical name for each key, plus possible aliases. Historically, the XKB protocol restricts these names to at most 4 (ASCII) characters, but this library does not share this limit.

xkb_keycode_t keycode_A = KEY_A + 8;
uint32_t xkb_keycode_t
A number used to represent a physical key on a keyboard.
Definition: xkbcommon.h:134
See also
xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()

◆ xkb_keysym_t

typedef uint32_t xkb_keysym_t

A number used to represent the symbols generated from a key on a keyboard.

A key, represented by a keycode, may generate different symbols according to keyboard state. For example, on a QWERTY keyboard, pressing the key labled <A> generates the symbol 'a'. If the Shift key is held, it generates the symbol 'A'. If a different layout is used, say Greek, it generates the symbol 'α'. And so on.

Each such symbol is represented by a keysym. Note that keysyms are somewhat more general, in that they can also represent some "function", such as "Left" or "Right" for the arrow keys. For more information, see:

Specifically named keysyms can be found in the xkbcommon/xkbcommon-keysyms.h header file. Their name does not include the XKB_KEY_ prefix.

Besides those, any Unicode/ISO 10646 character in the range U0100 to U10FFFF can be represented by a keysym value in the range 0x01000100 to 0x0110FFFF. The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".

The name of other unnamed keysyms is the hexadecimal representation of their value, e.g. "0xabcd1234".

Keysym names are case-sensitive.

◆ xkb_layout_index_t

typedef uint32_t xkb_layout_index_t

Index of a keyboard layout.

The layout index is a state component which detemines which keyboard layout is active. These may be different alphabets, different key arrangements, etc.

Layout indices are consecutive. The first layout has index 0.

Each layout is not required to have a name, and the names are not guaranteed to be unique (though they are usually provided and unique). Therefore, it is not safe to use the name as a unique identifier for a layout. Layout names are case-sensitive.

Layout names are specified in the layout's definition, for example "English (US)". These are different from the (conventionally) short names which are used to locate the layout, for example "us" or "us(intl)". These names are not present in a compiled keymap.

If the user selects layouts from a list generated from the XKB registry (using libxkbregistry or directly), and this metadata is needed later on, it is recommended to store it along with the keymap.

Layouts are also called "groups" by XKB.

See also
xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()

◆ xkb_level_index_t

typedef uint32_t xkb_level_index_t

Index of a shift level.

Any key, in any layout, can have several shift levels. Each shift level can assign different keysyms to the key. The shift level to use is chosen according to the current keyboard state; for example, if no keys are pressed, the first level may be used; if the Left Shift key is pressed, the second; if Num Lock is pressed, the third; and many such combinations are possible (see xkb_mod_index_t).

Level indices are consecutive. The first level has index 0.

◆ xkb_mod_index_t

typedef uint32_t xkb_mod_index_t

Index of a modifier.

A modifier is a state component which changes the way keys are interpreted. A keymap defines a set of modifiers, such as Alt, Shift, Num Lock or Meta, and specifies which keys may activate which modifiers (in a many-to-many relationship, i.e. a key can activate several modifiers, and a modifier may be activated by several keys. Different keymaps do this differently).

When retrieving the keysyms for a key, the active modifier set is consulted; this detemines the correct shift level to use within the currently active layout (see xkb_level_index_t).

Modifier indices are consecutive. The first modifier has index 0.

Each modifier must have a name, and the names are unique. Therefore, it is safe to use the name as a unique identifier for a modifier. The names of some common modifiers are provided in the xkbcommon/xkbcommon-names.h header file. Modifier names are case-sensitive.

See also

◆ xkb_led_index_t

typedef uint32_t xkb_led_index_t

Index of a keyboard LED.

LEDs are logical objects which may be active or inactive. They typically correspond to the lights on the keyboard. Their state is determined by the current keyboard state.

LED indices are non-consecutive. The first LED has index 0.

Each LED must have a name, and the names are unique. Therefore, it is safe to use the name as a unique identifier for a LED. The names of some common LEDs are provided in the xkbcommon/xkbcommon-names.h header file. LED names are case-sensitive.

A given keymap may specify an exact index for a given LED. Therefore, LED indexing is not necessarily sequential, as opposed to modifiers and layouts. This means that when iterating over the LEDs in a keymap using e.g. xkb_keymap_num_leds(), some indices might be invalid. Given such an index, functions like xkb_keymap_led_get_name() will return NULL, and xkb_state_led_index_is_active() will return -1.

LEDs are also called "indicators" by XKB.

See also