Path: blob/master/thirdparty/linuxbsd_headers/xkbcommon/xkbcommon.h
9903 views
/*1* Copyright 1985, 1987, 1990, 1998 The Open Group2* Copyright 2008 Dan Nicholson3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice shall be included in12* all copies or substantial portions of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE17* AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN18* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN19* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.20*21* Except as contained in this notice, the names of the authors or their22* institutions shall not be used in advertising or otherwise to promote the23* sale, use or other dealings in this Software without prior written24* authorization from the authors.25*/2627/************************************************************28* Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.29*30* Permission to use, copy, modify, and distribute this31* software and its documentation for any purpose and without32* fee is hereby granted, provided that the above copyright33* notice appear in all copies and that both that copyright34* notice and this permission notice appear in supporting35* documentation, and that the name of Silicon Graphics not be36* used in advertising or publicity pertaining to distribution37* of the software without specific prior written permission.38* Silicon Graphics makes no representation about the suitability39* of this software for any purpose. It is provided "as is"40* without any express or implied warranty.41*42* SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS43* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY44* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON45* GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL46* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,47* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE48* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH49* THE USE OR PERFORMANCE OF THIS SOFTWARE.50*51********************************************************/5253/*54* Copyright © 2009-2012 Daniel Stone55* Copyright © 2012 Intel Corporation56* Copyright © 2012 Ran Benita57*58* Permission is hereby granted, free of charge, to any person obtaining a59* copy of this software and associated documentation files (the "Software"),60* to deal in the Software without restriction, including without limitation61* the rights to use, copy, modify, merge, publish, distribute, sublicense,62* and/or sell copies of the Software, and to permit persons to whom the63* Software is furnished to do so, subject to the following conditions:64*65* The above copyright notice and this permission notice (including the next66* paragraph) shall be included in all copies or substantial portions of the67* Software.68*69* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR70* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,71* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL72* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER73* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING74* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER75* DEALINGS IN THE SOFTWARE.76*77* Author: Daniel Stone <[email protected]>78*/7980#ifndef _XKBCOMMON_H_81#define _XKBCOMMON_H_8283#include <stdint.h>84#include <stdio.h>85#include <stdarg.h>8687#include <xkbcommon/xkbcommon-names.h>88#include <xkbcommon/xkbcommon-keysyms.h>8990#ifdef __cplusplus91extern "C" {92#endif9394/**95* @file96* Main libxkbcommon API.97*/9899/**100* @struct xkb_context101* Opaque top level library context object.102*103* The context contains various general library data and state, like104* logging level and include paths.105*106* Objects are created in a specific context, and multiple contexts may107* coexist simultaneously. Objects from different contexts are completely108* separated and do not share any memory or state.109*/110struct xkb_context;111112/**113* @struct xkb_keymap114* Opaque compiled keymap object.115*116* The keymap object holds all of the static keyboard information obtained117* from compiling XKB files.118*119* A keymap is immutable after it is created (besides reference counts, etc.);120* if you need to change it, you must create a new one.121*/122struct xkb_keymap;123124/**125* @struct xkb_state126* Opaque keyboard state object.127*128* State objects contain the active state of a keyboard (or keyboards), such129* as the currently effective layout and the active modifiers. It acts as a130* simple state machine, wherein key presses and releases are the input, and131* key symbols (keysyms) are the output.132*/133struct xkb_state;134135/**136* A number used to represent a physical key on a keyboard.137*138* A standard PC-compatible keyboard might have 102 keys. An appropriate139* keymap would assign each of them a keycode, by which the user should140* refer to the key throughout the library.141*142* Historically, the X11 protocol, and consequentially the XKB protocol,143* assign only 8 bits for keycodes. This limits the number of different144* keys that can be used simultaneously in a single keymap to 256145* (disregarding other limitations). This library does not share this limit;146* keycodes beyond 255 ('extended keycodes') are not treated specially.147* Keymaps and applications which are compatible with X11 should not use148* these keycodes.149*150* The values of specific keycodes are determined by the keymap and the151* underlying input system. For example, with an X11-compatible keymap152* and Linux evdev scan codes (see linux/input.h), a fixed offset is used:153*154* The keymap defines a canonical name for each key, plus possible aliases.155* Historically, the XKB protocol restricts these names to at most 4 (ASCII)156* characters, but this library does not share this limit.157*158* @code159* xkb_keycode_t keycode_A = KEY_A + 8;160* @endcode161*162* @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()163*/164typedef uint32_t xkb_keycode_t;165166/**167* A number used to represent the symbols generated from a key on a keyboard.168*169* A key, represented by a keycode, may generate different symbols according170* to keyboard state. For example, on a QWERTY keyboard, pressing the key171* labled \<A\> generates the symbol 'a'. If the Shift key is held, it172* generates the symbol 'A'. If a different layout is used, say Greek,173* it generates the symbol 'α'. And so on.174*175* Each such symbol is represented by a keysym. Note that keysyms are176* somewhat more general, in that they can also represent some "function",177* such as "Left" or "Right" for the arrow keys. For more information,178* see:179* https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding180*181* Specifically named keysyms can be found in the182* xkbcommon/xkbcommon-keysyms.h header file. Their name does not include183* the XKB_KEY_ prefix.184*185* Besides those, any Unicode/ISO 10646 character in the range U0100 to186* U10FFFF can be represented by a keysym value in the range 0x01000100 to187* 0x0110FFFF. The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".188*189* The name of other unnamed keysyms is the hexadecimal representation of190* their value, e.g. "0xabcd1234".191*192* Keysym names are case-sensitive.193*/194typedef uint32_t xkb_keysym_t;195196/**197* Index of a keyboard layout.198*199* The layout index is a state component which detemines which <em>keyboard200* layout</em> is active. These may be different alphabets, different key201* arrangements, etc.202*203* Layout indices are consecutive. The first layout has index 0.204*205* Each layout is not required to have a name, and the names are not206* guaranteed to be unique (though they are usually provided and unique).207* Therefore, it is not safe to use the name as a unique identifier for a208* layout. Layout names are case-sensitive.209*210* Layout names are specified in the layout's definition, for example211* "English (US)". These are different from the (conventionally) short names212* which are used to locate the layout, for example "us" or "us(intl)". These213* names are not present in a compiled keymap.214*215* If the user selects layouts from a list generated from the XKB registry216* (using libxkbregistry or directly), and this metadata is needed later on, it217* is recommended to store it along with the keymap.218*219* Layouts are also called "groups" by XKB.220*221* @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()222*/223typedef uint32_t xkb_layout_index_t;224/** A mask of layout indices. */225typedef uint32_t xkb_layout_mask_t;226227/**228* Index of a shift level.229*230* Any key, in any layout, can have several <em>shift levels</em>. Each231* shift level can assign different keysyms to the key. The shift level232* to use is chosen according to the current keyboard state; for example,233* if no keys are pressed, the first level may be used; if the Left Shift234* key is pressed, the second; if Num Lock is pressed, the third; and235* many such combinations are possible (see xkb_mod_index_t).236*237* Level indices are consecutive. The first level has index 0.238*/239typedef uint32_t xkb_level_index_t;240241/**242* Index of a modifier.243*244* A @e modifier is a state component which changes the way keys are245* interpreted. A keymap defines a set of modifiers, such as Alt, Shift,246* Num Lock or Meta, and specifies which keys may @e activate which247* modifiers (in a many-to-many relationship, i.e. a key can activate248* several modifiers, and a modifier may be activated by several keys.249* Different keymaps do this differently).250*251* When retrieving the keysyms for a key, the active modifier set is252* consulted; this detemines the correct shift level to use within the253* currently active layout (see xkb_level_index_t).254*255* Modifier indices are consecutive. The first modifier has index 0.256*257* Each modifier must have a name, and the names are unique. Therefore, it258* is safe to use the name as a unique identifier for a modifier. The names259* of some common modifiers are provided in the xkbcommon/xkbcommon-names.h260* header file. Modifier names are case-sensitive.261*262* @sa xkb_keymap_num_mods()263*/264typedef uint32_t xkb_mod_index_t;265/** A mask of modifier indices. */266typedef uint32_t xkb_mod_mask_t;267268/**269* Index of a keyboard LED.270*271* LEDs are logical objects which may be @e active or @e inactive. They272* typically correspond to the lights on the keyboard. Their state is273* determined by the current keyboard state.274*275* LED indices are non-consecutive. The first LED has index 0.276*277* Each LED must have a name, and the names are unique. Therefore,278* it is safe to use the name as a unique identifier for a LED. The names279* of some common LEDs are provided in the xkbcommon/xkbcommon-names.h280* header file. LED names are case-sensitive.281*282* @warning A given keymap may specify an exact index for a given LED.283* Therefore, LED indexing is not necessarily sequential, as opposed to284* modifiers and layouts. This means that when iterating over the LEDs285* in a keymap using e.g. xkb_keymap_num_leds(), some indices might be286* invalid. Given such an index, functions like xkb_keymap_led_get_name()287* will return NULL, and xkb_state_led_index_is_active() will return -1.288*289* LEDs are also called "indicators" by XKB.290*291* @sa xkb_keymap_num_leds()292*/293typedef uint32_t xkb_led_index_t;294/** A mask of LED indices. */295typedef uint32_t xkb_led_mask_t;296297#define XKB_KEYCODE_INVALID (0xffffffff)298#define XKB_LAYOUT_INVALID (0xffffffff)299#define XKB_LEVEL_INVALID (0xffffffff)300#define XKB_MOD_INVALID (0xffffffff)301#define XKB_LED_INVALID (0xffffffff)302303#define XKB_KEYCODE_MAX (0xffffffff - 1)304305/**306* Test whether a value is a valid extended keycode.307* @sa xkb_keycode_t308**/309#define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)310311/**312* Test whether a value is a valid X11 keycode.313* @sa xkb_keycode_t314*/315#define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)316317/**318* Names to compile a keymap with, also known as RMLVO.319*320* The names are the common configuration values by which a user picks321* a keymap.322*323* If the entire struct is NULL, then each field is taken to be NULL.324* You should prefer passing NULL instead of choosing your own defaults.325*/326struct xkb_rule_names {327/**328* The rules file to use. The rules file describes how to interpret329* the values of the model, layout, variant and options fields.330*331* If NULL or the empty string "", a default value is used.332* If the XKB_DEFAULT_RULES environment variable is set, it is used333* as the default. Otherwise the system default is used.334*/335const char *rules;336/**337* The keyboard model by which to interpret keycodes and LEDs.338*339* If NULL or the empty string "", a default value is used.340* If the XKB_DEFAULT_MODEL environment variable is set, it is used341* as the default. Otherwise the system default is used.342*/343const char *model;344/**345* A comma separated list of layouts (languages) to include in the346* keymap.347*348* If NULL or the empty string "", a default value is used.349* If the XKB_DEFAULT_LAYOUT environment variable is set, it is used350* as the default. Otherwise the system default is used.351*/352const char *layout;353/**354* A comma separated list of variants, one per layout, which may355* modify or augment the respective layout in various ways.356*357* Generally, should either be empty or have the same number of values358* as the number of layouts. You may use empty values as in "intl,,neo".359*360* If NULL or the empty string "", and a default value is also used361* for the layout, a default value is used. Otherwise no variant is362* used.363* If the XKB_DEFAULT_VARIANT environment variable is set, it is used364* as the default. Otherwise the system default is used.365*/366const char *variant;367/**368* A comma separated list of options, through which the user specifies369* non-layout related preferences, like which key combinations are used370* for switching layouts, or which key is the Compose key.371*372* If NULL, a default value is used. If the empty string "", no373* options are used.374* If the XKB_DEFAULT_OPTIONS environment variable is set, it is used375* as the default. Otherwise the system default is used.376*/377const char *options;378};379380/**381* @defgroup keysyms Keysyms382* Utility functions related to keysyms.383*384* @{385*/386387/**388* @page keysym-transformations Keysym Transformations389*390* Keysym translation is subject to several "keysym transformations",391* as described in the XKB specification. These are:392*393* - Capitalization transformation. If the Caps Lock modifier is394* active and was not consumed by the translation process, a single395* keysym is transformed to its upper-case form (if applicable).396* Similarly, the UTF-8/UTF-32 string produced is capitalized.397*398* This is described in:399* https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier400*401* - Control transformation. If the Control modifier is active and402* was not consumed by the translation process, the string produced403* is transformed to its matching ASCII control character (if404* applicable). Keysyms are not affected.405*406* This is described in:407* https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier408*409* Each relevant function discusses which transformations it performs.410*411* These transformations are not applicable when a key produces multiple412* keysyms.413*/414415416/**417* Get the name of a keysym.418*419* For a description of how keysyms are named, see @ref xkb_keysym_t.420*421* @param[in] keysym The keysym.422* @param[out] buffer A string buffer to write the name into.423* @param[in] size Size of the buffer.424*425* @warning If the buffer passed is too small, the string is truncated426* (though still NUL-terminated); a size of at least 64 bytes is recommended.427*428* @returns The number of bytes in the name, excluding the NUL byte. If429* the keysym is invalid, returns -1.430*431* You may check if truncation has occurred by comparing the return value432* with the length of buffer, similarly to the snprintf(3) function.433*434* @sa xkb_keysym_t435*/436int437xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);438439/** Flags for xkb_keysym_from_name(). */440enum xkb_keysym_flags {441/** Do not apply any flags. */442XKB_KEYSYM_NO_FLAGS = 0,443/** Find keysym by case-insensitive search. */444XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)445};446447/**448* Get a keysym from its name.449*450* @param name The name of a keysym. See remarks in xkb_keysym_get_name();451* this function will accept any name returned by that function.452* @param flags A set of flags controlling how the search is done. If453* invalid flags are passed, this will fail with XKB_KEY_NoSymbol.454*455* If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names456* differ only by case, then the lower-case keysym is returned. For457* instance, for KEY_a and KEY_A, this function would return KEY_a for the458* case-insensitive search. If this functionality is needed, it is459* recommended to first call this function without this flag; and if that460* fails, only then to try with this flag, while possibly warning the user461* he had misspelled the name, and might get wrong results.462*463* Case folding is done according to the C locale; the current locale is not464* consulted.465*466* @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.467*468* @sa xkb_keysym_t469*/470xkb_keysym_t471xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);472473/**474* Get the Unicode/UTF-8 representation of a keysym.475*476* @param[in] keysym The keysym.477* @param[out] buffer A buffer to write the UTF-8 string into.478* @param[in] size The size of buffer. Must be at least 7.479*480* @returns The number of bytes written to the buffer (including the481* terminating byte). If the keysym does not have a Unicode482* representation, returns 0. If the buffer is too small, returns -1.483*484* This function does not perform any @ref keysym-transformations.485* Therefore, prefer to use xkb_state_key_get_utf8() if possible.486*487* @sa xkb_state_key_get_utf8()488*/489int490xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);491492/**493* Get the Unicode/UTF-32 representation of a keysym.494*495* @returns The Unicode/UTF-32 representation of keysym, which is also496* compatible with UCS-4. If the keysym does not have a Unicode497* representation, returns 0.498*499* This function does not perform any @ref keysym-transformations.500* Therefore, prefer to use xkb_state_key_get_utf32() if possible.501*502* @sa xkb_state_key_get_utf32()503*/504uint32_t505xkb_keysym_to_utf32(xkb_keysym_t keysym);506507/**508* Get the keysym corresponding to a Unicode/UTF-32 codepoint.509*510* @returns The keysym corresponding to the specified Unicode511* codepoint, or XKB_KEY_NoSymbol if there is none.512*513* This function is the inverse of @ref xkb_keysym_to_utf32. In cases514* where a single codepoint corresponds to multiple keysyms, returns515* the keysym with the lowest value.516*517* Unicode codepoints which do not have a special (legacy) keysym518* encoding use a direct encoding scheme. These keysyms don't usually519* have an associated keysym constant (XKB_KEY_*).520*521* For noncharacter Unicode codepoints and codepoints outside of the522* defined Unicode planes this function returns XKB_KEY_NoSymbol.523*524* @sa xkb_keysym_to_utf32()525* @since 1.0.0526*/527xkb_keysym_t528xkb_utf32_to_keysym(uint32_t ucs);529530/**531* Convert a keysym to its uppercase form.532*533* If there is no such form, the keysym is returned unchanged.534*535* The conversion rules may be incomplete; prefer to work with the Unicode536* representation instead, when possible.537*/538xkb_keysym_t539xkb_keysym_to_upper(xkb_keysym_t ks);540541/**542* Convert a keysym to its lowercase form.543*544* The conversion rules may be incomplete; prefer to work with the Unicode545* representation instead, when possible.546*/547xkb_keysym_t548xkb_keysym_to_lower(xkb_keysym_t ks);549550/** @} */551552/**553* @defgroup context Library Context554* Creating, destroying and using library contexts.555*556* Every keymap compilation request must have a context associated with557* it. The context keeps around state such as the include path.558*559* @{560*/561562/**563* @page envvars Environment Variables564*565* The user may set some environment variables which affect the library:566*567* - `XKB_CONFIG_ROOT`, `XKB_CONFIG_EXTRA_PATH`, `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.568* - `XKB_LOG_LEVEL` - see xkb_context_set_log_level().569* - `XKB_LOG_VERBOSITY` - see xkb_context_set_log_verbosity().570* - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,571* `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see xkb_rule_names.572*/573574/** Flags for context creation. */575enum xkb_context_flags {576/** Do not apply any context flags. */577XKB_CONTEXT_NO_FLAGS = 0,578/** Create this context with an empty include path. */579XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),580/**581* Don't take RMLVO names from the environment.582* @since 0.3.0583*/584XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1)585};586587/**588* Create a new context.589*590* @param flags Optional flags for the context, or 0.591*592* @returns A new context, or NULL on failure.593*594* @memberof xkb_context595*/596struct xkb_context *597xkb_context_new(enum xkb_context_flags flags);598599/**600* Take a new reference on a context.601*602* @returns The passed in context.603*604* @memberof xkb_context605*/606struct xkb_context *607xkb_context_ref(struct xkb_context *context);608609/**610* Release a reference on a context, and possibly free it.611*612* @param context The context. If it is NULL, this function does nothing.613*614* @memberof xkb_context615*/616void617xkb_context_unref(struct xkb_context *context);618619/**620* Store custom user data in the context.621*622* This may be useful in conjunction with xkb_context_set_log_fn() or other623* callbacks.624*625* @memberof xkb_context626*/627void628xkb_context_set_user_data(struct xkb_context *context, void *user_data);629630/**631* Retrieves stored user data from the context.632*633* @returns The stored user data. If the user data wasn't set, or the634* passed in context is NULL, returns NULL.635*636* This may be useful to access private user data from callbacks like a637* custom logging function.638*639* @memberof xkb_context640**/641void *642xkb_context_get_user_data(struct xkb_context *context);643644/** @} */645646/**647* @defgroup include-path Include Paths648* Manipulating the include paths in a context.649*650* The include paths are the file-system paths that are searched when an651* include statement is encountered during keymap compilation.652*653* The default include paths are, in that lookup order:654* - The path `$XDG_CONFIG_HOME/xkb`, with the usual `XDG_CONFIG_HOME`655* fallback to `$HOME/.config/` if unset.656* - The path `$HOME/.xkb`, where $HOME is the value of the environment657* variable `HOME`.658* - The `XKB_CONFIG_EXTRA_PATH` environment variable, if defined, otherwise the659* system configuration directory, defined at library configuration time660* (usually `/etc/xkb`).661* - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise662* the system XKB root, defined at library configuration time.663*664* @{665*/666667/**668* Append a new entry to the context's include path.669*670* @returns 1 on success, or 0 if the include path could not be added or is671* inaccessible.672*673* @memberof xkb_context674*/675int676xkb_context_include_path_append(struct xkb_context *context, const char *path);677678/**679* Append the default include paths to the context's include path.680*681* @returns 1 on success, or 0 if the primary include path could not be added.682*683* @memberof xkb_context684*/685int686xkb_context_include_path_append_default(struct xkb_context *context);687688/**689* Reset the context's include path to the default.690*691* Removes all entries from the context's include path, and inserts the692* default paths.693*694* @returns 1 on success, or 0 if the primary include path could not be added.695*696* @memberof xkb_context697*/698int699xkb_context_include_path_reset_defaults(struct xkb_context *context);700701/**702* Remove all entries from the context's include path.703*704* @memberof xkb_context705*/706void707xkb_context_include_path_clear(struct xkb_context *context);708709/**710* Get the number of paths in the context's include path.711*712* @memberof xkb_context713*/714unsigned int715xkb_context_num_include_paths(struct xkb_context *context);716717/**718* Get a specific include path from the context's include path.719*720* @returns The include path at the specified index. If the index is721* invalid, returns NULL.722*723* @memberof xkb_context724*/725const char *726xkb_context_include_path_get(struct xkb_context *context, unsigned int index);727728/** @} */729730/**731* @defgroup logging Logging Handling732* Manipulating how logging from this library is handled.733*734* @{735*/736737/** Specifies a logging level. */738enum xkb_log_level {739XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */740XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */741XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */742XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */743XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */744};745746/**747* Set the current logging level.748*749* @param context The context in which to set the logging level.750* @param level The logging level to use. Only messages from this level751* and below will be logged.752*753* The default level is XKB_LOG_LEVEL_ERROR. The environment variable754* XKB_LOG_LEVEL, if set in the time the context was created, overrides the755* default value. It may be specified as a level number or name.756*757* @memberof xkb_context758*/759void760xkb_context_set_log_level(struct xkb_context *context,761enum xkb_log_level level);762763/**764* Get the current logging level.765*766* @memberof xkb_context767*/768enum xkb_log_level769xkb_context_get_log_level(struct xkb_context *context);770771/**772* Sets the current logging verbosity.773*774* The library can generate a number of warnings which are not helpful to775* ordinary users of the library. The verbosity may be increased if more776* information is desired (e.g. when developing a new keymap).777*778* The default verbosity is 0. The environment variable XKB_LOG_VERBOSITY,779* if set in the time the context was created, overrides the default value.780*781* @param context The context in which to use the set verbosity.782* @param verbosity The verbosity to use. Currently used values are783* 1 to 10, higher values being more verbose. 0 would result in no verbose784* messages being logged.785*786* Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.787*788* @memberof xkb_context789*/790void791xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);792793/**794* Get the current logging verbosity of the context.795*796* @memberof xkb_context797*/798int799xkb_context_get_log_verbosity(struct xkb_context *context);800801/**802* Set a custom function to handle logging messages.803*804* @param context The context in which to use the set logging function.805* @param log_fn The function that will be called for logging messages.806* Passing NULL restores the default function, which logs to stderr.807*808* By default, log messages from this library are printed to stderr. This809* function allows you to replace the default behavior with a custom810* handler. The handler is only called with messages which match the811* current logging level and verbosity settings for the context.812* level is the logging level of the message. @a format and @a args are813* the same as in the vprintf(3) function.814*815* You may use xkb_context_set_user_data() on the context, and then call816* xkb_context_get_user_data() from within the logging function to provide817* it with additional private context.818*819* @memberof xkb_context820*/821void822xkb_context_set_log_fn(struct xkb_context *context,823void (*log_fn)(struct xkb_context *context,824enum xkb_log_level level,825const char *format, va_list args));826827/** @} */828829/**830* @defgroup keymap Keymap Creation831* Creating and destroying keymaps.832*833* @{834*/835836/** Flags for keymap compilation. */837enum xkb_keymap_compile_flags {838/** Do not apply any flags. */839XKB_KEYMAP_COMPILE_NO_FLAGS = 0840};841842/**843* Create a keymap from RMLVO names.844*845* The primary keymap entry point: creates a new XKB keymap from a set of846* RMLVO (Rules + Model + Layouts + Variants + Options) names.847*848* @param context The context in which to create the keymap.849* @param names The RMLVO names to use. See xkb_rule_names.850* @param flags Optional flags for the keymap, or 0.851*852* @returns A keymap compiled according to the RMLVO names, or NULL if853* the compilation failed.854*855* @sa xkb_rule_names856* @memberof xkb_keymap857*/858struct xkb_keymap *859xkb_keymap_new_from_names(struct xkb_context *context,860const struct xkb_rule_names *names,861enum xkb_keymap_compile_flags flags);862863/** The possible keymap formats. */864enum xkb_keymap_format {865/** The current/classic XKB text format, as generated by xkbcomp -xkb. */866XKB_KEYMAP_FORMAT_TEXT_V1 = 1867};868869/**870* Create a keymap from a keymap file.871*872* @param context The context in which to create the keymap.873* @param file The keymap file to compile.874* @param format The text format of the keymap file to compile.875* @param flags Optional flags for the keymap, or 0.876*877* @returns A keymap compiled from the given XKB keymap file, or NULL if878* the compilation failed.879*880* The file must contain a complete keymap. For example, in the881* XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one882* top level '%xkb_keymap' section, which in turn contains other required883* sections.884*885* @memberof xkb_keymap886*/887struct xkb_keymap *888xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,889enum xkb_keymap_format format,890enum xkb_keymap_compile_flags flags);891892/**893* Create a keymap from a keymap string.894*895* This is just like xkb_keymap_new_from_file(), but instead of a file, gets896* the keymap as one enormous string.897*898* @see xkb_keymap_new_from_file()899* @memberof xkb_keymap900*/901struct xkb_keymap *902xkb_keymap_new_from_string(struct xkb_context *context, const char *string,903enum xkb_keymap_format format,904enum xkb_keymap_compile_flags flags);905906/**907* Create a keymap from a memory buffer.908*909* This is just like xkb_keymap_new_from_string(), but takes a length argument910* so the input string does not have to be zero-terminated.911*912* @see xkb_keymap_new_from_string()913* @memberof xkb_keymap914* @since 0.3.0915*/916struct xkb_keymap *917xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,918size_t length, enum xkb_keymap_format format,919enum xkb_keymap_compile_flags flags);920921/**922* Take a new reference on a keymap.923*924* @returns The passed in keymap.925*926* @memberof xkb_keymap927*/928struct xkb_keymap *929xkb_keymap_ref(struct xkb_keymap *keymap);930931/**932* Release a reference on a keymap, and possibly free it.933*934* @param keymap The keymap. If it is NULL, this function does nothing.935*936* @memberof xkb_keymap937*/938void939xkb_keymap_unref(struct xkb_keymap *keymap);940941/**942* Get the keymap as a string in the format from which it was created.943* @sa xkb_keymap_get_as_string()944**/945#define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)946947/**948* Get the compiled keymap as a string.949*950* @param keymap The keymap to get as a string.951* @param format The keymap format to use for the string. You can pass952* in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format953* from which the keymap was originally created.954*955* @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.956*957* The returned string may be fed back into xkb_keymap_new_from_string() to get958* the exact same keymap (possibly in another process, etc.).959*960* The returned string is dynamically allocated and should be freed by the961* caller.962*963* @memberof xkb_keymap964*/965char *966xkb_keymap_get_as_string(struct xkb_keymap *keymap,967enum xkb_keymap_format format);968969/** @} */970971/**972* @defgroup components Keymap Components973* Enumeration of state components in a keymap.974*975* @{976*/977978/**979* Get the minimum keycode in the keymap.980*981* @sa xkb_keycode_t982* @memberof xkb_keymap983* @since 0.3.1984*/985xkb_keycode_t986xkb_keymap_min_keycode(struct xkb_keymap *keymap);987988/**989* Get the maximum keycode in the keymap.990*991* @sa xkb_keycode_t992* @memberof xkb_keymap993* @since 0.3.1994*/995xkb_keycode_t996xkb_keymap_max_keycode(struct xkb_keymap *keymap);997998/**999* The iterator used by xkb_keymap_key_for_each().1000*1001* @sa xkb_keymap_key_for_each1002* @memberof xkb_keymap1003* @since 0.3.11004*/1005typedef void1006(*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,1007void *data);10081009/**1010* Run a specified function for every valid keycode in the keymap. If a1011* keymap is sparse, this function may be called fewer than1012* (max_keycode - min_keycode + 1) times.1013*1014* @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t1015* @memberof xkb_keymap1016* @since 0.3.11017*/1018void1019xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,1020void *data);10211022/**1023* Find the name of the key with the given keycode.1024*1025* This function always returns the canonical name of the key (see1026* description in xkb_keycode_t).1027*1028* @returns The key name. If no key with this keycode exists,1029* returns NULL.1030*1031* @sa xkb_keycode_t1032* @memberof xkb_keymap1033* @since 0.6.01034*/1035const char *1036xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);10371038/**1039* Find the keycode of the key with the given name.1040*1041* The name can be either a canonical name or an alias.1042*1043* @returns The keycode. If no key with this name exists,1044* returns XKB_KEYCODE_INVALID.1045*1046* @sa xkb_keycode_t1047* @memberof xkb_keymap1048* @since 0.6.01049*/1050xkb_keycode_t1051xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);10521053/**1054* Get the number of modifiers in the keymap.1055*1056* @sa xkb_mod_index_t1057* @memberof xkb_keymap1058*/1059xkb_mod_index_t1060xkb_keymap_num_mods(struct xkb_keymap *keymap);10611062/**1063* Get the name of a modifier by index.1064*1065* @returns The name. If the index is invalid, returns NULL.1066*1067* @sa xkb_mod_index_t1068* @memberof xkb_keymap1069*/1070const char *1071xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);10721073/**1074* Get the index of a modifier by name.1075*1076* @returns The index. If no modifier with this name exists, returns1077* XKB_MOD_INVALID.1078*1079* @sa xkb_mod_index_t1080* @memberof xkb_keymap1081*/1082xkb_mod_index_t1083xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);10841085/**1086* Get the number of layouts in the keymap.1087*1088* @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()1089* @memberof xkb_keymap1090*/1091xkb_layout_index_t1092xkb_keymap_num_layouts(struct xkb_keymap *keymap);10931094/**1095* Get the name of a layout by index.1096*1097* @returns The name. If the index is invalid, or the layout does not have1098* a name, returns NULL.1099*1100* @sa xkb_layout_index_t1101* For notes on layout names.1102* @memberof xkb_keymap1103*/1104const char *1105xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);11061107/**1108* Get the index of a layout by name.1109*1110* @returns The index. If no layout exists with this name, returns1111* XKB_LAYOUT_INVALID. If more than one layout in the keymap has this name,1112* returns the lowest index among them.1113*1114* @sa xkb_layout_index_t1115* For notes on layout names.1116* @memberof xkb_keymap1117*/1118xkb_layout_index_t1119xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);11201121/**1122* Get the number of LEDs in the keymap.1123*1124* @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs1125* in the keymap, but may also contain inactive LEDs. When iterating over1126* this range, you need the handle this case when calling functions such as1127* xkb_keymap_led_get_name() or xkb_state_led_index_is_active().1128*1129* @sa xkb_led_index_t1130* @memberof xkb_keymap1131*/1132xkb_led_index_t1133xkb_keymap_num_leds(struct xkb_keymap *keymap);11341135/**1136* Get the name of a LED by index.1137*1138* @returns The name. If the index is invalid, returns NULL.1139*1140* @memberof xkb_keymap1141*/1142const char *1143xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);11441145/**1146* Get the index of a LED by name.1147*1148* @returns The index. If no LED with this name exists, returns1149* XKB_LED_INVALID.1150*1151* @memberof xkb_keymap1152*/1153xkb_led_index_t1154xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);11551156/**1157* Get the number of layouts for a specific key.1158*1159* This number can be different from xkb_keymap_num_layouts(), but is always1160* smaller. It is the appropriate value to use when iterating over the1161* layouts of a key.1162*1163* @sa xkb_layout_index_t1164* @memberof xkb_keymap1165*/1166xkb_layout_index_t1167xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);11681169/**1170* Get the number of shift levels for a specific key and layout.1171*1172* If @c layout is out of range for this key (that is, larger or equal to1173* the value returned by xkb_keymap_num_layouts_for_key()), it is brought1174* back into range in a manner consistent with xkb_state_key_get_layout().1175*1176* @sa xkb_level_index_t1177* @memberof xkb_keymap1178*/1179xkb_level_index_t1180xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,1181xkb_layout_index_t layout);11821183/**1184* Retrieves every possible modifier mask that produces the specified1185* shift level for a specific key and layout.1186*1187* This API is useful for inverse key transformation; i.e. finding out1188* which modifiers need to be active in order to be able to type the1189* keysym(s) corresponding to the specific key code, layout and level.1190*1191* @warning It returns only up to masks_size modifier masks. If the1192* buffer passed is too small, some of the possible modifier combinations1193* will not be returned.1194*1195* @param[in] keymap The keymap.1196* @param[in] key The keycode of the key.1197* @param[in] layout The layout for which to get modifiers.1198* @param[in] level The shift level in the layout for which to get the1199* modifiers. This should be smaller than:1200* @code xkb_keymap_num_levels_for_key(keymap, key) @endcode1201* @param[out] masks_out A buffer in which the requested masks should be1202* stored.1203* @param[out] masks_size The size of the buffer pointed to by masks_out.1204*1205* If @c layout is out of range for this key (that is, larger or equal to1206* the value returned by xkb_keymap_num_layouts_for_key()), it is brought1207* back into range in a manner consistent with xkb_state_key_get_layout().1208*1209* @returns The number of modifier masks stored in the masks_out array.1210* If the key is not in the keymap or if the specified shift level cannot1211* be reached it returns 0 and does not modify the masks_out buffer.1212*1213* @sa xkb_level_index_t1214* @sa xkb_mod_mask_t1215* @memberof xkb_keymap1216* @since 1.0.01217*/1218size_t1219xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,1220xkb_keycode_t key,1221xkb_layout_index_t layout,1222xkb_level_index_t level,1223xkb_mod_mask_t *masks_out,1224size_t masks_size);12251226/**1227* Get the keysyms obtained from pressing a key in a given layout and1228* shift level.1229*1230* This function is like xkb_state_key_get_syms(), only the layout and1231* shift level are not derived from the keyboard state but are instead1232* specified explicitly.1233*1234* @param[in] keymap The keymap.1235* @param[in] key The keycode of the key.1236* @param[in] layout The layout for which to get the keysyms.1237* @param[in] level The shift level in the layout for which to get the1238* keysyms. This should be smaller than:1239* @code xkb_keymap_num_levels_for_key(keymap, key) @endcode1240* @param[out] syms_out An immutable array of keysyms corresponding to the1241* key in the given layout and shift level.1242*1243* If @c layout is out of range for this key (that is, larger or equal to1244* the value returned by xkb_keymap_num_layouts_for_key()), it is brought1245* back into range in a manner consistent with xkb_state_key_get_layout().1246*1247* @returns The number of keysyms in the syms_out array. If no keysyms1248* are produced by the key in the given layout and shift level, returns 01249* and sets syms_out to NULL.1250*1251* @sa xkb_state_key_get_syms()1252* @memberof xkb_keymap1253*/1254int1255xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,1256xkb_keycode_t key,1257xkb_layout_index_t layout,1258xkb_level_index_t level,1259const xkb_keysym_t **syms_out);12601261/**1262* Determine whether a key should repeat or not.1263*1264* A keymap may specify different repeat behaviors for different keys.1265* Most keys should generally exhibit repeat behavior; for example, holding1266* the 'a' key down in a text editor should normally insert a single 'a'1267* character every few milliseconds, until the key is released. However,1268* there are keys which should not or do not need to be repeated. For1269* example, repeating modifier keys such as Left/Right Shift or Caps Lock1270* is not generally useful or desired.1271*1272* @returns 1 if the key should repeat, 0 otherwise.1273*1274* @memberof xkb_keymap1275*/1276int1277xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);12781279/** @} */12801281/**1282* @defgroup state Keyboard State1283* Creating, destroying and manipulating keyboard state objects.1284*1285* @{1286*/12871288/**1289* Create a new keyboard state object.1290*1291* @param keymap The keymap which the state will use.1292*1293* @returns A new keyboard state object, or NULL on failure.1294*1295* @memberof xkb_state1296*/1297struct xkb_state *1298xkb_state_new(struct xkb_keymap *keymap);12991300/**1301* Take a new reference on a keyboard state object.1302*1303* @returns The passed in object.1304*1305* @memberof xkb_state1306*/1307struct xkb_state *1308xkb_state_ref(struct xkb_state *state);13091310/**1311* Release a reference on a keybaord state object, and possibly free it.1312*1313* @param state The state. If it is NULL, this function does nothing.1314*1315* @memberof xkb_state1316*/1317void1318xkb_state_unref(struct xkb_state *state);13191320/**1321* Get the keymap which a keyboard state object is using.1322*1323* @returns The keymap which was passed to xkb_state_new() when creating1324* this state object.1325*1326* This function does not take a new reference on the keymap; you must1327* explicitly reference it yourself if you plan to use it beyond the1328* lifetime of the state.1329*1330* @memberof xkb_state1331*/1332struct xkb_keymap *1333xkb_state_get_keymap(struct xkb_state *state);13341335/** Specifies the direction of the key (press / release). */1336enum xkb_key_direction {1337XKB_KEY_UP, /**< The key was released. */1338XKB_KEY_DOWN /**< The key was pressed. */1339};13401341/**1342* Modifier and layout types for state objects. This enum is bitmaskable,1343* e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to1344* exclude locked modifiers.1345*1346* In XKB, the DEPRESSED components are also known as 'base'.1347*/1348enum xkb_state_component {1349/** Depressed modifiers, i.e. a key is physically holding them. */1350XKB_STATE_MODS_DEPRESSED = (1 << 0),1351/** Latched modifiers, i.e. will be unset after the next non-modifier1352* key press. */1353XKB_STATE_MODS_LATCHED = (1 << 1),1354/** Locked modifiers, i.e. will be unset after the key provoking the1355* lock has been pressed again. */1356XKB_STATE_MODS_LOCKED = (1 << 2),1357/** Effective modifiers, i.e. currently active and affect key1358* processing (derived from the other state components).1359* Use this unless you explicitly care how the state came about. */1360XKB_STATE_MODS_EFFECTIVE = (1 << 3),1361/** Depressed layout, i.e. a key is physically holding it. */1362XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),1363/** Latched layout, i.e. will be unset after the next non-modifier1364* key press. */1365XKB_STATE_LAYOUT_LATCHED = (1 << 5),1366/** Locked layout, i.e. will be unset after the key provoking the lock1367* has been pressed again. */1368XKB_STATE_LAYOUT_LOCKED = (1 << 6),1369/** Effective layout, i.e. currently active and affects key processing1370* (derived from the other state components).1371* Use this unless you explicitly care how the state came about. */1372XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),1373/** LEDs (derived from the other state components). */1374XKB_STATE_LEDS = (1 << 8)1375};13761377/**1378* Update the keyboard state to reflect a given key being pressed or1379* released.1380*1381* This entry point is intended for programs which track the keyboard state1382* explicitly (like an evdev client). If the state is serialized to you by1383* a master process (like a Wayland compositor) using functions like1384* xkb_state_serialize_mods(), you should use xkb_state_update_mask() instead.1385* The two functions should not generally be used together.1386*1387* A series of calls to this function should be consistent; that is, a call1388* with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key1389* is pressed twice, it should be released twice; etc. Otherwise (e.g. due1390* to missed input events), situations like "stuck modifiers" may occur.1391*1392* This function is often used in conjunction with the function1393* xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,1394* when handling a key event. In this case, you should prefer to get the1395* keysyms *before* updating the key, such that the keysyms reported for1396* the key event are not affected by the event itself. This is the1397* conventional behavior.1398*1399* @returns A mask of state components that have changed as a result of1400* the update. If nothing in the state has changed, returns 0.1401*1402* @memberof xkb_state1403*1404* @sa xkb_state_update_mask()1405*/1406enum xkb_state_component1407xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,1408enum xkb_key_direction direction);14091410/**1411* Update a keyboard state from a set of explicit masks.1412*1413* This entry point is intended for window systems and the like, where a1414* master process holds an xkb_state, then serializes it over a wire1415* protocol, and clients then use the serialization to feed in to their own1416* xkb_state.1417*1418* All parameters must always be passed, or the resulting state may be1419* incoherent.1420*1421* The serialization is lossy and will not survive round trips; it must only1422* be used to feed slave state objects, and must not be used to update the1423* master state.1424*1425* If you do not fit the description above, you should use1426* xkb_state_update_key() instead. The two functions should not generally be1427* used together.1428*1429* @returns A mask of state components that have changed as a result of1430* the update. If nothing in the state has changed, returns 0.1431*1432* @memberof xkb_state1433*1434* @sa xkb_state_component1435* @sa xkb_state_update_key1436*/1437enum xkb_state_component1438xkb_state_update_mask(struct xkb_state *state,1439xkb_mod_mask_t depressed_mods,1440xkb_mod_mask_t latched_mods,1441xkb_mod_mask_t locked_mods,1442xkb_layout_index_t depressed_layout,1443xkb_layout_index_t latched_layout,1444xkb_layout_index_t locked_layout);14451446/**1447* Get the keysyms obtained from pressing a particular key in a given1448* keyboard state.1449*1450* Get the keysyms for a key according to the current active layout,1451* modifiers and shift level for the key, as determined by a keyboard1452* state.1453*1454* @param[in] state The keyboard state object.1455* @param[in] key The keycode of the key.1456* @param[out] syms_out An immutable array of keysyms corresponding the1457* key in the given keyboard state.1458*1459* As an extension to XKB, this function can return more than one keysym.1460* If you do not want to handle this case, you can use1461* xkb_state_key_get_one_sym() for a simpler interface.1462*1463* This function does not perform any @ref keysym-transformations.1464* (This might change).1465*1466* @returns The number of keysyms in the syms_out array. If no keysyms1467* are produced by the key in the given keyboard state, returns 0 and sets1468* syms_out to NULL.1469*1470* @memberof xkb_state1471*/1472int1473xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,1474const xkb_keysym_t **syms_out);14751476/**1477* Get the Unicode/UTF-8 string obtained from pressing a particular key1478* in a given keyboard state.1479*1480* @param[in] state The keyboard state object.1481* @param[in] key The keycode of the key.1482* @param[out] buffer A buffer to write the string into.1483* @param[in] size Size of the buffer.1484*1485* @warning If the buffer passed is too small, the string is truncated1486* (though still NUL-terminated).1487*1488* @returns The number of bytes required for the string, excluding the1489* NUL byte. If there is nothing to write, returns 0.1490*1491* You may check if truncation has occurred by comparing the return value1492* with the size of @p buffer, similarly to the snprintf(3) function.1493* You may safely pass NULL and 0 to @p buffer and @p size to find the1494* required size (without the NUL-byte).1495*1496* This function performs Capitalization and Control @ref1497* keysym-transformations.1498*1499* @memberof xkb_state1500* @since 0.4.11501*/1502int1503xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,1504char *buffer, size_t size);15051506/**1507* Get the Unicode/UTF-32 codepoint obtained from pressing a particular1508* key in a a given keyboard state.1509*1510* @returns The UTF-32 representation for the key, if it consists of only1511* a single codepoint. Otherwise, returns 0.1512*1513* This function performs Capitalization and Control @ref1514* keysym-transformations.1515*1516* @memberof xkb_state1517* @since 0.4.11518*/1519uint32_t1520xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);15211522/**1523* Get the single keysym obtained from pressing a particular key in a1524* given keyboard state.1525*1526* This function is similar to xkb_state_key_get_syms(), but intended1527* for users which cannot or do not want to handle the case where1528* multiple keysyms are returned (in which case this function is1529* preferred).1530*1531* @returns The keysym. If the key does not have exactly one keysym,1532* returns XKB_KEY_NoSymbol1533*1534* This function performs Capitalization @ref keysym-transformations.1535*1536* @sa xkb_state_key_get_syms()1537* @memberof xkb_state1538*/1539xkb_keysym_t1540xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);15411542/**1543* Get the effective layout index for a key in a given keyboard state.1544*1545* @returns The layout index for the key in the given keyboard state. If1546* the given keycode is invalid, or if the key is not included in any1547* layout at all, returns XKB_LAYOUT_INVALID.1548*1549* @invariant If the returned layout is valid, the following always holds:1550* @code1551* xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)1552* @endcode1553*1554* @memberof xkb_state1555*/1556xkb_layout_index_t1557xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);15581559/**1560* Get the effective shift level for a key in a given keyboard state and1561* layout.1562*1563* @param state The keyboard state.1564* @param key The keycode of the key.1565* @param layout The layout for which to get the shift level. This must be1566* smaller than:1567* @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode1568* usually it would be:1569* @code xkb_state_key_get_layout(state, key) @endcode1570*1571* @return The shift level index. If the key or layout are invalid,1572* returns XKB_LEVEL_INVALID.1573*1574* @invariant If the returned level is valid, the following always holds:1575* @code1576* xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)1577* @endcode1578*1579* @memberof xkb_state1580*/1581xkb_level_index_t1582xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,1583xkb_layout_index_t layout);15841585/**1586* Match flags for xkb_state_mod_indices_are_active() and1587* xkb_state_mod_names_are_active(), specifying the conditions for a1588* successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with1589* the other modes.1590*/1591enum xkb_state_match {1592/** Returns true if any of the modifiers are active. */1593XKB_STATE_MATCH_ANY = (1 << 0),1594/** Returns true if all of the modifiers are active. */1595XKB_STATE_MATCH_ALL = (1 << 1),1596/** Makes matching non-exclusive, i.e. will not return false if a1597* modifier not specified in the arguments is active. */1598XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)1599};16001601/**1602* The counterpart to xkb_state_update_mask for modifiers, to be used on1603* the server side of serialization.1604*1605* @param state The keyboard state.1606* @param components A mask of the modifier state components to serialize.1607* State components other than XKB_STATE_MODS_* are ignored.1608* If XKB_STATE_MODS_EFFECTIVE is included, all other state components are1609* ignored.1610*1611* @returns A xkb_mod_mask_t representing the given components of the1612* modifier state.1613*1614* This function should not be used in regular clients; please use the1615* xkb_state_mod_*_is_active API instead.1616*1617* @memberof xkb_state1618*/1619xkb_mod_mask_t1620xkb_state_serialize_mods(struct xkb_state *state,1621enum xkb_state_component components);16221623/**1624* The counterpart to xkb_state_update_mask for layouts, to be used on1625* the server side of serialization.1626*1627* @param state The keyboard state.1628* @param components A mask of the layout state components to serialize.1629* State components other than XKB_STATE_LAYOUT_* are ignored.1630* If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are1631* ignored.1632*1633* @returns A layout index representing the given components of the1634* layout state.1635*1636* This function should not be used in regular clients; please use the1637* xkb_state_layout_*_is_active API instead.1638*1639* @memberof xkb_state1640*/1641xkb_layout_index_t1642xkb_state_serialize_layout(struct xkb_state *state,1643enum xkb_state_component components);16441645/**1646* Test whether a modifier is active in a given keyboard state by name.1647*1648* @returns 1 if the modifier is active, 0 if it is not. If the modifier1649* name does not exist in the keymap, returns -1.1650*1651* @memberof xkb_state1652*/1653int1654xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,1655enum xkb_state_component type);16561657/**1658* Test whether a set of modifiers are active in a given keyboard state by1659* name.1660*1661* @param state The keyboard state.1662* @param type The component of the state against which to match the1663* given modifiers.1664* @param match The manner by which to match the state against the1665* given modifiers.1666* @param ... The set of of modifier names to test, terminated by a NULL1667* argument (sentinel).1668*1669* @returns 1 if the modifiers are active, 0 if they are not. If any of1670* the modifier names do not exist in the keymap, returns -1.1671*1672* @memberof xkb_state1673*/1674int1675xkb_state_mod_names_are_active(struct xkb_state *state,1676enum xkb_state_component type,1677enum xkb_state_match match,1678...);16791680/**1681* Test whether a modifier is active in a given keyboard state by index.1682*1683* @returns 1 if the modifier is active, 0 if it is not. If the modifier1684* index is invalid in the keymap, returns -1.1685*1686* @memberof xkb_state1687*/1688int1689xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,1690enum xkb_state_component type);16911692/**1693* Test whether a set of modifiers are active in a given keyboard state by1694* index.1695*1696* @param state The keyboard state.1697* @param type The component of the state against which to match the1698* given modifiers.1699* @param match The manner by which to match the state against the1700* given modifiers.1701* @param ... The set of of modifier indices to test, terminated by a1702* XKB_MOD_INVALID argument (sentinel).1703*1704* @returns 1 if the modifiers are active, 0 if they are not. If any of1705* the modifier indices are invalid in the keymap, returns -1.1706*1707* @memberof xkb_state1708*/1709int1710xkb_state_mod_indices_are_active(struct xkb_state *state,1711enum xkb_state_component type,1712enum xkb_state_match match,1713...);17141715/**1716* @page consumed-modifiers Consumed Modifiers1717* @parblock1718*1719* Some functions, like xkb_state_key_get_syms(), look at the state of1720* the modifiers in the keymap and derive from it the correct shift level1721* to use for the key. For example, in a US layout, pressing the key1722* labeled \<A\> while the Shift modifier is active, generates the keysym1723* 'A'. In this case, the Shift modifier is said to be "consumed".1724* However, the Num Lock modifier does not affect this translation at all,1725* even if it is active, so it is not consumed by this translation.1726*1727* It may be desirable for some application to not reuse consumed modifiers1728* for further processing, e.g. for hotkeys or keyboard shortcuts. To1729* understand why, consider some requirements from a standard shortcut1730* mechanism, and how they are implemented:1731*1732* 1. The shortcut's modifiers must match exactly to the state. For1733* example, it is possible to bind separate actions to \<Alt\>\<Tab\>1734* and to \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is1735* bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not1736* trigger the shortcut.1737* Effectively, this means that the modifiers are compared using the1738* equality operator (==).1739*1740* 2. Only relevant modifiers are considered for the matching. For example,1741* Caps Lock and Num Lock should not generally affect the matching, e.g.1742* when matching \<Alt\>\<Tab\> against the state, it does not matter1743* whether Num Lock is active or not. These relevant, or "significant",1744* modifiers usually include Alt, Control, Shift, Super and similar.1745* Effectively, this means that non-significant modifiers are masked out,1746* before doing the comparison as described above.1747*1748* 3. The matching must be independent of the layout/keymap. For example,1749* the \<Plus\> (+) symbol is found on the first level on some layouts,1750* but requires holding Shift on others. If you simply bind the action1751* to the \<Plus\> keysym, it would work for the unshifted kind, but1752* not for the others, because the match against Shift would fail. If1753* you bind the action to \<Shift\>\<Plus\>, only the shifted kind would1754* work. So what is needed is to recognize that Shift is used up in the1755* translation of the keysym itself, and therefore should not be included1756* in the matching.1757* Effectively, this means that consumed modifiers (Shift in this example)1758* are masked out as well, before doing the comparison.1759*1760* In summary, this is approximately how the matching would be performed:1761* @code1762* (keysym == shortcut_keysym) &&1763* ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)1764* @endcode1765*1766* @c state_mods are the modifiers reported by1767* xkb_state_mod_index_is_active() and similar functions.1768* @c consumed_mods are the modifiers reported by1769* xkb_state_mod_index_is_consumed() and similar functions.1770* @c significant_mods are decided upon by the application/toolkit/user;1771* it is up to them to decide whether these are configurable or hard-coded.1772*1773* @endparblock1774*/17751776/**1777* Consumed modifiers mode.1778*1779* There are several possible methods for deciding which modifiers are1780* consumed and which are not, each applicable for different systems or1781* situations. The mode selects the method to use.1782*1783* Keep in mind that in all methods, the keymap may decide to "preserve"1784* a modifier, meaning it is not reported as consumed even if it would1785* have otherwise.1786*/1787enum xkb_consumed_mode {1788/**1789* This is the mode defined in the XKB specification and used by libX11.1790*1791* A modifier is consumed if and only if it *may affect* key translation.1792*1793* For example, if `Control+Alt+<Backspace>` produces some assigned keysym,1794* then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,1795* even though they are not active, since if they *were* active they would1796* have affected key translation.1797*/1798XKB_CONSUMED_MODE_XKB,1799/**1800* This is the mode used by the GTK+ toolkit.1801*1802* The mode consists of the following two independent heuristics:1803*1804* - The currently active set of modifiers, excluding modifiers which do1805* not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are1806* considered consumed, if the keysyms produced when all of them are1807* active are different from the keysyms produced when no modifiers are1808* active.1809*1810* - A single modifier is considered consumed if the keysyms produced for1811* the key when it is the only active modifier are different from the1812* keysyms produced when no modifiers are active.1813*/1814XKB_CONSUMED_MODE_GTK1815};18161817/**1818* Get the mask of modifiers consumed by translating a given key.1819*1820* @param state The keyboard state.1821* @param key The keycode of the key.1822* @param mode The consumed modifiers mode to use; see enum description.1823*1824* @returns a mask of the consumed modifiers.1825*1826* @memberof xkb_state1827* @since 0.7.01828*/1829xkb_mod_mask_t1830xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,1831enum xkb_consumed_mode mode);18321833/**1834* Same as xkb_state_key_get_consumed_mods2() with mode XKB_CONSUMED_MODE_XKB.1835*1836* @memberof xkb_state1837* @since 0.4.11838*/1839xkb_mod_mask_t1840xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);18411842/**1843* Test whether a modifier is consumed by keyboard state translation for1844* a key.1845*1846* @param state The keyboard state.1847* @param key The keycode of the key.1848* @param idx The index of the modifier to check.1849* @param mode The consumed modifiers mode to use; see enum description.1850*1851* @returns 1 if the modifier is consumed, 0 if it is not. If the modifier1852* index is not valid in the keymap, returns -1.1853*1854* @sa xkb_state_mod_mask_remove_consumed()1855* @sa xkb_state_key_get_consumed_mods()1856* @memberof xkb_state1857* @since 0.7.01858*/1859int1860xkb_state_mod_index_is_consumed2(struct xkb_state *state,1861xkb_keycode_t key,1862xkb_mod_index_t idx,1863enum xkb_consumed_mode mode);18641865/**1866* Same as xkb_state_mod_index_is_consumed2() with mode XKB_CONSUMED_MOD_XKB.1867*1868* @memberof xkb_state1869* @since 0.4.11870*/1871int1872xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,1873xkb_mod_index_t idx);18741875/**1876* Remove consumed modifiers from a modifier mask for a key.1877*1878* @deprecated Use xkb_state_key_get_consumed_mods2() instead.1879*1880* Takes the given modifier mask, and removes all modifiers which are1881* consumed for that particular key (as in xkb_state_mod_index_is_consumed()).1882*1883* @sa xkb_state_mod_index_is_consumed()1884* @memberof xkb_state1885*/1886xkb_mod_mask_t1887xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,1888xkb_mod_mask_t mask);18891890/**1891* Test whether a layout is active in a given keyboard state by name.1892*1893* @returns 1 if the layout is active, 0 if it is not. If no layout with1894* this name exists in the keymap, return -1.1895*1896* If multiple layouts in the keymap have this name, the one with the lowest1897* index is tested.1898*1899* @sa xkb_layout_index_t1900* @memberof xkb_state1901*/1902int1903xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,1904enum xkb_state_component type);19051906/**1907* Test whether a layout is active in a given keyboard state by index.1908*1909* @returns 1 if the layout is active, 0 if it is not. If the layout index1910* is not valid in the keymap, returns -1.1911*1912* @sa xkb_layout_index_t1913* @memberof xkb_state1914*/1915int1916xkb_state_layout_index_is_active(struct xkb_state *state,1917xkb_layout_index_t idx,1918enum xkb_state_component type);19191920/**1921* Test whether a LED is active in a given keyboard state by name.1922*1923* @returns 1 if the LED is active, 0 if it not. If no LED with this name1924* exists in the keymap, returns -1.1925*1926* @sa xkb_led_index_t1927* @memberof xkb_state1928*/1929int1930xkb_state_led_name_is_active(struct xkb_state *state, const char *name);19311932/**1933* Test whether a LED is active in a given keyboard state by index.1934*1935* @returns 1 if the LED is active, 0 if it not. If the LED index is not1936* valid in the keymap, returns -1.1937*1938* @sa xkb_led_index_t1939* @memberof xkb_state1940*/1941int1942xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);19431944/** @} */19451946/* Leave this include last, so it can pick up our types, etc. */1947#include <xkbcommon/xkbcommon-compat.h>19481949#ifdef __cplusplus1950} /* extern "C" */1951#endif19521953#endif /* _XKBCOMMON_H_ */195419551956