xkb

package
v1.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package xkb binds libxkbcommon (through purego, SPEC §8.1) and turns key presses into Flutter key data: the physical key, the logical key and the text, for any keyboard layout, with dead keys and compose sequences. Wayland and X11 both use it.

Flutter: no counterpart (the embedders use GTK or the platform's own key code for this)

Index

Constants

View Source
const LibraryEnv = "GLUTTER_XKBCOMMON_LIBRARY"

LibraryEnv names the environment variable that overrides the path of libxkbcommon, for setups such as NixOS (SPEC §8.1).

View Source
const X11LibraryEnv = "GLUTTER_XKBCOMMON_X11_LIBRARY"

X11LibraryEnv names the environment variable that overrides the path of libxkbcommon-x11.

Variables

This section is empty.

Functions

func KeysymToUTF32

func KeysymToUTF32(sym Keysym) (rune, error)

KeysymToUTF32 returns the Unicode character of a keysym, or 0 when it has none (dead keys, function keys). Keysyms for control keys give the control characters: Return gives 13, BackSpace 8.

Flutter: no counterpart

func LocaleFromEnv

func LocaleFromEnv(getenv func(string) string) string

LocaleFromEnv picks the locale for the compose table the way libc does: LC_ALL, then LC_CTYPE, then LANG, then "C".

Flutter: no counterpart

Types

type Compose

type Compose struct {
	// contains filtered or unexported fields
}

Compose is the compose state for dead keys and the Compose key. A sequence such as dead_circumflex then "e" turns into "ê".

Flutter: no counterpart

func (*Compose) Close

func (c *Compose) Close()

Close releases the compose state and table. It is safe to call twice.

Flutter: no counterpart

func (*Compose) Feed

func (c *Compose) Feed(sym Keysym) ComposeStatus

Feed gives a pressed key's keysym to the sequence and returns the status after it. Modifier keysyms leave the sequence alone.

Flutter: no counterpart

func (*Compose) Reset

func (c *Compose) Reset()

Reset drops the sequence in progress.

Flutter: no counterpart

func (*Compose) Sym

func (c *Compose) Sym() Keysym

Sym returns the keysym of a completed sequence, or 0.

Flutter: no counterpart

func (*Compose) UTF8

func (c *Compose) UTF8() string

UTF8 returns the text of a completed sequence, or "".

Flutter: no counterpart

type ComposeStatus

type ComposeStatus int

ComposeStatus is the state of a compose sequence (enum xkb_compose_status).

Flutter: no counterpart

const (
	// ComposeNothing means no sequence is in progress and the key is not part of
	// one: the key's own text applies.
	//
	// Flutter: no counterpart
	ComposeNothing ComposeStatus = 0
	// Composing means a sequence is in progress; the keys produce no text yet.
	//
	// Flutter: no counterpart
	Composing ComposeStatus = 1
	// Composed means the sequence is complete; Compose.UTF8 holds the result.
	//
	// Flutter: no counterpart
	Composed ComposeStatus = 2
	// ComposeCancelled means the key did not continue the sequence, which was
	// dropped.
	//
	// Flutter: no counterpart
	ComposeCancelled ComposeStatus = 3
)

The values of ComposeStatus are those of enum xkb_compose_status.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Context is an xkb_context. Close releases it. It must outlive the keymaps made with it only until they exist: keymaps keep their own reference.

Flutter: no counterpart

func NewContext

func NewContext() (*Context, error)

NewContext opens libxkbcommon and creates a context with the default include path. It fails with XKBLoadFailed (or SymbolMissing) when the library is unusable and with XKBContextFailed when the context cannot be created.

Flutter: no counterpart

func (*Context) Close

func (c *Context) Close()

Close releases the context. It is safe to call twice.

Flutter: no counterpart

func (*Context) KeymapFromFD

func (c *Context) KeymapFromFD(fd int, size uint32) (*Keymap, error)

KeymapFromFD compiles the keymap that a compositor sends: size bytes of text in the file fd, which are read through a read-only mapping. The caller keeps ownership of fd. A trailing NUL byte is not part of the text.

Flutter: no counterpart

func (*Context) KeymapFromNames

func (c *Context) KeymapFromNames(n Names) (*Keymap, error)

KeymapFromNames compiles the keymap that the rule names select. It fails with XKBKeymapFailed when the xkb data files lack that layout.

Flutter: no counterpart

func (*Context) KeymapFromString

func (c *Context) KeymapFromString(text string) (*Keymap, error)

KeymapFromString compiles a keymap in the text format (what xkb_keymap_get_as_string and a compositor's keymap file contain).

Flutter: no counterpart

func (*Context) KeymapFromX11

func (c *Context) KeymapFromX11(conn uintptr) (*Keymap, int32, error)

KeymapFromX11 reads the keymap of the X server's core keyboard through the XKB extension, on the xcb connection (Xlib's, from XGetXCBConnection). It returns the keymap and the device id that NewStateFromX11 needs. It fails with XKBLoadFailed when libxkbcommon-x11 is missing, XKBX11SetupFailed when the server has no XKB extension or no core keyboard, and XKBKeymapFailed when the keymap cannot be read.

Flutter: no counterpart

func (*Context) NewCompose

func (c *Context) NewCompose(locale string) (*Compose, error)

NewCompose loads the compose table of the locale (such as "en_US.UTF-8") and starts a compose state. It fails with XKBComposeFailed when the locale has no table.

Flutter: no counterpart

type Key

type Key struct {
	// Physical is the id of the PhysicalKeyboardKey: the place of the key on the
	// keyboard, the same on every layout.
	Physical uint64
	// Logical is the id of the LogicalKeyboardKey: what the key means in the
	// current layout.
	Logical uint64
	// Character is the text the key press produces, or "" (for a key that makes
	// no text, and while a dead key or compose sequence is in progress).
	Character string
	// Repeats is whether holding the key produces repeats.
	Repeats bool
}

Key is a key press translated to Flutter's terms.

Flutter: no counterpart

type Keycode

type Keycode = uint32

Keycode is an XKB keycode: the evdev scancode plus 8.

Flutter: no counterpart

type Keymap

type Keymap struct {
	// contains filtered or unexported fields
}

Keymap is an xkb_keymap: the layouts of one keyboard.

Flutter: no counterpart

func (*Keymap) Close

func (k *Keymap) Close()

Close releases the keymap. It is safe to call twice.

Flutter: no counterpart

func (*Keymap) KeyRepeats

func (k *Keymap) KeyRepeats(key Keycode) bool

KeyRepeats reports whether holding the key produces repeats (modifiers do not).

Flutter: no counterpart

func (*Keymap) NewState

func (k *Keymap) NewState() (*State, error)

NewState creates the state of a keyboard with no key pressed. It fails with XKBStateFailed.

Flutter: no counterpart

func (*Keymap) NewStateFromX11

func (k *Keymap) NewStateFromX11(conn uintptr, device int32) (*State, error)

NewStateFromX11 creates the state of the X server's keyboard, with the modifiers and layout that are active now. It fails with XKBStateFailed.

Flutter: no counterpart

func (*Keymap) NumLayouts

func (k *Keymap) NumLayouts(key Keycode) uint32

NumLayouts returns the number of layouts (groups) that the key has.

Flutter: no counterpart

func (*Keymap) String

func (k *Keymap) String() string

String returns the keymap in the text format, which KeymapFromString reads back.

Flutter: no counterpart

func (*Keymap) SymAt

func (k *Keymap) SymAt(key Keycode, layout, level uint32) (Keysym, bool)

SymAt returns the keysym that the key produces in a layout at a shift level, and false when the key has none there or several (a key with several keysyms at one level is not a plain letter).

Flutter: no counterpart

type Keysym

type Keysym = uint32

Keysym is an XKB keysym, such as 0x61 for "a".

Flutter: no counterpart

func KeysymToLower

func KeysymToLower(sym Keysym) (Keysym, error)

KeysymToLower returns the lower-case keysym of a keysym, or the keysym itself when it has no case.

Flutter: no counterpart

type Layout

type Layout struct {
	// contains filtered or unexported fields
}

Layout translates evdev key presses with a keymap, its modifier state and a compose table. It is the keyboard of one seat. A Layout is used on the UI thread only.

Flutter: no counterpart (the GTK embedder's FlKeyboardManager and FlKeyEmbedderResponder do this on Linux)

func NewLayout

func NewLayout(keymap *Keymap, compose *Compose) (*Layout, error)

NewLayout makes the keyboard from a keymap and, optionally, a compose table. The Layout takes ownership of both and releases them in Close; on an error they are released at once. It fails with XKBStateFailed.

Flutter: no counterpart

func NewLayoutWithState

func NewLayoutWithState(keymap *Keymap, state *State, compose *Compose) *Layout

NewLayoutWithState is NewLayout with a state that already exists, such as one from NewStateFromX11. The Layout takes ownership of the state as well.

Flutter: no counterpart

func (*Layout) Close

func (l *Layout) Close()

Close releases the keymap, the state and the compose table.

Flutter: no counterpart

func (*Layout) Keymap

func (l *Layout) Keymap() *Keymap

Keymap returns the keymap of the layout.

Flutter: no counterpart

func (*Layout) Keysym

func (l *Layout) Keysym(evdev uint32) Keysym

Keysym returns the keysym that the key has with the modifiers and the group that apply now, without touching the compose state. An input method gets this together with XState.

Flutter: no counterpart

func (*Layout) Lookup

func (l *Layout) Lookup(evdev uint32) (Key, error)

Lookup translates a key without touching the compose state: for key releases and repeats.

Flutter: no counterpart

func (*Layout) ModActive

func (l *Layout) ModActive(name string) bool

ModActive reports whether an xkb modifier ("Shift", "Control", "Mod1", ...) is effective.

Flutter: no counterpart

func (*Layout) Press

func (l *Layout) Press(evdev uint32) (Key, error)

Press translates a key press. evdev is the scancode that the compositor sends. The character goes through the compose state, so a dead key gives no text and the key after it gives the composed character.

Flutter: no counterpart

func (*Layout) UpdateMask

func (l *Layout) UpdateMask(depressed, latched, locked, group uint32)

UpdateMask sets the modifiers and the layout group, as wl_keyboard.modifiers reports them. A pending compose sequence is not touched.

Flutter: no counterpart

func (*Layout) UpdateMaskGroups

func (l *Layout) UpdateMaskGroups(depressed, latched, locked, baseGroup, latchedGroup, lockedGroup uint32)

UpdateMaskGroups sets the modifiers and the layout group the way X11 reports them: the group in its base, latched and locked parts.

Flutter: no counterpart

func (*Layout) XState

func (l *Layout) XState() uint32

XState returns the effective modifiers as the X11 core modifier mask (Shift 1, Lock 2, Control 4, Mod1 8, Mod2 16, Mod3 32, Mod4 64, Mod5 128), which IBus and Fcitx5 take as the state of a key event.

Flutter: no counterpart

type Names

type Names struct {
	// Rules is the rules file, such as "evdev".
	Rules string
	// Model is the keyboard model, such as "pc105".
	Model string
	// Layout is the layout, or a comma-separated list of layouts, such as "de" or
	// "us,ru".
	Layout string
	// Variant is the variant of each layout, such as "nodeadkeys".
	Variant string
	// Options is a comma-separated list of options, such as "grp:alt_shift_toggle".
	Options string
}

Names selects a keymap from the xkb data files, like setxkbmap does. An empty field uses the default from the environment (XKB_DEFAULT_*) or the library.

Flutter: no counterpart

type State

type State struct {
	// contains filtered or unexported fields
}

State is an xkb_state: the keymap plus which modifiers and layout are active.

Flutter: no counterpart

func (*State) Close

func (s *State) Close()

Close releases the state. It is safe to call twice.

Flutter: no counterpart

func (*State) KeyLayout

func (s *State) KeyLayout(key Keycode) uint32

KeyLayout returns the layout (group) that applies to the key now.

Flutter: no counterpart

func (*State) KeyOneSym

func (s *State) KeyOneSym(key Keycode) Keysym

KeyOneSym returns the keysym that the key produces now, with the active modifiers and layout, or 0 when there is none or there are several.

Flutter: no counterpart

func (*State) KeyUTF8

func (s *State) KeyUTF8(key Keycode) string

KeyUTF8 returns the text that the key produces now, with the active modifiers (so Control+a gives "\x01"), or "".

Flutter: no counterpart

func (*State) ModActive

func (s *State) ModActive(name string) bool

ModActive reports whether the modifier, named as in xkb ("Shift", "Control", "Mod1" for Alt, "Lock" for Caps Lock, "Mod2" for Num Lock), is effective now.

Flutter: no counterpart

func (*State) UpdateMask

func (s *State) UpdateMask(depressed, latched, locked, group uint32)

UpdateMask sets the modifiers and layout from what the compositor sent in wl_keyboard.modifiers (depressed, latched, locked and the group). The compositor, not the client, tracks which keys are down.

Flutter: no counterpart

func (*State) UpdateMaskGroups

func (s *State) UpdateMaskGroups(depressed, latched, locked, baseGroup, latchedGroup, lockedGroup uint32)

UpdateMaskGroups is UpdateMask for a source that reports the layout group in three parts, as X11 does: the base (depressed), latched and locked group.

Flutter: no counterpart

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL