libxkbcommon 1.7.0
|
Data Structures | |
struct | xkb_compose_table |
struct | xkb_compose_state |
struct | xkb_compose_table_entry |
struct | xkb_compose_table_iterator |
Enumerations | |
enum | xkb_compose_compile_flags { XKB_COMPOSE_COMPILE_NO_FLAGS = 0 } |
enum | xkb_compose_format { XKB_COMPOSE_FORMAT_TEXT_V1 = 1 } |
enum | xkb_compose_state_flags { XKB_COMPOSE_STATE_NO_FLAGS = 0 } |
enum | xkb_compose_status { XKB_COMPOSE_NOTHING , XKB_COMPOSE_COMPOSING , XKB_COMPOSE_COMPOSED , XKB_COMPOSE_CANCELLED } |
enum | xkb_compose_feed_result { XKB_COMPOSE_FEED_IGNORED , XKB_COMPOSE_FEED_ACCEPTED } |
Support for Compose and dead-keys.
Compose and dead-keys are a common feature of many keyboard input systems. They extend the range of the keysysm that can be produced directly from a keyboard by using a sequence of key strokes, instead of just one.
Here are some example sequences, in the libX11 Compose file format:
<dead_acute> <a> : "á" aacute # LATIN SMALL LETTER A WITH ACUTE <Multi_key> <A> <T> : "@" at # COMMERCIAL AT
When the user presses a key which produces the <dead_acute>
keysym, nothing initially happens (thus the key is dubbed a "dead-key"). But when the user enters <a>
, "á" is "composed", in place of "a". If instead the user had entered a keysym which does not follow <dead_acute>
in any compose sequence, the sequence is said to be "cancelled".
Compose files define many such sequences. For a description of the common file format for Compose files, see the Compose(5) man page.
A successfuly-composed sequence has two results: a keysym and a UTF-8 string. At least one of the two is defined for each sequence. If only a keysym is given, the keysym's string representation is used for the result string (using xkb_keysym_to_utf8()).
This library provides low-level support for Compose file parsing and processing. Higher-level APIs (such as libX11's Xutf8LookupString
(3)) may be built upon it, or it can be used directly.
To avoid ambiguity, a sequence is not allowed to be a prefix of another. In such a case, the conflict is resolved thus:
Sequences of length 1 are allowed.
What should happen when a sequence is cancelled? For example, consider there are only the above sequences, and the input keysyms are <dead_acute> <b>
. There are a few approaches:
<b>
is produced.<dead_acute> <b>
is produced. This is the approach taken by Microsoft Windows (approximately; instead of <dead_acute>
, the underlying key is used. This is difficult to simulate with XKB keymaps).You can program whichever approach best fits users' expectations.
Compose files are locale dependent:
As such, functions like xkb_compose_table_new_from_locale() require a locale
parameter. This will usually be the current locale (see locale(7) for more details). You may also want to allow the user to explicitly configure it, so he can use the Compose file of a given locale, but not use that locale for other things.
You may query the current locale as follows:
This will only give useful results if the program had previously set the current locale using setlocale(3), with LC_CTYPE
or LC_ALL
and a non-NULL argument.
If you prefer not to use the locale system of the C runtime library, you may nevertheless obtain the user's locale directly using environment variables, as described in locale(7). For example,
Note that some locales supported by the C standard library may not have a Compose file assigned.
enum xkb_compose_format |
enum xkb_compose_status |
Status of the Compose sequence state machine.
struct xkb_compose_table * xkb_compose_table_new_from_locale | ( | struct xkb_context * | context, |
const char * | locale, | ||
enum xkb_compose_compile_flags | flags ) |
Create a compose table for a given locale.
The locale is used for searching the file-system for an appropriate Compose file. The search order is described in Compose(5). It is affected by the following environment variables:
XCOMPOSEFILE
- see Compose(5).XDG_CONFIG_HOME
- before $HOME/.XCompose
is checked, $XDG_CONFIG_HOME/XCompose
is checked (with a fall back to $HOME/.config/XCompose
if XDG_CONFIG_HOME
is not defined). This is a libxkbcommon extension to the search procedure in Compose(5) (since libxkbcommon 1.0.0). Note that other implementations, such as libX11, might not find a Compose file in this path.HOME
- see Compose(5).XLOCALEDIR
- if set, used as the base directory for the system's X locale files, e.g. /usr/share/X11/locale
, instead of the preconfigured directory.context | The library context in which to create the compose table. |
locale | The current locale. See Compose Locale. The value is copied, so it is safe to pass the result of getenv(3) (or similar) without fear of it being invalidated by a subsequent setenv(3) (or similar). |
flags | Optional flags for the compose table, or 0. |
struct xkb_compose_table * xkb_compose_table_new_from_file | ( | struct xkb_context * | context, |
FILE * | file, | ||
const char * | locale, | ||
enum xkb_compose_format | format, | ||
enum xkb_compose_compile_flags | flags ) |
Create a new compose table from a Compose file.
context | The library context in which to create the compose table. |
file | The Compose file to compile. |
locale | The current locale. See Compose Locale. |
format | The text format of the Compose file to compile. |
flags | Optional flags for the compose table, or 0. |
struct xkb_compose_table * xkb_compose_table_new_from_buffer | ( | struct xkb_context * | context, |
const char * | buffer, | ||
size_t | length, | ||
const char * | locale, | ||
enum xkb_compose_format | format, | ||
enum xkb_compose_compile_flags | flags ) |
Create a new compose table from a memory buffer.
This is just like xkb_compose_table_new_from_file(), but instead of a file, gets the table as one enormous string.
struct xkb_compose_table * xkb_compose_table_ref | ( | struct xkb_compose_table * | table | ) |
Take a new reference on a compose table.
void xkb_compose_table_unref | ( | struct xkb_compose_table * | table | ) |
Release a reference on a compose table, and possibly free it.
table | The object. If it is NULL, this function does nothing. |
const xkb_keysym_t * xkb_compose_table_entry_sequence | ( | struct xkb_compose_table_entry * | entry, |
size_t * | sequence_length ) |
Get the left-hand keysym sequence of a Compose table entry.
For example, given the following entry:
it will return {XKB_KEY_dead_tilde, XKB_KEY_space}
.
[in] | entry | The compose table entry object to process. |
[out] | sequence_length | Number of keysyms in the sequence. |
sequence_length
out-parameter.xkb_keysym_t xkb_compose_table_entry_keysym | ( | struct xkb_compose_table_entry * | entry | ) |
Get the right-hand result keysym of a Compose table entry.
For example, given the following entry:
it will return XKB_KEY_asciitilde
.
The keysym is optional; if the entry does not specify a keysym, returns XKB_KEY_NoSymbol
.
const char * xkb_compose_table_entry_utf8 | ( | struct xkb_compose_table_entry * | entry | ) |
Get the right-hand result string of a Compose table entry.
The string is UTF-8 encoded and NULL-terminated.
For example, given the following entry:
it will return "~"
.
The string is optional; if the entry does not specify a string, returns the empty string.
struct xkb_compose_table_iterator * xkb_compose_table_iterator_new | ( | struct xkb_compose_table * | table | ) |
Create a new iterator for a compose table.
Intended use:
NULL
on failure.void xkb_compose_table_iterator_free | ( | struct xkb_compose_table_iterator * | iter | ) |
Free a compose iterator.
struct xkb_compose_table_entry * xkb_compose_table_iterator_next | ( | struct xkb_compose_table_iterator * | iter | ) |
Get the next compose entry from a compose table iterator.
The entries are returned in lexicographic order of the left-hand side of entries. This does not correspond to the order in which the entries appear in the Compose file.
Returns NULL
in case there is no more entries.
struct xkb_compose_state * xkb_compose_state_new | ( | struct xkb_compose_table * | table, |
enum xkb_compose_state_flags | flags ) |
Create a new compose state object.
table | The compose table the state will use. |
flags | Optional flags for the compose state, or 0. |
struct xkb_compose_state * xkb_compose_state_ref | ( | struct xkb_compose_state * | state | ) |
Take a new reference on a compose state object.
void xkb_compose_state_unref | ( | struct xkb_compose_state * | state | ) |
Release a reference on a compose state object, and possibly free it.
state | The object. If NULL, do nothing. |
struct xkb_compose_table * xkb_compose_state_get_compose_table | ( | struct xkb_compose_state * | state | ) |
Get the compose table which a compose state object is using.
This function does not take a new reference on the compose table; you must explicitly reference it yourself if you plan to use it beyond the lifetime of the state.
enum xkb_compose_feed_result xkb_compose_state_feed | ( | struct xkb_compose_state * | state, |
xkb_keysym_t | keysym ) |
Feed one keysym to the Compose sequence state machine.
This function can advance into a compose sequence, cancel a sequence, start a new sequence, or do nothing in particular. The resulting status may be observed with xkb_compose_state_get_status().
Some keysyms, such as keysyms for modifier keys, are ignored - they have no effect on the status or otherwise.
The following is a description of the possible status transitions, in the format CURRENT STATUS => NEXT STATUS, given a non-ignored input keysym keysym
:
NOTHING or CANCELLED or COMPOSED => NOTHING if keysym does not start a sequence. COMPOSING if keysym starts a sequence. COMPOSED if keysym starts and terminates a single-keysym sequence. COMPOSING => COMPOSING if keysym advances any of the currently possible sequences but does not terminate any of them. COMPOSED if keysym terminates one of the currently possible sequences. CANCELLED if keysym does not advance any of the currently possible sequences.
The current Compose formats do not support multiple-keysyms. Therefore, if you are using a function such as xkb_state_key_get_syms() and it returns more than one keysym, consider feeding XKB_KEY_NoSymbol instead.
state | The compose state object. |
keysym | A keysym, usually obtained after a key-press event, with a function such as xkb_state_key_get_one_sym(). |
void xkb_compose_state_reset | ( | struct xkb_compose_state * | state | ) |
Reset the Compose sequence state machine.
The status is set to XKB_COMPOSE_NOTHING, and the current sequence is discarded.
enum xkb_compose_status xkb_compose_state_get_status | ( | struct xkb_compose_state * | state | ) |
Get the current status of the compose state machine.
int xkb_compose_state_get_utf8 | ( | struct xkb_compose_state * | state, |
char * | buffer, | ||
size_t | size ) |
Get the result Unicode/UTF-8 string for a composed sequence.
See Overview for more details. This function is only useful when the status is XKB_COMPOSE_COMPOSED.
[in] | state | The compose state. |
[out] | buffer | A buffer to write the string into. |
[in] | size | Size of the buffer. |
buffer
to the empty string (if possible). buffer
, similarly to the snprintf
(3) function. You may safely pass NULL and 0 to buffer
and size
to find the required size (without the NUL-byte). xkb_keysym_t xkb_compose_state_get_one_sym | ( | struct xkb_compose_state * | state | ) |
Get the result keysym for a composed sequence.
See Overview for more details. This function is only useful when the status is XKB_COMPOSE_COMPOSED.