diff options
author | Ran Benita <ran234@gmail.com> | 2013-08-01 20:24:27 +0300 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2013-08-02 11:39:39 +0300 |
commit | e731b2514b96fcf92513c3f680a84666c0de3173 (patch) | |
tree | ff344c4bf15b5d62fa85847dba6667d5d843c566 /src/xkbcomp/keycodes.c | |
parent | d2383d385252d2bf583e9d56a31bb62490fa5cb6 (diff) | |
download | libxkbcommon-e731b2514b96fcf92513c3f680a84666c0de3173.tar.gz libxkbcommon-e731b2514b96fcf92513c3f680a84666c0de3173.tar.bz2 libxkbcommon-e731b2514b96fcf92513c3f680a84666c0de3173.zip |
xkbcomp: handle empty keymaps
We should handle empty xkb_keycode and xkb_symbol sections, since
xkbcomp handles them, and apparently XQuartz uses it. There are also
files for it in xkeyboard-config (rules=base model=empty layout=empty,
which translate to keycodes/empty and symbols/empty).
https://bugs.freedesktop.org/show_bug.cgi?id=67654
Reported-By: Gatis Paeglis <gatis.paeglis@digia.com>
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/xkbcomp/keycodes.c')
-rw-r--r-- | src/xkbcomp/keycodes.c | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 44e11bc..59916b7 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -231,7 +231,10 @@ InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx) { memset(info, 0, sizeof(*info)); info->ctx = ctx; - info->min_key_code = XKB_KEYCODE_MAX; + info->min_key_code = XKB_KEYCODE_INVALID; +#if XKB_KEYCODE_INVALID < XKB_KEYCODE_MAX +#error "Hey, you can't be changing stuff like that." +#endif } static xkb_keycode_t @@ -606,15 +609,26 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info) keymap->keycodes_section_name = strdup_safe(info->name); XkbEscapeMapName(keymap->keycodes_section_name); - keymap->min_key_code = info->min_key_code; - keymap->max_key_code = info->max_key_code; + if (info->min_key_code != XKB_KEYCODE_INVALID) { + keymap->min_key_code = info->min_key_code; + keymap->max_key_code = info->max_key_code; + } + else { + /* + * If the keymap has no keys, let's just use the safest pair + * we know. + */ + keymap->min_key_code = 8; + keymap->max_key_code = 255; + } - /* Copy key names. */ - keymap->keys = calloc(info->max_key_code + 1, sizeof(*keymap->keys)); - for (kc = info->min_key_code; kc <= info->max_key_code; kc++) { + keymap->keys = calloc(keymap->max_key_code + 1, sizeof(*keymap->keys)); + for (kc = keymap->min_key_code; kc <= keymap->max_key_code; kc++) keymap->keys[kc].keycode = kc; + + /* Copy key names. */ + for (kc = info->min_key_code; kc <= info->max_key_code; kc++) keymap->keys[kc].name = darray_item(info->key_names, kc); - } /* * Do some sanity checking on the aliases. We can't do it before |