xkbcommon.h 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955
  1. /*
  2. * Copyright 1985, 1987, 1990, 1998 The Open Group
  3. * Copyright 2008 Dan Nicholson
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  19. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Except as contained in this notice, the names of the authors or their
  23. * institutions shall not be used in advertising or otherwise to promote the
  24. * sale, use or other dealings in this Software without prior written
  25. * authorization from the authors.
  26. */
  27. /************************************************************
  28. * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
  29. *
  30. * Permission to use, copy, modify, and distribute this
  31. * software and its documentation for any purpose and without
  32. * fee is hereby granted, provided that the above copyright
  33. * notice appear in all copies and that both that copyright
  34. * notice and this permission notice appear in supporting
  35. * documentation, and that the name of Silicon Graphics not be
  36. * used in advertising or publicity pertaining to distribution
  37. * of the software without specific prior written permission.
  38. * Silicon Graphics makes no representation about the suitability
  39. * 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 THIS
  43. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  44. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  45. * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
  46. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  47. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  48. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
  49. * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  50. *
  51. ********************************************************/
  52. /*
  53. * Copyright © 2009-2012 Daniel Stone
  54. * Copyright © 2012 Intel Corporation
  55. * Copyright © 2012 Ran Benita
  56. *
  57. * Permission is hereby granted, free of charge, to any person obtaining a
  58. * copy of this software and associated documentation files (the "Software"),
  59. * to deal in the Software without restriction, including without limitation
  60. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  61. * and/or sell copies of the Software, and to permit persons to whom the
  62. * Software is furnished to do so, subject to the following conditions:
  63. *
  64. * The above copyright notice and this permission notice (including the next
  65. * paragraph) shall be included in all copies or substantial portions of the
  66. * Software.
  67. *
  68. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  69. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  70. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  71. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  72. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  73. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  74. * DEALINGS IN THE SOFTWARE.
  75. *
  76. * Author: Daniel Stone <daniel@fooishbar.org>
  77. */
  78. #ifndef _XKBCOMMON_H_
  79. #define _XKBCOMMON_H_
  80. #include <stdint.h>
  81. #include <stdio.h>
  82. #include <stdarg.h>
  83. #include <xkbcommon/xkbcommon-names.h>
  84. #include <xkbcommon/xkbcommon-keysyms.h>
  85. #ifdef __cplusplus
  86. extern "C" {
  87. #endif
  88. /**
  89. * @file
  90. * Main libxkbcommon API.
  91. */
  92. /**
  93. * @struct xkb_context
  94. * Opaque top level library context object.
  95. *
  96. * The context contains various general library data and state, like
  97. * logging level and include paths.
  98. *
  99. * Objects are created in a specific context, and multiple contexts may
  100. * coexist simultaneously. Objects from different contexts are completely
  101. * separated and do not share any memory or state.
  102. */
  103. struct xkb_context;
  104. /**
  105. * @struct xkb_keymap
  106. * Opaque compiled keymap object.
  107. *
  108. * The keymap object holds all of the static keyboard information obtained
  109. * from compiling XKB files.
  110. *
  111. * A keymap is immutable after it is created (besides reference counts, etc.);
  112. * if you need to change it, you must create a new one.
  113. */
  114. struct xkb_keymap;
  115. /**
  116. * @struct xkb_state
  117. * Opaque keyboard state object.
  118. *
  119. * State objects contain the active state of a keyboard (or keyboards), such
  120. * as the currently effective layout and the active modifiers. It acts as a
  121. * simple state machine, wherein key presses and releases are the input, and
  122. * key symbols (keysyms) are the output.
  123. */
  124. struct xkb_state;
  125. /**
  126. * A number used to represent a physical key on a keyboard.
  127. *
  128. * A standard PC-compatible keyboard might have 102 keys. An appropriate
  129. * keymap would assign each of them a keycode, by which the user should
  130. * refer to the key throughout the library.
  131. *
  132. * Historically, the X11 protocol, and consequentially the XKB protocol,
  133. * assign only 8 bits for keycodes. This limits the number of different
  134. * keys that can be used simultaneously in a single keymap to 256
  135. * (disregarding other limitations). This library does not share this limit;
  136. * keycodes beyond 255 ('extended keycodes') are not treated specially.
  137. * Keymaps and applications which are compatible with X11 should not use
  138. * these keycodes.
  139. *
  140. * The values of specific keycodes are determined by the keymap and the
  141. * underlying input system. For example, with an X11-compatible keymap
  142. * and Linux evdev scan codes (see linux/input.h), a fixed offset is used:
  143. *
  144. * The keymap defines a canonical name for each key, plus possible aliases.
  145. * Historically, the XKB protocol restricts these names to at most 4 (ASCII)
  146. * characters, but this library does not share this limit.
  147. *
  148. * @code
  149. * xkb_keycode_t keycode_A = KEY_A + 8;
  150. * @endcode
  151. *
  152. * @sa xkb_keycode_is_legal_ext() xkb_keycode_is_legal_x11()
  153. */
  154. typedef uint32_t xkb_keycode_t;
  155. /**
  156. * A number used to represent the symbols generated from a key on a keyboard.
  157. *
  158. * A key, represented by a keycode, may generate different symbols according
  159. * to keyboard state. For example, on a QWERTY keyboard, pressing the key
  160. * labled \<A\> generates the symbol 'a'. If the Shift key is held, it
  161. * generates the symbol 'A'. If a different layout is used, say Greek,
  162. * it generates the symbol 'α'. And so on.
  163. *
  164. * Each such symbol is represented by a keysym. Note that keysyms are
  165. * somewhat more general, in that they can also represent some "function",
  166. * such as "Left" or "Right" for the arrow keys. For more information,
  167. * see:
  168. * https://www.x.org/releases/current/doc/xproto/x11protocol.html#keysym_encoding
  169. *
  170. * Specifically named keysyms can be found in the
  171. * xkbcommon/xkbcommon-keysyms.h header file. Their name does not include
  172. * the XKB_KEY_ prefix.
  173. *
  174. * Besides those, any Unicode/ISO 10646 character in the range U0100 to
  175. * U10FFFF can be represented by a keysym value in the range 0x01000100 to
  176. * 0x0110FFFF. The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".
  177. *
  178. * The name of other unnamed keysyms is the hexadecimal representation of
  179. * their value, e.g. "0xabcd1234".
  180. *
  181. * Keysym names are case-sensitive.
  182. */
  183. typedef uint32_t xkb_keysym_t;
  184. /**
  185. * Index of a keyboard layout.
  186. *
  187. * The layout index is a state component which detemines which <em>keyboard
  188. * layout</em> is active. These may be different alphabets, different key
  189. * arrangements, etc.
  190. *
  191. * Layout indices are consecutive. The first layout has index 0.
  192. *
  193. * Each layout is not required to have a name, and the names are not
  194. * guaranteed to be unique (though they are usually provided and unique).
  195. * Therefore, it is not safe to use the name as a unique identifier for a
  196. * layout. Layout names are case-sensitive.
  197. *
  198. * Layout names are specified in the layout's definition, for example
  199. * "English (US)". These are different from the (conventionally) short names
  200. * which are used to locate the layout, for example "us" or "us(intl)". These
  201. * names are not present in a compiled keymap.
  202. *
  203. * If the user selects layouts from a list generated from the XKB registry
  204. * (using libxkbregistry or directly), and this metadata is needed later on, it
  205. * is recommended to store it along with the keymap.
  206. *
  207. * Layouts are also called "groups" by XKB.
  208. *
  209. * @sa xkb_keymap_num_layouts() xkb_keymap_num_layouts_for_key()
  210. */
  211. typedef uint32_t xkb_layout_index_t;
  212. /** A mask of layout indices. */
  213. typedef uint32_t xkb_layout_mask_t;
  214. /**
  215. * Index of a shift level.
  216. *
  217. * Any key, in any layout, can have several <em>shift levels</em>. Each
  218. * shift level can assign different keysyms to the key. The shift level
  219. * to use is chosen according to the current keyboard state; for example,
  220. * if no keys are pressed, the first level may be used; if the Left Shift
  221. * key is pressed, the second; if Num Lock is pressed, the third; and
  222. * many such combinations are possible (see xkb_mod_index_t).
  223. *
  224. * Level indices are consecutive. The first level has index 0.
  225. */
  226. typedef uint32_t xkb_level_index_t;
  227. /**
  228. * Index of a modifier.
  229. *
  230. * A @e modifier is a state component which changes the way keys are
  231. * interpreted. A keymap defines a set of modifiers, such as Alt, Shift,
  232. * Num Lock or Meta, and specifies which keys may @e activate which
  233. * modifiers (in a many-to-many relationship, i.e. a key can activate
  234. * several modifiers, and a modifier may be activated by several keys.
  235. * Different keymaps do this differently).
  236. *
  237. * When retrieving the keysyms for a key, the active modifier set is
  238. * consulted; this detemines the correct shift level to use within the
  239. * currently active layout (see xkb_level_index_t).
  240. *
  241. * Modifier indices are consecutive. The first modifier has index 0.
  242. *
  243. * Each modifier must have a name, and the names are unique. Therefore, it
  244. * is safe to use the name as a unique identifier for a modifier. The names
  245. * of some common modifiers are provided in the xkbcommon/xkbcommon-names.h
  246. * header file. Modifier names are case-sensitive.
  247. *
  248. * @sa xkb_keymap_num_mods()
  249. */
  250. typedef uint32_t xkb_mod_index_t;
  251. /** A mask of modifier indices. */
  252. typedef uint32_t xkb_mod_mask_t;
  253. /**
  254. * Index of a keyboard LED.
  255. *
  256. * LEDs are logical objects which may be @e active or @e inactive. They
  257. * typically correspond to the lights on the keyboard. Their state is
  258. * determined by the current keyboard state.
  259. *
  260. * LED indices are non-consecutive. The first LED has index 0.
  261. *
  262. * Each LED must have a name, and the names are unique. Therefore,
  263. * it is safe to use the name as a unique identifier for a LED. The names
  264. * of some common LEDs are provided in the xkbcommon/xkbcommon-names.h
  265. * header file. LED names are case-sensitive.
  266. *
  267. * @warning A given keymap may specify an exact index for a given LED.
  268. * Therefore, LED indexing is not necessarily sequential, as opposed to
  269. * modifiers and layouts. This means that when iterating over the LEDs
  270. * in a keymap using e.g. xkb_keymap_num_leds(), some indices might be
  271. * invalid. Given such an index, functions like xkb_keymap_led_get_name()
  272. * will return NULL, and xkb_state_led_index_is_active() will return -1.
  273. *
  274. * LEDs are also called "indicators" by XKB.
  275. *
  276. * @sa xkb_keymap_num_leds()
  277. */
  278. typedef uint32_t xkb_led_index_t;
  279. /** A mask of LED indices. */
  280. typedef uint32_t xkb_led_mask_t;
  281. #define XKB_KEYCODE_INVALID (0xffffffff)
  282. #define XKB_LAYOUT_INVALID (0xffffffff)
  283. #define XKB_LEVEL_INVALID (0xffffffff)
  284. #define XKB_MOD_INVALID (0xffffffff)
  285. #define XKB_LED_INVALID (0xffffffff)
  286. #define XKB_KEYCODE_MAX (0xffffffff - 1)
  287. /**
  288. * Test whether a value is a valid extended keycode.
  289. * @sa xkb_keycode_t
  290. **/
  291. #define xkb_keycode_is_legal_ext(key) (key <= XKB_KEYCODE_MAX)
  292. /**
  293. * Test whether a value is a valid X11 keycode.
  294. * @sa xkb_keycode_t
  295. */
  296. #define xkb_keycode_is_legal_x11(key) (key >= 8 && key <= 255)
  297. /**
  298. * Names to compile a keymap with, also known as RMLVO.
  299. *
  300. * The names are the common configuration values by which a user picks
  301. * a keymap.
  302. *
  303. * If the entire struct is NULL, then each field is taken to be NULL.
  304. * You should prefer passing NULL instead of choosing your own defaults.
  305. */
  306. struct xkb_rule_names {
  307. /**
  308. * The rules file to use. The rules file describes how to interpret
  309. * the values of the model, layout, variant and options fields.
  310. *
  311. * If NULL or the empty string "", a default value is used.
  312. * If the XKB_DEFAULT_RULES environment variable is set, it is used
  313. * as the default. Otherwise the system default is used.
  314. */
  315. const char *rules;
  316. /**
  317. * The keyboard model by which to interpret keycodes and LEDs.
  318. *
  319. * If NULL or the empty string "", a default value is used.
  320. * If the XKB_DEFAULT_MODEL environment variable is set, it is used
  321. * as the default. Otherwise the system default is used.
  322. */
  323. const char *model;
  324. /**
  325. * A comma separated list of layouts (languages) to include in the
  326. * keymap.
  327. *
  328. * If NULL or the empty string "", a default value is used.
  329. * If the XKB_DEFAULT_LAYOUT environment variable is set, it is used
  330. * as the default. Otherwise the system default is used.
  331. */
  332. const char *layout;
  333. /**
  334. * A comma separated list of variants, one per layout, which may
  335. * modify or augment the respective layout in various ways.
  336. *
  337. * Generally, should either be empty or have the same number of values
  338. * as the number of layouts. You may use empty values as in "intl,,neo".
  339. *
  340. * If NULL or the empty string "", and a default value is also used
  341. * for the layout, a default value is used. Otherwise no variant is
  342. * used.
  343. * If the XKB_DEFAULT_VARIANT environment variable is set, it is used
  344. * as the default. Otherwise the system default is used.
  345. */
  346. const char *variant;
  347. /**
  348. * A comma separated list of options, through which the user specifies
  349. * non-layout related preferences, like which key combinations are used
  350. * for switching layouts, or which key is the Compose key.
  351. *
  352. * If NULL, a default value is used. If the empty string "", no
  353. * options are used.
  354. * If the XKB_DEFAULT_OPTIONS environment variable is set, it is used
  355. * as the default. Otherwise the system default is used.
  356. */
  357. const char *options;
  358. };
  359. /**
  360. * @defgroup keysyms Keysyms
  361. * Utility functions related to keysyms.
  362. *
  363. * @{
  364. */
  365. /**
  366. * @page keysym-transformations Keysym Transformations
  367. *
  368. * Keysym translation is subject to several "keysym transformations",
  369. * as described in the XKB specification. These are:
  370. *
  371. * - Capitalization transformation. If the Caps Lock modifier is
  372. * active and was not consumed by the translation process, a single
  373. * keysym is transformed to its upper-case form (if applicable).
  374. * Similarly, the UTF-8/UTF-32 string produced is capitalized.
  375. *
  376. * This is described in:
  377. * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Lock_Modifier
  378. *
  379. * - Control transformation. If the Control modifier is active and
  380. * was not consumed by the translation process, the string produced
  381. * is transformed to its matching ASCII control character (if
  382. * applicable). Keysyms are not affected.
  383. *
  384. * This is described in:
  385. * https://www.x.org/releases/current/doc/kbproto/xkbproto.html#Interpreting_the_Control_Modifier
  386. *
  387. * Each relevant function discusses which transformations it performs.
  388. *
  389. * These transformations are not applicable when a key produces multiple
  390. * keysyms.
  391. */
  392. /**
  393. * Get the name of a keysym.
  394. *
  395. * For a description of how keysyms are named, see @ref xkb_keysym_t.
  396. *
  397. * @param[in] keysym The keysym.
  398. * @param[out] buffer A string buffer to write the name into.
  399. * @param[in] size Size of the buffer.
  400. *
  401. * @warning If the buffer passed is too small, the string is truncated
  402. * (though still NUL-terminated); a size of at least 64 bytes is recommended.
  403. *
  404. * @returns The number of bytes in the name, excluding the NUL byte. If
  405. * the keysym is invalid, returns -1.
  406. *
  407. * You may check if truncation has occurred by comparing the return value
  408. * with the length of buffer, similarly to the snprintf(3) function.
  409. *
  410. * @sa xkb_keysym_t
  411. */
  412. int
  413. xkb_keysym_get_name(xkb_keysym_t keysym, char *buffer, size_t size);
  414. /** Flags for xkb_keysym_from_name(). */
  415. enum xkb_keysym_flags {
  416. /** Do not apply any flags. */
  417. XKB_KEYSYM_NO_FLAGS = 0,
  418. /** Find keysym by case-insensitive search. */
  419. XKB_KEYSYM_CASE_INSENSITIVE = (1 << 0)
  420. };
  421. /**
  422. * Get a keysym from its name.
  423. *
  424. * @param name The name of a keysym. See remarks in xkb_keysym_get_name();
  425. * this function will accept any name returned by that function.
  426. * @param flags A set of flags controlling how the search is done. If
  427. * invalid flags are passed, this will fail with XKB_KEY_NoSymbol.
  428. *
  429. * If you use the XKB_KEYSYM_CASE_INSENSITIVE flag and two keysym names
  430. * differ only by case, then the lower-case keysym is returned. For
  431. * instance, for KEY_a and KEY_A, this function would return KEY_a for the
  432. * case-insensitive search. If this functionality is needed, it is
  433. * recommended to first call this function without this flag; and if that
  434. * fails, only then to try with this flag, while possibly warning the user
  435. * he had misspelled the name, and might get wrong results.
  436. *
  437. * Case folding is done according to the C locale; the current locale is not
  438. * consulted.
  439. *
  440. * @returns The keysym. If the name is invalid, returns XKB_KEY_NoSymbol.
  441. *
  442. * @sa xkb_keysym_t
  443. */
  444. xkb_keysym_t
  445. xkb_keysym_from_name(const char *name, enum xkb_keysym_flags flags);
  446. /**
  447. * Get the Unicode/UTF-8 representation of a keysym.
  448. *
  449. * @param[in] keysym The keysym.
  450. * @param[out] buffer A buffer to write the UTF-8 string into.
  451. * @param[in] size The size of buffer. Must be at least 7.
  452. *
  453. * @returns The number of bytes written to the buffer (including the
  454. * terminating byte). If the keysym does not have a Unicode
  455. * representation, returns 0. If the buffer is too small, returns -1.
  456. *
  457. * This function does not perform any @ref keysym-transformations.
  458. * Therefore, prefer to use xkb_state_key_get_utf8() if possible.
  459. *
  460. * @sa xkb_state_key_get_utf8()
  461. */
  462. int
  463. xkb_keysym_to_utf8(xkb_keysym_t keysym, char *buffer, size_t size);
  464. /**
  465. * Get the Unicode/UTF-32 representation of a keysym.
  466. *
  467. * @returns The Unicode/UTF-32 representation of keysym, which is also
  468. * compatible with UCS-4. If the keysym does not have a Unicode
  469. * representation, returns 0.
  470. *
  471. * This function does not perform any @ref keysym-transformations.
  472. * Therefore, prefer to use xkb_state_key_get_utf32() if possible.
  473. *
  474. * @sa xkb_state_key_get_utf32()
  475. */
  476. uint32_t
  477. xkb_keysym_to_utf32(xkb_keysym_t keysym);
  478. /**
  479. * Get the keysym corresponding to a Unicode/UTF-32 codepoint.
  480. *
  481. * @returns The keysym corresponding to the specified Unicode
  482. * codepoint, or XKB_KEY_NoSymbol if there is none.
  483. *
  484. * This function is the inverse of @ref xkb_keysym_to_utf32. In cases
  485. * where a single codepoint corresponds to multiple keysyms, returns
  486. * the keysym with the lowest value.
  487. *
  488. * Unicode codepoints which do not have a special (legacy) keysym
  489. * encoding use a direct encoding scheme. These keysyms don't usually
  490. * have an associated keysym constant (XKB_KEY_*).
  491. *
  492. * For noncharacter Unicode codepoints and codepoints outside of the
  493. * defined Unicode planes this function returns XKB_KEY_NoSymbol.
  494. *
  495. * @sa xkb_keysym_to_utf32()
  496. * @since 1.0.0
  497. */
  498. xkb_keysym_t
  499. xkb_utf32_to_keysym(uint32_t ucs);
  500. /**
  501. * Convert a keysym to its uppercase form.
  502. *
  503. * If there is no such form, the keysym is returned unchanged.
  504. *
  505. * The conversion rules may be incomplete; prefer to work with the Unicode
  506. * representation instead, when possible.
  507. */
  508. xkb_keysym_t
  509. xkb_keysym_to_upper(xkb_keysym_t ks);
  510. /**
  511. * Convert a keysym to its lowercase form.
  512. *
  513. * The conversion rules may be incomplete; prefer to work with the Unicode
  514. * representation instead, when possible.
  515. */
  516. xkb_keysym_t
  517. xkb_keysym_to_lower(xkb_keysym_t ks);
  518. /** @} */
  519. /**
  520. * @defgroup context Library Context
  521. * Creating, destroying and using library contexts.
  522. *
  523. * Every keymap compilation request must have a context associated with
  524. * it. The context keeps around state such as the include path.
  525. *
  526. * @{
  527. */
  528. /**
  529. * @page envvars Environment Variables
  530. *
  531. * The user may set some environment variables which affect the library:
  532. *
  533. * - `XKB_CONFIG_ROOT`, `XKB_CONFIG_EXTRA_PATH`, `XDG_CONFIG_DIR`, `HOME` - see @ref include-path.
  534. * - `XKB_LOG_LEVEL` - see xkb_context_set_log_level().
  535. * - `XKB_LOG_VERBOSITY` - see xkb_context_set_log_verbosity().
  536. * - `XKB_DEFAULT_RULES`, `XKB_DEFAULT_MODEL`, `XKB_DEFAULT_LAYOUT`,
  537. * `XKB_DEFAULT_VARIANT`, `XKB_DEFAULT_OPTIONS` - see xkb_rule_names.
  538. */
  539. /** Flags for context creation. */
  540. enum xkb_context_flags {
  541. /** Do not apply any context flags. */
  542. XKB_CONTEXT_NO_FLAGS = 0,
  543. /** Create this context with an empty include path. */
  544. XKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
  545. /**
  546. * Don't take RMLVO names from the environment.
  547. * @since 0.3.0
  548. */
  549. XKB_CONTEXT_NO_ENVIRONMENT_NAMES = (1 << 1)
  550. };
  551. /**
  552. * Create a new context.
  553. *
  554. * @param flags Optional flags for the context, or 0.
  555. *
  556. * @returns A new context, or NULL on failure.
  557. *
  558. * @memberof xkb_context
  559. */
  560. struct xkb_context *
  561. xkb_context_new(enum xkb_context_flags flags);
  562. /**
  563. * Take a new reference on a context.
  564. *
  565. * @returns The passed in context.
  566. *
  567. * @memberof xkb_context
  568. */
  569. struct xkb_context *
  570. xkb_context_ref(struct xkb_context *context);
  571. /**
  572. * Release a reference on a context, and possibly free it.
  573. *
  574. * @param context The context. If it is NULL, this function does nothing.
  575. *
  576. * @memberof xkb_context
  577. */
  578. void
  579. xkb_context_unref(struct xkb_context *context);
  580. /**
  581. * Store custom user data in the context.
  582. *
  583. * This may be useful in conjunction with xkb_context_set_log_fn() or other
  584. * callbacks.
  585. *
  586. * @memberof xkb_context
  587. */
  588. void
  589. xkb_context_set_user_data(struct xkb_context *context, void *user_data);
  590. /**
  591. * Retrieves stored user data from the context.
  592. *
  593. * @returns The stored user data. If the user data wasn't set, or the
  594. * passed in context is NULL, returns NULL.
  595. *
  596. * This may be useful to access private user data from callbacks like a
  597. * custom logging function.
  598. *
  599. * @memberof xkb_context
  600. **/
  601. void *
  602. xkb_context_get_user_data(struct xkb_context *context);
  603. /** @} */
  604. /**
  605. * @defgroup include-path Include Paths
  606. * Manipulating the include paths in a context.
  607. *
  608. * The include paths are the file-system paths that are searched when an
  609. * include statement is encountered during keymap compilation.
  610. *
  611. * The default include paths are, in that lookup order:
  612. * - The path `$XDG_CONFIG_HOME/xkb`, with the usual `XDG_CONFIG_HOME`
  613. * fallback to `$HOME/.config/` if unset.
  614. * - The path `$HOME/.xkb`, where $HOME is the value of the environment
  615. * variable `HOME`.
  616. * - The `XKB_CONFIG_EXTRA_PATH` environment variable, if defined, otherwise the
  617. * system configuration directory, defined at library configuration time
  618. * (usually `/etc/xkb`).
  619. * - The `XKB_CONFIG_ROOT` environment variable, if defined, otherwise
  620. * the system XKB root, defined at library configuration time.
  621. *
  622. * @{
  623. */
  624. /**
  625. * Append a new entry to the context's include path.
  626. *
  627. * @returns 1 on success, or 0 if the include path could not be added or is
  628. * inaccessible.
  629. *
  630. * @memberof xkb_context
  631. */
  632. int
  633. xkb_context_include_path_append(struct xkb_context *context, const char *path);
  634. /**
  635. * Append the default include paths to the context's include path.
  636. *
  637. * @returns 1 on success, or 0 if the primary include path could not be added.
  638. *
  639. * @memberof xkb_context
  640. */
  641. int
  642. xkb_context_include_path_append_default(struct xkb_context *context);
  643. /**
  644. * Reset the context's include path to the default.
  645. *
  646. * Removes all entries from the context's include path, and inserts the
  647. * default paths.
  648. *
  649. * @returns 1 on success, or 0 if the primary include path could not be added.
  650. *
  651. * @memberof xkb_context
  652. */
  653. int
  654. xkb_context_include_path_reset_defaults(struct xkb_context *context);
  655. /**
  656. * Remove all entries from the context's include path.
  657. *
  658. * @memberof xkb_context
  659. */
  660. void
  661. xkb_context_include_path_clear(struct xkb_context *context);
  662. /**
  663. * Get the number of paths in the context's include path.
  664. *
  665. * @memberof xkb_context
  666. */
  667. unsigned int
  668. xkb_context_num_include_paths(struct xkb_context *context);
  669. /**
  670. * Get a specific include path from the context's include path.
  671. *
  672. * @returns The include path at the specified index. If the index is
  673. * invalid, returns NULL.
  674. *
  675. * @memberof xkb_context
  676. */
  677. const char *
  678. xkb_context_include_path_get(struct xkb_context *context, unsigned int index);
  679. /** @} */
  680. /**
  681. * @defgroup logging Logging Handling
  682. * Manipulating how logging from this library is handled.
  683. *
  684. * @{
  685. */
  686. /** Specifies a logging level. */
  687. enum xkb_log_level {
  688. XKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
  689. XKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
  690. XKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
  691. XKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
  692. XKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
  693. };
  694. /**
  695. * Set the current logging level.
  696. *
  697. * @param context The context in which to set the logging level.
  698. * @param level The logging level to use. Only messages from this level
  699. * and below will be logged.
  700. *
  701. * The default level is XKB_LOG_LEVEL_ERROR. The environment variable
  702. * XKB_LOG_LEVEL, if set in the time the context was created, overrides the
  703. * default value. It may be specified as a level number or name.
  704. *
  705. * @memberof xkb_context
  706. */
  707. void
  708. xkb_context_set_log_level(struct xkb_context *context,
  709. enum xkb_log_level level);
  710. /**
  711. * Get the current logging level.
  712. *
  713. * @memberof xkb_context
  714. */
  715. enum xkb_log_level
  716. xkb_context_get_log_level(struct xkb_context *context);
  717. /**
  718. * Sets the current logging verbosity.
  719. *
  720. * The library can generate a number of warnings which are not helpful to
  721. * ordinary users of the library. The verbosity may be increased if more
  722. * information is desired (e.g. when developing a new keymap).
  723. *
  724. * The default verbosity is 0. The environment variable XKB_LOG_VERBOSITY,
  725. * if set in the time the context was created, overrides the default value.
  726. *
  727. * @param context The context in which to use the set verbosity.
  728. * @param verbosity The verbosity to use. Currently used values are
  729. * 1 to 10, higher values being more verbose. 0 would result in no verbose
  730. * messages being logged.
  731. *
  732. * Most verbose messages are of level XKB_LOG_LEVEL_WARNING or lower.
  733. *
  734. * @memberof xkb_context
  735. */
  736. void
  737. xkb_context_set_log_verbosity(struct xkb_context *context, int verbosity);
  738. /**
  739. * Get the current logging verbosity of the context.
  740. *
  741. * @memberof xkb_context
  742. */
  743. int
  744. xkb_context_get_log_verbosity(struct xkb_context *context);
  745. /**
  746. * Set a custom function to handle logging messages.
  747. *
  748. * @param context The context in which to use the set logging function.
  749. * @param log_fn The function that will be called for logging messages.
  750. * Passing NULL restores the default function, which logs to stderr.
  751. *
  752. * By default, log messages from this library are printed to stderr. This
  753. * function allows you to replace the default behavior with a custom
  754. * handler. The handler is only called with messages which match the
  755. * current logging level and verbosity settings for the context.
  756. * level is the logging level of the message. @a format and @a args are
  757. * the same as in the vprintf(3) function.
  758. *
  759. * You may use xkb_context_set_user_data() on the context, and then call
  760. * xkb_context_get_user_data() from within the logging function to provide
  761. * it with additional private context.
  762. *
  763. * @memberof xkb_context
  764. */
  765. void
  766. xkb_context_set_log_fn(struct xkb_context *context,
  767. void (*log_fn)(struct xkb_context *context,
  768. enum xkb_log_level level,
  769. const char *format, va_list args));
  770. /** @} */
  771. /**
  772. * @defgroup keymap Keymap Creation
  773. * Creating and destroying keymaps.
  774. *
  775. * @{
  776. */
  777. /** Flags for keymap compilation. */
  778. enum xkb_keymap_compile_flags {
  779. /** Do not apply any flags. */
  780. XKB_KEYMAP_COMPILE_NO_FLAGS = 0
  781. };
  782. /**
  783. * Create a keymap from RMLVO names.
  784. *
  785. * The primary keymap entry point: creates a new XKB keymap from a set of
  786. * RMLVO (Rules + Model + Layouts + Variants + Options) names.
  787. *
  788. * @param context The context in which to create the keymap.
  789. * @param names The RMLVO names to use. See xkb_rule_names.
  790. * @param flags Optional flags for the keymap, or 0.
  791. *
  792. * @returns A keymap compiled according to the RMLVO names, or NULL if
  793. * the compilation failed.
  794. *
  795. * @sa xkb_rule_names
  796. * @memberof xkb_keymap
  797. */
  798. struct xkb_keymap *
  799. xkb_keymap_new_from_names(struct xkb_context *context,
  800. const struct xkb_rule_names *names,
  801. enum xkb_keymap_compile_flags flags);
  802. /** The possible keymap formats. */
  803. enum xkb_keymap_format {
  804. /** The current/classic XKB text format, as generated by xkbcomp -xkb. */
  805. XKB_KEYMAP_FORMAT_TEXT_V1 = 1
  806. };
  807. /**
  808. * Create a keymap from a keymap file.
  809. *
  810. * @param context The context in which to create the keymap.
  811. * @param file The keymap file to compile.
  812. * @param format The text format of the keymap file to compile.
  813. * @param flags Optional flags for the keymap, or 0.
  814. *
  815. * @returns A keymap compiled from the given XKB keymap file, or NULL if
  816. * the compilation failed.
  817. *
  818. * The file must contain a complete keymap. For example, in the
  819. * XKB_KEYMAP_FORMAT_TEXT_V1 format, this means the file must contain one
  820. * top level '%xkb_keymap' section, which in turn contains other required
  821. * sections.
  822. *
  823. * @memberof xkb_keymap
  824. */
  825. struct xkb_keymap *
  826. xkb_keymap_new_from_file(struct xkb_context *context, FILE *file,
  827. enum xkb_keymap_format format,
  828. enum xkb_keymap_compile_flags flags);
  829. /**
  830. * Create a keymap from a keymap string.
  831. *
  832. * This is just like xkb_keymap_new_from_file(), but instead of a file, gets
  833. * the keymap as one enormous string.
  834. *
  835. * @see xkb_keymap_new_from_file()
  836. * @memberof xkb_keymap
  837. */
  838. struct xkb_keymap *
  839. xkb_keymap_new_from_string(struct xkb_context *context, const char *string,
  840. enum xkb_keymap_format format,
  841. enum xkb_keymap_compile_flags flags);
  842. /**
  843. * Create a keymap from a memory buffer.
  844. *
  845. * This is just like xkb_keymap_new_from_string(), but takes a length argument
  846. * so the input string does not have to be zero-terminated.
  847. *
  848. * @see xkb_keymap_new_from_string()
  849. * @memberof xkb_keymap
  850. * @since 0.3.0
  851. */
  852. struct xkb_keymap *
  853. xkb_keymap_new_from_buffer(struct xkb_context *context, const char *buffer,
  854. size_t length, enum xkb_keymap_format format,
  855. enum xkb_keymap_compile_flags flags);
  856. /**
  857. * Take a new reference on a keymap.
  858. *
  859. * @returns The passed in keymap.
  860. *
  861. * @memberof xkb_keymap
  862. */
  863. struct xkb_keymap *
  864. xkb_keymap_ref(struct xkb_keymap *keymap);
  865. /**
  866. * Release a reference on a keymap, and possibly free it.
  867. *
  868. * @param keymap The keymap. If it is NULL, this function does nothing.
  869. *
  870. * @memberof xkb_keymap
  871. */
  872. void
  873. xkb_keymap_unref(struct xkb_keymap *keymap);
  874. /**
  875. * Get the keymap as a string in the format from which it was created.
  876. * @sa xkb_keymap_get_as_string()
  877. **/
  878. #define XKB_KEYMAP_USE_ORIGINAL_FORMAT ((enum xkb_keymap_format) -1)
  879. /**
  880. * Get the compiled keymap as a string.
  881. *
  882. * @param keymap The keymap to get as a string.
  883. * @param format The keymap format to use for the string. You can pass
  884. * in the special value XKB_KEYMAP_USE_ORIGINAL_FORMAT to use the format
  885. * from which the keymap was originally created.
  886. *
  887. * @returns The keymap as a NUL-terminated string, or NULL if unsuccessful.
  888. *
  889. * The returned string may be fed back into xkb_keymap_new_from_string() to get
  890. * the exact same keymap (possibly in another process, etc.).
  891. *
  892. * The returned string is dynamically allocated and should be freed by the
  893. * caller.
  894. *
  895. * @memberof xkb_keymap
  896. */
  897. char *
  898. xkb_keymap_get_as_string(struct xkb_keymap *keymap,
  899. enum xkb_keymap_format format);
  900. /** @} */
  901. /**
  902. * @defgroup components Keymap Components
  903. * Enumeration of state components in a keymap.
  904. *
  905. * @{
  906. */
  907. /**
  908. * Get the minimum keycode in the keymap.
  909. *
  910. * @sa xkb_keycode_t
  911. * @memberof xkb_keymap
  912. * @since 0.3.1
  913. */
  914. xkb_keycode_t
  915. xkb_keymap_min_keycode(struct xkb_keymap *keymap);
  916. /**
  917. * Get the maximum keycode in the keymap.
  918. *
  919. * @sa xkb_keycode_t
  920. * @memberof xkb_keymap
  921. * @since 0.3.1
  922. */
  923. xkb_keycode_t
  924. xkb_keymap_max_keycode(struct xkb_keymap *keymap);
  925. /**
  926. * The iterator used by xkb_keymap_key_for_each().
  927. *
  928. * @sa xkb_keymap_key_for_each
  929. * @memberof xkb_keymap
  930. * @since 0.3.1
  931. */
  932. typedef void
  933. (*xkb_keymap_key_iter_t)(struct xkb_keymap *keymap, xkb_keycode_t key,
  934. void *data);
  935. /**
  936. * Run a specified function for every valid keycode in the keymap. If a
  937. * keymap is sparse, this function may be called fewer than
  938. * (max_keycode - min_keycode + 1) times.
  939. *
  940. * @sa xkb_keymap_min_keycode() xkb_keymap_max_keycode() xkb_keycode_t
  941. * @memberof xkb_keymap
  942. * @since 0.3.1
  943. */
  944. void
  945. xkb_keymap_key_for_each(struct xkb_keymap *keymap, xkb_keymap_key_iter_t iter,
  946. void *data);
  947. /**
  948. * Find the name of the key with the given keycode.
  949. *
  950. * This function always returns the canonical name of the key (see
  951. * description in xkb_keycode_t).
  952. *
  953. * @returns The key name. If no key with this keycode exists,
  954. * returns NULL.
  955. *
  956. * @sa xkb_keycode_t
  957. * @memberof xkb_keymap
  958. * @since 0.6.0
  959. */
  960. const char *
  961. xkb_keymap_key_get_name(struct xkb_keymap *keymap, xkb_keycode_t key);
  962. /**
  963. * Find the keycode of the key with the given name.
  964. *
  965. * The name can be either a canonical name or an alias.
  966. *
  967. * @returns The keycode. If no key with this name exists,
  968. * returns XKB_KEYCODE_INVALID.
  969. *
  970. * @sa xkb_keycode_t
  971. * @memberof xkb_keymap
  972. * @since 0.6.0
  973. */
  974. xkb_keycode_t
  975. xkb_keymap_key_by_name(struct xkb_keymap *keymap, const char *name);
  976. /**
  977. * Get the number of modifiers in the keymap.
  978. *
  979. * @sa xkb_mod_index_t
  980. * @memberof xkb_keymap
  981. */
  982. xkb_mod_index_t
  983. xkb_keymap_num_mods(struct xkb_keymap *keymap);
  984. /**
  985. * Get the name of a modifier by index.
  986. *
  987. * @returns The name. If the index is invalid, returns NULL.
  988. *
  989. * @sa xkb_mod_index_t
  990. * @memberof xkb_keymap
  991. */
  992. const char *
  993. xkb_keymap_mod_get_name(struct xkb_keymap *keymap, xkb_mod_index_t idx);
  994. /**
  995. * Get the index of a modifier by name.
  996. *
  997. * @returns The index. If no modifier with this name exists, returns
  998. * XKB_MOD_INVALID.
  999. *
  1000. * @sa xkb_mod_index_t
  1001. * @memberof xkb_keymap
  1002. */
  1003. xkb_mod_index_t
  1004. xkb_keymap_mod_get_index(struct xkb_keymap *keymap, const char *name);
  1005. /**
  1006. * Get the number of layouts in the keymap.
  1007. *
  1008. * @sa xkb_layout_index_t xkb_rule_names xkb_keymap_num_layouts_for_key()
  1009. * @memberof xkb_keymap
  1010. */
  1011. xkb_layout_index_t
  1012. xkb_keymap_num_layouts(struct xkb_keymap *keymap);
  1013. /**
  1014. * Get the name of a layout by index.
  1015. *
  1016. * @returns The name. If the index is invalid, or the layout does not have
  1017. * a name, returns NULL.
  1018. *
  1019. * @sa xkb_layout_index_t
  1020. * For notes on layout names.
  1021. * @memberof xkb_keymap
  1022. */
  1023. const char *
  1024. xkb_keymap_layout_get_name(struct xkb_keymap *keymap, xkb_layout_index_t idx);
  1025. /**
  1026. * Get the index of a layout by name.
  1027. *
  1028. * @returns The index. If no layout exists with this name, returns
  1029. * XKB_LAYOUT_INVALID. If more than one layout in the keymap has this name,
  1030. * returns the lowest index among them.
  1031. *
  1032. * @sa xkb_layout_index_t
  1033. * For notes on layout names.
  1034. * @memberof xkb_keymap
  1035. */
  1036. xkb_layout_index_t
  1037. xkb_keymap_layout_get_index(struct xkb_keymap *keymap, const char *name);
  1038. /**
  1039. * Get the number of LEDs in the keymap.
  1040. *
  1041. * @warning The range [ 0...xkb_keymap_num_leds() ) includes all of the LEDs
  1042. * in the keymap, but may also contain inactive LEDs. When iterating over
  1043. * this range, you need the handle this case when calling functions such as
  1044. * xkb_keymap_led_get_name() or xkb_state_led_index_is_active().
  1045. *
  1046. * @sa xkb_led_index_t
  1047. * @memberof xkb_keymap
  1048. */
  1049. xkb_led_index_t
  1050. xkb_keymap_num_leds(struct xkb_keymap *keymap);
  1051. /**
  1052. * Get the name of a LED by index.
  1053. *
  1054. * @returns The name. If the index is invalid, returns NULL.
  1055. *
  1056. * @memberof xkb_keymap
  1057. */
  1058. const char *
  1059. xkb_keymap_led_get_name(struct xkb_keymap *keymap, xkb_led_index_t idx);
  1060. /**
  1061. * Get the index of a LED by name.
  1062. *
  1063. * @returns The index. If no LED with this name exists, returns
  1064. * XKB_LED_INVALID.
  1065. *
  1066. * @memberof xkb_keymap
  1067. */
  1068. xkb_led_index_t
  1069. xkb_keymap_led_get_index(struct xkb_keymap *keymap, const char *name);
  1070. /**
  1071. * Get the number of layouts for a specific key.
  1072. *
  1073. * This number can be different from xkb_keymap_num_layouts(), but is always
  1074. * smaller. It is the appropriate value to use when iterating over the
  1075. * layouts of a key.
  1076. *
  1077. * @sa xkb_layout_index_t
  1078. * @memberof xkb_keymap
  1079. */
  1080. xkb_layout_index_t
  1081. xkb_keymap_num_layouts_for_key(struct xkb_keymap *keymap, xkb_keycode_t key);
  1082. /**
  1083. * Get the number of shift levels for a specific key and layout.
  1084. *
  1085. * If @c layout is out of range for this key (that is, larger or equal to
  1086. * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
  1087. * back into range in a manner consistent with xkb_state_key_get_layout().
  1088. *
  1089. * @sa xkb_level_index_t
  1090. * @memberof xkb_keymap
  1091. */
  1092. xkb_level_index_t
  1093. xkb_keymap_num_levels_for_key(struct xkb_keymap *keymap, xkb_keycode_t key,
  1094. xkb_layout_index_t layout);
  1095. /**
  1096. * Retrieves every possible modifier mask that produces the specified
  1097. * shift level for a specific key and layout.
  1098. *
  1099. * This API is useful for inverse key transformation; i.e. finding out
  1100. * which modifiers need to be active in order to be able to type the
  1101. * keysym(s) corresponding to the specific key code, layout and level.
  1102. *
  1103. * @warning It returns only up to masks_size modifier masks. If the
  1104. * buffer passed is too small, some of the possible modifier combinations
  1105. * will not be returned.
  1106. *
  1107. * @param[in] keymap The keymap.
  1108. * @param[in] key The keycode of the key.
  1109. * @param[in] layout The layout for which to get modifiers.
  1110. * @param[in] level The shift level in the layout for which to get the
  1111. * modifiers. This should be smaller than:
  1112. * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
  1113. * @param[out] masks_out A buffer in which the requested masks should be
  1114. * stored.
  1115. * @param[out] masks_size The size of the buffer pointed to by masks_out.
  1116. *
  1117. * If @c layout is out of range for this key (that is, larger or equal to
  1118. * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
  1119. * back into range in a manner consistent with xkb_state_key_get_layout().
  1120. *
  1121. * @returns The number of modifier masks stored in the masks_out array.
  1122. * If the key is not in the keymap or if the specified shift level cannot
  1123. * be reached it returns 0 and does not modify the masks_out buffer.
  1124. *
  1125. * @sa xkb_level_index_t
  1126. * @sa xkb_mod_mask_t
  1127. * @memberof xkb_keymap
  1128. * @since 1.0.0
  1129. */
  1130. size_t
  1131. xkb_keymap_key_get_mods_for_level(struct xkb_keymap *keymap,
  1132. xkb_keycode_t key,
  1133. xkb_layout_index_t layout,
  1134. xkb_level_index_t level,
  1135. xkb_mod_mask_t *masks_out,
  1136. size_t masks_size);
  1137. /**
  1138. * Get the keysyms obtained from pressing a key in a given layout and
  1139. * shift level.
  1140. *
  1141. * This function is like xkb_state_key_get_syms(), only the layout and
  1142. * shift level are not derived from the keyboard state but are instead
  1143. * specified explicitly.
  1144. *
  1145. * @param[in] keymap The keymap.
  1146. * @param[in] key The keycode of the key.
  1147. * @param[in] layout The layout for which to get the keysyms.
  1148. * @param[in] level The shift level in the layout for which to get the
  1149. * keysyms. This should be smaller than:
  1150. * @code xkb_keymap_num_levels_for_key(keymap, key) @endcode
  1151. * @param[out] syms_out An immutable array of keysyms corresponding to the
  1152. * key in the given layout and shift level.
  1153. *
  1154. * If @c layout is out of range for this key (that is, larger or equal to
  1155. * the value returned by xkb_keymap_num_layouts_for_key()), it is brought
  1156. * back into range in a manner consistent with xkb_state_key_get_layout().
  1157. *
  1158. * @returns The number of keysyms in the syms_out array. If no keysyms
  1159. * are produced by the key in the given layout and shift level, returns 0
  1160. * and sets syms_out to NULL.
  1161. *
  1162. * @sa xkb_state_key_get_syms()
  1163. * @memberof xkb_keymap
  1164. */
  1165. int
  1166. xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
  1167. xkb_keycode_t key,
  1168. xkb_layout_index_t layout,
  1169. xkb_level_index_t level,
  1170. const xkb_keysym_t **syms_out);
  1171. /**
  1172. * Determine whether a key should repeat or not.
  1173. *
  1174. * A keymap may specify different repeat behaviors for different keys.
  1175. * Most keys should generally exhibit repeat behavior; for example, holding
  1176. * the 'a' key down in a text editor should normally insert a single 'a'
  1177. * character every few milliseconds, until the key is released. However,
  1178. * there are keys which should not or do not need to be repeated. For
  1179. * example, repeating modifier keys such as Left/Right Shift or Caps Lock
  1180. * is not generally useful or desired.
  1181. *
  1182. * @returns 1 if the key should repeat, 0 otherwise.
  1183. *
  1184. * @memberof xkb_keymap
  1185. */
  1186. int
  1187. xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
  1188. /** @} */
  1189. /**
  1190. * @defgroup state Keyboard State
  1191. * Creating, destroying and manipulating keyboard state objects.
  1192. *
  1193. * @{
  1194. */
  1195. /**
  1196. * Create a new keyboard state object.
  1197. *
  1198. * @param keymap The keymap which the state will use.
  1199. *
  1200. * @returns A new keyboard state object, or NULL on failure.
  1201. *
  1202. * @memberof xkb_state
  1203. */
  1204. struct xkb_state *
  1205. xkb_state_new(struct xkb_keymap *keymap);
  1206. /**
  1207. * Take a new reference on a keyboard state object.
  1208. *
  1209. * @returns The passed in object.
  1210. *
  1211. * @memberof xkb_state
  1212. */
  1213. struct xkb_state *
  1214. xkb_state_ref(struct xkb_state *state);
  1215. /**
  1216. * Release a reference on a keybaord state object, and possibly free it.
  1217. *
  1218. * @param state The state. If it is NULL, this function does nothing.
  1219. *
  1220. * @memberof xkb_state
  1221. */
  1222. void
  1223. xkb_state_unref(struct xkb_state *state);
  1224. /**
  1225. * Get the keymap which a keyboard state object is using.
  1226. *
  1227. * @returns The keymap which was passed to xkb_state_new() when creating
  1228. * this state object.
  1229. *
  1230. * This function does not take a new reference on the keymap; you must
  1231. * explicitly reference it yourself if you plan to use it beyond the
  1232. * lifetime of the state.
  1233. *
  1234. * @memberof xkb_state
  1235. */
  1236. struct xkb_keymap *
  1237. xkb_state_get_keymap(struct xkb_state *state);
  1238. /** Specifies the direction of the key (press / release). */
  1239. enum xkb_key_direction {
  1240. XKB_KEY_UP, /**< The key was released. */
  1241. XKB_KEY_DOWN /**< The key was pressed. */
  1242. };
  1243. /**
  1244. * Modifier and layout types for state objects. This enum is bitmaskable,
  1245. * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
  1246. * exclude locked modifiers.
  1247. *
  1248. * In XKB, the DEPRESSED components are also known as 'base'.
  1249. */
  1250. enum xkb_state_component {
  1251. /** Depressed modifiers, i.e. a key is physically holding them. */
  1252. XKB_STATE_MODS_DEPRESSED = (1 << 0),
  1253. /** Latched modifiers, i.e. will be unset after the next non-modifier
  1254. * key press. */
  1255. XKB_STATE_MODS_LATCHED = (1 << 1),
  1256. /** Locked modifiers, i.e. will be unset after the key provoking the
  1257. * lock has been pressed again. */
  1258. XKB_STATE_MODS_LOCKED = (1 << 2),
  1259. /** Effective modifiers, i.e. currently active and affect key
  1260. * processing (derived from the other state components).
  1261. * Use this unless you explicitly care how the state came about. */
  1262. XKB_STATE_MODS_EFFECTIVE = (1 << 3),
  1263. /** Depressed layout, i.e. a key is physically holding it. */
  1264. XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
  1265. /** Latched layout, i.e. will be unset after the next non-modifier
  1266. * key press. */
  1267. XKB_STATE_LAYOUT_LATCHED = (1 << 5),
  1268. /** Locked layout, i.e. will be unset after the key provoking the lock
  1269. * has been pressed again. */
  1270. XKB_STATE_LAYOUT_LOCKED = (1 << 6),
  1271. /** Effective layout, i.e. currently active and affects key processing
  1272. * (derived from the other state components).
  1273. * Use this unless you explicitly care how the state came about. */
  1274. XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
  1275. /** LEDs (derived from the other state components). */
  1276. XKB_STATE_LEDS = (1 << 8)
  1277. };
  1278. /**
  1279. * Update the keyboard state to reflect a given key being pressed or
  1280. * released.
  1281. *
  1282. * This entry point is intended for programs which track the keyboard state
  1283. * explicitly (like an evdev client). If the state is serialized to you by
  1284. * a master process (like a Wayland compositor) using functions like
  1285. * xkb_state_serialize_mods(), you should use xkb_state_update_mask() instead.
  1286. * The two functions should not generally be used together.
  1287. *
  1288. * A series of calls to this function should be consistent; that is, a call
  1289. * with XKB_KEY_DOWN for a key should be matched by an XKB_KEY_UP; if a key
  1290. * is pressed twice, it should be released twice; etc. Otherwise (e.g. due
  1291. * to missed input events), situations like "stuck modifiers" may occur.
  1292. *
  1293. * This function is often used in conjunction with the function
  1294. * xkb_state_key_get_syms() (or xkb_state_key_get_one_sym()), for example,
  1295. * when handling a key event. In this case, you should prefer to get the
  1296. * keysyms *before* updating the key, such that the keysyms reported for
  1297. * the key event are not affected by the event itself. This is the
  1298. * conventional behavior.
  1299. *
  1300. * @returns A mask of state components that have changed as a result of
  1301. * the update. If nothing in the state has changed, returns 0.
  1302. *
  1303. * @memberof xkb_state
  1304. *
  1305. * @sa xkb_state_update_mask()
  1306. */
  1307. enum xkb_state_component
  1308. xkb_state_update_key(struct xkb_state *state, xkb_keycode_t key,
  1309. enum xkb_key_direction direction);
  1310. /**
  1311. * Update a keyboard state from a set of explicit masks.
  1312. *
  1313. * This entry point is intended for window systems and the like, where a
  1314. * master process holds an xkb_state, then serializes it over a wire
  1315. * protocol, and clients then use the serialization to feed in to their own
  1316. * xkb_state.
  1317. *
  1318. * All parameters must always be passed, or the resulting state may be
  1319. * incoherent.
  1320. *
  1321. * The serialization is lossy and will not survive round trips; it must only
  1322. * be used to feed slave state objects, and must not be used to update the
  1323. * master state.
  1324. *
  1325. * If you do not fit the description above, you should use
  1326. * xkb_state_update_key() instead. The two functions should not generally be
  1327. * used together.
  1328. *
  1329. * @returns A mask of state components that have changed as a result of
  1330. * the update. If nothing in the state has changed, returns 0.
  1331. *
  1332. * @memberof xkb_state
  1333. *
  1334. * @sa xkb_state_component
  1335. * @sa xkb_state_update_key
  1336. */
  1337. enum xkb_state_component
  1338. xkb_state_update_mask(struct xkb_state *state,
  1339. xkb_mod_mask_t depressed_mods,
  1340. xkb_mod_mask_t latched_mods,
  1341. xkb_mod_mask_t locked_mods,
  1342. xkb_layout_index_t depressed_layout,
  1343. xkb_layout_index_t latched_layout,
  1344. xkb_layout_index_t locked_layout);
  1345. /**
  1346. * Get the keysyms obtained from pressing a particular key in a given
  1347. * keyboard state.
  1348. *
  1349. * Get the keysyms for a key according to the current active layout,
  1350. * modifiers and shift level for the key, as determined by a keyboard
  1351. * state.
  1352. *
  1353. * @param[in] state The keyboard state object.
  1354. * @param[in] key The keycode of the key.
  1355. * @param[out] syms_out An immutable array of keysyms corresponding the
  1356. * key in the given keyboard state.
  1357. *
  1358. * As an extension to XKB, this function can return more than one keysym.
  1359. * If you do not want to handle this case, you can use
  1360. * xkb_state_key_get_one_sym() for a simpler interface.
  1361. *
  1362. * This function does not perform any @ref keysym-transformations.
  1363. * (This might change).
  1364. *
  1365. * @returns The number of keysyms in the syms_out array. If no keysyms
  1366. * are produced by the key in the given keyboard state, returns 0 and sets
  1367. * syms_out to NULL.
  1368. *
  1369. * @memberof xkb_state
  1370. */
  1371. int
  1372. xkb_state_key_get_syms(struct xkb_state *state, xkb_keycode_t key,
  1373. const xkb_keysym_t **syms_out);
  1374. /**
  1375. * Get the Unicode/UTF-8 string obtained from pressing a particular key
  1376. * in a given keyboard state.
  1377. *
  1378. * @param[in] state The keyboard state object.
  1379. * @param[in] key The keycode of the key.
  1380. * @param[out] buffer A buffer to write the string into.
  1381. * @param[in] size Size of the buffer.
  1382. *
  1383. * @warning If the buffer passed is too small, the string is truncated
  1384. * (though still NUL-terminated).
  1385. *
  1386. * @returns The number of bytes required for the string, excluding the
  1387. * NUL byte. If there is nothing to write, returns 0.
  1388. *
  1389. * You may check if truncation has occurred by comparing the return value
  1390. * with the size of @p buffer, similarly to the snprintf(3) function.
  1391. * You may safely pass NULL and 0 to @p buffer and @p size to find the
  1392. * required size (without the NUL-byte).
  1393. *
  1394. * This function performs Capitalization and Control @ref
  1395. * keysym-transformations.
  1396. *
  1397. * @memberof xkb_state
  1398. * @since 0.4.1
  1399. */
  1400. int
  1401. xkb_state_key_get_utf8(struct xkb_state *state, xkb_keycode_t key,
  1402. char *buffer, size_t size);
  1403. /**
  1404. * Get the Unicode/UTF-32 codepoint obtained from pressing a particular
  1405. * key in a a given keyboard state.
  1406. *
  1407. * @returns The UTF-32 representation for the key, if it consists of only
  1408. * a single codepoint. Otherwise, returns 0.
  1409. *
  1410. * This function performs Capitalization and Control @ref
  1411. * keysym-transformations.
  1412. *
  1413. * @memberof xkb_state
  1414. * @since 0.4.1
  1415. */
  1416. uint32_t
  1417. xkb_state_key_get_utf32(struct xkb_state *state, xkb_keycode_t key);
  1418. /**
  1419. * Get the single keysym obtained from pressing a particular key in a
  1420. * given keyboard state.
  1421. *
  1422. * This function is similar to xkb_state_key_get_syms(), but intended
  1423. * for users which cannot or do not want to handle the case where
  1424. * multiple keysyms are returned (in which case this function is
  1425. * preferred).
  1426. *
  1427. * @returns The keysym. If the key does not have exactly one keysym,
  1428. * returns XKB_KEY_NoSymbol
  1429. *
  1430. * This function performs Capitalization @ref keysym-transformations.
  1431. *
  1432. * @sa xkb_state_key_get_syms()
  1433. * @memberof xkb_state
  1434. */
  1435. xkb_keysym_t
  1436. xkb_state_key_get_one_sym(struct xkb_state *state, xkb_keycode_t key);
  1437. /**
  1438. * Get the effective layout index for a key in a given keyboard state.
  1439. *
  1440. * @returns The layout index for the key in the given keyboard state. If
  1441. * the given keycode is invalid, or if the key is not included in any
  1442. * layout at all, returns XKB_LAYOUT_INVALID.
  1443. *
  1444. * @invariant If the returned layout is valid, the following always holds:
  1445. * @code
  1446. * xkb_state_key_get_layout(state, key) < xkb_keymap_num_layouts_for_key(keymap, key)
  1447. * @endcode
  1448. *
  1449. * @memberof xkb_state
  1450. */
  1451. xkb_layout_index_t
  1452. xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t key);
  1453. /**
  1454. * Get the effective shift level for a key in a given keyboard state and
  1455. * layout.
  1456. *
  1457. * @param state The keyboard state.
  1458. * @param key The keycode of the key.
  1459. * @param layout The layout for which to get the shift level. This must be
  1460. * smaller than:
  1461. * @code xkb_keymap_num_layouts_for_key(keymap, key) @endcode
  1462. * usually it would be:
  1463. * @code xkb_state_key_get_layout(state, key) @endcode
  1464. *
  1465. * @return The shift level index. If the key or layout are invalid,
  1466. * returns XKB_LEVEL_INVALID.
  1467. *
  1468. * @invariant If the returned level is valid, the following always holds:
  1469. * @code
  1470. * xkb_state_key_get_level(state, key, layout) < xkb_keymap_num_levels_for_key(keymap, key, layout)
  1471. * @endcode
  1472. *
  1473. * @memberof xkb_state
  1474. */
  1475. xkb_level_index_t
  1476. xkb_state_key_get_level(struct xkb_state *state, xkb_keycode_t key,
  1477. xkb_layout_index_t layout);
  1478. /**
  1479. * Match flags for xkb_state_mod_indices_are_active() and
  1480. * xkb_state_mod_names_are_active(), specifying the conditions for a
  1481. * successful match. XKB_STATE_MATCH_NON_EXCLUSIVE is bitmaskable with
  1482. * the other modes.
  1483. */
  1484. enum xkb_state_match {
  1485. /** Returns true if any of the modifiers are active. */
  1486. XKB_STATE_MATCH_ANY = (1 << 0),
  1487. /** Returns true if all of the modifiers are active. */
  1488. XKB_STATE_MATCH_ALL = (1 << 1),
  1489. /** Makes matching non-exclusive, i.e. will not return false if a
  1490. * modifier not specified in the arguments is active. */
  1491. XKB_STATE_MATCH_NON_EXCLUSIVE = (1 << 16)
  1492. };
  1493. /**
  1494. * The counterpart to xkb_state_update_mask for modifiers, to be used on
  1495. * the server side of serialization.
  1496. *
  1497. * @param state The keyboard state.
  1498. * @param components A mask of the modifier state components to serialize.
  1499. * State components other than XKB_STATE_MODS_* are ignored.
  1500. * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
  1501. * ignored.
  1502. *
  1503. * @returns A xkb_mod_mask_t representing the given components of the
  1504. * modifier state.
  1505. *
  1506. * This function should not be used in regular clients; please use the
  1507. * xkb_state_mod_*_is_active API instead.
  1508. *
  1509. * @memberof xkb_state
  1510. */
  1511. xkb_mod_mask_t
  1512. xkb_state_serialize_mods(struct xkb_state *state,
  1513. enum xkb_state_component components);
  1514. /**
  1515. * The counterpart to xkb_state_update_mask for layouts, to be used on
  1516. * the server side of serialization.
  1517. *
  1518. * @param state The keyboard state.
  1519. * @param components A mask of the layout state components to serialize.
  1520. * State components other than XKB_STATE_LAYOUT_* are ignored.
  1521. * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
  1522. * ignored.
  1523. *
  1524. * @returns A layout index representing the given components of the
  1525. * layout state.
  1526. *
  1527. * This function should not be used in regular clients; please use the
  1528. * xkb_state_layout_*_is_active API instead.
  1529. *
  1530. * @memberof xkb_state
  1531. */
  1532. xkb_layout_index_t
  1533. xkb_state_serialize_layout(struct xkb_state *state,
  1534. enum xkb_state_component components);
  1535. /**
  1536. * Test whether a modifier is active in a given keyboard state by name.
  1537. *
  1538. * @returns 1 if the modifier is active, 0 if it is not. If the modifier
  1539. * name does not exist in the keymap, returns -1.
  1540. *
  1541. * @memberof xkb_state
  1542. */
  1543. int
  1544. xkb_state_mod_name_is_active(struct xkb_state *state, const char *name,
  1545. enum xkb_state_component type);
  1546. /**
  1547. * Test whether a set of modifiers are active in a given keyboard state by
  1548. * name.
  1549. *
  1550. * @param state The keyboard state.
  1551. * @param type The component of the state against which to match the
  1552. * given modifiers.
  1553. * @param match The manner by which to match the state against the
  1554. * given modifiers.
  1555. * @param ... The set of of modifier names to test, terminated by a NULL
  1556. * argument (sentinel).
  1557. *
  1558. * @returns 1 if the modifiers are active, 0 if they are not. If any of
  1559. * the modifier names do not exist in the keymap, returns -1.
  1560. *
  1561. * @memberof xkb_state
  1562. */
  1563. int
  1564. xkb_state_mod_names_are_active(struct xkb_state *state,
  1565. enum xkb_state_component type,
  1566. enum xkb_state_match match,
  1567. ...);
  1568. /**
  1569. * Test whether a modifier is active in a given keyboard state by index.
  1570. *
  1571. * @returns 1 if the modifier is active, 0 if it is not. If the modifier
  1572. * index is invalid in the keymap, returns -1.
  1573. *
  1574. * @memberof xkb_state
  1575. */
  1576. int
  1577. xkb_state_mod_index_is_active(struct xkb_state *state, xkb_mod_index_t idx,
  1578. enum xkb_state_component type);
  1579. /**
  1580. * Test whether a set of modifiers are active in a given keyboard state by
  1581. * index.
  1582. *
  1583. * @param state The keyboard state.
  1584. * @param type The component of the state against which to match the
  1585. * given modifiers.
  1586. * @param match The manner by which to match the state against the
  1587. * given modifiers.
  1588. * @param ... The set of of modifier indices to test, terminated by a
  1589. * XKB_MOD_INVALID argument (sentinel).
  1590. *
  1591. * @returns 1 if the modifiers are active, 0 if they are not. If any of
  1592. * the modifier indices are invalid in the keymap, returns -1.
  1593. *
  1594. * @memberof xkb_state
  1595. */
  1596. int
  1597. xkb_state_mod_indices_are_active(struct xkb_state *state,
  1598. enum xkb_state_component type,
  1599. enum xkb_state_match match,
  1600. ...);
  1601. /**
  1602. * @page consumed-modifiers Consumed Modifiers
  1603. * @parblock
  1604. *
  1605. * Some functions, like xkb_state_key_get_syms(), look at the state of
  1606. * the modifiers in the keymap and derive from it the correct shift level
  1607. * to use for the key. For example, in a US layout, pressing the key
  1608. * labeled \<A\> while the Shift modifier is active, generates the keysym
  1609. * 'A'. In this case, the Shift modifier is said to be "consumed".
  1610. * However, the Num Lock modifier does not affect this translation at all,
  1611. * even if it is active, so it is not consumed by this translation.
  1612. *
  1613. * It may be desirable for some application to not reuse consumed modifiers
  1614. * for further processing, e.g. for hotkeys or keyboard shortcuts. To
  1615. * understand why, consider some requirements from a standard shortcut
  1616. * mechanism, and how they are implemented:
  1617. *
  1618. * 1. The shortcut's modifiers must match exactly to the state. For
  1619. * example, it is possible to bind separate actions to \<Alt\>\<Tab\>
  1620. * and to \<Alt\>\<Shift\>\<Tab\>. Further, if only \<Alt\>\<Tab\> is
  1621. * bound to an action, pressing \<Alt\>\<Shift\>\<Tab\> should not
  1622. * trigger the shortcut.
  1623. * Effectively, this means that the modifiers are compared using the
  1624. * equality operator (==).
  1625. *
  1626. * 2. Only relevant modifiers are considered for the matching. For example,
  1627. * Caps Lock and Num Lock should not generally affect the matching, e.g.
  1628. * when matching \<Alt\>\<Tab\> against the state, it does not matter
  1629. * whether Num Lock is active or not. These relevant, or "significant",
  1630. * modifiers usually include Alt, Control, Shift, Super and similar.
  1631. * Effectively, this means that non-significant modifiers are masked out,
  1632. * before doing the comparison as described above.
  1633. *
  1634. * 3. The matching must be independent of the layout/keymap. For example,
  1635. * the \<Plus\> (+) symbol is found on the first level on some layouts,
  1636. * but requires holding Shift on others. If you simply bind the action
  1637. * to the \<Plus\> keysym, it would work for the unshifted kind, but
  1638. * not for the others, because the match against Shift would fail. If
  1639. * you bind the action to \<Shift\>\<Plus\>, only the shifted kind would
  1640. * work. So what is needed is to recognize that Shift is used up in the
  1641. * translation of the keysym itself, and therefore should not be included
  1642. * in the matching.
  1643. * Effectively, this means that consumed modifiers (Shift in this example)
  1644. * are masked out as well, before doing the comparison.
  1645. *
  1646. * In summary, this is approximately how the matching would be performed:
  1647. * @code
  1648. * (keysym == shortcut_keysym) &&
  1649. * ((state_mods & ~consumed_mods & significant_mods) == shortcut_mods)
  1650. * @endcode
  1651. *
  1652. * @c state_mods are the modifiers reported by
  1653. * xkb_state_mod_index_is_active() and similar functions.
  1654. * @c consumed_mods are the modifiers reported by
  1655. * xkb_state_mod_index_is_consumed() and similar functions.
  1656. * @c significant_mods are decided upon by the application/toolkit/user;
  1657. * it is up to them to decide whether these are configurable or hard-coded.
  1658. *
  1659. * @endparblock
  1660. */
  1661. /**
  1662. * Consumed modifiers mode.
  1663. *
  1664. * There are several possible methods for deciding which modifiers are
  1665. * consumed and which are not, each applicable for different systems or
  1666. * situations. The mode selects the method to use.
  1667. *
  1668. * Keep in mind that in all methods, the keymap may decide to "preserve"
  1669. * a modifier, meaning it is not reported as consumed even if it would
  1670. * have otherwise.
  1671. */
  1672. enum xkb_consumed_mode {
  1673. /**
  1674. * This is the mode defined in the XKB specification and used by libX11.
  1675. *
  1676. * A modifier is consumed if and only if it *may affect* key translation.
  1677. *
  1678. * For example, if `Control+Alt+<Backspace>` produces some assigned keysym,
  1679. * then when pressing just `<Backspace>`, `Control` and `Alt` are consumed,
  1680. * even though they are not active, since if they *were* active they would
  1681. * have affected key translation.
  1682. */
  1683. XKB_CONSUMED_MODE_XKB,
  1684. /**
  1685. * This is the mode used by the GTK+ toolkit.
  1686. *
  1687. * The mode consists of the following two independent heuristics:
  1688. *
  1689. * - The currently active set of modifiers, excluding modifiers which do
  1690. * not affect the key (as described for @ref XKB_CONSUMED_MODE_XKB), are
  1691. * considered consumed, if the keysyms produced when all of them are
  1692. * active are different from the keysyms produced when no modifiers are
  1693. * active.
  1694. *
  1695. * - A single modifier is considered consumed if the keysyms produced for
  1696. * the key when it is the only active modifier are different from the
  1697. * keysyms produced when no modifiers are active.
  1698. */
  1699. XKB_CONSUMED_MODE_GTK
  1700. };
  1701. /**
  1702. * Get the mask of modifiers consumed by translating a given key.
  1703. *
  1704. * @param state The keyboard state.
  1705. * @param key The keycode of the key.
  1706. * @param mode The consumed modifiers mode to use; see enum description.
  1707. *
  1708. * @returns a mask of the consumed modifiers.
  1709. *
  1710. * @memberof xkb_state
  1711. * @since 0.7.0
  1712. */
  1713. xkb_mod_mask_t
  1714. xkb_state_key_get_consumed_mods2(struct xkb_state *state, xkb_keycode_t key,
  1715. enum xkb_consumed_mode mode);
  1716. /**
  1717. * Same as xkb_state_key_get_consumed_mods2() with mode XKB_CONSUMED_MODE_XKB.
  1718. *
  1719. * @memberof xkb_state
  1720. * @since 0.4.1
  1721. */
  1722. xkb_mod_mask_t
  1723. xkb_state_key_get_consumed_mods(struct xkb_state *state, xkb_keycode_t key);
  1724. /**
  1725. * Test whether a modifier is consumed by keyboard state translation for
  1726. * a key.
  1727. *
  1728. * @param state The keyboard state.
  1729. * @param key The keycode of the key.
  1730. * @param idx The index of the modifier to check.
  1731. * @param mode The consumed modifiers mode to use; see enum description.
  1732. *
  1733. * @returns 1 if the modifier is consumed, 0 if it is not. If the modifier
  1734. * index is not valid in the keymap, returns -1.
  1735. *
  1736. * @sa xkb_state_mod_mask_remove_consumed()
  1737. * @sa xkb_state_key_get_consumed_mods()
  1738. * @memberof xkb_state
  1739. * @since 0.7.0
  1740. */
  1741. int
  1742. xkb_state_mod_index_is_consumed2(struct xkb_state *state,
  1743. xkb_keycode_t key,
  1744. xkb_mod_index_t idx,
  1745. enum xkb_consumed_mode mode);
  1746. /**
  1747. * Same as xkb_state_mod_index_is_consumed2() with mode XKB_CONSUMED_MOD_XKB.
  1748. *
  1749. * @memberof xkb_state
  1750. * @since 0.4.1
  1751. */
  1752. int
  1753. xkb_state_mod_index_is_consumed(struct xkb_state *state, xkb_keycode_t key,
  1754. xkb_mod_index_t idx);
  1755. /**
  1756. * Remove consumed modifiers from a modifier mask for a key.
  1757. *
  1758. * @deprecated Use xkb_state_key_get_consumed_mods2() instead.
  1759. *
  1760. * Takes the given modifier mask, and removes all modifiers which are
  1761. * consumed for that particular key (as in xkb_state_mod_index_is_consumed()).
  1762. *
  1763. * @sa xkb_state_mod_index_is_consumed()
  1764. * @memberof xkb_state
  1765. */
  1766. xkb_mod_mask_t
  1767. xkb_state_mod_mask_remove_consumed(struct xkb_state *state, xkb_keycode_t key,
  1768. xkb_mod_mask_t mask);
  1769. /**
  1770. * Test whether a layout is active in a given keyboard state by name.
  1771. *
  1772. * @returns 1 if the layout is active, 0 if it is not. If no layout with
  1773. * this name exists in the keymap, return -1.
  1774. *
  1775. * If multiple layouts in the keymap have this name, the one with the lowest
  1776. * index is tested.
  1777. *
  1778. * @sa xkb_layout_index_t
  1779. * @memberof xkb_state
  1780. */
  1781. int
  1782. xkb_state_layout_name_is_active(struct xkb_state *state, const char *name,
  1783. enum xkb_state_component type);
  1784. /**
  1785. * Test whether a layout is active in a given keyboard state by index.
  1786. *
  1787. * @returns 1 if the layout is active, 0 if it is not. If the layout index
  1788. * is not valid in the keymap, returns -1.
  1789. *
  1790. * @sa xkb_layout_index_t
  1791. * @memberof xkb_state
  1792. */
  1793. int
  1794. xkb_state_layout_index_is_active(struct xkb_state *state,
  1795. xkb_layout_index_t idx,
  1796. enum xkb_state_component type);
  1797. /**
  1798. * Test whether a LED is active in a given keyboard state by name.
  1799. *
  1800. * @returns 1 if the LED is active, 0 if it not. If no LED with this name
  1801. * exists in the keymap, returns -1.
  1802. *
  1803. * @sa xkb_led_index_t
  1804. * @memberof xkb_state
  1805. */
  1806. int
  1807. xkb_state_led_name_is_active(struct xkb_state *state, const char *name);
  1808. /**
  1809. * Test whether a LED is active in a given keyboard state by index.
  1810. *
  1811. * @returns 1 if the LED is active, 0 if it not. If the LED index is not
  1812. * valid in the keymap, returns -1.
  1813. *
  1814. * @sa xkb_led_index_t
  1815. * @memberof xkb_state
  1816. */
  1817. int
  1818. xkb_state_led_index_is_active(struct xkb_state *state, xkb_led_index_t idx);
  1819. /** @} */
  1820. /* Leave this include last, so it can pick up our types, etc. */
  1821. #include <xkbcommon/xkbcommon-compat.h>
  1822. #ifdef __cplusplus
  1823. } /* extern "C" */
  1824. #endif
  1825. #endif /* _XKBCOMMON_H_ */