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 <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
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; "