1*2b949d04SAndroid Build Coastguard Worker /************************************************************
2*2b949d04SAndroid Build Coastguard Worker * Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3*2b949d04SAndroid Build Coastguard Worker *
4*2b949d04SAndroid Build Coastguard Worker * Permission to use, copy, modify, and distribute this
5*2b949d04SAndroid Build Coastguard Worker * software and its documentation for any purpose and without
6*2b949d04SAndroid Build Coastguard Worker * fee is hereby granted, provided that the above copyright
7*2b949d04SAndroid Build Coastguard Worker * notice appear in all copies and that both that copyright
8*2b949d04SAndroid Build Coastguard Worker * notice and this permission notice appear in supporting
9*2b949d04SAndroid Build Coastguard Worker * documentation, and that the name of Silicon Graphics not be
10*2b949d04SAndroid Build Coastguard Worker * used in advertising or publicity pertaining to distribution
11*2b949d04SAndroid Build Coastguard Worker * of the software without specific prior written permission.
12*2b949d04SAndroid Build Coastguard Worker * Silicon Graphics makes no representation about the suitability
13*2b949d04SAndroid Build Coastguard Worker * of this software for any purpose. It is provided "as is"
14*2b949d04SAndroid Build Coastguard Worker * without any express or implied warranty.
15*2b949d04SAndroid Build Coastguard Worker *
16*2b949d04SAndroid Build Coastguard Worker * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17*2b949d04SAndroid Build Coastguard Worker * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18*2b949d04SAndroid Build Coastguard Worker * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19*2b949d04SAndroid Build Coastguard Worker * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20*2b949d04SAndroid Build Coastguard Worker * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21*2b949d04SAndroid Build Coastguard Worker * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22*2b949d04SAndroid Build Coastguard Worker * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23*2b949d04SAndroid Build Coastguard Worker * THE USE OR PERFORMANCE OF THIS SOFTWARE.
24*2b949d04SAndroid Build Coastguard Worker *
25*2b949d04SAndroid Build Coastguard Worker ********************************************************/
26*2b949d04SAndroid Build Coastguard Worker
27*2b949d04SAndroid Build Coastguard Worker /*
28*2b949d04SAndroid Build Coastguard Worker * Copyright © 2012 Intel Corporation
29*2b949d04SAndroid Build Coastguard Worker *
30*2b949d04SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a
31*2b949d04SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"),
32*2b949d04SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation
33*2b949d04SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense,
34*2b949d04SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the
35*2b949d04SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions:
36*2b949d04SAndroid Build Coastguard Worker *
37*2b949d04SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next
38*2b949d04SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the
39*2b949d04SAndroid Build Coastguard Worker * Software.
40*2b949d04SAndroid Build Coastguard Worker *
41*2b949d04SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42*2b949d04SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43*2b949d04SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44*2b949d04SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45*2b949d04SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46*2b949d04SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47*2b949d04SAndroid Build Coastguard Worker * DEALINGS IN THE SOFTWARE.
48*2b949d04SAndroid Build Coastguard Worker *
49*2b949d04SAndroid Build Coastguard Worker * Author: Daniel Stone <[email protected]>
50*2b949d04SAndroid Build Coastguard Worker */
51*2b949d04SAndroid Build Coastguard Worker
52*2b949d04SAndroid Build Coastguard Worker #include "config.h"
53*2b949d04SAndroid Build Coastguard Worker
54*2b949d04SAndroid Build Coastguard Worker #include "xkbcomp-priv.h"
55*2b949d04SAndroid Build Coastguard Worker #include "text.h"
56*2b949d04SAndroid Build Coastguard Worker
57*2b949d04SAndroid Build Coastguard Worker #define BUF_CHUNK_SIZE 4096
58*2b949d04SAndroid Build Coastguard Worker
59*2b949d04SAndroid Build Coastguard Worker struct buf {
60*2b949d04SAndroid Build Coastguard Worker char *buf;
61*2b949d04SAndroid Build Coastguard Worker size_t size;
62*2b949d04SAndroid Build Coastguard Worker size_t alloc;
63*2b949d04SAndroid Build Coastguard Worker };
64*2b949d04SAndroid Build Coastguard Worker
65*2b949d04SAndroid Build Coastguard Worker static bool
do_realloc(struct buf * buf,size_t at_least)66*2b949d04SAndroid Build Coastguard Worker do_realloc(struct buf *buf, size_t at_least)
67*2b949d04SAndroid Build Coastguard Worker {
68*2b949d04SAndroid Build Coastguard Worker char *new;
69*2b949d04SAndroid Build Coastguard Worker
70*2b949d04SAndroid Build Coastguard Worker buf->alloc += BUF_CHUNK_SIZE;
71*2b949d04SAndroid Build Coastguard Worker if (at_least >= BUF_CHUNK_SIZE)
72*2b949d04SAndroid Build Coastguard Worker buf->alloc += at_least;
73*2b949d04SAndroid Build Coastguard Worker
74*2b949d04SAndroid Build Coastguard Worker new = realloc(buf->buf, buf->alloc);
75*2b949d04SAndroid Build Coastguard Worker if (!new)
76*2b949d04SAndroid Build Coastguard Worker return false;
77*2b949d04SAndroid Build Coastguard Worker
78*2b949d04SAndroid Build Coastguard Worker buf->buf = new;
79*2b949d04SAndroid Build Coastguard Worker return true;
80*2b949d04SAndroid Build Coastguard Worker }
81*2b949d04SAndroid Build Coastguard Worker
82*2b949d04SAndroid Build Coastguard Worker ATTR_PRINTF(2, 3) static bool
check_write_buf(struct buf * buf,const char * fmt,...)83*2b949d04SAndroid Build Coastguard Worker check_write_buf(struct buf *buf, const char *fmt, ...)
84*2b949d04SAndroid Build Coastguard Worker {
85*2b949d04SAndroid Build Coastguard Worker va_list args;
86*2b949d04SAndroid Build Coastguard Worker int printed;
87*2b949d04SAndroid Build Coastguard Worker size_t available;
88*2b949d04SAndroid Build Coastguard Worker
89*2b949d04SAndroid Build Coastguard Worker available = buf->alloc - buf->size;
90*2b949d04SAndroid Build Coastguard Worker va_start(args, fmt);
91*2b949d04SAndroid Build Coastguard Worker printed = vsnprintf(buf->buf + buf->size, available, fmt, args);
92*2b949d04SAndroid Build Coastguard Worker va_end(args);
93*2b949d04SAndroid Build Coastguard Worker
94*2b949d04SAndroid Build Coastguard Worker if (printed < 0)
95*2b949d04SAndroid Build Coastguard Worker goto err;
96*2b949d04SAndroid Build Coastguard Worker
97*2b949d04SAndroid Build Coastguard Worker if ((size_t) printed >= available)
98*2b949d04SAndroid Build Coastguard Worker if (!do_realloc(buf, printed))
99*2b949d04SAndroid Build Coastguard Worker goto err;
100*2b949d04SAndroid Build Coastguard Worker
101*2b949d04SAndroid Build Coastguard Worker /* The buffer has enough space now. */
102*2b949d04SAndroid Build Coastguard Worker
103*2b949d04SAndroid Build Coastguard Worker available = buf->alloc - buf->size;
104*2b949d04SAndroid Build Coastguard Worker va_start(args, fmt);
105*2b949d04SAndroid Build Coastguard Worker printed = vsnprintf(buf->buf + buf->size, available, fmt, args);
106*2b949d04SAndroid Build Coastguard Worker va_end(args);
107*2b949d04SAndroid Build Coastguard Worker
108*2b949d04SAndroid Build Coastguard Worker if (printed < 0 || (size_t) printed >= available)
109*2b949d04SAndroid Build Coastguard Worker goto err;
110*2b949d04SAndroid Build Coastguard Worker
111*2b949d04SAndroid Build Coastguard Worker buf->size += printed;
112*2b949d04SAndroid Build Coastguard Worker return true;
113*2b949d04SAndroid Build Coastguard Worker
114*2b949d04SAndroid Build Coastguard Worker err:
115*2b949d04SAndroid Build Coastguard Worker free(buf->buf);
116*2b949d04SAndroid Build Coastguard Worker buf->buf = NULL;
117*2b949d04SAndroid Build Coastguard Worker return false;
118*2b949d04SAndroid Build Coastguard Worker }
119*2b949d04SAndroid Build Coastguard Worker
120*2b949d04SAndroid Build Coastguard Worker #define write_buf(buf, ...) do { \
121*2b949d04SAndroid Build Coastguard Worker if (!check_write_buf(buf, __VA_ARGS__)) \
122*2b949d04SAndroid Build Coastguard Worker return false; \
123*2b949d04SAndroid Build Coastguard Worker } while (0)
124*2b949d04SAndroid Build Coastguard Worker
125*2b949d04SAndroid Build Coastguard Worker static bool
write_vmods(struct xkb_keymap * keymap,struct buf * buf)126*2b949d04SAndroid Build Coastguard Worker write_vmods(struct xkb_keymap *keymap, struct buf *buf)
127*2b949d04SAndroid Build Coastguard Worker {
128*2b949d04SAndroid Build Coastguard Worker const struct xkb_mod *mod;
129*2b949d04SAndroid Build Coastguard Worker xkb_mod_index_t num_vmods = 0;
130*2b949d04SAndroid Build Coastguard Worker
131*2b949d04SAndroid Build Coastguard Worker xkb_mods_foreach(mod, &keymap->mods) {
132*2b949d04SAndroid Build Coastguard Worker if (mod->type != MOD_VIRT)
133*2b949d04SAndroid Build Coastguard Worker continue;
134*2b949d04SAndroid Build Coastguard Worker
135*2b949d04SAndroid Build Coastguard Worker if (num_vmods == 0)
136*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tvirtual_modifiers ");
137*2b949d04SAndroid Build Coastguard Worker else
138*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ",");
139*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s", xkb_atom_text(keymap->ctx, mod->name));
140*2b949d04SAndroid Build Coastguard Worker num_vmods++;
141*2b949d04SAndroid Build Coastguard Worker }
142*2b949d04SAndroid Build Coastguard Worker
143*2b949d04SAndroid Build Coastguard Worker if (num_vmods > 0)
144*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ";\n\n");
145*2b949d04SAndroid Build Coastguard Worker
146*2b949d04SAndroid Build Coastguard Worker return true;
147*2b949d04SAndroid Build Coastguard Worker }
148*2b949d04SAndroid Build Coastguard Worker
149*2b949d04SAndroid Build Coastguard Worker static bool
write_keycodes(struct xkb_keymap * keymap,struct buf * buf)150*2b949d04SAndroid Build Coastguard Worker write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
151*2b949d04SAndroid Build Coastguard Worker {
152*2b949d04SAndroid Build Coastguard Worker const struct xkb_key *key;
153*2b949d04SAndroid Build Coastguard Worker xkb_led_index_t idx;
154*2b949d04SAndroid Build Coastguard Worker const struct xkb_led *led;
155*2b949d04SAndroid Build Coastguard Worker
156*2b949d04SAndroid Build Coastguard Worker if (keymap->keycodes_section_name)
157*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_keycodes \"%s\" {\n",
158*2b949d04SAndroid Build Coastguard Worker keymap->keycodes_section_name);
159*2b949d04SAndroid Build Coastguard Worker else
160*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_keycodes {\n");
161*2b949d04SAndroid Build Coastguard Worker
162*2b949d04SAndroid Build Coastguard Worker /* xkbcomp and X11 really want to see keymaps with a minimum of 8, and
163*2b949d04SAndroid Build Coastguard Worker * a maximum of at least 255, else XWayland really starts hating life.
164*2b949d04SAndroid Build Coastguard Worker * If this is a problem and people really need strictly bounded keymaps,
165*2b949d04SAndroid Build Coastguard Worker * we should probably control this with a flag. */
166*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tminimum = %u;\n", MIN(keymap->min_key_code, 8));
167*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tmaximum = %u;\n", MAX(keymap->max_key_code, 255));
168*2b949d04SAndroid Build Coastguard Worker
169*2b949d04SAndroid Build Coastguard Worker xkb_keys_foreach(key, keymap) {
170*2b949d04SAndroid Build Coastguard Worker if (key->name == XKB_ATOM_NONE)
171*2b949d04SAndroid Build Coastguard Worker continue;
172*2b949d04SAndroid Build Coastguard Worker
173*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t%-20s = %u;\n",
174*2b949d04SAndroid Build Coastguard Worker KeyNameText(keymap->ctx, key->name), key->keycode);
175*2b949d04SAndroid Build Coastguard Worker }
176*2b949d04SAndroid Build Coastguard Worker
177*2b949d04SAndroid Build Coastguard Worker xkb_leds_enumerate(idx, led, keymap)
178*2b949d04SAndroid Build Coastguard Worker if (led->name != XKB_ATOM_NONE)
179*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tindicator %u = \"%s\";\n",
180*2b949d04SAndroid Build Coastguard Worker idx + 1, xkb_atom_text(keymap->ctx, led->name));
181*2b949d04SAndroid Build Coastguard Worker
182*2b949d04SAndroid Build Coastguard Worker
183*2b949d04SAndroid Build Coastguard Worker for (unsigned i = 0; i < keymap->num_key_aliases; i++)
184*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\talias %-14s = %s;\n",
185*2b949d04SAndroid Build Coastguard Worker KeyNameText(keymap->ctx, keymap->key_aliases[i].alias),
186*2b949d04SAndroid Build Coastguard Worker KeyNameText(keymap->ctx, keymap->key_aliases[i].real));
187*2b949d04SAndroid Build Coastguard Worker
188*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "};\n\n");
189*2b949d04SAndroid Build Coastguard Worker return true;
190*2b949d04SAndroid Build Coastguard Worker }
191*2b949d04SAndroid Build Coastguard Worker
192*2b949d04SAndroid Build Coastguard Worker static bool
write_types(struct xkb_keymap * keymap,struct buf * buf)193*2b949d04SAndroid Build Coastguard Worker write_types(struct xkb_keymap *keymap, struct buf *buf)
194*2b949d04SAndroid Build Coastguard Worker {
195*2b949d04SAndroid Build Coastguard Worker if (keymap->types_section_name)
196*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_types \"%s\" {\n",
197*2b949d04SAndroid Build Coastguard Worker keymap->types_section_name);
198*2b949d04SAndroid Build Coastguard Worker else
199*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_types {\n");
200*2b949d04SAndroid Build Coastguard Worker
201*2b949d04SAndroid Build Coastguard Worker write_vmods(keymap, buf);
202*2b949d04SAndroid Build Coastguard Worker
203*2b949d04SAndroid Build Coastguard Worker for (unsigned i = 0; i < keymap->num_types; i++) {
204*2b949d04SAndroid Build Coastguard Worker const struct xkb_key_type *type = &keymap->types[i];
205*2b949d04SAndroid Build Coastguard Worker
206*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\ttype \"%s\" {\n",
207*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, type->name));
208*2b949d04SAndroid Build Coastguard Worker
209*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tmodifiers= %s;\n",
210*2b949d04SAndroid Build Coastguard Worker ModMaskText(keymap->ctx, &keymap->mods, type->mods.mods));
211*2b949d04SAndroid Build Coastguard Worker
212*2b949d04SAndroid Build Coastguard Worker for (unsigned j = 0; j < type->num_entries; j++) {
213*2b949d04SAndroid Build Coastguard Worker const char *str;
214*2b949d04SAndroid Build Coastguard Worker const struct xkb_key_type_entry *entry = &type->entries[j];
215*2b949d04SAndroid Build Coastguard Worker
216*2b949d04SAndroid Build Coastguard Worker /*
217*2b949d04SAndroid Build Coastguard Worker * Printing level 1 entries is redundant, it's the default,
218*2b949d04SAndroid Build Coastguard Worker * unless there's preserve info.
219*2b949d04SAndroid Build Coastguard Worker */
220*2b949d04SAndroid Build Coastguard Worker if (entry->level == 0 && entry->preserve.mods == 0)
221*2b949d04SAndroid Build Coastguard Worker continue;
222*2b949d04SAndroid Build Coastguard Worker
223*2b949d04SAndroid Build Coastguard Worker str = ModMaskText(keymap->ctx, &keymap->mods, entry->mods.mods);
224*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tmap[%s]= %u;\n",
225*2b949d04SAndroid Build Coastguard Worker str, entry->level + 1);
226*2b949d04SAndroid Build Coastguard Worker
227*2b949d04SAndroid Build Coastguard Worker if (entry->preserve.mods)
228*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tpreserve[%s]= %s;\n",
229*2b949d04SAndroid Build Coastguard Worker str, ModMaskText(keymap->ctx, &keymap->mods,
230*2b949d04SAndroid Build Coastguard Worker entry->preserve.mods));
231*2b949d04SAndroid Build Coastguard Worker }
232*2b949d04SAndroid Build Coastguard Worker
233*2b949d04SAndroid Build Coastguard Worker for (xkb_level_index_t n = 0; n < type->num_level_names; n++)
234*2b949d04SAndroid Build Coastguard Worker if (type->level_names[n])
235*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tlevel_name[%u]= \"%s\";\n", n + 1,
236*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, type->level_names[n]));
237*2b949d04SAndroid Build Coastguard Worker
238*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t};\n");
239*2b949d04SAndroid Build Coastguard Worker }
240*2b949d04SAndroid Build Coastguard Worker
241*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "};\n\n");
242*2b949d04SAndroid Build Coastguard Worker return true;
243*2b949d04SAndroid Build Coastguard Worker }
244*2b949d04SAndroid Build Coastguard Worker
245*2b949d04SAndroid Build Coastguard Worker static bool
write_led_map(struct xkb_keymap * keymap,struct buf * buf,const struct xkb_led * led)246*2b949d04SAndroid Build Coastguard Worker write_led_map(struct xkb_keymap *keymap, struct buf *buf,
247*2b949d04SAndroid Build Coastguard Worker const struct xkb_led *led)
248*2b949d04SAndroid Build Coastguard Worker {
249*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tindicator \"%s\" {\n",
250*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, led->name));
251*2b949d04SAndroid Build Coastguard Worker
252*2b949d04SAndroid Build Coastguard Worker if (led->which_groups) {
253*2b949d04SAndroid Build Coastguard Worker if (led->which_groups != XKB_STATE_LAYOUT_EFFECTIVE) {
254*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\twhichGroupState= %s;\n",
255*2b949d04SAndroid Build Coastguard Worker LedStateMaskText(keymap->ctx, led->which_groups));
256*2b949d04SAndroid Build Coastguard Worker }
257*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tgroups= 0x%02x;\n",
258*2b949d04SAndroid Build Coastguard Worker led->groups);
259*2b949d04SAndroid Build Coastguard Worker }
260*2b949d04SAndroid Build Coastguard Worker
261*2b949d04SAndroid Build Coastguard Worker if (led->which_mods) {
262*2b949d04SAndroid Build Coastguard Worker if (led->which_mods != XKB_STATE_MODS_EFFECTIVE) {
263*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\twhichModState= %s;\n",
264*2b949d04SAndroid Build Coastguard Worker LedStateMaskText(keymap->ctx, led->which_mods));
265*2b949d04SAndroid Build Coastguard Worker }
266*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tmodifiers= %s;\n",
267*2b949d04SAndroid Build Coastguard Worker ModMaskText(keymap->ctx, &keymap->mods, led->mods.mods));
268*2b949d04SAndroid Build Coastguard Worker }
269*2b949d04SAndroid Build Coastguard Worker
270*2b949d04SAndroid Build Coastguard Worker if (led->ctrls) {
271*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tcontrols= %s;\n",
272*2b949d04SAndroid Build Coastguard Worker ControlMaskText(keymap->ctx, led->ctrls));
273*2b949d04SAndroid Build Coastguard Worker }
274*2b949d04SAndroid Build Coastguard Worker
275*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t};\n");
276*2b949d04SAndroid Build Coastguard Worker return true;
277*2b949d04SAndroid Build Coastguard Worker }
278*2b949d04SAndroid Build Coastguard Worker
279*2b949d04SAndroid Build Coastguard Worker static const char *
affect_lock_text(enum xkb_action_flags flags,bool show_both)280*2b949d04SAndroid Build Coastguard Worker affect_lock_text(enum xkb_action_flags flags, bool show_both)
281*2b949d04SAndroid Build Coastguard Worker {
282*2b949d04SAndroid Build Coastguard Worker switch (flags & (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK)) {
283*2b949d04SAndroid Build Coastguard Worker case 0:
284*2b949d04SAndroid Build Coastguard Worker return show_both ? ",affect=both" : "";
285*2b949d04SAndroid Build Coastguard Worker case ACTION_LOCK_NO_UNLOCK:
286*2b949d04SAndroid Build Coastguard Worker return ",affect=lock";
287*2b949d04SAndroid Build Coastguard Worker case ACTION_LOCK_NO_LOCK:
288*2b949d04SAndroid Build Coastguard Worker return ",affect=unlock";
289*2b949d04SAndroid Build Coastguard Worker case ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK:
290*2b949d04SAndroid Build Coastguard Worker return ",affect=neither";
291*2b949d04SAndroid Build Coastguard Worker }
292*2b949d04SAndroid Build Coastguard Worker return "";
293*2b949d04SAndroid Build Coastguard Worker }
294*2b949d04SAndroid Build Coastguard Worker
295*2b949d04SAndroid Build Coastguard Worker static bool
write_action(struct xkb_keymap * keymap,struct buf * buf,const union xkb_action * action,const char * prefix,const char * suffix)296*2b949d04SAndroid Build Coastguard Worker write_action(struct xkb_keymap *keymap, struct buf *buf,
297*2b949d04SAndroid Build Coastguard Worker const union xkb_action *action,
298*2b949d04SAndroid Build Coastguard Worker const char *prefix, const char *suffix)
299*2b949d04SAndroid Build Coastguard Worker {
300*2b949d04SAndroid Build Coastguard Worker const char *type;
301*2b949d04SAndroid Build Coastguard Worker const char *args = NULL;
302*2b949d04SAndroid Build Coastguard Worker
303*2b949d04SAndroid Build Coastguard Worker if (!prefix)
304*2b949d04SAndroid Build Coastguard Worker prefix = "";
305*2b949d04SAndroid Build Coastguard Worker if (!suffix)
306*2b949d04SAndroid Build Coastguard Worker suffix = "";
307*2b949d04SAndroid Build Coastguard Worker
308*2b949d04SAndroid Build Coastguard Worker type = ActionTypeText(action->type);
309*2b949d04SAndroid Build Coastguard Worker
310*2b949d04SAndroid Build Coastguard Worker switch (action->type) {
311*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_MOD_SET:
312*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_MOD_LATCH:
313*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_MOD_LOCK:
314*2b949d04SAndroid Build Coastguard Worker if (action->mods.flags & ACTION_MODS_LOOKUP_MODMAP)
315*2b949d04SAndroid Build Coastguard Worker args = "modMapMods";
316*2b949d04SAndroid Build Coastguard Worker else
317*2b949d04SAndroid Build Coastguard Worker args = ModMaskText(keymap->ctx, &keymap->mods,
318*2b949d04SAndroid Build Coastguard Worker action->mods.mods.mods);
319*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(modifiers=%s%s%s%s)%s", prefix, type, args,
320*2b949d04SAndroid Build Coastguard Worker (action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
321*2b949d04SAndroid Build Coastguard Worker (action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
322*2b949d04SAndroid Build Coastguard Worker (action->type == ACTION_TYPE_MOD_LOCK) ? affect_lock_text(action->mods.flags, false) : "",
323*2b949d04SAndroid Build Coastguard Worker suffix);
324*2b949d04SAndroid Build Coastguard Worker break;
325*2b949d04SAndroid Build Coastguard Worker
326*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_GROUP_SET:
327*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_GROUP_LATCH:
328*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_GROUP_LOCK:
329*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(group=%s%d%s%s)%s", prefix, type,
330*2b949d04SAndroid Build Coastguard Worker (!(action->group.flags & ACTION_ABSOLUTE_SWITCH) && action->group.group > 0) ? "+" : "",
331*2b949d04SAndroid Build Coastguard Worker (action->group.flags & ACTION_ABSOLUTE_SWITCH) ? action->group.group + 1 : action->group.group,
332*2b949d04SAndroid Build Coastguard Worker (action->type != ACTION_TYPE_GROUP_LOCK && (action->group.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
333*2b949d04SAndroid Build Coastguard Worker (action->type != ACTION_TYPE_GROUP_LOCK && (action->group.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
334*2b949d04SAndroid Build Coastguard Worker suffix);
335*2b949d04SAndroid Build Coastguard Worker break;
336*2b949d04SAndroid Build Coastguard Worker
337*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_TERMINATE:
338*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s()%s", prefix, type, suffix);
339*2b949d04SAndroid Build Coastguard Worker break;
340*2b949d04SAndroid Build Coastguard Worker
341*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_PTR_MOVE:
342*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(x=%s%d,y=%s%d%s)%s", prefix, type,
343*2b949d04SAndroid Build Coastguard Worker (!(action->ptr.flags & ACTION_ABSOLUTE_X) && action->ptr.x >= 0) ? "+" : "",
344*2b949d04SAndroid Build Coastguard Worker action->ptr.x,
345*2b949d04SAndroid Build Coastguard Worker (!(action->ptr.flags & ACTION_ABSOLUTE_Y) && action->ptr.y >= 0) ? "+" : "",
346*2b949d04SAndroid Build Coastguard Worker action->ptr.y,
347*2b949d04SAndroid Build Coastguard Worker (action->ptr.flags & ACTION_ACCEL) ? "" : ",!accel",
348*2b949d04SAndroid Build Coastguard Worker suffix);
349*2b949d04SAndroid Build Coastguard Worker break;
350*2b949d04SAndroid Build Coastguard Worker
351*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_PTR_LOCK:
352*2b949d04SAndroid Build Coastguard Worker args = affect_lock_text(action->btn.flags, true);
353*2b949d04SAndroid Build Coastguard Worker /* fallthrough */
354*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_PTR_BUTTON:
355*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(button=", prefix, type);
356*2b949d04SAndroid Build Coastguard Worker if (action->btn.button > 0 && action->btn.button <= 5)
357*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%d", action->btn.button);
358*2b949d04SAndroid Build Coastguard Worker else
359*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "default");
360*2b949d04SAndroid Build Coastguard Worker if (action->btn.count)
361*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ",count=%d", action->btn.count);
362*2b949d04SAndroid Build Coastguard Worker if (args)
363*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s", args);
364*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ")%s", suffix);
365*2b949d04SAndroid Build Coastguard Worker break;
366*2b949d04SAndroid Build Coastguard Worker
367*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_PTR_DEFAULT:
368*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(", prefix, type);
369*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "affect=button,button=%s%d",
370*2b949d04SAndroid Build Coastguard Worker (!(action->dflt.flags & ACTION_ABSOLUTE_SWITCH) && action->dflt.value >= 0) ? "+" : "",
371*2b949d04SAndroid Build Coastguard Worker action->dflt.value);
372*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ")%s", suffix);
373*2b949d04SAndroid Build Coastguard Worker break;
374*2b949d04SAndroid Build Coastguard Worker
375*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_SWITCH_VT:
376*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(screen=%s%d,%ssame)%s", prefix, type,
377*2b949d04SAndroid Build Coastguard Worker (!(action->screen.flags & ACTION_ABSOLUTE_SWITCH) && action->screen.screen >= 0) ? "+" : "",
378*2b949d04SAndroid Build Coastguard Worker action->screen.screen,
379*2b949d04SAndroid Build Coastguard Worker (action->screen.flags & ACTION_SAME_SCREEN) ? "" : "!",
380*2b949d04SAndroid Build Coastguard Worker suffix);
381*2b949d04SAndroid Build Coastguard Worker break;
382*2b949d04SAndroid Build Coastguard Worker
383*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_CTRL_SET:
384*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_CTRL_LOCK:
385*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s(controls=%s%s)%s", prefix, type,
386*2b949d04SAndroid Build Coastguard Worker ControlMaskText(keymap->ctx, action->ctrls.ctrls),
387*2b949d04SAndroid Build Coastguard Worker (action->type == ACTION_TYPE_CTRL_LOCK) ? affect_lock_text(action->ctrls.flags, false) : "",
388*2b949d04SAndroid Build Coastguard Worker suffix);
389*2b949d04SAndroid Build Coastguard Worker break;
390*2b949d04SAndroid Build Coastguard Worker
391*2b949d04SAndroid Build Coastguard Worker case ACTION_TYPE_NONE:
392*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%sNoAction()%s", prefix, suffix);
393*2b949d04SAndroid Build Coastguard Worker break;
394*2b949d04SAndroid Build Coastguard Worker
395*2b949d04SAndroid Build Coastguard Worker default:
396*2b949d04SAndroid Build Coastguard Worker write_buf(buf,
397*2b949d04SAndroid Build Coastguard Worker "%s%s(type=0x%02x,data[0]=0x%02x,data[1]=0x%02x,data[2]=0x%02x,data[3]=0x%02x,data[4]=0x%02x,data[5]=0x%02x,data[6]=0x%02x)%s",
398*2b949d04SAndroid Build Coastguard Worker prefix, type, action->type, action->priv.data[0],
399*2b949d04SAndroid Build Coastguard Worker action->priv.data[1], action->priv.data[2],
400*2b949d04SAndroid Build Coastguard Worker action->priv.data[3], action->priv.data[4],
401*2b949d04SAndroid Build Coastguard Worker action->priv.data[5], action->priv.data[6],
402*2b949d04SAndroid Build Coastguard Worker suffix);
403*2b949d04SAndroid Build Coastguard Worker break;
404*2b949d04SAndroid Build Coastguard Worker }
405*2b949d04SAndroid Build Coastguard Worker
406*2b949d04SAndroid Build Coastguard Worker return true;
407*2b949d04SAndroid Build Coastguard Worker }
408*2b949d04SAndroid Build Coastguard Worker
409*2b949d04SAndroid Build Coastguard Worker static bool
write_compat(struct xkb_keymap * keymap,struct buf * buf)410*2b949d04SAndroid Build Coastguard Worker write_compat(struct xkb_keymap *keymap, struct buf *buf)
411*2b949d04SAndroid Build Coastguard Worker {
412*2b949d04SAndroid Build Coastguard Worker const struct xkb_led *led;
413*2b949d04SAndroid Build Coastguard Worker
414*2b949d04SAndroid Build Coastguard Worker if (keymap->compat_section_name)
415*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_compatibility \"%s\" {\n",
416*2b949d04SAndroid Build Coastguard Worker keymap->compat_section_name);
417*2b949d04SAndroid Build Coastguard Worker else
418*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_compatibility {\n");
419*2b949d04SAndroid Build Coastguard Worker
420*2b949d04SAndroid Build Coastguard Worker write_vmods(keymap, buf);
421*2b949d04SAndroid Build Coastguard Worker
422*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tinterpret.useModMapMods= AnyLevel;\n");
423*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tinterpret.repeat= False;\n");
424*2b949d04SAndroid Build Coastguard Worker
425*2b949d04SAndroid Build Coastguard Worker for (unsigned i = 0; i < keymap->num_sym_interprets; i++) {
426*2b949d04SAndroid Build Coastguard Worker const struct xkb_sym_interpret *si = &keymap->sym_interprets[i];
427*2b949d04SAndroid Build Coastguard Worker
428*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tinterpret %s+%s(%s) {\n",
429*2b949d04SAndroid Build Coastguard Worker si->sym ? KeysymText(keymap->ctx, si->sym) : "Any",
430*2b949d04SAndroid Build Coastguard Worker SIMatchText(si->match),
431*2b949d04SAndroid Build Coastguard Worker ModMaskText(keymap->ctx, &keymap->mods, si->mods));
432*2b949d04SAndroid Build Coastguard Worker
433*2b949d04SAndroid Build Coastguard Worker if (si->virtual_mod != XKB_MOD_INVALID)
434*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tvirtualModifier= %s;\n",
435*2b949d04SAndroid Build Coastguard Worker ModIndexText(keymap->ctx, &keymap->mods,
436*2b949d04SAndroid Build Coastguard Worker si->virtual_mod));
437*2b949d04SAndroid Build Coastguard Worker
438*2b949d04SAndroid Build Coastguard Worker if (si->level_one_only)
439*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\tuseModMapMods=level1;\n");
440*2b949d04SAndroid Build Coastguard Worker
441*2b949d04SAndroid Build Coastguard Worker if (si->repeat)
442*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t\trepeat= True;\n");
443*2b949d04SAndroid Build Coastguard Worker
444*2b949d04SAndroid Build Coastguard Worker write_action(keymap, buf, &si->action, "\t\taction= ", ";\n");
445*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t};\n");
446*2b949d04SAndroid Build Coastguard Worker }
447*2b949d04SAndroid Build Coastguard Worker
448*2b949d04SAndroid Build Coastguard Worker xkb_leds_foreach(led, keymap)
449*2b949d04SAndroid Build Coastguard Worker if (led->which_groups || led->groups || led->which_mods ||
450*2b949d04SAndroid Build Coastguard Worker led->mods.mods || led->ctrls)
451*2b949d04SAndroid Build Coastguard Worker write_led_map(keymap, buf, led);
452*2b949d04SAndroid Build Coastguard Worker
453*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "};\n\n");
454*2b949d04SAndroid Build Coastguard Worker
455*2b949d04SAndroid Build Coastguard Worker return true;
456*2b949d04SAndroid Build Coastguard Worker }
457*2b949d04SAndroid Build Coastguard Worker
458*2b949d04SAndroid Build Coastguard Worker static bool
write_keysyms(struct xkb_keymap * keymap,struct buf * buf,const struct xkb_key * key,xkb_layout_index_t group)459*2b949d04SAndroid Build Coastguard Worker write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
460*2b949d04SAndroid Build Coastguard Worker const struct xkb_key *key, xkb_layout_index_t group)
461*2b949d04SAndroid Build Coastguard Worker {
462*2b949d04SAndroid Build Coastguard Worker for (xkb_level_index_t level = 0; level < XkbKeyNumLevels(key, group);
463*2b949d04SAndroid Build Coastguard Worker level++) {
464*2b949d04SAndroid Build Coastguard Worker const xkb_keysym_t *syms;
465*2b949d04SAndroid Build Coastguard Worker int num_syms;
466*2b949d04SAndroid Build Coastguard Worker
467*2b949d04SAndroid Build Coastguard Worker if (level != 0)
468*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ", ");
469*2b949d04SAndroid Build Coastguard Worker
470*2b949d04SAndroid Build Coastguard Worker num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode,
471*2b949d04SAndroid Build Coastguard Worker group, level, &syms);
472*2b949d04SAndroid Build Coastguard Worker if (num_syms == 0) {
473*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%15s", "NoSymbol");
474*2b949d04SAndroid Build Coastguard Worker }
475*2b949d04SAndroid Build Coastguard Worker else if (num_syms == 1) {
476*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%15s", KeysymText(keymap->ctx, syms[0]));
477*2b949d04SAndroid Build Coastguard Worker }
478*2b949d04SAndroid Build Coastguard Worker else {
479*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "{ ");
480*2b949d04SAndroid Build Coastguard Worker for (int s = 0; s < num_syms; s++) {
481*2b949d04SAndroid Build Coastguard Worker if (s != 0)
482*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ", ");
483*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s", KeysymText(keymap->ctx, syms[s]));
484*2b949d04SAndroid Build Coastguard Worker }
485*2b949d04SAndroid Build Coastguard Worker write_buf(buf, " }");
486*2b949d04SAndroid Build Coastguard Worker }
487*2b949d04SAndroid Build Coastguard Worker }
488*2b949d04SAndroid Build Coastguard Worker
489*2b949d04SAndroid Build Coastguard Worker return true;
490*2b949d04SAndroid Build Coastguard Worker }
491*2b949d04SAndroid Build Coastguard Worker
492*2b949d04SAndroid Build Coastguard Worker static bool
write_key(struct xkb_keymap * keymap,struct buf * buf,const struct xkb_key * key)493*2b949d04SAndroid Build Coastguard Worker write_key(struct xkb_keymap *keymap, struct buf *buf,
494*2b949d04SAndroid Build Coastguard Worker const struct xkb_key *key)
495*2b949d04SAndroid Build Coastguard Worker {
496*2b949d04SAndroid Build Coastguard Worker xkb_layout_index_t group;
497*2b949d04SAndroid Build Coastguard Worker bool simple = true;
498*2b949d04SAndroid Build Coastguard Worker bool explicit_types = false;
499*2b949d04SAndroid Build Coastguard Worker bool multi_type = false;
500*2b949d04SAndroid Build Coastguard Worker bool show_actions;
501*2b949d04SAndroid Build Coastguard Worker
502*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tkey %-20s {", KeyNameText(keymap->ctx, key->name));
503*2b949d04SAndroid Build Coastguard Worker
504*2b949d04SAndroid Build Coastguard Worker for (group = 0; group < key->num_groups; group++) {
505*2b949d04SAndroid Build Coastguard Worker if (key->groups[group].explicit_type)
506*2b949d04SAndroid Build Coastguard Worker explicit_types = true;
507*2b949d04SAndroid Build Coastguard Worker
508*2b949d04SAndroid Build Coastguard Worker if (group != 0 && key->groups[group].type != key->groups[0].type)
509*2b949d04SAndroid Build Coastguard Worker multi_type = true;
510*2b949d04SAndroid Build Coastguard Worker }
511*2b949d04SAndroid Build Coastguard Worker
512*2b949d04SAndroid Build Coastguard Worker if (explicit_types) {
513*2b949d04SAndroid Build Coastguard Worker const struct xkb_key_type *type;
514*2b949d04SAndroid Build Coastguard Worker simple = false;
515*2b949d04SAndroid Build Coastguard Worker
516*2b949d04SAndroid Build Coastguard Worker if (multi_type) {
517*2b949d04SAndroid Build Coastguard Worker for (group = 0; group < key->num_groups; group++) {
518*2b949d04SAndroid Build Coastguard Worker if (!key->groups[group].explicit_type)
519*2b949d04SAndroid Build Coastguard Worker continue;
520*2b949d04SAndroid Build Coastguard Worker
521*2b949d04SAndroid Build Coastguard Worker type = key->groups[group].type;
522*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\ttype[Group%u]= \"%s\",",
523*2b949d04SAndroid Build Coastguard Worker group + 1,
524*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, type->name));
525*2b949d04SAndroid Build Coastguard Worker }
526*2b949d04SAndroid Build Coastguard Worker }
527*2b949d04SAndroid Build Coastguard Worker else {
528*2b949d04SAndroid Build Coastguard Worker type = key->groups[0].type;
529*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\ttype= \"%s\",",
530*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, type->name));
531*2b949d04SAndroid Build Coastguard Worker }
532*2b949d04SAndroid Build Coastguard Worker }
533*2b949d04SAndroid Build Coastguard Worker
534*2b949d04SAndroid Build Coastguard Worker if (key->explicit & EXPLICIT_REPEAT) {
535*2b949d04SAndroid Build Coastguard Worker if (key->repeats)
536*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\trepeat= Yes,");
537*2b949d04SAndroid Build Coastguard Worker else
538*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\trepeat= No,");
539*2b949d04SAndroid Build Coastguard Worker simple = false;
540*2b949d04SAndroid Build Coastguard Worker }
541*2b949d04SAndroid Build Coastguard Worker
542*2b949d04SAndroid Build Coastguard Worker if (key->vmodmap && (key->explicit & EXPLICIT_VMODMAP))
543*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\tvirtualMods= %s,",
544*2b949d04SAndroid Build Coastguard Worker ModMaskText(keymap->ctx, &keymap->mods, key->vmodmap));
545*2b949d04SAndroid Build Coastguard Worker
546*2b949d04SAndroid Build Coastguard Worker switch (key->out_of_range_group_action) {
547*2b949d04SAndroid Build Coastguard Worker case RANGE_SATURATE:
548*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\tgroupsClamp,");
549*2b949d04SAndroid Build Coastguard Worker break;
550*2b949d04SAndroid Build Coastguard Worker
551*2b949d04SAndroid Build Coastguard Worker case RANGE_REDIRECT:
552*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\tgroupsRedirect= Group%u,",
553*2b949d04SAndroid Build Coastguard Worker key->out_of_range_group_number + 1);
554*2b949d04SAndroid Build Coastguard Worker break;
555*2b949d04SAndroid Build Coastguard Worker
556*2b949d04SAndroid Build Coastguard Worker default:
557*2b949d04SAndroid Build Coastguard Worker break;
558*2b949d04SAndroid Build Coastguard Worker }
559*2b949d04SAndroid Build Coastguard Worker
560*2b949d04SAndroid Build Coastguard Worker show_actions = (key->explicit & EXPLICIT_INTERP);
561*2b949d04SAndroid Build Coastguard Worker
562*2b949d04SAndroid Build Coastguard Worker if (key->num_groups > 1 || show_actions)
563*2b949d04SAndroid Build Coastguard Worker simple = false;
564*2b949d04SAndroid Build Coastguard Worker
565*2b949d04SAndroid Build Coastguard Worker if (simple) {
566*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\t[ ");
567*2b949d04SAndroid Build Coastguard Worker if (!write_keysyms(keymap, buf, key, 0))
568*2b949d04SAndroid Build Coastguard Worker return false;
569*2b949d04SAndroid Build Coastguard Worker write_buf(buf, " ] };\n");
570*2b949d04SAndroid Build Coastguard Worker }
571*2b949d04SAndroid Build Coastguard Worker else {
572*2b949d04SAndroid Build Coastguard Worker xkb_level_index_t level;
573*2b949d04SAndroid Build Coastguard Worker
574*2b949d04SAndroid Build Coastguard Worker for (group = 0; group < key->num_groups; group++) {
575*2b949d04SAndroid Build Coastguard Worker if (group != 0)
576*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ",");
577*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t\tsymbols[Group%u]= [ ", group + 1);
578*2b949d04SAndroid Build Coastguard Worker if (!write_keysyms(keymap, buf, key, group))
579*2b949d04SAndroid Build Coastguard Worker return false;
580*2b949d04SAndroid Build Coastguard Worker write_buf(buf, " ]");
581*2b949d04SAndroid Build Coastguard Worker if (show_actions) {
582*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ",\n\t\tactions[Group%u]= [ ", group + 1);
583*2b949d04SAndroid Build Coastguard Worker for (level = 0; level < XkbKeyNumLevels(key, group); level++) {
584*2b949d04SAndroid Build Coastguard Worker if (level != 0)
585*2b949d04SAndroid Build Coastguard Worker write_buf(buf, ", ");
586*2b949d04SAndroid Build Coastguard Worker write_action(keymap, buf,
587*2b949d04SAndroid Build Coastguard Worker &key->groups[group].levels[level].action,
588*2b949d04SAndroid Build Coastguard Worker NULL, NULL);
589*2b949d04SAndroid Build Coastguard Worker }
590*2b949d04SAndroid Build Coastguard Worker write_buf(buf, " ]");
591*2b949d04SAndroid Build Coastguard Worker }
592*2b949d04SAndroid Build Coastguard Worker }
593*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n\t};\n");
594*2b949d04SAndroid Build Coastguard Worker }
595*2b949d04SAndroid Build Coastguard Worker
596*2b949d04SAndroid Build Coastguard Worker return true;
597*2b949d04SAndroid Build Coastguard Worker }
598*2b949d04SAndroid Build Coastguard Worker
599*2b949d04SAndroid Build Coastguard Worker static bool
write_symbols(struct xkb_keymap * keymap,struct buf * buf)600*2b949d04SAndroid Build Coastguard Worker write_symbols(struct xkb_keymap *keymap, struct buf *buf)
601*2b949d04SAndroid Build Coastguard Worker {
602*2b949d04SAndroid Build Coastguard Worker const struct xkb_key *key;
603*2b949d04SAndroid Build Coastguard Worker xkb_layout_index_t group;
604*2b949d04SAndroid Build Coastguard Worker xkb_mod_index_t i;
605*2b949d04SAndroid Build Coastguard Worker const struct xkb_mod *mod;
606*2b949d04SAndroid Build Coastguard Worker
607*2b949d04SAndroid Build Coastguard Worker if (keymap->symbols_section_name)
608*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_symbols \"%s\" {\n",
609*2b949d04SAndroid Build Coastguard Worker keymap->symbols_section_name);
610*2b949d04SAndroid Build Coastguard Worker else
611*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "xkb_symbols {\n");
612*2b949d04SAndroid Build Coastguard Worker
613*2b949d04SAndroid Build Coastguard Worker for (group = 0; group < keymap->num_group_names; group++)
614*2b949d04SAndroid Build Coastguard Worker if (keymap->group_names[group])
615*2b949d04SAndroid Build Coastguard Worker write_buf(buf,
616*2b949d04SAndroid Build Coastguard Worker "\tname[Group%u]=\"%s\";\n", group + 1,
617*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, keymap->group_names[group]));
618*2b949d04SAndroid Build Coastguard Worker if (group > 0)
619*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\n");
620*2b949d04SAndroid Build Coastguard Worker
621*2b949d04SAndroid Build Coastguard Worker xkb_keys_foreach(key, keymap)
622*2b949d04SAndroid Build Coastguard Worker if (key->num_groups > 0)
623*2b949d04SAndroid Build Coastguard Worker write_key(keymap, buf, key);
624*2b949d04SAndroid Build Coastguard Worker
625*2b949d04SAndroid Build Coastguard Worker xkb_mods_enumerate(i, mod, &keymap->mods) {
626*2b949d04SAndroid Build Coastguard Worker bool had_any = false;
627*2b949d04SAndroid Build Coastguard Worker xkb_keys_foreach(key, keymap) {
628*2b949d04SAndroid Build Coastguard Worker if (key->modmap & (1u << i)) {
629*2b949d04SAndroid Build Coastguard Worker if (!had_any)
630*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "\tmodifier_map %s { ",
631*2b949d04SAndroid Build Coastguard Worker xkb_atom_text(keymap->ctx, mod->name));
632*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "%s%s",
633*2b949d04SAndroid Build Coastguard Worker had_any ? ", " : "",
634*2b949d04SAndroid Build Coastguard Worker KeyNameText(keymap->ctx, key->name));
635*2b949d04SAndroid Build Coastguard Worker had_any = true;
636*2b949d04SAndroid Build Coastguard Worker }
637*2b949d04SAndroid Build Coastguard Worker }
638*2b949d04SAndroid Build Coastguard Worker if (had_any)
639*2b949d04SAndroid Build Coastguard Worker write_buf(buf, " };\n");
640*2b949d04SAndroid Build Coastguard Worker }
641*2b949d04SAndroid Build Coastguard Worker
642*2b949d04SAndroid Build Coastguard Worker write_buf(buf, "};\n\n");
643*2b949d04SAndroid Build Coastguard Worker return true;
644*2b949d04SAndroid Build Coastguard Worker }
645*2b949d04SAndroid Build Coastguard Worker
646*2b949d04SAndroid Build Coastguard Worker static bool
write_keymap(struct xkb_keymap * keymap,struct buf * buf)647*2b949d04SAndroid Build Coastguard Worker write_keymap(struct xkb_keymap *keymap, struct buf *buf)
648*2b949d04SAndroid Build Coastguard Worker {
649*2b949d04SAndroid Build Coastguard Worker return (check_write_buf(buf, "xkb_keymap {\n") &&
650*2b949d04SAndroid Build Coastguard Worker write_keycodes(keymap, buf) &&
651*2b949d04SAndroid Build Coastguard Worker write_types(keymap, buf) &&
652*2b949d04SAndroid Build Coastguard Worker write_compat(keymap, buf) &&
653*2b949d04SAndroid Build Coastguard Worker write_symbols(keymap, buf) &&
654*2b949d04SAndroid Build Coastguard Worker check_write_buf(buf, "};\n"));
655*2b949d04SAndroid Build Coastguard Worker }
656*2b949d04SAndroid Build Coastguard Worker
657*2b949d04SAndroid Build Coastguard Worker char *
text_v1_keymap_get_as_string(struct xkb_keymap * keymap)658*2b949d04SAndroid Build Coastguard Worker text_v1_keymap_get_as_string(struct xkb_keymap *keymap)
659*2b949d04SAndroid Build Coastguard Worker {
660*2b949d04SAndroid Build Coastguard Worker struct buf buf = { NULL, 0, 0 };
661*2b949d04SAndroid Build Coastguard Worker
662*2b949d04SAndroid Build Coastguard Worker if (!write_keymap(keymap, &buf)) {
663*2b949d04SAndroid Build Coastguard Worker free(buf.buf);
664*2b949d04SAndroid Build Coastguard Worker return NULL;
665*2b949d04SAndroid Build Coastguard Worker }
666*2b949d04SAndroid Build Coastguard Worker
667*2b949d04SAndroid Build Coastguard Worker return buf.buf;
668*2b949d04SAndroid Build Coastguard Worker }
669