xref: /aosp_15_r20/external/libxkbcommon/include/xkbcommon/xkbcommon-compose.h (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard Worker /*
2*2b949d04SAndroid Build Coastguard Worker  * Copyright © 2013 Ran Benita
3*2b949d04SAndroid Build Coastguard Worker  *
4*2b949d04SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*2b949d04SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*2b949d04SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*2b949d04SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*2b949d04SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*2b949d04SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*2b949d04SAndroid Build Coastguard Worker  *
11*2b949d04SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*2b949d04SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*2b949d04SAndroid Build Coastguard Worker  * Software.
14*2b949d04SAndroid Build Coastguard Worker  *
15*2b949d04SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*2b949d04SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*2b949d04SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*2b949d04SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*2b949d04SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*2b949d04SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*2b949d04SAndroid Build Coastguard Worker  * DEALINGS IN THE SOFTWARE.
22*2b949d04SAndroid Build Coastguard Worker  */
23*2b949d04SAndroid Build Coastguard Worker 
24*2b949d04SAndroid Build Coastguard Worker #ifndef _XKBCOMMON_COMPOSE_H
25*2b949d04SAndroid Build Coastguard Worker #define _XKBCOMMON_COMPOSE_H
26*2b949d04SAndroid Build Coastguard Worker 
27*2b949d04SAndroid Build Coastguard Worker #include <xkbcommon/xkbcommon.h>
28*2b949d04SAndroid Build Coastguard Worker 
29*2b949d04SAndroid Build Coastguard Worker #ifdef __cplusplus
30*2b949d04SAndroid Build Coastguard Worker extern "C" {
31*2b949d04SAndroid Build Coastguard Worker #endif
32*2b949d04SAndroid Build Coastguard Worker 
33*2b949d04SAndroid Build Coastguard Worker /**
34*2b949d04SAndroid Build Coastguard Worker  * @file
35*2b949d04SAndroid Build Coastguard Worker  * libxkbcommon Compose API - support for Compose and dead-keys.
36*2b949d04SAndroid Build Coastguard Worker  */
37*2b949d04SAndroid Build Coastguard Worker 
38*2b949d04SAndroid Build Coastguard Worker /**
39*2b949d04SAndroid Build Coastguard Worker  * @defgroup compose Compose and dead-keys support
40*2b949d04SAndroid Build Coastguard Worker  * Support for Compose and dead-keys.
41*2b949d04SAndroid Build Coastguard Worker  * @since 0.5.0
42*2b949d04SAndroid Build Coastguard Worker  *
43*2b949d04SAndroid Build Coastguard Worker  * @{
44*2b949d04SAndroid Build Coastguard Worker  */
45*2b949d04SAndroid Build Coastguard Worker 
46*2b949d04SAndroid Build Coastguard Worker /**
47*2b949d04SAndroid Build Coastguard Worker  * @page compose-overview Overview
48*2b949d04SAndroid Build Coastguard Worker  * @parblock
49*2b949d04SAndroid Build Coastguard Worker  *
50*2b949d04SAndroid Build Coastguard Worker  * Compose and dead-keys are a common feature of many keyboard input
51*2b949d04SAndroid Build Coastguard Worker  * systems.  They extend the range of the keysysm that can be produced
52*2b949d04SAndroid Build Coastguard Worker  * directly from a keyboard by using a sequence of key strokes, instead
53*2b949d04SAndroid Build Coastguard Worker  * of just one.
54*2b949d04SAndroid Build Coastguard Worker  *
55*2b949d04SAndroid Build Coastguard Worker  * Here are some example sequences, in the libX11 Compose file format:
56*2b949d04SAndroid Build Coastguard Worker  *
57*2b949d04SAndroid Build Coastguard Worker  *     <dead_acute> <a>         : "á"   aacute # LATIN SMALL LETTER A WITH ACUTE
58*2b949d04SAndroid Build Coastguard Worker  *     <Multi_key> <A> <T>      : "@"   at     # COMMERCIAL AT
59*2b949d04SAndroid Build Coastguard Worker  *
60*2b949d04SAndroid Build Coastguard Worker  * When the user presses a key which produces the `<dead_acute>` keysym,
61*2b949d04SAndroid Build Coastguard Worker  * nothing initially happens (thus the key is dubbed a "dead-key").  But
62*2b949d04SAndroid Build Coastguard Worker  * when the user enters `<a>`, "á" is "composed", in place of "a".  If
63*2b949d04SAndroid Build Coastguard Worker  * instead the user had entered a keysym which does not follow
64*2b949d04SAndroid Build Coastguard Worker  * `<dead_acute>` in any compose sequence, the sequence is said to be
65*2b949d04SAndroid Build Coastguard Worker  * "cancelled".
66*2b949d04SAndroid Build Coastguard Worker  *
67*2b949d04SAndroid Build Coastguard Worker  * Compose files define many such sequences.  For a description of the
68*2b949d04SAndroid Build Coastguard Worker  * common file format for Compose files, see the Compose(5) man page.
69*2b949d04SAndroid Build Coastguard Worker  *
70*2b949d04SAndroid Build Coastguard Worker  * A successfuly-composed sequence has two results: a keysym and a UTF-8
71*2b949d04SAndroid Build Coastguard Worker  * string.  At least one of the two is defined for each sequence.  If only
72*2b949d04SAndroid Build Coastguard Worker  * a keysym is given, the keysym's string representation is used for the
73*2b949d04SAndroid Build Coastguard Worker  * result string (using xkb_keysym_to_utf8()).
74*2b949d04SAndroid Build Coastguard Worker  *
75*2b949d04SAndroid Build Coastguard Worker  * This library provides low-level support for Compose file parsing and
76*2b949d04SAndroid Build Coastguard Worker  * processing.  Higher-level APIs (such as libX11's `Xutf8LookupString`(3))
77*2b949d04SAndroid Build Coastguard Worker  * may be built upon it, or it can be used directly.
78*2b949d04SAndroid Build Coastguard Worker  *
79*2b949d04SAndroid Build Coastguard Worker  * @endparblock
80*2b949d04SAndroid Build Coastguard Worker  */
81*2b949d04SAndroid Build Coastguard Worker 
82*2b949d04SAndroid Build Coastguard Worker /**
83*2b949d04SAndroid Build Coastguard Worker  * @page compose-conflicting Conflicting Sequences
84*2b949d04SAndroid Build Coastguard Worker  * @parblock
85*2b949d04SAndroid Build Coastguard Worker  *
86*2b949d04SAndroid Build Coastguard Worker  * To avoid ambiguity, a sequence is not allowed to be a prefix of another.
87*2b949d04SAndroid Build Coastguard Worker  * In such a case, the conflict is resolved thus:
88*2b949d04SAndroid Build Coastguard Worker  *
89*2b949d04SAndroid Build Coastguard Worker  * 1. A longer sequence overrides a shorter one.
90*2b949d04SAndroid Build Coastguard Worker  * 2. An equal sequence overrides an existing one.
91*2b949d04SAndroid Build Coastguard Worker  * 3. A shorter sequence does not override a longer one.
92*2b949d04SAndroid Build Coastguard Worker  *
93*2b949d04SAndroid Build Coastguard Worker  * Sequences of length 1 are allowed.
94*2b949d04SAndroid Build Coastguard Worker  *
95*2b949d04SAndroid Build Coastguard Worker  * @endparblock
96*2b949d04SAndroid Build Coastguard Worker  */
97*2b949d04SAndroid Build Coastguard Worker 
98*2b949d04SAndroid Build Coastguard Worker /**
99*2b949d04SAndroid Build Coastguard Worker  * @page compose-cancellation Cancellation Behavior
100*2b949d04SAndroid Build Coastguard Worker  * @parblock
101*2b949d04SAndroid Build Coastguard Worker  *
102*2b949d04SAndroid Build Coastguard Worker  * What should happen when a sequence is cancelled?  For example, consider
103*2b949d04SAndroid Build Coastguard Worker  * there are only the above sequences, and the input keysyms are
104*2b949d04SAndroid Build Coastguard Worker  * `<dead_acute> <b>`.  There are a few approaches:
105*2b949d04SAndroid Build Coastguard Worker  *
106*2b949d04SAndroid Build Coastguard Worker  * 1. Swallow the cancelling keysym; that is, no keysym is produced.
107*2b949d04SAndroid Build Coastguard Worker  *    This is the approach taken by libX11.
108*2b949d04SAndroid Build Coastguard Worker  * 2. Let the cancelling keysym through; that is, `<b>` is produced.
109*2b949d04SAndroid Build Coastguard Worker  * 3. Replay the entire sequence; that is, `<dead_acute> <b>` is produced.
110*2b949d04SAndroid Build Coastguard Worker  *    This is the approach taken by Microsoft Windows (approximately;
111*2b949d04SAndroid Build Coastguard Worker  *    instead of `<dead_acute>`, the underlying key is used.  This is
112*2b949d04SAndroid Build Coastguard Worker  *    difficult to simulate with XKB keymaps).
113*2b949d04SAndroid Build Coastguard Worker  *
114*2b949d04SAndroid Build Coastguard Worker  * You can program whichever approach best fits users' expectations.
115*2b949d04SAndroid Build Coastguard Worker  *
116*2b949d04SAndroid Build Coastguard Worker  * @endparblock
117*2b949d04SAndroid Build Coastguard Worker  */
118*2b949d04SAndroid Build Coastguard Worker 
119*2b949d04SAndroid Build Coastguard Worker /**
120*2b949d04SAndroid Build Coastguard Worker  * @struct xkb_compose_table
121*2b949d04SAndroid Build Coastguard Worker  * Opaque Compose table object.
122*2b949d04SAndroid Build Coastguard Worker  *
123*2b949d04SAndroid Build Coastguard Worker  * The compose table holds the definitions of the Compose sequences, as
124*2b949d04SAndroid Build Coastguard Worker  * gathered from Compose files.  It is immutable.
125*2b949d04SAndroid Build Coastguard Worker  */
126*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table;
127*2b949d04SAndroid Build Coastguard Worker 
128*2b949d04SAndroid Build Coastguard Worker /**
129*2b949d04SAndroid Build Coastguard Worker  * @struct xkb_compose_state
130*2b949d04SAndroid Build Coastguard Worker  * Opaque Compose state object.
131*2b949d04SAndroid Build Coastguard Worker  *
132*2b949d04SAndroid Build Coastguard Worker  * The compose state maintains state for compose sequence matching, such
133*2b949d04SAndroid Build Coastguard Worker  * as which possible sequences are being matched, and the position within
134*2b949d04SAndroid Build Coastguard Worker  * these sequences.  It acts as a simple state machine wherein keysyms are
135*2b949d04SAndroid Build Coastguard Worker  * the input, and composed keysyms and strings are the output.
136*2b949d04SAndroid Build Coastguard Worker  *
137*2b949d04SAndroid Build Coastguard Worker  * The compose state is usually associated with a keyboard device.
138*2b949d04SAndroid Build Coastguard Worker  */
139*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_state;
140*2b949d04SAndroid Build Coastguard Worker 
141*2b949d04SAndroid Build Coastguard Worker /** Flags affecting Compose file compilation. */
142*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_compile_flags {
143*2b949d04SAndroid Build Coastguard Worker     /** Do not apply any flags. */
144*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_COMPILE_NO_FLAGS = 0
145*2b949d04SAndroid Build Coastguard Worker };
146*2b949d04SAndroid Build Coastguard Worker 
147*2b949d04SAndroid Build Coastguard Worker /** The recognized Compose file formats. */
148*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_format {
149*2b949d04SAndroid Build Coastguard Worker     /** The classic libX11 Compose text format, described in Compose(5). */
150*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_FORMAT_TEXT_V1 = 1
151*2b949d04SAndroid Build Coastguard Worker };
152*2b949d04SAndroid Build Coastguard Worker 
153*2b949d04SAndroid Build Coastguard Worker /**
154*2b949d04SAndroid Build Coastguard Worker  * @page compose-locale Compose Locale
155*2b949d04SAndroid Build Coastguard Worker  * @parblock
156*2b949d04SAndroid Build Coastguard Worker  *
157*2b949d04SAndroid Build Coastguard Worker  * Compose files are locale dependent:
158*2b949d04SAndroid Build Coastguard Worker  * - Compose files are written for a locale, and the locale is used when
159*2b949d04SAndroid Build Coastguard Worker  *   searching for the appropriate file to use.
160*2b949d04SAndroid Build Coastguard Worker  * - Compose files may reference the locale internally, with directives
161*2b949d04SAndroid Build Coastguard Worker  *   such as \%L.
162*2b949d04SAndroid Build Coastguard Worker  *
163*2b949d04SAndroid Build Coastguard Worker  * As such, functions like xkb_compose_table_new_from_locale() require
164*2b949d04SAndroid Build Coastguard Worker  * a `locale` parameter.  This will usually be the current locale (see
165*2b949d04SAndroid Build Coastguard Worker  * locale(7) for more details).  You may also want to allow the user to
166*2b949d04SAndroid Build Coastguard Worker  * explicitly configure it, so he can use the Compose file of a given
167*2b949d04SAndroid Build Coastguard Worker  * locale, but not use that locale for other things.
168*2b949d04SAndroid Build Coastguard Worker  *
169*2b949d04SAndroid Build Coastguard Worker  * You may query the current locale as follows:
170*2b949d04SAndroid Build Coastguard Worker  * @code
171*2b949d04SAndroid Build Coastguard Worker  *     const char *locale;
172*2b949d04SAndroid Build Coastguard Worker  *     locale = setlocale(LC_CTYPE, NULL);
173*2b949d04SAndroid Build Coastguard Worker  * @endcode
174*2b949d04SAndroid Build Coastguard Worker  *
175*2b949d04SAndroid Build Coastguard Worker  * This will only give useful results if the program had previously set
176*2b949d04SAndroid Build Coastguard Worker  * the current locale using setlocale(3), with `LC_CTYPE` or `LC_ALL`
177*2b949d04SAndroid Build Coastguard Worker  * and a non-NULL argument.
178*2b949d04SAndroid Build Coastguard Worker  *
179*2b949d04SAndroid Build Coastguard Worker  * If you prefer not to use the locale system of the C runtime library,
180*2b949d04SAndroid Build Coastguard Worker  * you may nevertheless obtain the user's locale directly using
181*2b949d04SAndroid Build Coastguard Worker  * environment variables, as described in locale(7).  For example,
182*2b949d04SAndroid Build Coastguard Worker  * @code
183*2b949d04SAndroid Build Coastguard Worker  *     const char *locale;
184*2b949d04SAndroid Build Coastguard Worker  *     locale = getenv("LC_ALL");
185*2b949d04SAndroid Build Coastguard Worker  *     if (!locale || !*locale)
186*2b949d04SAndroid Build Coastguard Worker  *         locale = getenv("LC_CTYPE");
187*2b949d04SAndroid Build Coastguard Worker  *     if (!locale || !*locale)
188*2b949d04SAndroid Build Coastguard Worker  *         locale = getenv("LANG");
189*2b949d04SAndroid Build Coastguard Worker  *     if (!locale || !*locale)
190*2b949d04SAndroid Build Coastguard Worker  *         locale = "C";
191*2b949d04SAndroid Build Coastguard Worker  * @endcode
192*2b949d04SAndroid Build Coastguard Worker  *
193*2b949d04SAndroid Build Coastguard Worker  * Note that some locales supported by the C standard library may not
194*2b949d04SAndroid Build Coastguard Worker  * have a Compose file assigned.
195*2b949d04SAndroid Build Coastguard Worker  *
196*2b949d04SAndroid Build Coastguard Worker  * @endparblock
197*2b949d04SAndroid Build Coastguard Worker  */
198*2b949d04SAndroid Build Coastguard Worker 
199*2b949d04SAndroid Build Coastguard Worker /**
200*2b949d04SAndroid Build Coastguard Worker  * Create a compose table for a given locale.
201*2b949d04SAndroid Build Coastguard Worker  *
202*2b949d04SAndroid Build Coastguard Worker  * The locale is used for searching the file-system for an appropriate
203*2b949d04SAndroid Build Coastguard Worker  * Compose file.  The search order is described in Compose(5).  It is
204*2b949d04SAndroid Build Coastguard Worker  * affected by the following environment variables:
205*2b949d04SAndroid Build Coastguard Worker  *
206*2b949d04SAndroid Build Coastguard Worker  * 1. `XCOMPOSEFILE` - see Compose(5).
207*2b949d04SAndroid Build Coastguard Worker  * 2. `XDG_CONFIG_HOME` - before `$HOME/.XCompose` is checked,
208*2b949d04SAndroid Build Coastguard Worker  *    `$XDG_CONFIG_HOME/XCompose` is checked (with a fall back to
209*2b949d04SAndroid Build Coastguard Worker  *    `$HOME/.config/XCompose` if `XDG_CONFIG_HOME` is not defined).
210*2b949d04SAndroid Build Coastguard Worker  *    This is a libxkbcommon extension to the search procedure in
211*2b949d04SAndroid Build Coastguard Worker  *    Compose(5) (since libxkbcommon 1.0.0). Note that other
212*2b949d04SAndroid Build Coastguard Worker  *    implementations, such as libX11, might not find a Compose file in
213*2b949d04SAndroid Build Coastguard Worker  *    this path.
214*2b949d04SAndroid Build Coastguard Worker  * 3. `HOME` - see Compose(5).
215*2b949d04SAndroid Build Coastguard Worker  * 4. `XLOCALEDIR` - if set, used as the base directory for the system's
216*2b949d04SAndroid Build Coastguard Worker  *    X locale files, e.g. `/usr/share/X11/locale`, instead of the
217*2b949d04SAndroid Build Coastguard Worker  *    preconfigured directory.
218*2b949d04SAndroid Build Coastguard Worker  *
219*2b949d04SAndroid Build Coastguard Worker  * @param context
220*2b949d04SAndroid Build Coastguard Worker  *     The library context in which to create the compose table.
221*2b949d04SAndroid Build Coastguard Worker  * @param locale
222*2b949d04SAndroid Build Coastguard Worker  *     The current locale.  See @ref compose-locale.
223*2b949d04SAndroid Build Coastguard Worker  *     \n
224*2b949d04SAndroid Build Coastguard Worker  *     The value is copied, so it is safe to pass the result of getenv(3)
225*2b949d04SAndroid Build Coastguard Worker  *     (or similar) without fear of it being invalidated by a subsequent
226*2b949d04SAndroid Build Coastguard Worker  *     setenv(3) (or similar).
227*2b949d04SAndroid Build Coastguard Worker  * @param flags
228*2b949d04SAndroid Build Coastguard Worker  *     Optional flags for the compose table, or 0.
229*2b949d04SAndroid Build Coastguard Worker  *
230*2b949d04SAndroid Build Coastguard Worker  * @returns A compose table for the given locale, or NULL if the
231*2b949d04SAndroid Build Coastguard Worker  * compilation failed or a Compose file was not found.
232*2b949d04SAndroid Build Coastguard Worker  *
233*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_table
234*2b949d04SAndroid Build Coastguard Worker  */
235*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table *
236*2b949d04SAndroid Build Coastguard Worker xkb_compose_table_new_from_locale(struct xkb_context *context,
237*2b949d04SAndroid Build Coastguard Worker                                   const char *locale,
238*2b949d04SAndroid Build Coastguard Worker                                   enum xkb_compose_compile_flags flags);
239*2b949d04SAndroid Build Coastguard Worker 
240*2b949d04SAndroid Build Coastguard Worker /**
241*2b949d04SAndroid Build Coastguard Worker  * Create a new compose table from a Compose file.
242*2b949d04SAndroid Build Coastguard Worker  *
243*2b949d04SAndroid Build Coastguard Worker  * @param context
244*2b949d04SAndroid Build Coastguard Worker  *     The library context in which to create the compose table.
245*2b949d04SAndroid Build Coastguard Worker  * @param file
246*2b949d04SAndroid Build Coastguard Worker  *     The Compose file to compile.
247*2b949d04SAndroid Build Coastguard Worker  * @param locale
248*2b949d04SAndroid Build Coastguard Worker  *     The current locale.  See @ref compose-locale.
249*2b949d04SAndroid Build Coastguard Worker  * @param format
250*2b949d04SAndroid Build Coastguard Worker  *     The text format of the Compose file to compile.
251*2b949d04SAndroid Build Coastguard Worker  * @param flags
252*2b949d04SAndroid Build Coastguard Worker  *     Optional flags for the compose table, or 0.
253*2b949d04SAndroid Build Coastguard Worker  *
254*2b949d04SAndroid Build Coastguard Worker  * @returns A compose table compiled from the given file, or NULL if
255*2b949d04SAndroid Build Coastguard Worker  * the compilation failed.
256*2b949d04SAndroid Build Coastguard Worker  *
257*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_table
258*2b949d04SAndroid Build Coastguard Worker  */
259*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table *
260*2b949d04SAndroid Build Coastguard Worker xkb_compose_table_new_from_file(struct xkb_context *context,
261*2b949d04SAndroid Build Coastguard Worker                                 FILE *file,
262*2b949d04SAndroid Build Coastguard Worker                                 const char *locale,
263*2b949d04SAndroid Build Coastguard Worker                                 enum xkb_compose_format format,
264*2b949d04SAndroid Build Coastguard Worker                                 enum xkb_compose_compile_flags flags);
265*2b949d04SAndroid Build Coastguard Worker 
266*2b949d04SAndroid Build Coastguard Worker /**
267*2b949d04SAndroid Build Coastguard Worker  * Create a new compose table from a memory buffer.
268*2b949d04SAndroid Build Coastguard Worker  *
269*2b949d04SAndroid Build Coastguard Worker  * This is just like xkb_compose_table_new_from_file(), but instead of
270*2b949d04SAndroid Build Coastguard Worker  * a file, gets the table as one enormous string.
271*2b949d04SAndroid Build Coastguard Worker  *
272*2b949d04SAndroid Build Coastguard Worker  * @see xkb_compose_table_new_from_file()
273*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_table
274*2b949d04SAndroid Build Coastguard Worker  */
275*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table *
276*2b949d04SAndroid Build Coastguard Worker xkb_compose_table_new_from_buffer(struct xkb_context *context,
277*2b949d04SAndroid Build Coastguard Worker                                   const char *buffer, size_t length,
278*2b949d04SAndroid Build Coastguard Worker                                   const char *locale,
279*2b949d04SAndroid Build Coastguard Worker                                   enum xkb_compose_format format,
280*2b949d04SAndroid Build Coastguard Worker                                   enum xkb_compose_compile_flags flags);
281*2b949d04SAndroid Build Coastguard Worker 
282*2b949d04SAndroid Build Coastguard Worker /**
283*2b949d04SAndroid Build Coastguard Worker  * Take a new reference on a compose table.
284*2b949d04SAndroid Build Coastguard Worker  *
285*2b949d04SAndroid Build Coastguard Worker  * @returns The passed in object.
286*2b949d04SAndroid Build Coastguard Worker  *
287*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_table
288*2b949d04SAndroid Build Coastguard Worker  */
289*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table *
290*2b949d04SAndroid Build Coastguard Worker xkb_compose_table_ref(struct xkb_compose_table *table);
291*2b949d04SAndroid Build Coastguard Worker 
292*2b949d04SAndroid Build Coastguard Worker /**
293*2b949d04SAndroid Build Coastguard Worker  * Release a reference on a compose table, and possibly free it.
294*2b949d04SAndroid Build Coastguard Worker  *
295*2b949d04SAndroid Build Coastguard Worker  * @param table The object.  If it is NULL, this function does nothing.
296*2b949d04SAndroid Build Coastguard Worker  *
297*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_table
298*2b949d04SAndroid Build Coastguard Worker  */
299*2b949d04SAndroid Build Coastguard Worker void
300*2b949d04SAndroid Build Coastguard Worker xkb_compose_table_unref(struct xkb_compose_table *table);
301*2b949d04SAndroid Build Coastguard Worker 
302*2b949d04SAndroid Build Coastguard Worker /** Flags for compose state creation. */
303*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_state_flags {
304*2b949d04SAndroid Build Coastguard Worker     /** Do not apply any flags. */
305*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_STATE_NO_FLAGS = 0
306*2b949d04SAndroid Build Coastguard Worker };
307*2b949d04SAndroid Build Coastguard Worker 
308*2b949d04SAndroid Build Coastguard Worker /**
309*2b949d04SAndroid Build Coastguard Worker  * Create a new compose state object.
310*2b949d04SAndroid Build Coastguard Worker  *
311*2b949d04SAndroid Build Coastguard Worker  * @param table
312*2b949d04SAndroid Build Coastguard Worker  *     The compose table the state will use.
313*2b949d04SAndroid Build Coastguard Worker  * @param flags
314*2b949d04SAndroid Build Coastguard Worker  *     Optional flags for the compose state, or 0.
315*2b949d04SAndroid Build Coastguard Worker  *
316*2b949d04SAndroid Build Coastguard Worker  * @returns A new compose state, or NULL on failure.
317*2b949d04SAndroid Build Coastguard Worker  *
318*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
319*2b949d04SAndroid Build Coastguard Worker  */
320*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_state *
321*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_new(struct xkb_compose_table *table,
322*2b949d04SAndroid Build Coastguard Worker                       enum xkb_compose_state_flags flags);
323*2b949d04SAndroid Build Coastguard Worker 
324*2b949d04SAndroid Build Coastguard Worker /**
325*2b949d04SAndroid Build Coastguard Worker  * Take a new reference on a compose state object.
326*2b949d04SAndroid Build Coastguard Worker  *
327*2b949d04SAndroid Build Coastguard Worker  * @returns The passed in object.
328*2b949d04SAndroid Build Coastguard Worker  *
329*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
330*2b949d04SAndroid Build Coastguard Worker  */
331*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_state *
332*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_ref(struct xkb_compose_state *state);
333*2b949d04SAndroid Build Coastguard Worker 
334*2b949d04SAndroid Build Coastguard Worker /**
335*2b949d04SAndroid Build Coastguard Worker  * Release a reference on a compose state object, and possibly free it.
336*2b949d04SAndroid Build Coastguard Worker  *
337*2b949d04SAndroid Build Coastguard Worker  * @param state The object.  If NULL, do nothing.
338*2b949d04SAndroid Build Coastguard Worker  *
339*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
340*2b949d04SAndroid Build Coastguard Worker  */
341*2b949d04SAndroid Build Coastguard Worker void
342*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_unref(struct xkb_compose_state *state);
343*2b949d04SAndroid Build Coastguard Worker 
344*2b949d04SAndroid Build Coastguard Worker /**
345*2b949d04SAndroid Build Coastguard Worker  * Get the compose table which a compose state object is using.
346*2b949d04SAndroid Build Coastguard Worker  *
347*2b949d04SAndroid Build Coastguard Worker  * @returns The compose table which was passed to xkb_compose_state_new()
348*2b949d04SAndroid Build Coastguard Worker  * when creating this state object.
349*2b949d04SAndroid Build Coastguard Worker  *
350*2b949d04SAndroid Build Coastguard Worker  * This function does not take a new reference on the compose table; you
351*2b949d04SAndroid Build Coastguard Worker  * must explicitly reference it yourself if you plan to use it beyond the
352*2b949d04SAndroid Build Coastguard Worker  * lifetime of the state.
353*2b949d04SAndroid Build Coastguard Worker  *
354*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
355*2b949d04SAndroid Build Coastguard Worker  */
356*2b949d04SAndroid Build Coastguard Worker struct xkb_compose_table *
357*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_get_compose_table(struct xkb_compose_state *state);
358*2b949d04SAndroid Build Coastguard Worker 
359*2b949d04SAndroid Build Coastguard Worker /** Status of the Compose sequence state machine. */
360*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_status {
361*2b949d04SAndroid Build Coastguard Worker     /** The initial state; no sequence has started yet. */
362*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_NOTHING,
363*2b949d04SAndroid Build Coastguard Worker     /** In the middle of a sequence. */
364*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_COMPOSING,
365*2b949d04SAndroid Build Coastguard Worker     /** A complete sequence has been matched. */
366*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_COMPOSED,
367*2b949d04SAndroid Build Coastguard Worker     /** The last sequence was cancelled due to an unmatched keysym. */
368*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_CANCELLED
369*2b949d04SAndroid Build Coastguard Worker };
370*2b949d04SAndroid Build Coastguard Worker 
371*2b949d04SAndroid Build Coastguard Worker /** The effect of a keysym fed to xkb_compose_state_feed(). */
372*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_feed_result {
373*2b949d04SAndroid Build Coastguard Worker     /** The keysym had no effect - it did not affect the status. */
374*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_FEED_IGNORED,
375*2b949d04SAndroid Build Coastguard Worker     /** The keysym started, advanced or cancelled a sequence. */
376*2b949d04SAndroid Build Coastguard Worker     XKB_COMPOSE_FEED_ACCEPTED
377*2b949d04SAndroid Build Coastguard Worker };
378*2b949d04SAndroid Build Coastguard Worker 
379*2b949d04SAndroid Build Coastguard Worker /**
380*2b949d04SAndroid Build Coastguard Worker  * Feed one keysym to the Compose sequence state machine.
381*2b949d04SAndroid Build Coastguard Worker  *
382*2b949d04SAndroid Build Coastguard Worker  * This function can advance into a compose sequence, cancel a sequence,
383*2b949d04SAndroid Build Coastguard Worker  * start a new sequence, or do nothing in particular.  The resulting
384*2b949d04SAndroid Build Coastguard Worker  * status may be observed with xkb_compose_state_get_status().
385*2b949d04SAndroid Build Coastguard Worker  *
386*2b949d04SAndroid Build Coastguard Worker  * Some keysyms, such as keysyms for modifier keys, are ignored - they
387*2b949d04SAndroid Build Coastguard Worker  * have no effect on the status or otherwise.
388*2b949d04SAndroid Build Coastguard Worker  *
389*2b949d04SAndroid Build Coastguard Worker  * The following is a description of the possible status transitions, in
390*2b949d04SAndroid Build Coastguard Worker  * the format CURRENT STATUS => NEXT STATUS, given a non-ignored input
391*2b949d04SAndroid Build Coastguard Worker  * keysym `keysym`:
392*2b949d04SAndroid Build Coastguard Worker  *
393*2b949d04SAndroid Build Coastguard Worker    @verbatim
394*2b949d04SAndroid Build Coastguard Worker    NOTHING or CANCELLED or COMPOSED =>
395*2b949d04SAndroid Build Coastguard Worker       NOTHING   if keysym does not start a sequence.
396*2b949d04SAndroid Build Coastguard Worker       COMPOSING if keysym starts a sequence.
397*2b949d04SAndroid Build Coastguard Worker       COMPOSED  if keysym starts and terminates a single-keysym sequence.
398*2b949d04SAndroid Build Coastguard Worker 
399*2b949d04SAndroid Build Coastguard Worker    COMPOSING =>
400*2b949d04SAndroid Build Coastguard Worker       COMPOSING if keysym advances any of the currently possible
401*2b949d04SAndroid Build Coastguard Worker                 sequences but does not terminate any of them.
402*2b949d04SAndroid Build Coastguard Worker       COMPOSED  if keysym terminates one of the currently possible
403*2b949d04SAndroid Build Coastguard Worker                 sequences.
404*2b949d04SAndroid Build Coastguard Worker       CANCELLED if keysym does not advance any of the currently
405*2b949d04SAndroid Build Coastguard Worker                 possible sequences.
406*2b949d04SAndroid Build Coastguard Worker    @endverbatim
407*2b949d04SAndroid Build Coastguard Worker  *
408*2b949d04SAndroid Build Coastguard Worker  * The current Compose formats do not support multiple-keysyms.
409*2b949d04SAndroid Build Coastguard Worker  * Therefore, if you are using a function such as xkb_state_key_get_syms()
410*2b949d04SAndroid Build Coastguard Worker  * and it returns more than one keysym, consider feeding XKB_KEY_NoSymbol
411*2b949d04SAndroid Build Coastguard Worker  * instead.
412*2b949d04SAndroid Build Coastguard Worker  *
413*2b949d04SAndroid Build Coastguard Worker  * @param state
414*2b949d04SAndroid Build Coastguard Worker  *     The compose state object.
415*2b949d04SAndroid Build Coastguard Worker  * @param keysym
416*2b949d04SAndroid Build Coastguard Worker  *     A keysym, usually obtained after a key-press event, with a
417*2b949d04SAndroid Build Coastguard Worker  *     function such as xkb_state_key_get_one_sym().
418*2b949d04SAndroid Build Coastguard Worker  *
419*2b949d04SAndroid Build Coastguard Worker  * @returns Whether the keysym was ignored.  This is useful, for example,
420*2b949d04SAndroid Build Coastguard Worker  * if you want to keep a record of the sequence matched thus far.
421*2b949d04SAndroid Build Coastguard Worker  *
422*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
423*2b949d04SAndroid Build Coastguard Worker  */
424*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_feed_result
425*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_feed(struct xkb_compose_state *state,
426*2b949d04SAndroid Build Coastguard Worker                        xkb_keysym_t keysym);
427*2b949d04SAndroid Build Coastguard Worker 
428*2b949d04SAndroid Build Coastguard Worker /**
429*2b949d04SAndroid Build Coastguard Worker  * Reset the Compose sequence state machine.
430*2b949d04SAndroid Build Coastguard Worker  *
431*2b949d04SAndroid Build Coastguard Worker  * The status is set to XKB_COMPOSE_NOTHING, and the current sequence
432*2b949d04SAndroid Build Coastguard Worker  * is discarded.
433*2b949d04SAndroid Build Coastguard Worker  *
434*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
435*2b949d04SAndroid Build Coastguard Worker  */
436*2b949d04SAndroid Build Coastguard Worker void
437*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_reset(struct xkb_compose_state *state);
438*2b949d04SAndroid Build Coastguard Worker 
439*2b949d04SAndroid Build Coastguard Worker /**
440*2b949d04SAndroid Build Coastguard Worker  * Get the current status of the compose state machine.
441*2b949d04SAndroid Build Coastguard Worker  *
442*2b949d04SAndroid Build Coastguard Worker  * @see xkb_compose_status
443*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
444*2b949d04SAndroid Build Coastguard Worker  **/
445*2b949d04SAndroid Build Coastguard Worker enum xkb_compose_status
446*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_get_status(struct xkb_compose_state *state);
447*2b949d04SAndroid Build Coastguard Worker 
448*2b949d04SAndroid Build Coastguard Worker /**
449*2b949d04SAndroid Build Coastguard Worker  * Get the result Unicode/UTF-8 string for a composed sequence.
450*2b949d04SAndroid Build Coastguard Worker  *
451*2b949d04SAndroid Build Coastguard Worker  * See @ref compose-overview for more details.  This function is only
452*2b949d04SAndroid Build Coastguard Worker  * useful when the status is XKB_COMPOSE_COMPOSED.
453*2b949d04SAndroid Build Coastguard Worker  *
454*2b949d04SAndroid Build Coastguard Worker  * @param[in] state
455*2b949d04SAndroid Build Coastguard Worker  *     The compose state.
456*2b949d04SAndroid Build Coastguard Worker  * @param[out] buffer
457*2b949d04SAndroid Build Coastguard Worker  *     A buffer to write the string into.
458*2b949d04SAndroid Build Coastguard Worker  * @param[in] size
459*2b949d04SAndroid Build Coastguard Worker  *     Size of the buffer.
460*2b949d04SAndroid Build Coastguard Worker  *
461*2b949d04SAndroid Build Coastguard Worker  * @warning If the buffer passed is too small, the string is truncated
462*2b949d04SAndroid Build Coastguard Worker  * (though still NUL-terminated).
463*2b949d04SAndroid Build Coastguard Worker  *
464*2b949d04SAndroid Build Coastguard Worker  * @returns
465*2b949d04SAndroid Build Coastguard Worker  *   The number of bytes required for the string, excluding the NUL byte.
466*2b949d04SAndroid Build Coastguard Worker  *   If the sequence is not complete, or does not have a viable result
467*2b949d04SAndroid Build Coastguard Worker  *   string, returns 0, and sets `buffer` to the empty string (if possible).
468*2b949d04SAndroid Build Coastguard Worker  * @returns
469*2b949d04SAndroid Build Coastguard Worker  *   You may check if truncation has occurred by comparing the return value
470*2b949d04SAndroid Build Coastguard Worker  *   with the size of `buffer`, similarly to the `snprintf`(3) function.
471*2b949d04SAndroid Build Coastguard Worker  *   You may safely pass NULL and 0 to `buffer` and `size` to find the
472*2b949d04SAndroid Build Coastguard Worker  *   required size (without the NUL-byte).
473*2b949d04SAndroid Build Coastguard Worker  *
474*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
475*2b949d04SAndroid Build Coastguard Worker  **/
476*2b949d04SAndroid Build Coastguard Worker int
477*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_get_utf8(struct xkb_compose_state *state,
478*2b949d04SAndroid Build Coastguard Worker                            char *buffer, size_t size);
479*2b949d04SAndroid Build Coastguard Worker 
480*2b949d04SAndroid Build Coastguard Worker /**
481*2b949d04SAndroid Build Coastguard Worker  * Get the result keysym for a composed sequence.
482*2b949d04SAndroid Build Coastguard Worker  *
483*2b949d04SAndroid Build Coastguard Worker  * See @ref compose-overview for more details.  This function is only
484*2b949d04SAndroid Build Coastguard Worker  * useful when the status is XKB_COMPOSE_COMPOSED.
485*2b949d04SAndroid Build Coastguard Worker  *
486*2b949d04SAndroid Build Coastguard Worker  * @returns The result keysym.  If the sequence is not complete, or does
487*2b949d04SAndroid Build Coastguard Worker  * not specify a result keysym, returns XKB_KEY_NoSymbol.
488*2b949d04SAndroid Build Coastguard Worker  *
489*2b949d04SAndroid Build Coastguard Worker  * @memberof xkb_compose_state
490*2b949d04SAndroid Build Coastguard Worker  **/
491*2b949d04SAndroid Build Coastguard Worker xkb_keysym_t
492*2b949d04SAndroid Build Coastguard Worker xkb_compose_state_get_one_sym(struct xkb_compose_state *state);
493*2b949d04SAndroid Build Coastguard Worker 
494*2b949d04SAndroid Build Coastguard Worker /** @} */
495*2b949d04SAndroid Build Coastguard Worker 
496*2b949d04SAndroid Build Coastguard Worker #ifdef __cplusplus
497*2b949d04SAndroid Build Coastguard Worker } /* extern "C" */
498*2b949d04SAndroid Build Coastguard Worker #endif
499*2b949d04SAndroid Build Coastguard Worker 
500*2b949d04SAndroid Build Coastguard Worker #endif /* _XKBCOMMON_COMPOSE_H */
501