xkbcommon 1.14.0-beta2
Reference library implementing the XKB specification for parsing keyboard descriptions and handling keyboard state
Loading...
Searching...
No Matches
Modules | Enumerations
Keyboard State
Collaboration diagram for Keyboard State:

Modules

 Events
 
 Keyboard server state machine
 
 Keyboard state objects
 

Enumerations

enum  xkb_key_direction {
  XKB_KEY_UP ,
  XKB_KEY_DOWN ,
  XKB_KEY_REPEATED
}
 
enum  xkb_state_component {
  XKB_STATE_NO_COMPONENT = 0 ,
  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_EFFECTIVE = (1 << 12)
}
 
enum  xkb_keyboard_control_flags {
  XKB_KEYBOARD_CONTROL_NO_FLAGS = 0 ,
  XKB_KEYBOARD_CONTROL_A11Y_STICKY_KEYS = (1 << 0) ,
  XKB_KEYBOARD_CONTROL_MOUSE_KEYS = (1 << 1)
}
 

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_machine: the server API

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

xkb_machine is a Mealy machine‌: it is a finite-state machine that takes a stream of raw key events – a pair (keycode, direction) – as input, and produces a stream of atomic XKB events as output.

The observable state of the machine is exposed via a companion xkb_state object:

Note that the xkb_machine API supports events other than state components changes, such as key press/release events, so that it enables handling 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.

Client applications
Create the state object with xkb_state::xkb_state_new_with_mode() using XKB_STATE_MODE_CLIENT, then update it via xkb_state::xkb_state_update_mask() from server serializations.
Server applications not using xkb_machine
Create the state object with xkb_state::xkb_state_new_with_mode() using XKB_STATE_MODE_SERVER, or with the legacy xkb_state::xkb_state_new() constructor, then update it via xkb_state::xkb_state_update_key() for key events and xkb_state::xkb_state_update_synthetic() for out-of-band inputs such as layout switchers.
Warning
Some entry points in the xkb_state API are only meant for servers and some are only meant for clients. Thus it is recommended to use xkb_state::xkb_state_new_with_mode() because it enforces correct usage at runtime and logs misuse as XKB_ERROR_UNEXPECTED_STATE_MODE. Using xkb_state::xkb_state_new() does not enforce this: mixing entry points may lead to incorrect state.
Note
Since version 1.14.0, server applications should use the xkb_machine API, which supports more features.

See the examples for clients in the quick guide.

Enumeration Type Documentation

◆ xkb_key_direction

Specifies the direction of the key (press / release) or a repetition.

Enumerator
XKB_KEY_UP 

The key was released.

XKB_KEY_DOWN 

The key was pressed.

XKB_KEY_REPEATED 

The key was repeated.

This should be used by the compositor only if it handles key repetition itself.

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.

Remarks
Values 0x200..0x800 are reserved for future use.
Enumerator
XKB_STATE_NO_COMPONENT 

Represents the empty set of state components.

This is the identity value for state component bitmask operations. It corresponds also to the result of updates operation when the state components remain unchanged.

Since
1.14.0
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 

Effective keyboard controls.

Since
1.14.0

◆ xkb_keyboard_control_flags

Boolean global keyboard controls, which affect the way xkbcommon handles the keyboard as a whole.

This enumeration is bit-maskable.

Since
1.14.0
Enumerator
XKB_KEYBOARD_CONTROL_NO_FLAGS 

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_A11Y_STICKY_KEYS_LATCH_TO_LOCK
Since
1.14.0
XKB_KEYBOARD_CONTROL_MOUSE_KEYS 

Enable mouse keys for controlling the mouse functions from the keyboard.

When mouse keys are enabled, all keys with pointer actions bound to them generate pointer events instead of normal key press and release events.

Since
1.14.0