Debian Codegraph @

include/xkbcommon/xkbregistry.h

raw
1 /*
2 * Copyright © 2020 Red Hat, Inc.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef _XKBREGISTRY_H_
7 #define _XKBREGISTRY_H_
8
9 #include <stdarg.h>
10 #include <stdbool.h>
11
12 /**
13 * @file
14 * @brief Query for available RMLVO
15 *
16 */
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #if defined(__GNUC__) && !defined(__CYGWIN__)
23 # define RXKB_EXPORT __attribute__((visibility("default")))
24 #elif defined(_WIN32)
25 # define RXKB_EXPORT __declspec(dllexport)
26 #else
27 # define RXKB_EXPORT
28 #endif
29
30 /**
31 * @defgroup registry Query for available RMLVO
32 *
33 * The libxkbregistry API to query for available rules, models, layouts,
34 * variants and options (RMLVO). libxkbregistry is a separate library to
35 * libxkbcommon.
36 *
37 * This library is the replacement for clients currently parsing evdev.xml
38 * directly. The library is intended to provide easy access to the set of
39 * **possible** MLVO configurations for a given ruleset. It is not a library to
40 * apply these configurations, merely to enumerate them. The intended users of
41 * this library are the configuration UIs that allow a user to select their
42 * keyboard layout of choice.
43 *
44 * @{
45 */
46
47 /**
48 * @struct rxkb_context
49 *
50 * Opaque top level library context object.
51 *
52 * The context contains general library state, like include paths and parsed
53 * data. Objects are created in a specific context, and multiple contexts
54 * may coexist simultaneously. Objects from different contexts are
55 * completely separated and do not share any memory or state.
56 */
57 struct rxkb_context;
58
59 /**
60 * @struct rxkb_model
61 *
62 * Opaque struct representing an XKB model.
63 */
64 struct rxkb_model;
65
66 /**
67 * @struct rxkb_layout
68 *
69 * Opaque struct representing an XKB layout, including an optional variant.
70 * Where the variant is `NULL`, the layout is the base layout.
71 *
72 * For example, `us` is the base layout, `us(intl)` is the `intl` variant of the
73 * layout `us`.
74 */
75 struct rxkb_layout;
76
77 /**
78 * @struct rxkb_option_group
79 *
80 * Opaque struct representing an option group. Option groups divide the
81 * individual options into logical groups. Their main purpose is to indicate
82 * whether some options are mutually exclusive or not.
83 */
84 struct rxkb_option_group;
85
86 /**
87 * @struct rxkb_option
88 *
89 * Opaque struct representing an XKB option. Options are grouped inside an @ref
90 * rxkb_option_group.
91 */
92 struct rxkb_option;
93
94 /**
95 *
96 * @struct rxkb_iso639_code
97 *
98 * Opaque struct representing an ISO 639-3 code (e.g. `eng`, `fra`). There
99 * is no guarantee that two identical ISO codes share the same struct. You
100 * must not rely on the pointer value of this struct.
101 *
102 * See https://iso639-3.sil.org/code_tables/639/data for a list of codes.
103 */
104 struct rxkb_iso639_code;
105
106 /**
107 *
108 * @struct rxkb_iso3166_code
109 *
110 * Opaque struct representing an ISO 3166 Alpha 2 code (e.g. `US`, `FR`).
111 * There is no guarantee that two identical ISO codes share the same struct.
112 * You must not rely on the pointer value of this struct.
113 *
114 * See https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes for a list
115 * of codes.
116 */
117 struct rxkb_iso3166_code;
118
119 /**
120 * Describes the popularity of an item. Historically, some highly specialized or
121 * experimental definitions are excluded from the default list and shipped in
122 * separate files. If these extra definitions are loaded (see @ref
123 * RXKB_CONTEXT_LOAD_EXOTIC_RULES), the popularity of the item is set
124 * accordingly.
125 *
126 * If the exotic items are not loaded, all items will have the standard
127 * popularity.
128 */
129 enum rxkb_popularity {
130 RXKB_POPULARITY_STANDARD = 1,
131 RXKB_POPULARITY_EXOTIC,
132 };
133
134 /**
135 * Flags for context creation.
136 */
137 enum rxkb_context_flags {
138 RXKB_CONTEXT_NO_FLAGS = 0,
139 /**
140 * Skip the default include paths. This requires the caller to call
141 * `rxkb_context_include_path_append()` or
142 * `rxkb_context_include_path_append_default()`.
143 */
144 RXKB_CONTEXT_NO_DEFAULT_INCLUDES = (1 << 0),
145 /**
146 * Load the extra items that are considered too exotic for the default list.
147 *
148 * For historical reasons, xkeyboard-config ships those exotic rules in a
149 * separate file (e.g. `evdev.extras.xml`). Where the exotic rules are
150 * requested, libxkbregistry will look for and load `$ruleset.extras.xml`
151 * in the include paths, see `rxkb_context_include_path_append()` for
152 * details on the lookup behavior.
153 */
154 RXKB_CONTEXT_LOAD_EXOTIC_RULES = (1 << 1),
155 /**
156 * Disable the use of `secure_getenv()` for this context, so that privileged
157 * processes can use environment variables. Client uses at their own risk.
158 *
159 * @since 1.5.0
160 */
161 RXKB_CONTEXT_NO_SECURE_GETENV = (1 << 2)
162 };
163
164 /**
165 * Create a new xkb registry context.
166 *
167 * The context has an initial refcount of 1. Use `rxkb_context_unref()` to
168 * release memory associated with this context.
169 *
170 * Creating a context does not parse the files yet, use
171 * `rxkb_context_parse()`.
172 *
173 * @param flags Flags affecting context behavior
174 * @return A new xkb registry context or `NULL` on failure
175 */
176 RXKB_EXPORT struct rxkb_context *
177 rxkb_context_new(enum rxkb_context_flags flags);
178
179 /** Specifies a logging level. */
180 enum rxkb_log_level {
181 RXKB_LOG_LEVEL_CRITICAL = 10, /**< Log critical internal errors only. */
182 RXKB_LOG_LEVEL_ERROR = 20, /**< Log all errors. */
183 RXKB_LOG_LEVEL_WARNING = 30, /**< Log warnings and errors. */
184 RXKB_LOG_LEVEL_INFO = 40, /**< Log information, warnings, and errors. */
185 RXKB_LOG_LEVEL_DEBUG = 50 /**< Log everything. */
186 };
187
188 /**
189 * Set the current logging level.
190 *
191 * @param ctx The context in which to set the logging level.
192 * @param level The logging level to use. Only messages from this level
193 * and below will be logged.
194 *
195 * The default level is `::RXKB_LOG_LEVEL_ERROR`. The environment variable
196 * `RXKB_LOG_LEVEL`, if set at the time the context was created, overrides the
197 * default value. It may be specified as a level number or name.
198 */
199 RXKB_EXPORT void
200 rxkb_context_set_log_level(struct rxkb_context *ctx,
201 enum rxkb_log_level level);
202
203 /**
204 * Get the current logging level.
205 */
206 RXKB_EXPORT enum rxkb_log_level
207 rxkb_context_get_log_level(struct rxkb_context *ctx);
208
209 /**
210 * Set a custom function to handle logging messages.
211 *
212 * @param ctx The context in which to use the set logging function.
213 * @param log_fn The function that will be called for logging messages.
214 * Passing `NULL` restores the default function, which logs to `stderr`.
215 *
216 * By default, log messages from this library are printed to stderr. This
217 * function allows you to replace the default behavior with a custom
218 * handler. The handler is only called with messages which match the
219 * current logging level and verbosity settings for the context.
220 * level is the logging level of the message. @a format and @a args are
221 * the same as in the `vprintf(3)` function.
222 *
223 * You may use `rxkb_context_set_user_data()` on the context, and then call
224 * `rxkb_context_get_user_data()` from within the logging function to provide
225 * it with additional private context.
226 */
227 RXKB_EXPORT void
228 rxkb_context_set_log_fn(struct rxkb_context *ctx,
229 void (*log_fn)(struct rxkb_context *ctx,
230 enum rxkb_log_level level,
231 const char *format, va_list args));
232
233
234 /**
235 * Parse the given ruleset. This can only be called once per context and once
236 * parsed the data in the context is considered constant and will never
237 * change.
238 *
239 * This function parses all files with the given ruleset name. See
240 * rxkb_context_include_path_append() for details.
241 *
242 * If this function returns false, libxkbregistry failed to parse the xml files.
243 * This is usually caused by invalid files on the host and should be debugged by
244 * the host’s administrator using external tools. Callers should reduce the
245 * include paths to known good paths and/or fall back to a default RMLVO set.
246 *
247 * If this function returns false, the context should be be considered dead and
248 * must be released with `rxkb_context_unref()`.
249 *
250 * @param ctx The xkb registry context
251 * @param ruleset The ruleset to parse, e.g. `evdev`
252 * @return `true` on success or `false` on failure
253 */
254 RXKB_EXPORT bool
255 rxkb_context_parse(struct rxkb_context *ctx, const char *ruleset);
256
257 /**
258 * Parse the default ruleset as configured at build time. See
259 * `rxkb_context_parse()` for details.
260 */
261 RXKB_EXPORT bool
262 rxkb_context_parse_default_ruleset(struct rxkb_context *ctx);
263
264 /**
265 * Increases the refcount of this object by one and returns the object.
266 *
267 * @param ctx The xkb registry context
268 * @return The passed in object
269 */
270 RXKB_EXPORT struct rxkb_context*
271 rxkb_context_ref(struct rxkb_context *ctx);
272
273 /**
274 * Decreases the refcount of this object by one. Where the refcount of an
275 * object hits zero, associated resources will be freed.
276 *
277 * @param ctx The xkb registry context
278 * @return always `NULL`
279 */
280 RXKB_EXPORT struct rxkb_context*
281 rxkb_context_unref(struct rxkb_context *ctx);
282
283 /**
284 * Assign user-specific data. libxkbregistry will not look at or modify the
285 * data, it will merely return the same pointer in
286 * `rxkb_context_get_user_data()`.
287 *
288 * @param ctx The xkb registry context
289 * @param user_data User-specific data pointer
290 */
291 RXKB_EXPORT void
292 rxkb_context_set_user_data(struct rxkb_context *ctx, void *user_data);
293
294 /**
295 * Return the pointer passed into `rxkb_context_get_user_data()`.
296 *
297 * @param ctx The xkb registry context
298 * @return User-specific data pointer
299 */
300 RXKB_EXPORT void *
301 rxkb_context_get_user_data(struct rxkb_context *ctx);
302
303 /**
304 * Append a new entry to the context’s include path.
305 *
306 * The include path handling is optimized for the most common use-case: a set of
307 * system files that provide a complete set of MLVO and some
308 * custom MLVO provided by a user **in addition** to the system set.
309 *
310 * The include paths should be given so that the least complete path is
311 * specified first and the most complete path is appended last. For example:
312 *
313 * ```c
314 * ctx = rxkb_context_new(RXKB_CONTEXT_NO_DEFAULT_INCLUDES);
315 * rxkb_context_include_path_append(ctx, `/home/user/.config/xkb`);
316 * rxkb_context_include_path_append(ctx, `/usr/share/X11/xkb`);
317 * rxkb_context_parse(ctx, `evdev`);
318 * ```
319 *
320 * The above example reflects the default behavior unless @ref
321 * RXKB_CONTEXT_NO_DEFAULT_INCLUDES is provided.
322 *
323 * Loading of the files is in **reverse order**, i.e. the last path appended is
324 * loaded first - in this case the ``/usr/share/X11/xkb`` path.
325 * Any models, layouts, variants and options defined in the `evdev` ruleset
326 * are loaded into the context. Then, any RMLVO found in the `evdev` ruleset of
327 * the user’s path (``/home/user/.config/xkb`` in this example) are **appended**
328 * to the existing set.
329 *
330 * Note that data from previously loaded include paths is never overwritten,
331 * only appended to. It is not not possible to change the system-provided data,
332 * only to append new models, layouts, variants and options to it.
333 *
334 * In other words, to define a new variant of the `us` layout called `banana`,
335 * the following XML is sufficient.
336 *
337 * ```xml
338 * <xkbConfigRegistry version="1.1">
339 * <layoutList>
340 * <layout>
341 * <configItem>
342 * <name>us</name>
343 * </configItem>
344 * <variantList>
345 * <variant>
346 * <configItem>
347 * <name>banana</name>
348 * <description>English (Banana)</description>
349 * </configItem>
350 * </variant>
351 * </layout>
352 * </layoutList>
353 * </xkbConfigRegistry>
354 * ```
355 *
356 * The list of models, options and all other layouts (including `us` and its
357 * variants) is taken from the system files. The resulting list of layouts will
358 * thus have a `us` keyboard layout with the variant `banana` and all other
359 * system-provided variants (`dvorak`, `colemak`, `intl`, etc.)
360 *
361 * This function must be called before `rxkb_context_parse()` or
362 * `rxkb_context_parse_default_ruleset()`.
363 *
364 * @returns `true` on success, or `false` if the include path could not be added
365 * or is inaccessible.
366 */
367 RXKB_EXPORT bool
368 rxkb_context_include_path_append(struct rxkb_context *ctx, const char *path);
369
370 /**
371 * Append the default include paths to the context’s include path.
372 * See `rxkb_context_include_path_append()` for details about the merge order.
373 *
374 * This function must be called before `rxkb_context_parse()` or
375 * `rxkb_context_parse_default_ruleset()`.
376 *
377 * @returns `true` on success, or `false` if the include path could not be added
378 * or is inaccessible.
379 */
380 RXKB_EXPORT bool
381 rxkb_context_include_path_append_default(struct rxkb_context *ctx);
382
383 /**
384 * Return the first model for this context. Use this to start iterating over
385 * the models, followed by calls to `rxkb_model_next()`. Models are not sorted.
386 *
387 * The refcount of the returned model is not increased. Use `rxkb_model_ref()`
388 * if you need to keep this struct outside the immediate scope.
389 *
390 * @return The first model in the model list.
391 */
392 RXKB_EXPORT struct rxkb_model *
393 rxkb_model_first(struct rxkb_context *ctx);
394
395 /**
396 * Return the next model for this context. Returns `NULL` when no more models
397 * are available.
398 *
399 * The refcount of the returned model is not increased. Use `rxkb_model_ref()`
400 * if you need to keep this struct outside the immediate scope.
401 *
402 * @return the next model or `NULL` at the end of the list
403 */
404 RXKB_EXPORT struct rxkb_model *
405 rxkb_model_next(struct rxkb_model *m);
406
407 /**
408 * Increase the refcount of the argument by one.
409 *
410 * @returns The argument passed in to this function.
411 */
412 RXKB_EXPORT struct rxkb_model *
413 rxkb_model_ref(struct rxkb_model *m);
414
415 /**
416 * Decrease the refcount of the argument by one. When the refcount hits zero,
417 * all memory associated with this struct is freed.
418 *
419 * @returns always `NULL`
420 */
421 RXKB_EXPORT struct rxkb_model *
422 rxkb_model_unref(struct rxkb_model *m);
423
424 /**
425 * Return the name of this model. This is the value for M in RMLVO, to be used
426 * with libxkbcommon.
427 */
428 RXKB_EXPORT const char *
429 rxkb_model_get_name(struct rxkb_model *m);
430
431 /**
432 * Return a human-readable description of this model. This function may return
433 * `NULL`.
434 */
435 RXKB_EXPORT const char *
436 rxkb_model_get_description(struct rxkb_model *m);
437
438 /**
439 * Return the vendor name for this model. This function may return `NULL`.
440 */
441 RXKB_EXPORT const char *
442 rxkb_model_get_vendor(struct rxkb_model *m);
443
444 /**
445 * Return the popularity for this model.
446 */
447 RXKB_EXPORT enum rxkb_popularity
448 rxkb_model_get_popularity(struct rxkb_model *m);
449
450 /**
451 * Return the first layout for this context. Use this to start iterating over
452 * the layouts, followed by calls to `rxkb_layout_next()`.
453 *
454 * @note Layouts are not sorted.
455 *
456 * The refcount of the returned layout is not increased.
457 * Use `rxkb_layout_ref()` if you need to keep this struct outside the immediate
458 * scope.
459 *
460 * @return The first layout in the layout list.
461 */
462 RXKB_EXPORT struct rxkb_layout *
463 rxkb_layout_first(struct rxkb_context *ctx);
464
465 /**
466 * Return the next layout for this context. Returns `NULL` when no more layouts
467 * are available.
468 *
469 * The refcount of the returned layout is not increased. Use `rxkb_layout_ref()`
470 * if you need to keep this struct outside the immediate scope.
471 *
472 * @return the next layout or `NULL` at the end of the list
473 */
474 RXKB_EXPORT struct rxkb_layout *
475 rxkb_layout_next(struct rxkb_layout *l);
476
477 /**
478 * Increase the refcount of the argument by one.
479 *
480 * @returns The argument passed in to this function.
481 */
482 RXKB_EXPORT struct rxkb_layout *
483 rxkb_layout_ref(struct rxkb_layout *l);
484
485 /**
486 * Decrease the refcount of the argument by one. When the refcount hits zero,
487 * all memory associated with this struct is freed.
488 *
489 * @returns always `NULL`
490 */
491 RXKB_EXPORT struct rxkb_layout *
492 rxkb_layout_unref(struct rxkb_layout *l);
493
494 /**
495 * Return the name of this layout. This is the value for L in RMLVO, to be used
496 * with libxkbcommon.
497 */
498 RXKB_EXPORT const char *
499 rxkb_layout_get_name(struct rxkb_layout *l);
500
501 /**
502 * Return the variant of this layout. This is the value for V in RMLVO, to be
503 * used with libxkbcommon.
504 *
505 * A variant does not stand on its own, it always depends on the base layout.
506 * e.g. there may be multiple variants called `intl` but there is only one
507 * `us(intl)`.
508 *
509 * Where the variant is `NULL`, the layout is the base layout (e.g. `us`).
510 */
511 RXKB_EXPORT const char *
512 rxkb_layout_get_variant(struct rxkb_layout *l);
513
514 /**
515 * Return a short (one-word) description of this layout. This function may
516 * return `NULL`.
517 */
518 RXKB_EXPORT const char *
519 rxkb_layout_get_brief(struct rxkb_layout *l);
520
521 /**
522 * Return a human-readable description of this layout. This function may return
523 * `NULL`.
524 */
525 RXKB_EXPORT const char *
526 rxkb_layout_get_description(struct rxkb_layout *l);
527
528 /**
529 * Return the popularity for this layout.
530 */
531 RXKB_EXPORT enum rxkb_popularity
532 rxkb_layout_get_popularity(struct rxkb_layout *l);
533
534 /**
535 * Return the first option group for this context. Use this to start iterating
536 * over the option groups, followed by calls to `rxkb_option_group_next()`.
537 * Option groups are not sorted.
538 *
539 * The refcount of the returned option group is not increased. Use
540 * `rxkb_option_group_ref()` if you need to keep this struct outside the immediate
541 * scope.
542 *
543 * @return The first option group in the option group list.
544 */
545 RXKB_EXPORT struct rxkb_option_group *
546 rxkb_option_group_first(struct rxkb_context *ctx);
547
548 /**
549 * Return the next option group for this context. Returns `NULL` when no more
550 * option groups are available.
551 *
552 * The refcount of the returned option group is not increased. Use
553 * `rxkb_option_group_ref()` if you need to keep this struct outside the immediate
554 * scope.
555 *
556 * @return the next option group or `NULL` at the end of the list
557 */
558 RXKB_EXPORT struct rxkb_option_group *
559 rxkb_option_group_next(struct rxkb_option_group *g);
560
561 /**
562 * Increase the refcount of the argument by one.
563 *
564 * @returns The argument passed in to this function.
565 */
566 RXKB_EXPORT struct rxkb_option_group *
567 rxkb_option_group_ref(struct rxkb_option_group *g);
568
569 /**
570 * Decrease the refcount of the argument by one. When the refcount hits zero,
571 * all memory associated with this struct is freed.
572 *
573 * @returns always `NULL`
574 */
575 RXKB_EXPORT struct rxkb_option_group *
576 rxkb_option_group_unref(struct rxkb_option_group *g);
577
578 /**
579 * Return the name of this option group. This is **not** the value for O in
580 * RMLVO, the name can be used for internal sorting in the caller. This function
581 * may return `NULL`.
582 */
583 RXKB_EXPORT const char *
584 rxkb_option_group_get_name(struct rxkb_option_group *m);
585
586 /**
587 * Return a human-readable description of this option group. This function may
588 * return `NULL`.
589 */
590 RXKB_EXPORT const char *
591 rxkb_option_group_get_description(struct rxkb_option_group *m);
592
593 /**
594 * @return `true` if multiple options within this option group can be selected
595 * simultaneously, `false` if all options within this option
596 * group are mutually exclusive.
597 */
598 RXKB_EXPORT bool
599 rxkb_option_group_allows_multiple(struct rxkb_option_group *g);
600
601 /**
602 * Return the popularity for this option group.
603 */
604 RXKB_EXPORT enum rxkb_popularity
605 rxkb_option_group_get_popularity(struct rxkb_option_group *g);
606
607 /**
608 * Return the first option for this option group. Use this to start iterating
609 * over the options, followed by calls to `rxkb_option_next()`. Options are not
610 * sorted.
611 *
612 * The refcount of the returned option is not increased. Use `rxkb_option_ref()`
613 * if you need to keep this struct outside the immediate scope.
614 *
615 * @return The first option in the option list.
616 */
617 RXKB_EXPORT struct rxkb_option *
618 rxkb_option_first(struct rxkb_option_group *group);
619
620 /**
621 * Return the next option for this option group. Returns `NULL` when no more
622 * options are available.
623 *
624 * The refcount of the returned options is not increased. Use `rxkb_option_ref()`
625 * if you need to keep this struct outside the immediate scope.
626 *
627 * @returns The next option or `NULL` at the end of the list
628 */
629 RXKB_EXPORT struct rxkb_option *
630 rxkb_option_next(struct rxkb_option *o);
631
632 /**
633 * Increase the refcount of the argument by one.
634 *
635 * @returns The argument passed in to this function.
636 */
637 RXKB_EXPORT struct rxkb_option *
638 rxkb_option_ref(struct rxkb_option *o);
639
640 /**
641 * Decrease the refcount of the argument by one. When the refcount hits zero,
642 * all memory associated with this struct is freed.
643 *
644 * @returns always `NULL`
645 */
646 RXKB_EXPORT struct rxkb_option *
647 rxkb_option_unref(struct rxkb_option *o);
648
649 /**
650 * Return the name of this option. This is the value for O in RMLVO, to be used
651 * with libxkbcommon.
652 */
653 RXKB_EXPORT const char *
654 rxkb_option_get_name(struct rxkb_option *o);
655
656 /**
657 * Return a short (one-word) description of this option. This function may
658 * return `NULL`.
659 */
660 RXKB_EXPORT const char *
661 rxkb_option_get_brief(struct rxkb_option *o);
662
663 /**
664 * Return a human-readable description of this option. This function may return
665 * `NULL`.
666 */
667 RXKB_EXPORT const char *
668 rxkb_option_get_description(struct rxkb_option *o);
669
670 /**
671 * Return the popularity for this option.
672 */
673 RXKB_EXPORT enum rxkb_popularity
674 rxkb_option_get_popularity(struct rxkb_option *o);
675
676 /**
677 * Return `true` if the given option accepts layout index specifiers to restrict
678 * its application to the corresponding layouts, `false` otherwise.
679 *
680 * @sa `xkb_rmlvo_builder::xkb_rmlvo_builder_append_layout()`
681 * @sa `xkb_rule_names::options`
682 */
683 RXKB_EXPORT bool
684 rxkb_option_is_layout_specific(struct rxkb_option *o);
685
686 /**
687 * Increase the refcount of the argument by one.
688 *
689 * @returns The argument passed in to this function.
690 */
691 RXKB_EXPORT struct rxkb_iso639_code *
692 rxkb_iso639_code_ref(struct rxkb_iso639_code *iso639);
693
694 /**
695 * Decrease the refcount of the argument by one. When the refcount hits zero,
696 * all memory associated with this struct is freed.
697 *
698 * @returns always `NULL`
699 */
700 RXKB_EXPORT struct rxkb_iso639_code *
701 rxkb_iso639_code_unref(struct rxkb_iso639_code *iso639);
702
703 /**
704 * Return the ISO 639-3 code for this code. E.g. `eng`, `fra`.
705 */
706 RXKB_EXPORT const char *
707 rxkb_iso639_code_get_code(struct rxkb_iso639_code *iso639);
708
709 /**
710 * Return the first ISO 639 for this layout. Use this to start iterating over
711 * the codes, followed by calls to `rxkb_iso639_code_next()`. Codes are not
712 * sorted.
713 *
714 * The refcount of the returned code is not increased.
715 * Use `rxkb_iso639_code_ref()` if you need to keep this struct outside the
716 * immediate scope.
717 *
718 * @return The first code in the code list.
719 */
720 RXKB_EXPORT struct rxkb_iso639_code *
721 rxkb_layout_get_iso639_first(struct rxkb_layout *layout);
722
723 /**
724 * Return the next code in the list. Returns `NULL` when no more codes
725 * are available.
726 *
727 * The refcount of the returned codes is not increased.
728 * Use `rxkb_iso639_code_ref()` if you need to keep this struct outside the
729 * immediate scope.
730 *
731 * @returns The next code or `NULL` at the end of the list
732 */
733 RXKB_EXPORT struct rxkb_iso639_code *
734 rxkb_iso639_code_next(struct rxkb_iso639_code *iso639);
735
736 /**
737 * Increase the refcount of the argument by one.
738 *
739 * @returns The argument passed in to this function.
740 */
741 RXKB_EXPORT struct rxkb_iso3166_code *
742 rxkb_iso3166_code_ref(struct rxkb_iso3166_code *iso3166);
743
744 /**
745 * Decrease the refcount of the argument by one. When the refcount hits zero,
746 * all memory associated with this struct is freed.
747 *
748 * @returns always `NULL`
749 */
750 RXKB_EXPORT struct rxkb_iso3166_code *
751 rxkb_iso3166_code_unref(struct rxkb_iso3166_code *iso3166);
752
753 /**
754 * Return the ISO 3166 Alpha 2 code for this code (e.g. `US`, `FR`).
755 */
756 RXKB_EXPORT const char *
757 rxkb_iso3166_code_get_code(struct rxkb_iso3166_code *iso3166);
758
759 /**
760 * Return the first ISO 3166 for this layout. Use this to start iterating over
761 * the codes, followed by calls to `rxkb_iso3166_code_next()`. Codes are not
762 * sorted.
763 *
764 * The refcount of the returned code is not increased. Use
765 * `rxkb_iso3166_code_ref()` if you need to keep this struct outside the immediate
766 * scope.
767 *
768 * @return The first code in the code list.
769 */
770 RXKB_EXPORT struct rxkb_iso3166_code *
771 rxkb_layout_get_iso3166_first(struct rxkb_layout *layout);
772
773 /**
774 * Return the next code in the list. Returns `NULL` when no more codes
775 * are available.
776 *
777 * The refcount of the returned codes is not increased. Use
778 * `rxkb_iso3166_code_ref()` if you need to keep this struct outside the immediate
779 * scope.
780 *
781 * @returns The next code or `NULL` at the end of the list
782 */
783 RXKB_EXPORT struct rxkb_iso3166_code *
784 rxkb_iso3166_code_next(struct rxkb_iso3166_code *iso3166);
785
786 /** @} */
787
788 #ifdef __cplusplus
789 } /* extern "C" */
790 #endif
791
792 #endif /* _XKBREGISTRY_H_ */