spiegel-keyman/core/docs/api/background.md
Eberhard Beilharz f30e3fbd95
docs(core): update generated files
This change updates the documentation files that get generated out of
the the content in the source files. These files showed up as changed
when building.

Build-bot: skip
Test-bot: skip
2026-04-23 16:39:25 +02:00

14 KiB
Raw Blame History

title
Background - Keyman Core API

Namespace

All calls, types and enums are prefixed with the namespace identifier km_core_

API idioms

Error Handling

Error handling and success failure notification are communicated through a general mechanism similar to COMs HRESULT scheme (unlike COM, any non-zero value is an error). Any functions that can fail will always return a status value and all results are returned via outparams passed to the function.

Passing variable length data out

Almost all calls marshalling variable length aggregate data in or out of an API object take the form:

km_core_status fn_name(object_ref, buffer_ptr, size_ptr)

where the buffer_ptr is nullable and all other arguments are required (will result in an KM_CORE_STATUS_INVALID_ARGUMENT status being returned if nulled). When buffer_ptr is nullptr or 0 the function will place the size of the required buffer in the variable pointed to by size_ptr.

Resource management

Calls which result in the allocation of resources, regardless of resulting ownership, are of the form:

km_core_status fn_name(object_ref, handle_out_ptr)

where handle_out_ptr is a valid pointer to a caller allocated variable to hold the resulting resource handle. This is often a reference to a created object. Unless stated all arguments are required (will result in an KM_CORE_STATUS_INVALID_ARGUMENT status being returned if nulled).

All dispose calls are designed to accept nullptr or 0 as a valid value and will do nothing in that event.

Fixed size attribute access

For accessors to fixed size attributes of an object these will take the form:

attr_value fn_name(object_ref)

object_ref is required to be valid and will result in a nonsense value being returned if nullptr or 0.

Versioning scheme

This follows the libtool interface versioning scheme of current.age.revision:

current

The most recent interface number that the engine implements.

age

How many interface numbers back from current the library implements. E.g. 5.2.0 would mean the library provides interface versions 3-5 and 5.0.0 would mean just interface version 5 and nothing older.

revision

The implementation version of the current interface. This represents improvements to the code that don't change the intended behaviour of the interface such as bug fixes and optimisations.

For Linux and other OS which support this scheme the dynamic linker will automatically choose the most updated version if more than one implementation is available. For Windows or dynamic loaded shared objects on Linux you can use the [km_core_get_engine_attrs] call and Library version macros to check the loaded DLL supplies the correct interface.


Common functions, types, and macros

Basic types

Fundamental types for representing data passed across the API.

km_core_cu type

uint16_t/char16_t

Represents a UTF16 codepoint, most strings are passed as UTF16.

km_core_usv type

uint32_t/char32_t

An integral type capable of holding a single Unicode Scalar Value, a decoded UTF codepoint.

km_core_virtual_key type

uint16_t

An integral type capable of holding a platform specific virtual key code.

km_core_status type

uint32_t

An integral 32 bit wide type capable of holding any valid status code as defined by the enum [km_core_status_codes].

km_core_modifier_state type

uint16_t

An integral type bitmask representing the state of each modifier key.

Resource types

Opaque types for representing resources provided or created by the keyboard processor implementation.

km_core_keyboard struct

Represents a keyboard loaded from disk, that can be executed by the keyboard processor to consume events, update state associated with an insertion point and produce action items. A keyboard object may be referenced by any number of state objects but must be disposed of after all state objects referencing it have first been disposed of.

km_core_state struct

Represents all state associated with an insertion point using a keyboard. This tracks context, and current action items resulting from a processed keyboard event. There can be many state objects using the same keyboard. A state object may not live longer than the keyboard it manages state for.

km_core_options struct

Represents a set of option items for environmental state and keyboard state.


km_core_status_codes enum

Description

An error code mechanism similar to COM's HRESULT scheme (unlike COM, any non-zero value is an error).

Specification

--> // keep in sync with web/src/engine/src/core-adapter/KM_Core.ts // (see https://github.com/emscripten-core/emscripten/issues/18585)