libxkbcommon 1.7.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>
Include dependency graph for xkbcommon.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  xkb_rule_names
 

Macros

#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_KEYSYM_MAX   0x1fffffff
 
#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)
 

Typedefs

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
 

Enumerations

enum  xkb_keysym_flags {
  XKB_KEYSYM_NO_FLAGS = 0 ,
  XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
}
 
enum  xkb_context_flags {
  XKB_CONTEXT_NO_FLAGS = 0 ,
  XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0) ,
  XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1) ,
  XKB_CONTEXT_NO_SECURE_GETENV = (1 << 2)
}
 
enum  xkb_log_level {
  XKB_LOG_LEVEL_CRITICAL = 10 ,
  XKB_LOG_LEVEL_ERROR = 20 ,
  XKB_LOG_LEVEL_WARNING = 30 ,
  XKB_LOG_LEVEL_INFO = 40 ,
  XKB_LOG_LEVEL_DEBUG = 50
}
 
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 {
  XKB_KEY_UP ,
  XKB_KEY_DOWN
}
 
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)
}
 
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

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_t

◆ 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
xkb_keycode_t

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:165
See also
xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()

◆ 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_keymap_num_mods()

◆ 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.

Warning
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
xkb_keymap_num_leds()