keycodes: add KeyNameInfo Instead of keeping the two files and names arrays. 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
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index e637c66..c80787b 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -51,9 +51,9 @@
* always used to refer to a key by name.
*
* [ The naming convention <AE01> just denoted the position of the key
- * in the main alphanumric section of the keyboard, with the top left key
- * (usually "~") acting as origin. <AE01> is the key in the first row
- * second column (which is usually "1"). ]
+ * in the main alphanumric section of the keyboard, with the two letters
+ * specifying the row and the two digits specifying the column, from
+ * the bottom left.]
*
* In the common case this just maps to the evdev scancodes from
* /usr/include/linux/input.h, e.g. the following definitions:
@@ -116,6 +116,11 @@ typedef struct _AliasInfo {
unsigned long real;
} AliasInfo;
+typedef struct {
+ unsigned int file_id;
+ unsigned long name;
+} KeyNameInfo;
+
typedef struct _IndicatorNameInfo {
enum merge_mode merge;
unsigned file_id;
@@ -131,8 +136,7 @@ typedef struct _KeyNamesInfo {
xkb_keycode_t min_key_code;
xkb_keycode_t max_key_code;
- darray(unsigned long) names;
- darray(unsigned int) files;
+ darray(KeyNameInfo) key_names;
IndicatorNameInfo indicator_names[XKB_NUM_INDICATORS];
darray(AliasInfo) aliases;
@@ -140,16 +144,6 @@ typedef struct _KeyNamesInfo {
} KeyNamesInfo;
static void
-ResizeKeyNameArrays(KeyNamesInfo *info, int newMax)
-{
- if (newMax < darray_size(info->names))
- return;
-
- darray_resize0(info->names, newMax + 1);
- darray_resize0(info->files, newMax + 1);
-}
-
-static void
InitAliasInfo(AliasInfo *info, enum merge_mode merge, unsigned file_id,
char alias[XKB_KEY_NAME_LENGTH], char real[XKB_KEY_NAME_LENGTH])
{
@@ -252,8 +246,7 @@ static void
ClearKeyNamesInfo(KeyNamesInfo *info)
{
free(info->name);
- darray_free(info->names);
- darray_free(info->files);
+ darray_free(info->key_names);
darray_free(info->aliases);
}
@@ -268,86 +261,89 @@ InitKeyNamesInfo(KeyNamesInfo *info, struct xkb_context *ctx,
info->min_key_code = XKB_KEYCODE_MAX;
}
-static int
+static xkb_keycode_t
FindKeyByLong(KeyNamesInfo * info, unsigned long name)
{
xkb_keycode_t i;
for (i = info->min_key_code; i <= info->max_key_code; i++)
- if (darray_item(info->names, i) == name)
+ if (darray_item(info->key_names, i).name == name)
return i;
- return 0;
+ return XKB_KEYCODE_INVALID;
}
-/**
- * Store the name of the key as a long in the info struct under the given
- * keycode. If the same keys is referred to twice, print a warning.
- * Note that the key's name is stored as a long, the keycode is the index.
- */
static bool
AddKeyName(KeyNamesInfo *info, xkb_keycode_t kc, unsigned long name,
- enum merge_mode merge, unsigned file_id, bool reportCollisions)
+ enum merge_mode merge, unsigned file_id, bool report)
{
+ KeyNameInfo *namei;
xkb_keycode_t old;
int verbosity = xkb_get_log_verbosity(info->ctx);
- ResizeKeyNameArrays(info, kc);
+ if (kc >= darray_size(info->key_names))
+ darray_resize0(info->key_names, kc + 1);
info->min_key_code = MIN(info->min_key_code, kc);
info->max_key_code = MAX(info->max_key_code, kc);
- if (reportCollisions)
- reportCollisions = (verbosity > 7 ||
- (verbosity > 0 &&
- file_id == darray_item(info->files, kc)));
+ namei = &darray_item(info->key_names, kc);
+
+ report = report && ((verbosity > 0 && file_id == namei->file_id) ||
+ verbosity > 7);
- if (darray_item(info->names, kc) != 0) {
- const char *lname = LongKeyNameText(darray_item(info->names, kc));
+ if (namei->name != 0) {
+ const char *lname = LongKeyNameText(namei->name);
const char *kname = LongKeyNameText(name);
- if (darray_item(info->names, kc) == name && reportCollisions) {
- log_warn(info->ctx, "Multiple identical key name definitions; "
- "Later occurences of \"%s = %d\" ignored\n", lname, kc);
+ if (namei->name == name) {
+ if (report)
+ log_warn(info->ctx,
+ "Multiple identical key name definitions; "
+ "Later occurences of \"%s = %d\" ignored\n",
+ lname, kc);
return true;
}
-
- if (merge == MERGE_AUGMENT) {
- if (reportCollisions)
- log_warn(info->ctx, "Multiple names for keycode %d; "
+ else if (merge == MERGE_AUGMENT) {
+ if (report)
+ log_warn(info->ctx,
+ "Multiple names for keycode %d; "
"Using %s, ignoring %s\n", kc, lname, kname);
return true;
}
else {
- if (reportCollisions)
- log_warn(info->ctx, "Multiple names for keycode %d; "
+ if (report)
+ log_warn(info->ctx,
+ "Multiple names for keycode %d; "
"Using %s, ignoring %s\n", kc, kname, lname);
- darray_item(info->names, kc) = 0;
- darray_item(info->files, kc) = 0;
+ namei->name = 0;
+ namei->file_id = 0;
}
}
old = FindKeyByLong(info, name);
- if (old != 0 && old != kc) {
+ if (old != XKB_KEYCODE_INVALID && old != kc) {
const char *kname = LongKeyNameText(name);
if (merge == MERGE_OVERRIDE) {
- darray_item(info->names, old) = 0;
- darray_item(info->files, old) = 0;
- if (reportCollisions)
- log_warn(info->ctx, "Key name %s assigned to multiple keys; "
+ darray_item(info->key_names, old).name = 0;
+ darray_item(info->key_names, old).file_id = 0;
+ if (report)
+ log_warn(info->ctx,
+ "Key name %s assigned to multiple keys; "
"Using %d, ignoring %d\n", kname, kc, old);
}
else {
- if (reportCollisions && verbosity > 3)
- log_warn(info->ctx, "Key name %s assigned to multiple keys; "
- "Using %d, ignoring %d\n", kname, old, kc);
+ if (report)
+ log_vrb(info->ctx, 3,
+ "Key name %s assigned to multiple keys; "
+ "Using %d, ignoring %d\n", kname, old, kc);
return true;
}
}
- darray_item(info->names, kc) = name;
- darray_item(info->files, kc) = file_id;
+ namei->name = name;
+ namei->file_id = file_id;
return true;
}
@@ -403,10 +399,11 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
from->name = NULL;
}
- ResizeKeyNameArrays(into, from->max_key_code);
+ if (darray_size(into->key_names) < darray_size(from->key_names))
+ darray_resize0(into->key_names, darray_size(from->key_names));
for (i = from->min_key_code; i <= from->max_key_code; i++) {
- unsigned long name = darray_item(from->names, i);
+ unsigned long name = darray_item(from->key_names, i).name;
if (name == 0)
continue;
@@ -700,7 +697,7 @@ CopyKeyNamesToKeymap(struct xkb_keymap *keymap, KeyNamesInfo *info)
darray_resize0(keymap->keys, keymap->max_key_code + 1);
for (kc = info->min_key_code; kc <= info->max_key_code; kc++)
- LongToKeyName(darray_item(info->names, kc),
+ LongToKeyName(darray_item(info->key_names, kc).name,
darray_item(keymap->keys, kc).name);
keymap->keycodes_section_name = strdup_safe(info->name);