From: Ran Benita Date: Sun, 3 Mar 2013 19:35:43 +0000 (+0200) Subject: Move a couple of general keymap functions from keycodes.c X-Git-Tag: xkbcommon-0.3.0~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=71eb033eefe2f0f2a2d3fc7c54ebd5f0d4c2d3f5;p=platform%2Fupstream%2Flibxkbcommon.git Move a couple of general keymap functions from keycodes.c To get a key by name and resolve an alias - this makes sense for everyone. Signed-off-by: Ran Benita --- diff --git a/Makefile.am b/Makefile.am index 02a93b2..87b2b51 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,7 +36,6 @@ libxkbcommon_la_SOURCES = \ src/xkbcomp/include.c \ src/xkbcomp/include.h \ src/xkbcomp/keycodes.c \ - src/xkbcomp/keycodes.h \ src/xkbcomp/keymap.c \ src/xkbcomp/keymap-dump.c \ src/xkbcomp/parser.y \ diff --git a/src/keymap.c b/src/keymap.c index 9c581d5..758a35b 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -477,3 +477,33 @@ xkb_keymap_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t kc) return key->repeats; } + +struct xkb_key * +XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases) +{ + struct xkb_key *key; + + xkb_foreach_key(key, keymap) + if (key->name == name) + return key; + + if (use_aliases) { + xkb_atom_t new_name = XkbResolveKeyAlias(keymap, name); + if (new_name != XKB_ATOM_NONE) + return XkbKeyByName(keymap, new_name, false); + } + + return NULL; +} + +xkb_atom_t +XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name) +{ + const struct xkb_key_alias *alias; + + darray_foreach(alias, keymap->key_aliases) + if (name == alias->alias) + return alias->real; + + return XKB_ATOM_NONE; +} diff --git a/src/keymap.h b/src/keymap.h index 30733bf..f4b80eb 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -403,6 +403,11 @@ struct xkb_keymap { char *compat_section_name; }; +#define xkb_foreach_key(iter, keymap) \ + for (iter = keymap->keys + keymap->min_key_code; \ + iter <= keymap->keys + keymap->max_key_code; \ + iter++) + static inline const struct xkb_key * XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc) { @@ -411,17 +416,18 @@ XkbKey(struct xkb_keymap *keymap, xkb_keycode_t kc) return &keymap->keys[kc]; } -#define xkb_foreach_key(iter, keymap) \ - for (iter = keymap->keys + keymap->min_key_code; \ - iter <= keymap->keys + keymap->max_key_code; \ - iter++) - static inline xkb_level_index_t XkbKeyGroupWidth(const struct xkb_key *key, xkb_layout_index_t layout) { return key->groups[layout].type->num_levels; } +struct xkb_key * +XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases); + +xkb_atom_t +XkbResolveKeyAlias(struct xkb_keymap *keymap, xkb_atom_t name); + xkb_layout_index_t wrap_group_into_range(int32_t group, xkb_layout_index_t num_groups, diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index d45b143..3c5c5c7 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -55,7 +55,6 @@ #include "text.h" #include "expr.h" #include "action.h" -#include "keycodes.h" static const ExprDef constTrue = { .common = { .type = STMT_EXPR, .next = NULL }, diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 5b262d9..e25d141 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -27,7 +27,6 @@ #include "xkbcomp-priv.h" #include "text.h" #include "expr.h" -#include "keycodes.h" #include "include.h" /* @@ -625,7 +624,7 @@ CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap) struct xkb_key_alias new; /* Check that ->real is a key. */ - key = FindNamedKey(keymap, alias->real, false); + key = XkbKeyByName(keymap, alias->real, false); if (!key) { log_vrb(info->ctx, 5, "Attempt to alias %s to non-existent key %s; Ignored\n", @@ -635,7 +634,7 @@ CopyAliasesToKeymap(KeyNamesInfo *info, struct xkb_keymap *keymap) } /* Check that ->alias is not a key. */ - key = FindNamedKey(keymap, alias->alias, false); + key = XkbKeyByName(keymap, alias->alias, false); if (key) { log_vrb(info->ctx, 5, "Attempt to create alias with the name of a real key; " @@ -712,39 +711,3 @@ err_info: ClearKeyNamesInfo(&info); return false; } - -/***====================================================================***/ - -struct xkb_key * -FindNamedKey(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases) -{ - struct xkb_key *key; - - xkb_foreach_key(key, keymap) - if (key->name == name) - return key; - - if (use_aliases) { - xkb_atom_t new_name; - if (FindKeyNameForAlias(keymap, name, &new_name)) - return FindNamedKey(keymap, new_name, false); - } - - return NULL; -} - -bool -FindKeyNameForAlias(struct xkb_keymap *keymap, xkb_atom_t name, - xkb_atom_t *real_name) -{ - const struct xkb_key_alias *a; - - darray_foreach(a, keymap->key_aliases) { - if (name == a->alias) { - *real_name = a->real; - return true; - } - } - - return false; -} diff --git a/src/xkbcomp/keycodes.h b/src/xkbcomp/keycodes.h deleted file mode 100644 index 395478b..0000000 --- a/src/xkbcomp/keycodes.h +++ /dev/null @@ -1,37 +0,0 @@ -/************************************************************ - * 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. - * - ********************************************************/ - -#ifndef XKBCOMP_KEYCODES_H -#define XKBCOMP_KEYCODES_H - -struct xkb_key * -FindNamedKey(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases); - -bool -FindKeyNameForAlias(struct xkb_keymap *keymap, xkb_atom_t name, - xkb_atom_t *real_name); - -#endif diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index c0f8cde..2ae184c 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -56,7 +56,6 @@ #include "expr.h" #include "action.h" #include "vmod.h" -#include "keycodes.h" #include "include.h" #include "keysym.h" @@ -427,7 +426,8 @@ AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi) * following loop) is enough, and we won't get multiple KeyInfo's * for the same key because of aliases. */ - if (FindKeyNameForAlias(info->keymap, keyi->name, &real_name)) + real_name = XkbResolveKeyAlias(info->keymap, keyi->name); + if (real_name != XKB_ATOM_NONE) keyi->name = real_name; darray_foreach(iter, info->keys) @@ -1450,7 +1450,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi) * The name is guaranteed to be real and not an alias (see * AddKeySymbols), so 'false' is safe here. */ - key = FindNamedKey(keymap, keyi->name, false); + key = XkbKeyByName(keymap, keyi->name, false); if (!key) { log_vrb(info->keymap->ctx, 5, "Key %s not found in keycodes; Symbols ignored\n", @@ -1547,7 +1547,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry) struct xkb_keymap *keymap = info->keymap; if (!entry->haveSymbol) { - key = FindNamedKey(keymap, entry->u.keyName, true); + key = XkbKeyByName(keymap, entry->u.keyName, true); if (!key) { log_vrb(info->keymap->ctx, 5, "Key %s not found in keycodes; "