Skip to content

xkb ​

Package xkb is the XKB keyboard model in pure Go: keymap compilation from rules and text, the key state machine, keysyms and Compose. Package xkb/registry lists what a ruleset offers. Package xkb/x11 is the small X11 client that xkb.SetupX11 can read keymaps through.

It follows libxkbcommon 1.13, whose sources (MIT) it was written against, and differential tests hold it to that library: every layout, variant, option and model evdev.xml and evdev.extras.xml offer, in both keymap formats, with key events, masks and latches driven through both.

Keymap formats ​

FormatTextV1 is the classic format, at most 4 layouts. FormatTextV2 adds up to 32 layouts, several actions per level, canonical virtual modifiers and the unlockOnPress, latchOnPress and lockOnRelease action fields, and a latch survives a key that does not break it while the latching key is held.

NewKeymapFromNames compiles in FormatTextV2, as xkb_keymap_new_from_names does. NewKeymapFromString parses in FormatTextV1, what a client should use for the keymap a compositor sends. Keymap.Text is always FormatTextV1, what a compositor should send: anything the format cannot express degrades and logs an error. Use Keymap.AsString to choose.

Differences from libxkbcommon ​

These are deliberate, and each one is tested:

  • There is no reference counting. ref and unref have no equivalent, and the garbage collector frees everything. Nothing holds an operating system resource.
  • A variadic C function takes a Go variadic parameter.
  • A file included several times is parsed once, so the warnings its parser logs appear once. Every other message is logged as many times as libxkbcommon logs it, with the same level and [XKB-NNN] code.
  • One failure logs its codes in one chain rather than a line of context each, so error codes match libxkbcommon by presence and warnings by count. Messages are worded like libxkbcommon's without being byte for byte equal: masks print as numbers, and an error carries the same detail in the returned error value.
  • An environment variable set to the empty string counts as unset.
  • On a system with neither glibc locale data nor musl, a locale other than C and POSIX counts as not installed, as glibc's newlocale reports it.
  • xkb_x11_keymap_new_from_device takes an xcb_connection_t. Here the connection is the X11Conn interface, so this package links no X client library: xkb/x11 implements it, and any other connection can.

Function coverage ​

libxkbcommonGo
xkb_context_newNewContext, NewContextFlags
xkb_context_ref, xkb_context_unrefgarbage collected
xkb_context_get_user_data, xkb_context_set_user_dataContext.UserData, Context.SetUserData
xkb_context_include_path_appendContext.AppendIncludePath
xkb_context_include_path_append_defaultContext.AppendDefaultIncludePaths
xkb_context_include_path_reset_defaultsContext.ResetDefaultIncludePaths
xkb_context_include_path_clearContext.ClearIncludePaths
xkb_context_num_include_pathsContext.NumIncludePaths
xkb_context_include_path_getContext.IncludePath, Context.IncludePaths
xkb_context_set_log_level, xkb_context_get_log_levelContext.SetLogLevel, Context.LogLevel
xkb_context_set_log_verbosity, xkb_context_get_log_verbosityContext.SetLogVerbosity, Context.LogVerbosity
xkb_context_set_log_fnContext.SetLogFunc
xkb_components_names_from_rulesContext.ComponentsFromNames
xkb_keymap_new_from_namesContext.NewKeymapFromNames
xkb_keymap_new_from_names2Context.NewKeymapFromNamesFormat
xkb_keymap_new_from_rmlvoRMLVOBuilder.NewKeymap
xkb_keymap_new_from_stringContext.NewKeymapFromString, Context.NewKeymapFromBuffer
xkb_keymap_new_from_bufferContext.NewKeymapFromBuffer
xkb_keymap_new_from_fileContext.NewKeymapFromFile
xkb_keymap_ref, xkb_keymap_unrefgarbage collected
xkb_keymap_get_as_string, xkb_keymap_get_as_string2Keymap.AsString, Keymap.Text
xkb_keymap_min_keycode, xkb_keymap_max_keycodeKeymap.MinKeycode, Keymap.MaxKeycode
xkb_keymap_key_for_eachKeymap.KeyForEach
xkb_keymap_key_get_name, xkb_keymap_key_by_nameKeymap.KeyGetName, Keymap.KeyByName
xkb_keymap_num_mods, xkb_keymap_mod_get_name, xkb_keymap_mod_get_indexKeymap.NumMods, Keymap.ModName, Keymap.ModIndex
xkb_keymap_mod_get_mask, xkb_keymap_mod_get_mask2Keymap.ModMaskOf, Keymap.ModMaskOfIndex
xkb_keymap_num_layouts, xkb_keymap_layout_get_name, xkb_keymap_layout_get_indexKeymap.NumLayouts, Keymap.LayoutName, Keymap.LayoutIndex
xkb_keymap_num_leds, xkb_keymap_led_get_name, xkb_keymap_led_get_indexKeymap.NumLEDs, Keymap.LEDName, Keymap.LEDIndex
xkb_keymap_num_layouts_for_key, xkb_keymap_num_levels_for_keyKeymap.NumLayoutsForKey, Keymap.NumLevels
xkb_keymap_key_get_mods_for_levelKeymap.KeyGetModsForLevel
xkb_keymap_key_get_syms_by_levelKeymap.KeySymsByLevel
xkb_keymap_key_repeatsKeymap.KeyRepeats
xkb_keycode_is_legal_ext, xkb_keycode_is_legal_x11KeycodeIsLegalExt, KeycodeIsLegalX11
xkb_keysym_get_name, xkb_keysym_from_nameKeysymGetName, KeysymFromName
xkb_keysym_to_utf8, xkb_keysym_to_utf32, xkb_utf32_to_keysymKeysymToUTF8, KeysymToUTF32, UTF32ToKeysym
xkb_keysym_to_upper, xkb_keysym_to_lowerKeysymToUpper, KeysymToLower
xkb_rmlvo_builder_newContext.NewRMLVOBuilder
xkb_rmlvo_builder_append_layout, xkb_rmlvo_builder_append_optionRMLVOBuilder.AppendLayout, RMLVOBuilder.AppendOption
xkb_rmlvo_builder_ref, xkb_rmlvo_builder_unrefgarbage collected
xkb_state_new, xkb_state_get_keymapKeymap.NewState, State.Keymap
xkb_state_ref, xkb_state_unrefgarbage collected
xkb_state_update_key, xkb_state_update_mask, xkb_state_update_latched_lockedState.UpdateKey, State.UpdateMask, State.UpdateLatchedLocked
xkb_state_key_get_syms, xkb_state_key_get_one_symState.KeyGetSyms, State.KeyGetOneSym
xkb_state_key_get_utf8, xkb_state_key_get_utf32State.KeyGetUTF8, State.AppendKeyUTF8, State.KeyGetUTF32
xkb_state_key_get_layout, xkb_state_key_get_levelState.KeyGetLayout, State.KeyGetLevel
xkb_state_serialize_mods, xkb_state_serialize_layoutState.SerializeMods, State.SerializeLayout
xkb_state_mod_name_is_active, xkb_state_mod_index_is_activeState.ModNameIsActive, State.ModIndexIsActive
xkb_state_mod_names_are_active, xkb_state_mod_indices_are_activeState.ModNamesAreActive, State.ModIndicesAreActive
xkb_state_layout_name_is_active, xkb_state_layout_index_is_activeState.LayoutNameIsActive, State.LayoutIndexIsActive
xkb_state_led_name_is_active, xkb_state_led_index_is_activeState.LEDNameIsActive, State.LEDIndexIsActive
xkb_state_key_get_consumed_mods, xkb_state_key_get_consumed_mods2State.KeyGetConsumedMods
xkb_state_mod_index_is_consumed, xkb_state_mod_index_is_consumed2State.ModIndexIsConsumed
xkb_state_mod_mask_remove_consumedState.ModMaskRemoveConsumed
xkb_compose_table_new_from_locale, xkb_compose_table_new_from_bufferContext.NewComposeTableFromLocale, Context.NewComposeTableFromBuffer
xkb_compose_table_new_from_fileContext.NewComposeTableFromFile, Context.NewComposeTableFromReader
xkb_compose_table_ref, xkb_compose_table_unrefgarbage collected
xkb_compose_table_iterator_new, xkb_compose_table_iterator_next, xkb_compose_table_iterator_freeComposeTable.Entries
xkb_compose_table_entry_sequence, xkb_compose_table_entry_keysym, xkb_compose_table_entry_utf8ComposeEntry
xkb_compose_state_new, xkb_compose_state_get_compose_tableComposeTable.NewState, ComposeState.Table
xkb_compose_state_ref, xkb_compose_state_unrefgarbage collected
xkb_compose_state_feed, xkb_compose_state_resetComposeState.Feed, ComposeState.Reset
xkb_compose_state_get_status, xkb_compose_state_get_utf8, xkb_compose_state_get_one_symComposeState.Status, ComposeState.UTF8, ComposeState.OneSym
xkb_x11_setup_xkb_extensionSetupX11
xkb_x11_get_core_keyboard_device_idX11.CoreKeyboardDeviceID
xkb_x11_keymap_new_from_device, xkb_x11_state_new_from_deviceX11.NewKeymapFromDevice, X11.NewStateFromDevice
rxkb_context_new, rxkb_context_ref, rxkb_context_unrefregistry.NewContext, garbage collected
rxkb_context_set_log_fn, rxkb_context_set_log_level, rxkb_context_get_log_levelContext.SetLogFunc, Context.SetLogLevel, Context.LogLevel
rxkb_context_set_user_data, rxkb_context_get_user_dataContext.SetUserData, Context.UserData
rxkb_context_include_path_append, rxkb_context_include_path_append_defaultContext.AppendIncludePath, Context.AppendDefaultIncludePaths
rxkb_context_parse, rxkb_context_parse_default_rulesetContext.Parse, Context.ParseDefaultRuleset
rxkb_model_first, rxkb_model_nextContext.Models
rxkb_model_get_name, rxkb_model_get_description, rxkb_model_get_vendor, rxkb_model_get_popularityModel fields
rxkb_model_ref, rxkb_model_unrefgarbage collected
rxkb_layout_first, rxkb_layout_nextContext.Layouts
rxkb_layout_get_name, rxkb_layout_get_variant, rxkb_layout_get_brief, rxkb_layout_get_description, rxkb_layout_get_popularityLayout fields
rxkb_layout_get_iso639_first, rxkb_iso639_code_next, rxkb_iso639_code_get_codeLayout.ISO639
rxkb_layout_get_iso3166_first, rxkb_iso3166_code_next, rxkb_iso3166_code_get_codeLayout.ISO3166
rxkb_layout_ref, rxkb_layout_unref, rxkb_iso639_code_ref, rxkb_iso639_code_unref, rxkb_iso3166_code_ref, rxkb_iso3166_code_unrefgarbage collected
rxkb_option_group_first, rxkb_option_group_nextContext.OptionGroups
rxkb_option_group_get_name, rxkb_option_group_get_description, rxkb_option_group_get_popularity, rxkb_option_group_allows_multipleOptionGroup fields
rxkb_option_group_ref, rxkb_option_group_unrefgarbage collected
rxkb_option_first, rxkb_option_nextOptionGroup.Options
rxkb_option_get_name, rxkb_option_get_brief, rxkb_option_get_description, rxkb_option_get_popularity, rxkb_option_is_layout_specificOption fields
rxkb_option_ref, rxkb_option_unrefgarbage collected

Released under the MIT License.