2012-05-25 10:05:39 -06:00
|
|
|
/************************************************************
|
2012-07-17 03:20:15 -06:00
|
|
|
* Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose and without
|
|
|
|
* fee is hereby granted, provided that the above copyright
|
|
|
|
* notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting
|
|
|
|
* documentation, and that the name of Silicon Graphics not be
|
|
|
|
* used in advertising or publicity pertaining to distribution
|
|
|
|
* of the software without specific prior written permission.
|
|
|
|
* Silicon Graphics makes no representation about the suitability
|
|
|
|
* of this software for any purpose. It is provided "as is"
|
|
|
|
* without any express or implied warranty.
|
|
|
|
*
|
|
|
|
* SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
|
|
|
|
* GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
|
|
|
|
* THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*
|
2012-05-25 10:05:39 -06:00
|
|
|
********************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright © 2012 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Author: Daniel Stone <daniel@fooishbar.org>
|
|
|
|
*/
|
|
|
|
|
2019-12-27 04:03:20 -07:00
|
|
|
#include "config.h"
|
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
#include "xkbcomp-priv.h"
|
2012-05-25 10:05:39 -06:00
|
|
|
#include "text.h"
|
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
#define BUF_CHUNK_SIZE 4096
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
struct buf {
|
|
|
|
char *buf;
|
|
|
|
size_t size;
|
|
|
|
size_t alloc;
|
|
|
|
};
|
|
|
|
|
2012-05-25 10:05:39 -06:00
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
do_realloc(struct buf *buf, size_t at_least)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
|
|
|
char *new;
|
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
buf->alloc += BUF_CHUNK_SIZE;
|
2012-05-25 10:05:39 -06:00
|
|
|
if (at_least >= BUF_CHUNK_SIZE)
|
2012-08-02 11:55:12 -06:00
|
|
|
buf->alloc += at_least;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
new = realloc(buf->buf, buf->alloc);
|
2012-05-25 10:05:39 -06:00
|
|
|
if (!new)
|
|
|
|
return false;
|
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
buf->buf = new;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ATTR_PRINTF(2, 3) static bool
|
|
|
|
check_write_buf(struct buf *buf, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
int printed;
|
|
|
|
size_t available;
|
|
|
|
|
|
|
|
available = buf->alloc - buf->size;
|
|
|
|
va_start(args, fmt);
|
|
|
|
printed = vsnprintf(buf->buf + buf->size, available, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
if (printed < 0)
|
|
|
|
goto err;
|
|
|
|
|
2014-02-07 15:27:54 -07:00
|
|
|
if ((size_t) printed >= available)
|
2012-08-02 11:55:12 -06:00
|
|
|
if (!do_realloc(buf, printed))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* The buffer has enough space now. */
|
|
|
|
|
|
|
|
available = buf->alloc - buf->size;
|
|
|
|
va_start(args, fmt);
|
|
|
|
printed = vsnprintf(buf->buf + buf->size, available, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
2014-02-07 15:27:54 -07:00
|
|
|
if (printed < 0 || (size_t) printed >= available)
|
2012-08-02 11:55:12 -06:00
|
|
|
goto err;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
buf->size += printed;
|
2012-05-25 10:05:39 -06:00
|
|
|
return true;
|
2012-08-02 11:55:12 -06:00
|
|
|
|
|
|
|
err:
|
|
|
|
free(buf->buf);
|
|
|
|
buf->buf = NULL;
|
|
|
|
return false;
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
#define write_buf(buf, ...) do { \
|
|
|
|
if (!check_write_buf(buf, __VA_ARGS__)) \
|
|
|
|
return false; \
|
|
|
|
} while (0)
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_vmods(struct xkb_keymap *keymap, struct buf *buf)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2012-10-05 14:46:21 -06:00
|
|
|
const struct xkb_mod *mod;
|
2012-10-03 04:57:53 -06:00
|
|
|
xkb_mod_index_t num_vmods = 0;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2014-04-22 02:47:23 -06:00
|
|
|
xkb_mods_foreach(mod, &keymap->mods) {
|
2012-10-05 14:46:21 -06:00
|
|
|
if (mod->type != MOD_VIRT)
|
|
|
|
continue;
|
|
|
|
|
2012-05-25 10:05:39 -06:00
|
|
|
if (num_vmods == 0)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\tvirtual_modifiers ");
|
2012-05-25 10:05:39 -06:00
|
|
|
else
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ",");
|
2012-10-05 14:46:21 -06:00
|
|
|
write_buf(buf, "%s", xkb_atom_text(keymap->ctx, mod->name));
|
2012-05-25 10:05:39 -06:00
|
|
|
num_vmods++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_vmods > 0)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ";\n\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_keycodes(struct xkb_keymap *keymap, struct buf *buf)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2013-02-25 02:50:26 -07:00
|
|
|
const struct xkb_key *key;
|
2013-03-04 03:27:06 -07:00
|
|
|
xkb_led_index_t idx;
|
2013-02-17 13:18:57 -07:00
|
|
|
const struct xkb_led *led;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-07-14 16:31:34 -06:00
|
|
|
if (keymap->keycodes_section_name)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "xkb_keycodes \"%s\" {\n",
|
2012-07-14 16:31:34 -06:00
|
|
|
keymap->keycodes_section_name);
|
2012-07-11 07:16:20 -06:00
|
|
|
else
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "xkb_keycodes {\n");
|
2012-07-11 07:16:20 -06:00
|
|
|
|
2013-05-09 07:47:09 -06:00
|
|
|
/* xkbcomp and X11 really want to see keymaps with a minimum of 8, and
|
|
|
|
* a maximum of at least 255, else XWayland really starts hating life.
|
|
|
|
* If this is a problem and people really need strictly bounded keymaps,
|
|
|
|
* we should probably control this with a flag. */
|
2019-12-27 03:34:49 -07:00
|
|
|
write_buf(buf, "\tminimum = %u;\n", MIN(keymap->min_key_code, 8));
|
|
|
|
write_buf(buf, "\tmaximum = %u;\n", MAX(keymap->max_key_code, 255));
|
2013-05-09 07:47:09 -06:00
|
|
|
|
2014-04-22 02:33:47 -06:00
|
|
|
xkb_keys_foreach(key, keymap) {
|
Don't limit key names to 4 characters
Currently you can't give a key in xkb_keycodes a name of more than
XKB_KEY_NAME_LENGTH (= 4) chars. This is a pretty annoying and arbitrary
limitation; it leads to names such as <RTSH>, <COMP>, <PRSC>, <KPAD>
etc. which may be hard to decipher, and makes it impossible to give
more standard names (e.g. from linux/input.h) to keycodes.
The purpose of this, as far as I can tell, was to save memory and to
allow encoding a key name directly to a 32 bit value (unsigned long it
was).
We remove this limitation by just storing the names as atoms; this lifts
the limit, allows for easy comparison like the unsigned long thing, and
doesn't use more memory than previous solution. It also relieves us from
doing all of the annoying conversions to/from long.
This has a large diffstat only because KeyNameText, which is used a lot,
now needs to take the context in order to resolve the atom.
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 10:49:13 -06:00
|
|
|
if (key->name == XKB_ATOM_NONE)
|
2012-05-25 10:05:39 -06:00
|
|
|
continue;
|
2012-07-13 09:34:11 -06:00
|
|
|
|
2013-08-01 11:44:46 -06:00
|
|
|
write_buf(buf, "\t%-20s = %u;\n",
|
Don't limit key names to 4 characters
Currently you can't give a key in xkb_keycodes a name of more than
XKB_KEY_NAME_LENGTH (= 4) chars. This is a pretty annoying and arbitrary
limitation; it leads to names such as <RTSH>, <COMP>, <PRSC>, <KPAD>
etc. which may be hard to decipher, and makes it impossible to give
more standard names (e.g. from linux/input.h) to keycodes.
The purpose of this, as far as I can tell, was to save memory and to
allow encoding a key name directly to a 32 bit value (unsigned long it
was).
We remove this limitation by just storing the names as atoms; this lifts
the limit, allows for easy comparison like the unsigned long thing, and
doesn't use more memory than previous solution. It also relieves us from
doing all of the annoying conversions to/from long.
This has a large diffstat only because KeyNameText, which is used a lot,
now needs to take the context in order to resolve the atom.
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-09-27 10:49:13 -06:00
|
|
|
KeyNameText(keymap->ctx, key->name), key->keycode);
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2014-04-22 04:15:21 -06:00
|
|
|
xkb_leds_enumerate(idx, led, keymap)
|
2013-02-17 13:18:57 -07:00
|
|
|
if (led->name != XKB_ATOM_NONE)
|
2013-08-01 11:44:46 -06:00
|
|
|
write_buf(buf, "\tindicator %u = \"%s\";\n",
|
2013-03-04 03:27:06 -07:00
|
|
|
idx + 1, xkb_atom_text(keymap->ctx, led->name));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-07-14 16:31:34 -06:00
|
|
|
|
2013-03-04 03:27:06 -07:00
|
|
|
for (unsigned i = 0; i < keymap->num_key_aliases; i++)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\talias %-14s = %s;\n",
|
2013-03-04 03:27:06 -07:00
|
|
|
KeyNameText(keymap->ctx, keymap->key_aliases[i].alias),
|
|
|
|
KeyNameText(keymap->ctx, keymap->key_aliases[i].real));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "};\n\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_types(struct xkb_keymap *keymap, struct buf *buf)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2012-07-14 16:31:34 -06:00
|
|
|
if (keymap->types_section_name)
|
2013-02-25 03:09:17 -07:00
|
|
|
write_buf(buf, "xkb_types \"%s\" {\n",
|
2012-07-14 16:31:34 -06:00
|
|
|
keymap->types_section_name);
|
2012-07-11 07:16:20 -06:00
|
|
|
else
|
2013-02-25 03:09:17 -07:00
|
|
|
write_buf(buf, "xkb_types {\n");
|
2012-07-11 07:16:20 -06:00
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
write_vmods(keymap, buf);
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
for (unsigned i = 0; i < keymap->num_types; i++) {
|
|
|
|
const struct xkb_key_type *type = &keymap->types[i];
|
2012-08-06 23:38:20 -06:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\ttype \"%s\" {\n",
|
2012-08-07 02:40:07 -06:00
|
|
|
xkb_atom_text(keymap->ctx, type->name));
|
2013-02-25 02:50:26 -07:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tmodifiers= %s;\n",
|
2013-02-08 04:21:27 -07:00
|
|
|
ModMaskText(keymap->ctx, &keymap->mods, type->mods.mods));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
for (unsigned j = 0; j < type->num_entries; j++) {
|
2012-08-08 11:47:51 -06:00
|
|
|
const char *str;
|
2013-03-04 09:41:13 -07:00
|
|
|
const struct xkb_key_type_entry *entry = &type->entries[j];
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-08-06 23:17:26 -06:00
|
|
|
/*
|
|
|
|
* Printing level 1 entries is redundant, it's the default,
|
|
|
|
* unless there's preserve info.
|
|
|
|
*/
|
Modernize struct xkb_mods
Currently xkb_mods has the following members:
- uint8_t real_mods - 8 X11 core mods
- xkb_mod_mask_t vmods - 16 virtual mods, zero-based index
- xkb_mod_mask_t mask - the computed effective *real* modifier mask,
basically a cache for the first two which is:
real_mods | real mods computed from vmods
Our API acts on masks which combine the real_mods and vmods into a
single value, which is:
8 first bits real mods | 16 next bits virtual mods
(XkbNumModifiers = 8, XkbNumVirtualMods = 16). This is also the format
which ResolveVModMask uses (which is where all the modifier masks really
"come from", e.g. "Shift+Lock+Level5" -> xkb_mod_mask_t).
What the code does now after getting the mask from ResolveVModMask, is
to break it into real part and virtual part and store them seperately,
and then join them back together when the effective mask is calculated.
This is all pretty useless work. We change xkb_mods to the following:
- xkb_mod_mask_t mods - usually what ResolveVModMask returns
- xkb_mod_mask_t mask - the computed mask cache
And try to consistently use the word "mods" for the original,
non-effective mods and mask for the effective mods (which can only
contain real mods for now, because things break otherwise).
The separation is also made clearer. The effective masks are computed by
UpdateModifiersFromCompat after all the sections have been compiled;
before this the mask field is never touched; after this (i.e. map.c and
state.c) the original mods field is never touched. This single execption
to this rule is keymap-dump.c: it needs to print out only the original
modifiers, not computed ones. This is also the reason why we actually
keep two fields instead keeping one and modifying it in place.
The next logical step is probably to turn the real mods into vmods
themselves, and get rid of the distinction entirely (in a compatible
way).
Signed-off-by: Ran Benita <ran234@gmail.com>
2012-08-08 17:33:51 -06:00
|
|
|
if (entry->level == 0 && entry->preserve.mods == 0)
|
2012-08-06 23:17:26 -06:00
|
|
|
continue;
|
|
|
|
|
2013-02-08 04:21:27 -07:00
|
|
|
str = ModMaskText(keymap->ctx, &keymap->mods, entry->mods.mods);
|
2019-10-16 01:27:12 -06:00
|
|
|
write_buf(buf, "\t\tmap[%s]= %u;\n",
|
2012-05-25 10:05:39 -06:00
|
|
|
str, entry->level + 1);
|
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
if (entry->preserve.mods)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tpreserve[%s]= %s;\n",
|
2013-02-08 04:21:27 -07:00
|
|
|
str, ModMaskText(keymap->ctx, &keymap->mods,
|
|
|
|
entry->preserve.mods));
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2017-12-12 05:30:21 -07:00
|
|
|
for (xkb_level_index_t n = 0; n < type->num_level_names; n++)
|
2013-02-25 02:50:26 -07:00
|
|
|
if (type->level_names[n])
|
2019-10-16 01:27:12 -06:00
|
|
|
write_buf(buf, "\t\tlevel_name[%u]= \"%s\";\n", n + 1,
|
2012-08-07 02:40:07 -06:00
|
|
|
xkb_atom_text(keymap->ctx, type->level_names[n]));
|
2013-02-25 02:50:26 -07:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t};\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "};\n\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2013-02-17 13:18:57 -07:00
|
|
|
write_led_map(struct xkb_keymap *keymap, struct buf *buf,
|
|
|
|
const struct xkb_led *led)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\tindicator \"%s\" {\n",
|
2012-10-10 11:08:01 -06:00
|
|
|
xkb_atom_text(keymap->ctx, led->name));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
if (led->which_groups) {
|
2012-10-22 12:49:44 -06:00
|
|
|
if (led->which_groups != XKB_STATE_LAYOUT_EFFECTIVE) {
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\twhichGroupState= %s;\n",
|
2013-03-01 09:33:40 -07:00
|
|
|
LedStateMaskText(keymap->ctx, led->which_groups));
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tgroups= 0x%02x;\n",
|
2012-05-25 10:05:39 -06:00
|
|
|
led->groups);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (led->which_mods) {
|
2012-10-22 12:49:44 -06:00
|
|
|
if (led->which_mods != XKB_STATE_MODS_EFFECTIVE) {
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\twhichModState= %s;\n",
|
2013-03-01 09:33:40 -07:00
|
|
|
LedStateMaskText(keymap->ctx, led->which_mods));
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tmodifiers= %s;\n",
|
2013-02-08 04:21:27 -07:00
|
|
|
ModMaskText(keymap->ctx, &keymap->mods, led->mods.mods));
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (led->ctrls) {
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tcontrols= %s;\n",
|
2012-10-18 15:08:10 -06:00
|
|
|
ControlMaskText(keymap->ctx, led->ctrls));
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t};\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-15 14:50:21 -07:00
|
|
|
static const char *
|
2020-11-23 10:51:04 -07:00
|
|
|
affect_lock_text(enum xkb_action_flags flags, bool show_both)
|
2014-02-15 14:50:21 -07:00
|
|
|
{
|
|
|
|
switch (flags & (ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK)) {
|
2020-11-23 10:51:04 -07:00
|
|
|
case 0:
|
|
|
|
return show_both ? ",affect=both" : "";
|
2014-02-15 14:50:21 -07:00
|
|
|
case ACTION_LOCK_NO_UNLOCK:
|
|
|
|
return ",affect=lock";
|
|
|
|
case ACTION_LOCK_NO_LOCK:
|
|
|
|
return ",affect=unlock";
|
|
|
|
case ACTION_LOCK_NO_LOCK | ACTION_LOCK_NO_UNLOCK:
|
|
|
|
return ",affect=neither";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2012-05-25 10:05:39 -06:00
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_action(struct xkb_keymap *keymap, struct buf *buf,
|
2012-09-14 02:17:30 -06:00
|
|
|
const union xkb_action *action,
|
|
|
|
const char *prefix, const char *suffix)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2012-08-02 14:40:31 -06:00
|
|
|
const char *type;
|
2012-05-25 10:05:39 -06:00
|
|
|
const char *args = NULL;
|
|
|
|
|
|
|
|
if (!prefix)
|
|
|
|
prefix = "";
|
|
|
|
if (!suffix)
|
|
|
|
suffix = "";
|
|
|
|
|
2012-08-10 13:38:07 -06:00
|
|
|
type = ActionTypeText(action->type);
|
2012-08-02 14:40:31 -06:00
|
|
|
|
2012-08-10 13:38:07 -06:00
|
|
|
switch (action->type) {
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_MOD_SET:
|
|
|
|
case ACTION_TYPE_MOD_LATCH:
|
2016-06-09 07:32:05 -06:00
|
|
|
case ACTION_TYPE_MOD_LOCK:
|
2012-09-10 13:38:46 -06:00
|
|
|
if (action->mods.flags & ACTION_MODS_LOOKUP_MODMAP)
|
2012-05-25 10:05:39 -06:00
|
|
|
args = "modMapMods";
|
|
|
|
else
|
2013-02-08 04:21:27 -07:00
|
|
|
args = ModMaskText(keymap->ctx, &keymap->mods,
|
|
|
|
action->mods.mods.mods);
|
2014-02-15 14:50:21 -07:00
|
|
|
write_buf(buf, "%s%s(modifiers=%s%s%s%s)%s", prefix, type, args,
|
2014-02-15 14:13:21 -07:00
|
|
|
(action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
|
|
|
|
(action->type != ACTION_TYPE_MOD_LOCK && (action->mods.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
|
2020-11-23 10:51:04 -07:00
|
|
|
(action->type == ACTION_TYPE_MOD_LOCK) ? affect_lock_text(action->mods.flags, false) : "",
|
2012-05-25 10:05:39 -06:00
|
|
|
suffix);
|
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_GROUP_SET:
|
|
|
|
case ACTION_TYPE_GROUP_LATCH:
|
|
|
|
case ACTION_TYPE_GROUP_LOCK:
|
2012-08-02 14:40:31 -06:00
|
|
|
write_buf(buf, "%s%s(group=%s%d%s%s)%s", prefix, type,
|
2014-02-15 14:13:21 -07:00
|
|
|
(!(action->group.flags & ACTION_ABSOLUTE_SWITCH) && action->group.group > 0) ? "+" : "",
|
|
|
|
(action->group.flags & ACTION_ABSOLUTE_SWITCH) ? action->group.group + 1 : action->group.group,
|
|
|
|
(action->type != ACTION_TYPE_GROUP_LOCK && (action->group.flags & ACTION_LOCK_CLEAR)) ? ",clearLocks" : "",
|
|
|
|
(action->type != ACTION_TYPE_GROUP_LOCK && (action->group.flags & ACTION_LATCH_TO_LOCK)) ? ",latchToLock" : "",
|
2012-08-02 11:55:12 -06:00
|
|
|
suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_TERMINATE:
|
2012-08-02 14:40:31 -06:00
|
|
|
write_buf(buf, "%s%s()%s", prefix, type, suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_PTR_MOVE:
|
2012-08-02 14:40:31 -06:00
|
|
|
write_buf(buf, "%s%s(x=%s%d,y=%s%d%s)%s", prefix, type,
|
2014-02-16 01:59:42 -07:00
|
|
|
(!(action->ptr.flags & ACTION_ABSOLUTE_X) && action->ptr.x >= 0) ? "+" : "",
|
2012-05-25 10:05:39 -06:00
|
|
|
action->ptr.x,
|
2014-02-16 01:59:42 -07:00
|
|
|
(!(action->ptr.flags & ACTION_ABSOLUTE_Y) && action->ptr.y >= 0) ? "+" : "",
|
2012-05-25 10:05:39 -06:00
|
|
|
action->ptr.y,
|
2014-02-16 01:59:42 -07:00
|
|
|
(action->ptr.flags & ACTION_ACCEL) ? "" : ",!accel",
|
2012-05-25 10:05:39 -06:00
|
|
|
suffix);
|
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_PTR_LOCK:
|
2020-11-23 10:51:04 -07:00
|
|
|
args = affect_lock_text(action->btn.flags, true);
|
2014-02-15 14:50:21 -07:00
|
|
|
/* fallthrough */
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_PTR_BUTTON:
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "%s%s(button=", prefix, type);
|
2012-05-25 10:05:39 -06:00
|
|
|
if (action->btn.button > 0 && action->btn.button <= 5)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "%d", action->btn.button);
|
2012-05-25 10:05:39 -06:00
|
|
|
else
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "default");
|
2012-05-25 10:05:39 -06:00
|
|
|
if (action->btn.count)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ",count=%d", action->btn.count);
|
2012-05-25 10:05:39 -06:00
|
|
|
if (args)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "%s", args);
|
|
|
|
write_buf(buf, ")%s", suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_PTR_DEFAULT:
|
2012-08-02 14:40:31 -06:00
|
|
|
write_buf(buf, "%s%s(", prefix, type);
|
2012-09-10 13:40:05 -06:00
|
|
|
write_buf(buf, "affect=button,button=%s%d",
|
2014-02-15 14:13:21 -07:00
|
|
|
(!(action->dflt.flags & ACTION_ABSOLUTE_SWITCH) && action->dflt.value >= 0) ? "+" : "",
|
2012-09-10 13:40:05 -06:00
|
|
|
action->dflt.value);
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ")%s", suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_SWITCH_VT:
|
2012-08-02 14:40:31 -06:00
|
|
|
write_buf(buf, "%s%s(screen=%s%d,%ssame)%s", prefix, type,
|
2014-02-15 14:13:21 -07:00
|
|
|
(!(action->screen.flags & ACTION_ABSOLUTE_SWITCH) && action->screen.screen >= 0) ? "+" : "",
|
2012-05-25 10:05:39 -06:00
|
|
|
action->screen.screen,
|
2014-02-16 01:22:32 -07:00
|
|
|
(action->screen.flags & ACTION_SAME_SCREEN) ? "" : "!",
|
2012-05-25 10:05:39 -06:00
|
|
|
suffix);
|
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_CTRL_SET:
|
|
|
|
case ACTION_TYPE_CTRL_LOCK:
|
2014-02-15 14:50:21 -07:00
|
|
|
write_buf(buf, "%s%s(controls=%s%s)%s", prefix, type,
|
|
|
|
ControlMaskText(keymap->ctx, action->ctrls.ctrls),
|
2020-11-23 10:51:04 -07:00
|
|
|
(action->type == ACTION_TYPE_CTRL_LOCK) ? affect_lock_text(action->ctrls.flags, false) : "",
|
2014-02-15 14:50:21 -07:00
|
|
|
suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-09-10 12:23:16 -06:00
|
|
|
case ACTION_TYPE_NONE:
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "%sNoAction()%s", prefix, suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2012-05-25 10:05:39 -06:00
|
|
|
default:
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf,
|
2012-08-02 14:40:31 -06:00
|
|
|
"%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",
|
2012-08-10 13:38:07 -06:00
|
|
|
prefix, type, action->type, action->priv.data[0],
|
|
|
|
action->priv.data[1], action->priv.data[2],
|
|
|
|
action->priv.data[3], action->priv.data[4],
|
|
|
|
action->priv.data[5], action->priv.data[6],
|
2012-07-17 03:20:15 -06:00
|
|
|
suffix);
|
2012-05-25 10:05:39 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_compat(struct xkb_keymap *keymap, struct buf *buf)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2013-02-17 13:18:57 -07:00
|
|
|
const struct xkb_led *led;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-07-14 16:31:34 -06:00
|
|
|
if (keymap->compat_section_name)
|
2013-02-25 03:09:17 -07:00
|
|
|
write_buf(buf, "xkb_compatibility \"%s\" {\n",
|
2012-07-14 16:31:34 -06:00
|
|
|
keymap->compat_section_name);
|
2012-07-11 07:16:20 -06:00
|
|
|
else
|
2013-02-25 03:09:17 -07:00
|
|
|
write_buf(buf, "xkb_compatibility {\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2012-08-02 11:55:12 -06:00
|
|
|
write_vmods(keymap, buf);
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\tinterpret.useModMapMods= AnyLevel;\n");
|
|
|
|
write_buf(buf, "\tinterpret.repeat= False;\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2014-02-07 15:27:54 -07:00
|
|
|
for (unsigned i = 0; i < keymap->num_sym_interprets; i++) {
|
2013-07-21 00:48:12 -06:00
|
|
|
const struct xkb_sym_interpret *si = &keymap->sym_interprets[i];
|
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\tinterpret %s+%s(%s) {\n",
|
2013-02-25 02:50:26 -07:00
|
|
|
si->sym ? KeysymText(keymap->ctx, si->sym) : "Any",
|
|
|
|
SIMatchText(si->match),
|
2013-02-08 04:21:27 -07:00
|
|
|
ModMaskText(keymap->ctx, &keymap->mods, si->mods));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
if (si->virtual_mod != XKB_MOD_INVALID)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tvirtualModifier= %s;\n",
|
2013-02-08 04:21:27 -07:00
|
|
|
ModIndexText(keymap->ctx, &keymap->mods,
|
|
|
|
si->virtual_mod));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 02:50:26 -07:00
|
|
|
if (si->level_one_only)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\tuseModMapMods=level1;\n");
|
2013-02-25 02:50:26 -07:00
|
|
|
|
|
|
|
if (si->repeat)
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "\t\trepeat= True;\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_action(keymap, buf, &si->action, "\t\taction= ", ";\n");
|
|
|
|
write_buf(buf, "\t};\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2014-04-22 04:15:21 -06:00
|
|
|
xkb_leds_foreach(led, keymap)
|
2012-10-10 11:08:01 -06:00
|
|
|
if (led->which_groups || led->groups || led->which_mods ||
|
|
|
|
led->mods.mods || led->ctrls)
|
2013-02-17 13:18:57 -07:00
|
|
|
write_led_map(keymap, buf, led);
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "};\n\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2012-08-02 11:55:12 -06:00
|
|
|
write_keysyms(struct xkb_keymap *keymap, struct buf *buf,
|
2013-02-25 02:50:26 -07:00
|
|
|
const struct xkb_key *key, xkb_layout_index_t group)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2014-09-25 13:01:17 -06:00
|
|
|
for (xkb_level_index_t level = 0; level < XkbKeyNumLevels(key, group);
|
2013-02-25 02:50:26 -07:00
|
|
|
level++) {
|
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
int num_syms;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
|
|
|
if (level != 0)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ", ");
|
2013-02-25 02:50:26 -07:00
|
|
|
|
2012-09-19 00:19:57 -06:00
|
|
|
num_syms = xkb_keymap_key_get_syms_by_level(keymap, key->keycode,
|
|
|
|
group, level, &syms);
|
2012-05-25 10:05:39 -06:00
|
|
|
if (num_syms == 0) {
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "%15s", "NoSymbol");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
else if (num_syms == 1) {
|
2013-02-25 02:50:26 -07:00
|
|
|
write_buf(buf, "%15s", KeysymText(keymap->ctx, syms[0]));
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
else {
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, "{ ");
|
2013-02-25 02:50:26 -07:00
|
|
|
for (int s = 0; s < num_syms; s++) {
|
2012-05-25 10:05:39 -06:00
|
|
|
if (s != 0)
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, ", ");
|
2013-02-25 02:50:26 -07:00
|
|
|
write_buf(buf, "%s", KeysymText(keymap->ctx, syms[s]));
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
2012-08-02 11:55:12 -06:00
|
|
|
write_buf(buf, " }");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2013-02-25 03:17:27 -07:00
|
|
|
write_key(struct xkb_keymap *keymap, struct buf *buf,
|
|
|
|
const struct xkb_key *key)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2012-10-23 01:58:11 -06:00
|
|
|
xkb_layout_index_t group;
|
2013-02-25 03:17:27 -07:00
|
|
|
bool simple = true;
|
|
|
|
bool explicit_types = false;
|
|
|
|
bool multi_type = false;
|
|
|
|
bool show_actions;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
write_buf(buf, "\tkey %-20s {", KeyNameText(keymap->ctx, key->name));
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
for (group = 0; group < key->num_groups; group++) {
|
|
|
|
if (key->groups[group].explicit_type)
|
|
|
|
explicit_types = true;
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (group != 0 && key->groups[group].type != key->groups[0].type)
|
|
|
|
multi_type = true;
|
|
|
|
}
|
2012-07-15 01:38:05 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (explicit_types) {
|
|
|
|
const struct xkb_key_type *type;
|
|
|
|
simple = false;
|
2012-07-15 01:38:05 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (multi_type) {
|
|
|
|
for (group = 0; group < key->num_groups; group++) {
|
|
|
|
if (!key->groups[group].explicit_type)
|
|
|
|
continue;
|
2012-09-24 04:11:31 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
type = key->groups[group].type;
|
2019-10-16 01:32:19 -06:00
|
|
|
write_buf(buf, "\n\t\ttype[Group%u]= \"%s\",",
|
2013-02-25 03:17:27 -07:00
|
|
|
group + 1,
|
|
|
|
xkb_atom_text(keymap->ctx, type->name));
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-25 03:17:27 -07:00
|
|
|
else {
|
|
|
|
type = key->groups[0].type;
|
|
|
|
write_buf(buf, "\n\t\ttype= \"%s\",",
|
|
|
|
xkb_atom_text(keymap->ctx, type->name));
|
2012-07-15 01:38:05 -06:00
|
|
|
}
|
2013-02-25 03:17:27 -07:00
|
|
|
}
|
2012-07-15 01:38:05 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (key->explicit & EXPLICIT_REPEAT) {
|
|
|
|
if (key->repeats)
|
|
|
|
write_buf(buf, "\n\t\trepeat= Yes,");
|
|
|
|
else
|
|
|
|
write_buf(buf, "\n\t\trepeat= No,");
|
|
|
|
simple = false;
|
|
|
|
}
|
2012-07-15 01:38:05 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (key->vmodmap && (key->explicit & EXPLICIT_VMODMAP))
|
|
|
|
write_buf(buf, "\n\t\tvirtualMods= %s,",
|
2013-02-08 04:21:27 -07:00
|
|
|
ModMaskText(keymap->ctx, &keymap->mods, key->vmodmap));
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
switch (key->out_of_range_group_action) {
|
|
|
|
case RANGE_SATURATE:
|
|
|
|
write_buf(buf, "\n\t\tgroupsClamp,");
|
|
|
|
break;
|
2012-09-10 13:44:52 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
case RANGE_REDIRECT:
|
|
|
|
write_buf(buf, "\n\t\tgroupsRedirect= Group%u,",
|
|
|
|
key->out_of_range_group_number + 1);
|
|
|
|
break;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2014-06-01 06:24:10 -06:00
|
|
|
show_actions = (key->explicit & EXPLICIT_INTERP);
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (key->num_groups > 1 || show_actions)
|
|
|
|
simple = false;
|
2012-07-17 03:20:15 -06:00
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
if (simple) {
|
|
|
|
write_buf(buf, "\t[ ");
|
|
|
|
if (!write_keysyms(keymap, buf, key, 0))
|
|
|
|
return false;
|
|
|
|
write_buf(buf, " ] };\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
xkb_level_index_t level;
|
|
|
|
|
|
|
|
for (group = 0; group < key->num_groups; group++) {
|
|
|
|
if (group != 0)
|
|
|
|
write_buf(buf, ",");
|
|
|
|
write_buf(buf, "\n\t\tsymbols[Group%u]= [ ", group + 1);
|
|
|
|
if (!write_keysyms(keymap, buf, key, group))
|
|
|
|
return false;
|
|
|
|
write_buf(buf, " ]");
|
|
|
|
if (show_actions) {
|
|
|
|
write_buf(buf, ",\n\t\tactions[Group%u]= [ ", group + 1);
|
2014-09-25 13:01:17 -06:00
|
|
|
for (level = 0; level < XkbKeyNumLevels(key, group); level++) {
|
2013-02-25 03:17:27 -07:00
|
|
|
if (level != 0)
|
|
|
|
write_buf(buf, ", ");
|
|
|
|
write_action(keymap, buf,
|
|
|
|
&key->groups[group].levels[level].action,
|
|
|
|
NULL, NULL);
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
2013-02-25 03:17:27 -07:00
|
|
|
write_buf(buf, " ]");
|
2012-07-17 03:20:15 -06:00
|
|
|
}
|
|
|
|
}
|
2013-02-25 03:17:27 -07:00
|
|
|
write_buf(buf, "\n\t};\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2013-02-25 03:17:27 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
write_symbols(struct xkb_keymap *keymap, struct buf *buf)
|
|
|
|
{
|
|
|
|
const struct xkb_key *key;
|
|
|
|
xkb_layout_index_t group;
|
2014-09-21 14:54:34 -06:00
|
|
|
xkb_mod_index_t i;
|
|
|
|
const struct xkb_mod *mod;
|
2013-02-25 03:17:27 -07:00
|
|
|
|
|
|
|
if (keymap->symbols_section_name)
|
|
|
|
write_buf(buf, "xkb_symbols \"%s\" {\n",
|
|
|
|
keymap->symbols_section_name);
|
|
|
|
else
|
|
|
|
write_buf(buf, "xkb_symbols {\n");
|
|
|
|
|
|
|
|
for (group = 0; group < keymap->num_group_names; group++)
|
|
|
|
if (keymap->group_names[group])
|
|
|
|
write_buf(buf,
|
2019-10-16 01:32:19 -06:00
|
|
|
"\tname[Group%u]=\"%s\";\n", group + 1,
|
2013-02-25 03:17:27 -07:00
|
|
|
xkb_atom_text(keymap->ctx, keymap->group_names[group]));
|
|
|
|
if (group > 0)
|
|
|
|
write_buf(buf, "\n");
|
|
|
|
|
2014-04-22 02:33:47 -06:00
|
|
|
xkb_keys_foreach(key, keymap)
|
2013-02-25 03:17:27 -07:00
|
|
|
if (key->num_groups > 0)
|
|
|
|
write_key(keymap, buf, key);
|
|
|
|
|
2014-09-21 14:54:34 -06:00
|
|
|
xkb_mods_enumerate(i, mod, &keymap->mods) {
|
|
|
|
bool had_any = false;
|
|
|
|
xkb_keys_foreach(key, keymap) {
|
|
|
|
if (key->modmap & (1u << i)) {
|
|
|
|
if (!had_any)
|
|
|
|
write_buf(buf, "\tmodifier_map %s { ",
|
|
|
|
xkb_atom_text(keymap->ctx, mod->name));
|
|
|
|
write_buf(buf, "%s%s",
|
|
|
|
had_any ? ", " : "",
|
2013-02-25 02:50:26 -07:00
|
|
|
KeyNameText(keymap->ctx, key->name));
|
2014-09-21 14:54:34 -06:00
|
|
|
had_any = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (had_any)
|
|
|
|
write_buf(buf, " };\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|
|
|
|
|
2013-02-25 03:03:06 -07:00
|
|
|
write_buf(buf, "};\n\n");
|
2012-05-25 10:05:39 -06:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
static bool
|
|
|
|
write_keymap(struct xkb_keymap *keymap, struct buf *buf)
|
2012-05-25 10:05:39 -06:00
|
|
|
{
|
2013-03-01 12:48:02 -07:00
|
|
|
return (check_write_buf(buf, "xkb_keymap {\n") &&
|
|
|
|
write_keycodes(keymap, buf) &&
|
|
|
|
write_types(keymap, buf) &&
|
|
|
|
write_compat(keymap, buf) &&
|
|
|
|
write_symbols(keymap, buf) &&
|
|
|
|
check_write_buf(buf, "};\n"));
|
|
|
|
}
|
2012-05-25 10:05:39 -06:00
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
char *
|
|
|
|
text_v1_keymap_get_as_string(struct xkb_keymap *keymap)
|
|
|
|
{
|
|
|
|
struct buf buf = { NULL, 0, 0 };
|
2012-09-23 09:52:51 -06:00
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
if (!write_keymap(keymap, &buf)) {
|
|
|
|
free(buf.buf);
|
2012-09-23 09:52:51 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-01 12:48:02 -07:00
|
|
|
return buf.buf;
|
2012-05-25 10:05:39 -06:00
|
|
|
}
|