| 1 |
/* |
| 2 |
* For HPND: |
| 3 |
* Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. |
| 4 |
* |
| 5 |
* For MIT: |
| 6 |
* Copyright © 2012 Intel Corporation |
| 7 |
* Copyright © 2012 Ran Benita <[email protected]> |
| 8 |
* |
| 9 |
* SPDX-License-Identifier: HPND AND MIT |
| 10 |
* |
| 11 |
* Author: Daniel Stone <[email protected]> |
| 12 |
* Author: Ran Benita <[email protected]> |
| 13 |
*/ |
| 14 |
|
| 15 |
#include "config.h" |
| 16 |
|
| 17 |
#include <limits.h> |
| 18 |
|
| 19 |
#include "xkbcommon/xkbcommon.h" |
| 20 |
#include "xkbcommon/xkbcommon-keysyms.h" |
| 21 |
|
| 22 |
#include "action.h" |
| 23 |
#include "expr.h" |
| 24 |
#include "darray.h" |
| 25 |
#include "include.h" |
| 26 |
#include "keymap.h" |
| 27 |
#include "keysym.h" |
| 28 |
#include "messages-codes.h" |
| 29 |
#include "text.h" |
| 30 |
#include "util-mem.h" |
| 31 |
#include "vmod.h" |
| 32 |
#include "xkbcomp-priv.h" |
| 33 |
#include "xkbcomp/ast.h" |
| 34 |
|
| 35 |
|
| 36 |
enum key_repeat { |
| 37 |
KEY_REPEAT_UNDEFINED = 0, |
| 38 |
KEY_REPEAT_YES = 1, |
| 39 |
KEY_REPEAT_NO = 2, |
| 40 |
}; |
| 41 |
|
| 42 |
enum group_field { |
| 43 |
GROUP_FIELD_SYMS = (1 << 0), |
| 44 |
GROUP_FIELD_ACTS = (1 << 1), |
| 45 |
GROUP_FIELD_TYPE = (1 << 2), |
| 46 |
}; |
| 47 |
|
| 48 |
enum key_field { |
| 49 |
KEY_FIELD_REPEAT = (1 << 0), |
| 50 |
KEY_FIELD_DEFAULT_TYPE = (1 << 1), |
| 51 |
KEY_FIELD_GROUPINFO = (1 << 2), |
| 52 |
KEY_FIELD_VMODMAP = (1 << 3), |
| 53 |
}; |
| 54 |
|
| 55 |
typedef struct { |
| 56 |
enum group_field defined; |
| 57 |
darray(struct xkb_level) levels; |
| 58 |
xkb_atom_t type; |
| 59 |
} GroupInfo; |
| 60 |
|
| 61 |
typedef struct { |
| 62 |
enum key_field defined; |
| 63 |
enum merge_mode merge; |
| 64 |
|
| 65 |
xkb_atom_t name; |
| 66 |
|
| 67 |
darray(GroupInfo) groups; |
| 68 |
|
| 69 |
enum key_repeat repeat; |
| 70 |
xkb_mod_mask_t vmodmap; |
| 71 |
xkb_atom_t default_type; |
| 72 |
|
| 73 |
enum xkb_range_exceed_type out_of_range_group_action; |
| 74 |
xkb_layout_index_t out_of_range_group_number; |
| 75 |
} KeyInfo; |
| 76 |
|
| 77 |
static void |
| 78 |
StealLevelInfo(struct xkb_level *into, struct xkb_level *from) |
| 79 |
{ |
| 80 |
clear_level(into); |
| 81 |
if (from->num_syms > 1) { |
| 82 |
/* Steal */ |
| 83 |
into->s.syms = steal(&from->s.syms); |
| 84 |
} else { |
| 85 |
into->s.sym = from->s.sym; |
| 86 |
} |
| 87 |
into->num_syms = from->num_syms; |
| 88 |
from->num_syms = 0; |
| 89 |
|
| 90 |
if (from->num_actions > 1) { |
| 91 |
into->a.actions = steal(&from->a.actions); |
| 92 |
} else { |
| 93 |
into->a.action = from->a.action; |
| 94 |
} |
| 95 |
into->num_actions = from->num_actions; |
| 96 |
from->num_actions = 0; |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
InitGroupInfo(GroupInfo *groupi) |
| 101 |
{ |
| 102 |
memset(groupi, 0, sizeof(*groupi)); |
| 103 |
} |
| 104 |
|
| 105 |
static void |
| 106 |
ClearGroupInfo(GroupInfo *groupi) |
| 107 |
{ |
| 108 |
struct xkb_level *leveli; |
| 109 |
darray_foreach(leveli, groupi->levels) |
| 110 |
clear_level(leveli); |
| 111 |
darray_free(groupi->levels); |
| 112 |
} |
| 113 |
|
| 114 |
static void |
| 115 |
CopyGroupInfo(GroupInfo *to, const GroupInfo *from) |
| 116 |
{ |
| 117 |
to->defined = from->defined; |
| 118 |
to->type = from->type; |
| 119 |
darray_init(to->levels); |
| 120 |
darray_copy(to->levels, from->levels); |
| 121 |
for (xkb_level_index_t j = 0; j < darray_size(to->levels); j++) { |
| 122 |
if (darray_item(from->levels, j).num_syms > 1) { |
| 123 |
darray_item(to->levels, j).s.syms = |
| 124 |
memdup(darray_item(from->levels, j).s.syms, |
| 125 |
darray_item(from->levels, j).num_syms, |
| 126 |
sizeof(xkb_keysym_t)); |
| 127 |
} |
| 128 |
if (darray_item(from->levels, j).num_actions > 1) { |
| 129 |
darray_item(to->levels, j).a.actions = |
| 130 |
memdup(darray_item(from->levels, j).a.actions, |
| 131 |
darray_item(from->levels, j).num_actions, |
| 132 |
sizeof(union xkb_action)); |
| 133 |
} |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
static void |
| 138 |
InitKeyInfo(struct xkb_context *ctx, KeyInfo *keyi) |
| 139 |
{ |
| 140 |
memset(keyi, 0, sizeof(*keyi)); |
| 141 |
keyi->name = xkb_atom_intern_literal(ctx, "*"); |
| 142 |
keyi->out_of_range_group_action = RANGE_WRAP; |
| 143 |
} |
| 144 |
|
| 145 |
static void |
| 146 |
ClearKeyInfo(KeyInfo *keyi) |
| 147 |
{ |
| 148 |
GroupInfo *groupi; |
| 149 |
darray_foreach(groupi, keyi->groups) |
| 150 |
ClearGroupInfo(groupi); |
| 151 |
darray_free(keyi->groups); |
| 152 |
} |
| 153 |
|
| 154 |
/***====================================================================***/ |
| 155 |
|
| 156 |
typedef struct { |
| 157 |
enum merge_mode merge; |
| 158 |
bool haveSymbol; |
| 159 |
/* NOTE: Can also be XKB_MOD_NONE, meaning |
| 160 |
* “don’t add a modifier to the modmap”. */ |
| 161 |
xkb_mod_index_t modifier; |
| 162 |
union { |
| 163 |
xkb_atom_t keyName; |
| 164 |
xkb_keysym_t keySym; |
| 165 |
} u; |
| 166 |
} ModMapEntry; |
| 167 |
|
| 168 |
typedef struct { |
| 169 |
char *name; /* e.g. pc+us+inet(evdev) */ |
| 170 |
int errorCount; |
| 171 |
unsigned int include_depth; |
| 172 |
xkb_layout_index_t explicit_group; |
| 173 |
darray(KeyInfo) keys; |
| 174 |
KeyInfo default_key; |
| 175 |
ActionsInfo default_actions; |
| 176 |
darray(xkb_atom_t) group_names; |
| 177 |
darray(ModMapEntry) modmaps; |
| 178 |
struct xkb_mod_set mods; |
| 179 |
|
| 180 |
xkb_layout_index_t max_groups; |
| 181 |
struct xkb_context *ctx; |
| 182 |
/* Needed for AddKeySymbols. */ |
| 183 |
const struct xkb_keymap *keymap; |
| 184 |
} SymbolsInfo; |
| 185 |
|
| 186 |
static void |
| 187 |
InitSymbolsInfo(SymbolsInfo *info, const struct xkb_keymap *keymap, |
| 188 |
unsigned int include_depth, const struct xkb_mod_set *mods) |
| 189 |
{ |
| 190 |
memset(info, 0, sizeof(*info)); |
| 191 |
info->ctx = keymap->ctx; |
| 192 |
info->include_depth = include_depth; |
| 193 |
info->keymap = keymap; |
| 194 |
info->max_groups = format_max_groups(keymap->format); |
| 195 |
InitKeyInfo(keymap->ctx, &info->default_key); |
| 196 |
InitActionsInfo(&info->default_actions); |
| 197 |
InitVMods(&info->mods, mods, include_depth > 0); |
| 198 |
info->explicit_group = XKB_LAYOUT_INVALID; |
| 199 |
} |
| 200 |
|
| 201 |
static void |
| 202 |
ClearSymbolsInfo(SymbolsInfo *info) |
| 203 |
{ |
| 204 |
KeyInfo *keyi; |
| 205 |
free(info->name); |
| 206 |
darray_foreach(keyi, info->keys) |
| 207 |
ClearKeyInfo(keyi); |
| 208 |
darray_free(info->keys); |
| 209 |
darray_free(info->group_names); |
| 210 |
darray_free(info->modmaps); |
| 211 |
ClearKeyInfo(&info->default_key); |
| 212 |
} |
| 213 |
|
| 214 |
static const char * |
| 215 |
KeyInfoText(SymbolsInfo *info, KeyInfo *keyi) |
| 216 |
{ |
| 217 |
return KeyNameText(info->ctx, keyi->name); |
| 218 |
} |
| 219 |
|
| 220 |
static bool |
| 221 |
MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, |
| 222 |
bool report, xkb_layout_index_t group, xkb_atom_t key_name) |
| 223 |
{ |
| 224 |
/* First find the type of the merged group. */ |
| 225 |
if (into->type != from->type) { |
| 226 |
if (from->type == XKB_ATOM_NONE) { |
| 227 |
/* it's empty for consistency with other comparisons */ |
| 228 |
} |
| 229 |
else if (into->type == XKB_ATOM_NONE) { |
| 230 |
into->type = from->type; |
| 231 |
} |
| 232 |
else { |
| 233 |
xkb_atom_t use = (clobber ? from->type : into->type); |
| 234 |
xkb_atom_t ignore = (clobber ? into->type : from->type); |
| 235 |
|
| 236 |
if (report) { |
| 237 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_KEY_TYPE_MERGING_GROUPS, |
| 238 |
"Multiple definitions for group %"PRIu32" type of key %s; " |
| 239 |
"Using %s, ignoring %s\n", |
| 240 |
group + 1, KeyNameText(info->ctx, key_name), |
| 241 |
xkb_atom_text(info->ctx, use), |
| 242 |
xkb_atom_text(info->ctx, ignore)); |
| 243 |
} |
| 244 |
|
| 245 |
into->type = use; |
| 246 |
} |
| 247 |
} |
| 248 |
into->defined |= (from->defined & GROUP_FIELD_TYPE); |
| 249 |
|
| 250 |
/* Now look at the levels. */ |
| 251 |
|
| 252 |
if (darray_empty(from->levels)) { |
| 253 |
InitGroupInfo(from); |
| 254 |
return true; |
| 255 |
} |
| 256 |
|
| 257 |
if (darray_empty(into->levels)) { |
| 258 |
from->type = into->type; |
| 259 |
*into = *from; |
| 260 |
InitGroupInfo(from); |
| 261 |
return true; |
| 262 |
} |
| 263 |
|
| 264 |
/* Merge the actions and syms. */ |
| 265 |
const darray_size_t levels_in_both = |
| 266 |
MIN(darray_size(into->levels), darray_size(from->levels)); |
| 267 |
darray_size_t fromKeysymsCount = 0; |
| 268 |
darray_size_t fromActionsCount = 0; |
| 269 |
for (darray_size_t i = 0; i < levels_in_both; i++) { |
| 270 |
struct xkb_level* const intoLevel = &darray_item(into->levels, i); |
| 271 |
struct xkb_level* const fromLevel = &darray_item(from->levels, i); |
| 272 |
|
| 273 |
const bool fromHasNoKeysym = fromLevel->num_syms == 0; |
| 274 |
const bool fromHasNoAction = fromLevel->num_actions == 0; |
| 275 |
if (fromHasNoKeysym && fromHasNoAction) { |
| 276 |
/* Empty `from`: do nothing */ |
| 277 |
continue; |
| 278 |
} |
| 279 |
|
| 280 |
const bool intoHasNoKeysym = intoLevel->num_syms == 0; |
| 281 |
const bool intoHasNoAction = intoLevel->num_actions == 0; |
| 282 |
if (intoHasNoKeysym && intoHasNoAction) { |
| 283 |
/* Empty `into`: use `from` keysyms and actions */ |
| 284 |
StealLevelInfo(intoLevel, fromLevel); |
| 285 |
fromKeysymsCount++; |
| 286 |
fromActionsCount++; |
| 287 |
continue; |
| 288 |
} |
| 289 |
|
| 290 |
/* Possible level conflict */ |
| 291 |
assert(intoLevel->num_syms > 0 || intoLevel->num_actions > 0); |
| 292 |
assert(fromLevel->num_syms > 0 || fromLevel->num_actions > 0); |
| 293 |
|
| 294 |
/* Handle keysyms */ |
| 295 |
if (!XkbLevelsSameSyms(fromLevel, intoLevel)) { |
| 296 |
/* Incompatible keysyms */ |
| 297 |
if (report && !(intoHasNoKeysym || fromHasNoKeysym)) { |
| 298 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_KEY_SYMBOL, |
| 299 |
"Multiple symbols for level %u/group " |
| 300 |
"%"PRIu32" on key %s; Using %s, ignoring %s\n", |
| 301 |
i + 1, group + 1, KeyNameText(info->ctx, key_name), |
| 302 |
(clobber ? "from" : "to"), |
| 303 |
(clobber ? "to" : "from")); |
| 304 |
} |
| 305 |
if (fromHasNoKeysym) { |
| 306 |
/* No keysym to copy */ |
| 307 |
} else if (clobber) { |
| 308 |
/* Override: copy any defined keysym from `from` */ |
| 309 |
if (unlikely(fromLevel->num_syms > 1)) { |
| 310 |
/* Multiple keysyms: always replace, all syms are defined */ |
| 311 |
if (unlikely(intoLevel->num_syms > 1)) |
| 312 |
free(intoLevel->s.syms); |
| 313 |
/* Steal */ |
| 314 |
intoLevel->s.syms = fromLevel->s.syms; |
| 315 |
intoLevel->num_syms = fromLevel->num_syms; |
| 316 |
fromLevel->num_syms = 0; |
| 317 |
fromKeysymsCount++; |
| 318 |
} else if (fromLevel->s.sym != XKB_KEY_NoSymbol) { |
| 319 |
/* Single defined keysym */ |
| 320 |
if (unlikely(intoLevel->num_syms > 1)) |
| 321 |
free(intoLevel->s.syms); |
| 322 |
intoLevel->s.sym = fromLevel->s.sym; |
| 323 |
intoLevel->num_syms = 1; |
| 324 |
fromKeysymsCount++; |
| 325 |
} |
| 326 |
} else { |
| 327 |
/* Augment: copy only the keysyms from `from` that are |
| 328 |
* undefined in `into` */ |
| 329 |
if (unlikely(intoLevel->num_syms > 1)) { |
| 330 |
/* Multiple keysyms: always ignore, all syms are defined */ |
| 331 |
} else if (intoLevel->s.sym == XKB_KEY_NoSymbol) { |
| 332 |
/* Single undefined keysym */ |
| 333 |
if (unlikely(fromLevel->num_syms > 1)) { |
| 334 |
/* Steal */ |
| 335 |
intoLevel->s.syms = fromLevel->s.syms; |
| 336 |
intoLevel->num_syms = fromLevel->num_syms; |
| 337 |
fromLevel->num_syms = 0; |
| 338 |
} else { |
| 339 |
intoLevel->s.sym = fromLevel->s.sym; |
| 340 |
intoLevel->num_syms = 1; |
| 341 |
} |
| 342 |
fromKeysymsCount++; |
| 343 |
} |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
/* Handle actions */ |
| 348 |
if (!XkbLevelsSameActions(intoLevel, fromLevel)) { |
| 349 |
/* Incompatible actions */ |
| 350 |
if (report && !(intoHasNoAction || fromHasNoAction)) { |
| 351 |
if (unlikely(intoLevel->num_actions > 1)) { |
| 352 |
log_warn( |
| 353 |
info->ctx, XKB_WARNING_CONFLICTING_KEY_ACTION, |
| 354 |
"Multiple actions for level %u/group %"PRIu32" " |
| 355 |
"on key %s; %s\n", |
| 356 |
i + 1, group + 1, KeyNameText(info->ctx, key_name), |
| 357 |
clobber ? "Using from, ignoring to" |
| 358 |
: "Using to, ignoring from"); |
| 359 |
} else { |
| 360 |
union xkb_action *use, *ignore; |
| 361 |
use = clobber |
| 362 |
? &fromLevel->a.action |
| 363 |
: &intoLevel->a.action; |
| 364 |
ignore = clobber |
| 365 |
? &intoLevel->a.action |
| 366 |
: &fromLevel->a.action; |
| 367 |
|
| 368 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_KEY_ACTION, |
| 369 |
"Multiple actions for level %u/group " |
| 370 |
"%"PRIu32" on key %s; Using %s, ignoring %s\n", |
| 371 |
i + 1, group + 1, |
| 372 |
KeyNameText(info->ctx, key_name), |
| 373 |
ActionTypeText(use->type), |
| 374 |
ActionTypeText(ignore->type)); |
| 375 |
} |
| 376 |
} |
| 377 |
if (fromHasNoAction) { |
| 378 |
/* No action to copy */ |
| 379 |
} else if (clobber) { |
| 380 |
/* Override: copy any defined action from `from` */ |
| 381 |
if (unlikely(fromLevel->num_actions > 1)) { |
| 382 |
/* Multiple actions: always replace, all syms are defined */ |
| 383 |
if (unlikely(intoLevel->num_actions > 1)) |
| 384 |
free(intoLevel->a.actions); |
| 385 |
/* Steal */ |
| 386 |
intoLevel->a.actions = fromLevel->a.actions; |
| 387 |
intoLevel->num_actions = fromLevel->num_actions; |
| 388 |
fromLevel->num_actions = 0; |
| 389 |
fromActionsCount++; |
| 390 |
} else if (fromLevel->a.action.type != ACTION_TYPE_NONE) { |
| 391 |
/* Single defined action */ |
| 392 |
if (unlikely(intoLevel->num_actions > 1)) |
| 393 |
free(intoLevel->a.actions); |
| 394 |
intoLevel->a.action = fromLevel->a.action; |
| 395 |
intoLevel->num_actions = 1; |
| 396 |
fromActionsCount++; |
| 397 |
} |
| 398 |
} else { |
| 399 |
/* Augment: copy only the actions from `from` that are |
| 400 |
* undefined in `into` */ |
| 401 |
if (unlikely(intoLevel->num_actions > 1)) { |
| 402 |
/* Multiple keysyms: always ignore, all syms are defined */ |
| 403 |
} else if (intoLevel->a.action.type == ACTION_TYPE_NONE) { |
| 404 |
/* Single undefined keysym */ |
| 405 |
if (unlikely(fromLevel->num_actions > 1)) { |
| 406 |
/* Steal */ |
| 407 |
intoLevel->a.actions = fromLevel->a.actions; |
| 408 |
intoLevel->num_actions = fromLevel->num_actions; |
| 409 |
fromLevel->num_actions = 0; |
| 410 |
} else { |
| 411 |
intoLevel->a.action = fromLevel->a.action; |
| 412 |
intoLevel->num_actions = 1; |
| 413 |
} |
| 414 |
fromActionsCount++; |
| 415 |
} |
| 416 |
} |
| 417 |
} |
| 418 |
} |
| 419 |
/* If @from has extra levels, get them as well. */ |
| 420 |
struct xkb_level *level; |
| 421 |
darray_foreach_from(level, from->levels, levels_in_both) { |
| 422 |
darray_append(into->levels, *level); |
| 423 |
/* We may have stolen keysyms or actions arrays: |
| 424 |
* do not free them when clearing `from` */ |
| 425 |
level->num_syms = 0; |
| 426 |
level->num_actions = 0; |
| 427 |
fromKeysymsCount++; |
| 428 |
fromActionsCount++; |
| 429 |
} |
| 430 |
if (fromKeysymsCount) { |
| 431 |
/* Reset defined keysyms field if we used no keysym from `into` */ |
| 432 |
if (fromKeysymsCount == darray_size(into->levels)) |
| 433 |
into->defined &= ~GROUP_FIELD_SYMS; |
| 434 |
into->defined |= (from->defined & GROUP_FIELD_SYMS); |
| 435 |
} |
| 436 |
if (fromActionsCount) { |
| 437 |
/* Reset defined actions field if we used no action from `into` */ |
| 438 |
if (fromActionsCount == darray_size(into->levels)) |
| 439 |
into->defined &= ~GROUP_FIELD_ACTS; |
| 440 |
into->defined |= (from->defined & GROUP_FIELD_ACTS); |
| 441 |
} |
| 442 |
|
| 443 |
return true; |
| 444 |
} |
| 445 |
|
| 446 |
static bool |
| 447 |
UseNewKeyField(enum key_field field, enum key_field old, enum key_field new, |
| 448 |
bool clobber, bool report, enum key_field *collide) |
| 449 |
{ |
| 450 |
if (!(old & field)) |
| 451 |
return (new & field); |
| 452 |
|
| 453 |
if (new & field) { |
| 454 |
if (report) |
| 455 |
*collide |= field; |
| 456 |
|
| 457 |
return clobber; |
| 458 |
} |
| 459 |
|
| 460 |
return false; |
| 461 |
} |
| 462 |
|
| 463 |
static bool |
| 464 |
MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from, bool same_file) |
| 465 |
{ |
| 466 |
xkb_layout_index_t i; |
| 467 |
xkb_layout_index_t groups_in_both; |
| 468 |
enum key_field collide = 0; |
| 469 |
const int verbosity = xkb_context_get_log_verbosity(info->ctx); |
| 470 |
const bool clobber = (from->merge != MERGE_AUGMENT); |
| 471 |
const bool report = (same_file && verbosity > 0) || verbosity > 9; |
| 472 |
|
| 473 |
if (from->merge == MERGE_REPLACE) { |
| 474 |
ClearKeyInfo(into); |
| 475 |
*into = *from; |
| 476 |
InitKeyInfo(info->ctx, from); |
| 477 |
return true; |
| 478 |
} |
| 479 |
|
| 480 |
groups_in_both = MIN(darray_size(into->groups), darray_size(from->groups)); |
| 481 |
for (i = 0; i < groups_in_both; i++) |
| 482 |
MergeGroups(info, |
| 483 |
&darray_item(into->groups, i), |
| 484 |
&darray_item(from->groups, i), |
| 485 |
clobber, report, i, into->name); |
| 486 |
/* If @from has extra groups, just move them to @into. */ |
| 487 |
for (i = groups_in_both; i < darray_size(from->groups); i++) { |
| 488 |
darray_append(into->groups, darray_item(from->groups, i)); |
| 489 |
InitGroupInfo(&darray_item(from->groups, i)); |
| 490 |
} |
| 491 |
|
| 492 |
if (UseNewKeyField(KEY_FIELD_VMODMAP, into->defined, from->defined, |
| 493 |
clobber, report, &collide)) { |
| 494 |
into->vmodmap = from->vmodmap; |
| 495 |
into->defined |= KEY_FIELD_VMODMAP; |
| 496 |
} |
| 497 |
if (UseNewKeyField(KEY_FIELD_REPEAT, into->defined, from->defined, |
| 498 |
clobber, report, &collide)) { |
| 499 |
into->repeat = from->repeat; |
| 500 |
into->defined |= KEY_FIELD_REPEAT; |
| 501 |
} |
| 502 |
if (UseNewKeyField(KEY_FIELD_DEFAULT_TYPE, into->defined, from->defined, |
| 503 |
clobber, report, &collide)) { |
| 504 |
into->default_type = from->default_type; |
| 505 |
into->defined |= KEY_FIELD_DEFAULT_TYPE; |
| 506 |
} |
| 507 |
if (UseNewKeyField(KEY_FIELD_GROUPINFO, into->defined, from->defined, |
| 508 |
clobber, report, &collide)) { |
| 509 |
into->out_of_range_group_action = from->out_of_range_group_action; |
| 510 |
into->out_of_range_group_number = from->out_of_range_group_number; |
| 511 |
into->defined |= KEY_FIELD_GROUPINFO; |
| 512 |
} |
| 513 |
|
| 514 |
if (collide) { |
| 515 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_KEY_FIELDS, |
| 516 |
"Symbol map for key %s redefined; " |
| 517 |
"Using %s definition for conflicting fields\n", |
| 518 |
KeyNameText(info->ctx, into->name), |
| 519 |
(clobber ? "first" : "last")); |
| 520 |
} |
| 521 |
|
| 522 |
ClearKeyInfo(from); |
| 523 |
InitKeyInfo(info->ctx, from); |
| 524 |
return true; |
| 525 |
} |
| 526 |
|
| 527 |
static struct xkb_key * |
| 528 |
XkbKeyByName(struct xkb_keymap *keymap, xkb_atom_t name, bool use_aliases) |
| 529 |
{ |
| 530 |
if (name < keymap->num_key_names) { |
| 531 |
const KeycodeMatch match = keymap->key_names[name]; |
| 532 |
if (match.found) { |
| 533 |
if (!match.is_alias) { |
| 534 |
assert(name == keymap->keys[match.key.index].name); |
| 535 |
return &keymap->keys[match.key.index]; |
| 536 |
} else if (use_aliases) { |
| 537 |
assert(match.alias.real == |
| 538 |
keymap->keys[keymap->key_names[match.alias.real].key.index].name); |
| 539 |
return &keymap->keys[keymap->key_names[match.alias.real].key.index]; |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
return NULL; |
| 544 |
} |
| 545 |
|
| 546 |
static xkb_atom_t |
| 547 |
XkbResolveKeyAlias(const struct xkb_keymap *keymap, xkb_atom_t name) |
| 548 |
{ |
| 549 |
if (name < keymap->num_key_names) { |
| 550 |
const KeycodeMatch match = keymap->key_names[name]; |
| 551 |
if (match.found && match.is_alias) { |
| 552 |
return match.alias.real; |
| 553 |
} |
| 554 |
} |
| 555 |
return name; |
| 556 |
} |
| 557 |
|
| 558 |
/* TODO: Make it so this function doesn't need the entire keymap. */ |
| 559 |
static bool |
| 560 |
AddKeySymbols(SymbolsInfo *info, KeyInfo *keyi, bool same_file) |
| 561 |
{ |
| 562 |
/* |
| 563 |
* Don't keep aliases in the keys array; this guarantees that |
| 564 |
* searching for keys to merge with by straight comparison (see the |
| 565 |
* following loop) is enough, and we won't get multiple KeyInfo's |
| 566 |
* for the same key because of aliases. |
| 567 |
*/ |
| 568 |
keyi->name = XkbResolveKeyAlias(info->keymap, keyi->name); |
| 569 |
|
| 570 |
KeyInfo *iter; |
| 571 |
darray_foreach(iter, info->keys) |
| 572 |
if (iter->name == keyi->name) |
| 573 |
return MergeKeys(info, iter, keyi, same_file); |
| 574 |
|
| 575 |
darray_append(info->keys, *keyi); |
| 576 |
InitKeyInfo(info->ctx, keyi); |
| 577 |
return true; |
| 578 |
} |
| 579 |
|
| 580 |
static bool |
| 581 |
AddModMapEntry(SymbolsInfo *info, ModMapEntry *new) |
| 582 |
{ |
| 583 |
ModMapEntry *old; |
| 584 |
bool clobber = (new->merge != MERGE_AUGMENT); |
| 585 |
|
| 586 |
darray_foreach(old, info->modmaps) { |
| 587 |
xkb_mod_index_t use, ignore; |
| 588 |
|
| 589 |
if ((new->haveSymbol != old->haveSymbol) || |
| 590 |
(new->haveSymbol && new->u.keySym != old->u.keySym) || |
| 591 |
(!new->haveSymbol && new->u.keyName != old->u.keyName)) |
| 592 |
continue; |
| 593 |
|
| 594 |
if (new->modifier == old->modifier) |
| 595 |
return true; |
| 596 |
|
| 597 |
use = (clobber ? new->modifier : old->modifier); |
| 598 |
ignore = (clobber ? old->modifier : new->modifier); |
| 599 |
|
| 600 |
if (new->haveSymbol) { |
| 601 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_MODMAP, |
| 602 |
"Symbol \"%s\" added to modifier map for multiple modifiers; " |
| 603 |
"Using %s, ignoring %s\n", |
| 604 |
KeysymText(info->ctx, new->u.keySym), |
| 605 |
ModIndexText(info->ctx, &info->mods, use), |
| 606 |
ModIndexText(info->ctx, &info->mods, ignore)); |
| 607 |
} else { |
| 608 |
log_warn(info->ctx, XKB_WARNING_CONFLICTING_MODMAP, |
| 609 |
"Key \"%s\" added to modifier map for multiple modifiers; " |
| 610 |
"Using %s, ignoring %s\n", |
| 611 |
KeyNameText(info->ctx, new->u.keyName), |
| 612 |
ModIndexText(info->ctx, &info->mods, use), |
| 613 |
ModIndexText(info->ctx, &info->mods, ignore)); |
| 614 |
} |
| 615 |
old->modifier = use; |
| 616 |
return true; |
| 617 |
} |
| 618 |
|
| 619 |
darray_append(info->modmaps, *new); |
| 620 |
return true; |
| 621 |
} |
| 622 |
|
| 623 |
/***====================================================================***/ |
| 624 |
|
| 625 |
static void |
| 626 |
MergeIncludedSymbols(SymbolsInfo *into, SymbolsInfo *from, |
| 627 |
enum merge_mode merge) |
| 628 |
{ |
| 629 |
xkb_atom_t *group_name; |
| 630 |
xkb_layout_index_t group_names_in_both; |
| 631 |
|
| 632 |
if (from->errorCount > 0) { |
| 633 |
into->errorCount += from->errorCount; |
| 634 |
return; |
| 635 |
} |
| 636 |
|
| 637 |
MergeModSets(into->ctx, &into->mods, &from->mods, merge); |
| 638 |
|
| 639 |
if (into->name == NULL) { |
| 640 |
into->name = steal(&from->name); |
| 641 |
} |
| 642 |
|
| 643 |
group_names_in_both = MIN(darray_size(into->group_names), |
| 644 |
darray_size(from->group_names)); |
| 645 |
for (xkb_layout_index_t i = 0; i < group_names_in_both; i++) { |
| 646 |
if (!darray_item(from->group_names, i)) |
| 647 |
continue; |
| 648 |
|
| 649 |
if (merge == MERGE_AUGMENT && darray_item(into->group_names, i)) |
| 650 |
continue; |
| 651 |
|
| 652 |
darray_item(into->group_names, i) = darray_item(from->group_names, i); |
| 653 |
} |
| 654 |
/* If @from has more, get them as well. */ |
| 655 |
darray_foreach_from(group_name, from->group_names, group_names_in_both) |
| 656 |
darray_append(into->group_names, *group_name); |
| 657 |
|
| 658 |
if (darray_empty(into->keys)) { |
| 659 |
into->keys = from->keys; |
| 660 |
darray_init(from->keys); |
| 661 |
} |
| 662 |
else { |
| 663 |
KeyInfo *keyi; |
| 664 |
darray_foreach(keyi, from->keys) { |
| 665 |
keyi->merge = merge; |
| 666 |
if (!AddKeySymbols(into, keyi, false)) |
| 667 |
into->errorCount++; |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
if (darray_empty(into->modmaps)) { |
| 672 |
into->modmaps = from->modmaps; |
| 673 |
darray_init(from->modmaps); |
| 674 |
} |
| 675 |
else { |
| 676 |
ModMapEntry *mm; |
| 677 |
darray_foreach(mm, from->modmaps) { |
| 678 |
mm->merge = merge; |
| 679 |
if (!AddModMapEntry(into, mm)) |
| 680 |
into->errorCount++; |
| 681 |
} |
| 682 |
} |
| 683 |
} |
| 684 |
|
| 685 |
static void |
| 686 |
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file); |
| 687 |
|
| 688 |
static bool |
| 689 |
HandleIncludeSymbols(SymbolsInfo *info, IncludeStmt *include) |
| 690 |
{ |
| 691 |
SymbolsInfo included; |
| 692 |
|
| 693 |
if (ExceedsIncludeMaxDepth(info->ctx, info->include_depth)) { |
| 694 |
info->errorCount += 10; |
| 695 |
return false; |
| 696 |
} |
| 697 |
|
| 698 |
InitSymbolsInfo(&included, info->keymap, info->include_depth + 1, |
| 699 |
&info->mods); |
| 700 |
included.name = steal(&include->stmt); |
| 701 |
|
| 702 |
for (IncludeStmt *stmt = include; stmt; stmt = stmt->next_incl) { |
| 703 |
SymbolsInfo next_incl; |
| 704 |
XkbFile *file; |
| 705 |
|
| 706 |
char path[PATH_MAX]; |
| 707 |
file = ProcessIncludeFile(info->ctx, stmt, FILE_TYPE_SYMBOLS, |
| 708 |
path, sizeof(path)); |
| 709 |
if (!file) { |
| 710 |
info->errorCount += 10; |
| 711 |
ClearSymbolsInfo(&included); |
| 712 |
return false; |
| 713 |
} |
| 714 |
|
| 715 |
InitSymbolsInfo(&next_incl, info->keymap, info->include_depth + 1, |
| 716 |
&included.mods); |
| 717 |
if (stmt->modifier) { |
| 718 |
next_incl.explicit_group = atoi(stmt->modifier) - 1; |
| 719 |
if (next_incl.explicit_group >= info->max_groups) { |
| 720 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 721 |
"Cannot set explicit group to %"PRIu32" - " |
| 722 |
"must be between 1..%u; Ignoring group number\n", |
| 723 |
next_incl.explicit_group + 1, info->max_groups); |
| 724 |
next_incl.explicit_group = info->explicit_group; |
| 725 |
} |
| 726 |
} |
| 727 |
else if (info->keymap->num_groups != 0 && next_incl.include_depth == 1) { |
| 728 |
/* If keymap is the result of RMLVO resolution and we are at the |
| 729 |
* first include depth, transform e.g. `pc` into `pc:1` in order to |
| 730 |
* force only one group per key using the explicit group. |
| 731 |
* |
| 732 |
* NOTE: X11’s xkbcomp does not apply this rule. */ |
| 733 |
next_incl.explicit_group = 0; |
| 734 |
} |
| 735 |
else { |
| 736 |
/* The keymap was not generated from rules or this is not the first |
| 737 |
* level of include: take the parent’s explicit group. */ |
| 738 |
next_incl.explicit_group = info->explicit_group; |
| 739 |
} |
| 740 |
|
| 741 |
HandleSymbolsFile(&next_incl, file); |
| 742 |
|
| 743 |
MergeIncludedSymbols(&included, &next_incl, stmt->merge); |
| 744 |
|
| 745 |
ClearSymbolsInfo(&next_incl); |
| 746 |
FreeXkbFile(file); |
| 747 |
} |
| 748 |
|
| 749 |
MergeIncludedSymbols(info, &included, include->merge); |
| 750 |
ClearSymbolsInfo(&included); |
| 751 |
|
| 752 |
return (info->errorCount == 0); |
| 753 |
} |
| 754 |
|
| 755 |
static bool |
| 756 |
GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, |
| 757 |
enum group_field field, xkb_layout_index_t *ndx_rtrn) |
| 758 |
{ |
| 759 |
assert (field == GROUP_FIELD_SYMS || field == GROUP_FIELD_ACTS); |
| 760 |
const char *name = (field == GROUP_FIELD_SYMS ? "symbols" : "actions"); |
| 761 |
|
| 762 |
if (arrayNdx == NULL) { |
| 763 |
xkb_layout_index_t i = 0; |
| 764 |
GroupInfo *groupi; |
| 765 |
|
| 766 |
darray_enumerate(i, groupi, keyi->groups) { |
| 767 |
if (!(groupi->defined & field)) { |
| 768 |
*ndx_rtrn = i; |
| 769 |
return true; |
| 770 |
} |
| 771 |
} |
| 772 |
|
| 773 |
if (i >= info->max_groups) { |
| 774 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 775 |
"Too many groups of %s for key %s (max %u); " |
| 776 |
"Ignoring %s defined for extra groups\n", |
| 777 |
name, KeyInfoText(info, keyi), info->max_groups, name); |
| 778 |
return false; |
| 779 |
} |
| 780 |
|
| 781 |
darray_resize0(keyi->groups, darray_size(keyi->groups) + 1); |
| 782 |
*ndx_rtrn = darray_size(keyi->groups) - 1; |
| 783 |
return true; |
| 784 |
} |
| 785 |
|
| 786 |
if (!ExprResolveGroup(info->ctx, info->max_groups, arrayNdx, ndx_rtrn)) { |
| 787 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 788 |
"Illegal group index for %s of key %s\n" |
| 789 |
"Definition with non-integer array index ignored\n", |
| 790 |
name, KeyInfoText(info, keyi)); |
| 791 |
return false; |
| 792 |
} |
| 793 |
|
| 794 |
(*ndx_rtrn)--; |
| 795 |
if (*ndx_rtrn >= darray_size(keyi->groups)) |
| 796 |
darray_resize0(keyi->groups, *ndx_rtrn + 1); |
| 797 |
|
| 798 |
return true; |
| 799 |
} |
| 800 |
|
| 801 |
static bool |
| 802 |
AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, |
| 803 |
ExprDef *value) |
| 804 |
{ |
| 805 |
xkb_layout_index_t ndx = 0; |
| 806 |
|
| 807 |
if (!GetGroupIndex(info, keyi, arrayNdx, GROUP_FIELD_SYMS, &ndx)) |
| 808 |
return false; |
| 809 |
|
| 810 |
GroupInfo *groupi = &darray_item(keyi->groups, ndx); |
| 811 |
|
| 812 |
if (value->common.type == STMT_EXPR_EMPTY_LIST) { |
| 813 |
groupi->defined |= GROUP_FIELD_SYMS; |
| 814 |
return true; |
| 815 |
} |
| 816 |
|
| 817 |
if (value->common.type != STMT_EXPR_KEYSYM_LIST) { |
| 818 |
log_err(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE, |
| 819 |
"Expected a list of symbols, found %s; " |
| 820 |
"Ignoring symbols for group %"PRIu32" of %s\n", |
| 821 |
stmt_type_to_string(value->common.type), ndx + 1, |
| 822 |
KeyInfoText(info, keyi)); |
| 823 |
return false; |
| 824 |
} |
| 825 |
|
| 826 |
if (groupi->defined & GROUP_FIELD_SYMS) { |
| 827 |
log_err(info->ctx, XKB_ERROR_CONFLICTING_KEY_SYMBOLS_ENTRY, |
| 828 |
"Symbols for key %s, group %"PRIu32" already defined; " |
| 829 |
"Ignoring duplicate definition\n", |
| 830 |
KeyInfoText(info, keyi), ndx + 1); |
| 831 |
return false; |
| 832 |
} |
| 833 |
|
| 834 |
xkb_level_index_t nLevels = 0; |
| 835 |
xkb_level_index_t nonEmptyLevels = 0; |
| 836 |
/* Contrary to actions, keysyms are already parsed at this point so we drop |
| 837 |
* trailing symbols by not adding them in the first place. */ |
| 838 |
for (ExprKeysymList *keysymList = (ExprKeysymList *) value; |
| 839 |
keysymList; |
| 840 |
keysymList = (ExprKeysymList *) keysymList->common.next) { |
| 841 |
nLevels++; |
| 842 |
/* Drop trailing NoSymbol */ |
| 843 |
if (darray_size(keysymList->syms) > 0) |
| 844 |
nonEmptyLevels = nLevels; |
| 845 |
} |
| 846 |
if (nonEmptyLevels < nLevels) |
| 847 |
nLevels = nonEmptyLevels; |
| 848 |
if (darray_size(groupi->levels) < nLevels) |
| 849 |
darray_resize0(groupi->levels, nLevels); |
| 850 |
|
| 851 |
groupi->defined |= GROUP_FIELD_SYMS; |
| 852 |
|
| 853 |
xkb_level_index_t level = 0; |
| 854 |
for (ExprKeysymList *keysymList = (ExprKeysymList *) value; |
| 855 |
keysymList && level < nLevels; |
| 856 |
keysymList = (ExprKeysymList *) keysymList->common.next, level++) { |
| 857 |
struct xkb_level *leveli = &darray_item(groupi->levels, level); |
| 858 |
assert(leveli->num_syms == 0); |
| 859 |
|
| 860 |
if (unlikely(darray_size(keysymList->syms) > MAX_KEYSYMS_PER_LEVEL)) { |
| 861 |
log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID, |
| 862 |
"Key %s has too many keysyms for group %"PRIu32", " |
| 863 |
"level %"PRIu32"; expected max %u, got: %u\n", |
| 864 |
KeyInfoText(info, keyi), ndx + 1, level + 1, |
| 865 |
MAX_KEYSYMS_PER_LEVEL, darray_size(keysymList->syms)); |
| 866 |
return false; |
| 867 |
} |
| 868 |
|
| 869 |
leveli->num_syms = (xkb_keysym_count_t) darray_size(keysymList->syms); |
| 870 |
switch (leveli->num_syms) { |
| 871 |
case 0: |
| 872 |
leveli->s.sym = XKB_KEY_NoSymbol; |
| 873 |
break; |
| 874 |
case 1: |
| 875 |
leveli->s.sym = darray_item(keysymList->syms, 0); |
| 876 |
assert(leveli->s.sym != XKB_KEY_NoSymbol); |
| 877 |
break; |
| 878 |
default: |
| 879 |
darray_shrink(keysymList->syms); |
| 880 |
darray_steal(keysymList->syms, &leveli->s.syms, NULL); |
| 881 |
#ifndef NDEBUG |
| 882 |
/* Canonical list: all NoSymbol were dropped */ |
| 883 |
for (xkb_keysym_count_t k = 0; k < leveli->num_syms; k++) |
| 884 |
assert(leveli->s.syms[k] != XKB_KEY_NoSymbol); |
| 885 |
#endif |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
return true; |
| 890 |
} |
| 891 |
|
| 892 |
static bool |
| 893 |
AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, |
| 894 |
ExprDef *value) |
| 895 |
{ |
| 896 |
xkb_layout_index_t ndx = 0; |
| 897 |
|
| 898 |
if (!GetGroupIndex(info, keyi, arrayNdx, GROUP_FIELD_ACTS, &ndx)) |
| 899 |
return false; |
| 900 |
|
| 901 |
GroupInfo *groupi = &darray_item(keyi->groups, ndx); |
| 902 |
|
| 903 |
if (value->common.type == STMT_EXPR_EMPTY_LIST) { |
| 904 |
groupi->defined |= GROUP_FIELD_ACTS; |
| 905 |
return true; |
| 906 |
} |
| 907 |
|
| 908 |
if (value->common.type != STMT_EXPR_ACTION_LIST) { |
| 909 |
log_wsgo(info->ctx, XKB_ERROR_INVALID_EXPRESSION_TYPE, |
| 910 |
"Bad expression type (%d) for action list value; " |
| 911 |
"Ignoring actions for group %"PRIu32" of %s\n", |
| 912 |
value->common.type, ndx, KeyInfoText(info, keyi)); |
| 913 |
return false; |
| 914 |
} |
| 915 |
|
| 916 |
if (groupi->defined & GROUP_FIELD_ACTS) { |
| 917 |
log_wsgo(info->ctx, XKB_WARNING_CONFLICTING_KEY_ACTION, |
| 918 |
"Actions for key %s, group %"PRIu32" already defined\n", |
| 919 |
KeyInfoText(info, keyi), ndx); |
| 920 |
return false; |
| 921 |
} |
| 922 |
|
| 923 |
xkb_level_index_t nLevels = 0; |
| 924 |
/* Contrary to keysyms with trailing `NoSymbol`, we cannot detect trailing |
| 925 |
* `NoAction()` now, because we need to parse the actions first. Jusr count |
| 926 |
* explicit actions for now. */ |
| 927 |
for (ParseCommon *p = &value->common; p; p = p->next) |
| 928 |
nLevels++; |
| 929 |
if (darray_size(groupi->levels) < nLevels) |
| 930 |
darray_resize0(groupi->levels, nLevels); |
| 931 |
|
| 932 |
groupi->defined |= GROUP_FIELD_ACTS; |
| 933 |
|
| 934 |
xkb_level_index_t level = 0; |
| 935 |
xkb_level_index_t nonEmptyLevels = 0; |
| 936 |
for (ExprActionList *actionList = (ExprActionList *) value; |
| 937 |
actionList; |
| 938 |
actionList = (ExprActionList *) actionList->common.next, level++) { |
| 939 |
struct xkb_level *leveli = &darray_item(groupi->levels, level); |
| 940 |
assert(leveli->num_actions == 0); |
| 941 |
|
| 942 |
unsigned int num_actions = 0; |
| 943 |
for (ExprDef *act = actionList->actions; |
| 944 |
act; act = (ExprDef *) act->common.next) |
| 945 |
num_actions++; |
| 946 |
|
| 947 |
if (unlikely(num_actions > MAX_ACTIONS_PER_LEVEL)) { |
| 948 |
log_err(info->ctx, XKB_LOG_MESSAGE_NO_ID, |
| 949 |
"Key %s has too many actions for group %"PRIu32", " |
| 950 |
"level %"PRIu32"; expected max %u, got: %u\n", |
| 951 |
KeyInfoText(info, keyi), ndx + 1, level + 1, |
| 952 |
MAX_ACTIONS_PER_LEVEL, num_actions); |
| 953 |
return false; |
| 954 |
} |
| 955 |
|
| 956 |
/* Parse actions and add only defined actions */ |
| 957 |
darray(union xkb_action) actions = darray_new(); |
| 958 |
for (ExprDef *act = actionList->actions; |
| 959 |
act; act = (ExprDef *) act->common.next) { |
| 960 |
union xkb_action toAct = { 0 }; |
| 961 |
if (!HandleActionDef(info->ctx, info->keymap->format, |
| 962 |
&info->default_actions, &info->mods, |
| 963 |
act, &toAct)) { |
| 964 |
log_err(info->ctx, XKB_ERROR_INVALID_VALUE, |
| 965 |
"Illegal action definition for %s; " |
| 966 |
"Action for group %"PRIu32"/level %"PRIu32" ignored\n", |
| 967 |
KeyInfoText(info, keyi), ndx + 1, level + 1); |
| 968 |
/* Ensure action type is reset */ |
| 969 |
toAct.type = ACTION_TYPE_NONE; |
| 970 |
} |
| 971 |
if (toAct.type == ACTION_TYPE_NONE) { |
| 972 |
/* Drop action */ |
| 973 |
} else if (likely(num_actions == 1)) { |
| 974 |
/* Only one action: do not allocate */ |
| 975 |
leveli->num_actions = 1; |
| 976 |
leveli->a.action = toAct; |
| 977 |
goto next_level; |
| 978 |
} else { |
| 979 |
darray_append(actions, toAct); |
| 980 |
} |
| 981 |
} |
| 982 |
if (darray_empty(actions)) { |
| 983 |
leveli->num_actions = 0; |
| 984 |
} else if (likely(darray_size(actions) > 1)) { |
| 985 |
leveli->num_actions = (xkb_action_count_t) darray_size(actions); |
| 986 |
darray_shrink(actions); |
| 987 |
darray_steal(actions, &leveli->a.actions, NULL); |
| 988 |
#ifndef NDEBUG |
| 989 |
/* Canonical list: all NoAction() were dropped */ |
| 990 |
for (xkb_action_count_t k = 0; k < leveli->num_actions; k++) |
| 991 |
assert(leveli->a.actions[k].type != ACTION_TYPE_NONE); |
| 992 |
#endif |
| 993 |
} else { |
| 994 |
/* Unlikely: some actions were dropped and only one remains */ |
| 995 |
assert(num_actions > darray_size(actions)); |
| 996 |
leveli->num_actions = 1; |
| 997 |
leveli->a.action = darray_item(actions, 0); |
| 998 |
assert(leveli->a.action.type != ACTION_TYPE_NONE); |
| 999 |
darray_free(actions); |
| 1000 |
} |
| 1001 |
next_level: |
| 1002 |
/* |
| 1003 |
* Check trailing `NoAction()`, but count as empty level only if there |
| 1004 |
* is no corresponding keysym. |
| 1005 |
*/ |
| 1006 |
if (leveli->num_actions > 0 || leveli->num_syms > 0) |
| 1007 |
nonEmptyLevels = level + 1; |
| 1008 |
} |
| 1009 |
|
| 1010 |
if (nonEmptyLevels < nLevels) { |
| 1011 |
/* Drop trailing `NoAction()`. |
| 1012 |
* No need to clear dropped levels: there are no keysyms nor actions */ |
| 1013 |
darray_size(groupi->levels) = nonEmptyLevels; |
| 1014 |
if (nonEmptyLevels > 0) |
| 1015 |
darray_shrink(groupi->levels); |
| 1016 |
else |
| 1017 |
darray_free(groupi->levels); |
| 1018 |
} |
| 1019 |
|
| 1020 |
return true; |
| 1021 |
} |
| 1022 |
|
| 1023 |
static const LookupEntry repeatEntries[] = { |
| 1024 |
{ "true", KEY_REPEAT_YES }, |
| 1025 |
{ "yes", KEY_REPEAT_YES }, |
| 1026 |
{ "on", KEY_REPEAT_YES }, |
| 1027 |
{ "false", KEY_REPEAT_NO }, |
| 1028 |
{ "no", KEY_REPEAT_NO }, |
| 1029 |
{ "off", KEY_REPEAT_NO }, |
| 1030 |
{ "default", KEY_REPEAT_UNDEFINED }, |
| 1031 |
{ NULL, 0 } |
| 1032 |
}; |
| 1033 |
|
| 1034 |
static bool |
| 1035 |
SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, |
| 1036 |
ExprDef *arrayNdx, ExprDef *value) |
| 1037 |
{ |
| 1038 |
if (istreq(field, "type")) { |
| 1039 |
xkb_layout_index_t ndx = 0; |
| 1040 |
xkb_atom_t val = XKB_ATOM_NONE; |
| 1041 |
|
| 1042 |
if (!ExprResolveString(info->ctx, value, &val)) { |
| 1043 |
log_err(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE, |
| 1044 |
"The type field of a key symbol map must be a string; " |
| 1045 |
"Ignoring illegal type definition\n"); |
| 1046 |
return false; |
| 1047 |
} |
| 1048 |
|
| 1049 |
if (!arrayNdx) { |
| 1050 |
keyi->default_type = val; |
| 1051 |
keyi->defined |= KEY_FIELD_DEFAULT_TYPE; |
| 1052 |
} |
| 1053 |
else if (!ExprResolveGroup(info->ctx, info->max_groups, arrayNdx, &ndx)) { |
| 1054 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 1055 |
"Illegal group index for type of key %s; " |
| 1056 |
"Definition with non-integer array index ignored\n", |
| 1057 |
KeyInfoText(info, keyi)); |
| 1058 |
return false; |
| 1059 |
} |
| 1060 |
else { |
| 1061 |
ndx--; |
| 1062 |
if (ndx >= darray_size(keyi->groups)) { |
| 1063 |
/* Avoid clang-tidy false positive */ |
| 1064 |
assert(darray_size(keyi->groups) < ndx + 1); |
| 1065 |
darray_resize0(keyi->groups, ndx + 1); |
| 1066 |
} |
| 1067 |
darray_item(keyi->groups, ndx).type = val; |
| 1068 |
darray_item(keyi->groups, ndx).defined |= GROUP_FIELD_TYPE; |
| 1069 |
} |
| 1070 |
} |
| 1071 |
else if (istreq(field, "symbols")) { |
| 1072 |
return AddSymbolsToKey(info, keyi, arrayNdx, value); |
| 1073 |
} |
| 1074 |
else if (istreq(field, "actions")) { |
| 1075 |
return AddActionsToKey(info, keyi, arrayNdx, value); |
| 1076 |
} |
| 1077 |
else if (istreq(field, "vmods") || |
| 1078 |
istreq(field, "virtualmods") || |
| 1079 |
istreq(field, "virtualmodifiers")) { |
| 1080 |
xkb_mod_mask_t mask = 0; |
| 1081 |
|
| 1082 |
if (!ExprResolveModMask(info->ctx, value, MOD_VIRT, &info->mods, |
| 1083 |
&mask)) { |
| 1084 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_MODIFIER_MASK, |
| 1085 |
"Expected a virtual modifier mask, found %s; " |
| 1086 |
"Ignoring virtual modifiers definition for key %s\n", |
| 1087 |
stmt_type_to_string(value->common.type), |
| 1088 |
KeyInfoText(info, keyi)); |
| 1089 |
return false; |
| 1090 |
} |
| 1091 |
|
| 1092 |
keyi->vmodmap = mask; |
| 1093 |
keyi->defined |= KEY_FIELD_VMODMAP; |
| 1094 |
} |
| 1095 |
else if (istreq(field, "locking") || |
| 1096 |
istreq(field, "lock") || |
| 1097 |
istreq(field, "locks")) { |
| 1098 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_BRIEF, |
| 1099 |
XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1100 |
"Key behaviors not supported; " |
| 1101 |
"Ignoring locking specification for key %s\n", |
| 1102 |
KeyInfoText(info, keyi)); |
| 1103 |
} |
| 1104 |
else if (istreq(field, "radiogroup") || |
| 1105 |
istreq(field, "permanentradiogroup") || |
| 1106 |
istreq(field, "allownone")) { |
| 1107 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_BRIEF, |
| 1108 |
XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1109 |
"Radio groups not supported; " |
| 1110 |
"Ignoring radio group specification for key %s\n", |
| 1111 |
KeyInfoText(info, keyi)); |
| 1112 |
} |
| 1113 |
else if (istreq_prefix("overlay", field) || |
| 1114 |
istreq_prefix("permanentoverlay", field)) { |
| 1115 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_BRIEF, |
| 1116 |
XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1117 |
"Overlays not supported; " |
| 1118 |
"Ignoring overlay specification for key %s\n", |
| 1119 |
KeyInfoText(info, keyi)); |
| 1120 |
} |
| 1121 |
else if (istreq(field, "repeating") || |
| 1122 |
istreq(field, "repeats") || |
| 1123 |
istreq(field, "repeat")) { |
| 1124 |
uint32_t val = 0; |
| 1125 |
|
| 1126 |
if (!ExprResolveEnum(info->ctx, value, &val, repeatEntries)) { |
| 1127 |
log_err(info->ctx, XKB_ERROR_INVALID_VALUE, |
| 1128 |
"Illegal repeat setting for %s; " |
| 1129 |
"Non-boolean repeat setting ignored\n", |
| 1130 |
KeyInfoText(info, keyi)); |
| 1131 |
return false; |
| 1132 |
} |
| 1133 |
|
| 1134 |
keyi->repeat = (enum key_repeat) val; |
| 1135 |
keyi->defined |= KEY_FIELD_REPEAT; |
| 1136 |
} |
| 1137 |
else if (istreq(field, "groupswrap") || |
| 1138 |
istreq(field, "wrapgroups")) { |
| 1139 |
bool set = false; |
| 1140 |
|
| 1141 |
if (!ExprResolveBoolean(info->ctx, value, &set)) { |
| 1142 |
log_err(info->ctx, XKB_ERROR_INVALID_VALUE, |
| 1143 |
"Illegal groupsWrap setting for %s; " |
| 1144 |
"Non-boolean value ignored\n", |
| 1145 |
KeyInfoText(info, keyi)); |
| 1146 |
return false; |
| 1147 |
} |
| 1148 |
|
| 1149 |
keyi->out_of_range_group_action = (set ? RANGE_WRAP : RANGE_SATURATE); |
| 1150 |
keyi->defined |= KEY_FIELD_GROUPINFO; |
| 1151 |
} |
| 1152 |
else if (istreq(field, "groupsclamp") || |
| 1153 |
istreq(field, "clampgroups")) { |
| 1154 |
bool set = false; |
| 1155 |
|
| 1156 |
if (!ExprResolveBoolean(info->ctx, value, &set)) { |
| 1157 |
log_err(info->ctx, XKB_ERROR_INVALID_VALUE, |
| 1158 |
"Illegal groupsClamp setting for %s; " |
| 1159 |
"Non-boolean value ignored\n", |
| 1160 |
KeyInfoText(info, keyi)); |
| 1161 |
return false; |
| 1162 |
} |
| 1163 |
|
| 1164 |
keyi->out_of_range_group_action = (set ? RANGE_SATURATE : RANGE_WRAP); |
| 1165 |
keyi->defined |= KEY_FIELD_GROUPINFO; |
| 1166 |
} |
| 1167 |
else if (istreq(field, "groupsredirect") || |
| 1168 |
istreq(field, "redirectgroups")) { |
| 1169 |
xkb_layout_index_t grp = 0; |
| 1170 |
|
| 1171 |
if (!ExprResolveGroup(info->ctx, info->max_groups, value, &grp)) { |
| 1172 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 1173 |
"Illegal group index for redirect of key %s; " |
| 1174 |
"Definition with non-integer group ignored\n", |
| 1175 |
KeyInfoText(info, keyi)); |
| 1176 |
return false; |
| 1177 |
} |
| 1178 |
|
| 1179 |
keyi->out_of_range_group_action = RANGE_REDIRECT; |
| 1180 |
keyi->out_of_range_group_number = grp - 1; |
| 1181 |
keyi->defined |= KEY_FIELD_GROUPINFO; |
| 1182 |
} |
| 1183 |
else { |
| 1184 |
log_err(info->ctx, XKB_ERROR_UNKNOWN_FIELD, |
| 1185 |
"Unknown field \"%s\" in a symbol interpretation; " |
| 1186 |
"Definition ignored\n", |
| 1187 |
field); |
| 1188 |
return false; |
| 1189 |
} |
| 1190 |
|
| 1191 |
return true; |
| 1192 |
} |
| 1193 |
|
| 1194 |
static bool |
| 1195 |
SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value, |
| 1196 |
enum merge_mode merge) |
| 1197 |
{ |
| 1198 |
if (!arrayNdx) { |
| 1199 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_BRIEF, |
| 1200 |
XKB_WARNING_MISSING_SYMBOLS_GROUP_NAME_INDEX, |
| 1201 |
"You must specify an index when specifying a group name; " |
| 1202 |
"Group name definition without array subscript ignored\n"); |
| 1203 |
return false; |
| 1204 |
} |
| 1205 |
|
| 1206 |
xkb_layout_index_t group = 0; |
| 1207 |
if (!ExprResolveGroup(info->ctx, info->max_groups, arrayNdx, &group)) { |
| 1208 |
log_err(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, |
| 1209 |
"Illegal index in group name definition; " |
| 1210 |
"Definition with non-integer array index ignored\n"); |
| 1211 |
return false; |
| 1212 |
} |
| 1213 |
|
| 1214 |
xkb_atom_t name = XKB_ATOM_NONE; |
| 1215 |
if (!ExprResolveString(info->ctx, value, &name)) { |
| 1216 |
log_err(info->ctx, XKB_ERROR_WRONG_FIELD_TYPE, |
| 1217 |
"Group name must be a string; " |
| 1218 |
"Illegal name for group %"PRIu32" ignored\n", group); |
| 1219 |
return false; |
| 1220 |
} |
| 1221 |
|
| 1222 |
xkb_layout_index_t group_to_use; |
| 1223 |
if (info->explicit_group == XKB_LAYOUT_INVALID) { |
| 1224 |
group_to_use = group - 1; |
| 1225 |
} |
| 1226 |
else if (group - 1 == 0) { |
| 1227 |
group_to_use = info->explicit_group; |
| 1228 |
} |
| 1229 |
else { |
| 1230 |
log_warn(info->ctx, XKB_WARNING_NON_BASE_GROUP_NAME, |
| 1231 |
"An explicit group was specified for the '%s' map, " |
| 1232 |
"but it provides a name for a group other than Group1 " |
| 1233 |
"(%"PRIu32"); Ignoring group name '%s'\n", |
| 1234 |
info->name, group, |
| 1235 |
xkb_atom_text(info->ctx, name)); |
| 1236 |
return false; |
| 1237 |
} |
| 1238 |
|
| 1239 |
if (group_to_use >= darray_size(info->group_names)) { |
| 1240 |
/* Avoid clang-tidy false positive */ |
| 1241 |
assert(darray_size(info->group_names) < group_to_use + 1); |
| 1242 |
darray_resize0(info->group_names, group_to_use + 1); |
| 1243 |
} else { |
| 1244 |
const xkb_atom_t old_name = darray_item(info->group_names, group_to_use); |
| 1245 |
if (old_name != XKB_ATOM_NONE && old_name != name) { |
| 1246 |
const bool replace = (merge != MERGE_AUGMENT); |
| 1247 |
const xkb_atom_t use = (replace ? name : old_name); |
| 1248 |
const xkb_atom_t ignore = (replace ? old_name : name); |
| 1249 |
log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID, |
| 1250 |
"Multiple definitions of group %"PRIu32" name " |
| 1251 |
"in map '%s'; Using '%s', ignoring '%s'\n", |
| 1252 |
group_to_use, info->name, |
| 1253 |
xkb_atom_text(info->ctx, use), |
| 1254 |
xkb_atom_text(info->ctx, ignore)); |
| 1255 |
name = use; |
| 1256 |
} |
| 1257 |
} |
| 1258 |
darray_item(info->group_names, group_to_use) = name; |
| 1259 |
|
| 1260 |
return true; |
| 1261 |
} |
| 1262 |
|
| 1263 |
static bool |
| 1264 |
HandleGlobalVar(SymbolsInfo *info, VarDef *stmt) |
| 1265 |
{ |
| 1266 |
const char *elem, *field; |
| 1267 |
ExprDef *arrayNdx; |
| 1268 |
bool ret; |
| 1269 |
|
| 1270 |
if (!ExprResolveLhs(info->ctx, stmt->name, &elem, &field, &arrayNdx)) |
| 1271 |
return false; |
| 1272 |
|
| 1273 |
if (elem && istreq(elem, "key")) { |
| 1274 |
KeyInfo temp = {0}; |
| 1275 |
InitKeyInfo(info->ctx, &temp); |
| 1276 |
/* Do not replace the whole key, only the current field */ |
| 1277 |
temp.merge = (temp.merge == MERGE_REPLACE) |
| 1278 |
? MERGE_OVERRIDE |
| 1279 |
: stmt->merge; |
| 1280 |
ret = SetSymbolsField(info, &temp, field, arrayNdx, stmt->value); |
| 1281 |
MergeKeys(info, &info->default_key, &temp, true); |
| 1282 |
} |
| 1283 |
else if (!elem && (istreq(field, "name") || |
| 1284 |
istreq(field, "groupname"))) { |
| 1285 |
ret = SetGroupName(info, arrayNdx, stmt->value, stmt->merge); |
| 1286 |
} |
| 1287 |
else if (!elem && (istreq(field, "groupswrap") || |
| 1288 |
istreq(field, "wrapgroups"))) { |
| 1289 |
log_err(info->ctx, XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1290 |
"Global \"groupswrap\" not supported; Ignored\n"); |
| 1291 |
ret = true; |
| 1292 |
} |
| 1293 |
else if (!elem && (istreq(field, "groupsclamp") || |
| 1294 |
istreq(field, "clampgroups"))) { |
| 1295 |
log_err(info->ctx, XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1296 |
"Global \"groupsclamp\" not supported; Ignored\n"); |
| 1297 |
ret = true; |
| 1298 |
} |
| 1299 |
else if (!elem && (istreq(field, "groupsredirect") || |
| 1300 |
istreq(field, "redirectgroups"))) { |
| 1301 |
log_err(info->ctx, XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1302 |
"Global \"groupsredirect\" not supported; Ignored\n"); |
| 1303 |
ret = true; |
| 1304 |
} |
| 1305 |
else if (!elem && istreq(field, "allownone")) { |
| 1306 |
log_err(info->ctx, XKB_WARNING_UNSUPPORTED_SYMBOLS_FIELD, |
| 1307 |
"Radio groups not supported; " |
| 1308 |
"Ignoring \"allownone\" specification\n"); |
| 1309 |
ret = true; |
| 1310 |
} |
| 1311 |
else if (elem) { |
| 1312 |
ret = SetDefaultActionField(info->ctx, info->keymap->format, |
| 1313 |
&info->default_actions, |
| 1314 |
&info->mods, elem, field, arrayNdx, |
| 1315 |
stmt->value, stmt->merge); |
| 1316 |
} else { |
| 1317 |
log_err(info->ctx, XKB_ERROR_UNKNOWN_DEFAULT_FIELD, |
| 1318 |
"Default defined for unknown field \"%s\"; Ignored\n", field); |
| 1319 |
return false; |
| 1320 |
} |
| 1321 |
|
| 1322 |
return ret; |
| 1323 |
} |
| 1324 |
|
| 1325 |
static bool |
| 1326 |
HandleSymbolsBody(SymbolsInfo *info, VarDef *def, KeyInfo *keyi) |
| 1327 |
{ |
| 1328 |
if (!def) |
| 1329 |
return true; /* Empty body */ |
| 1330 |
|
| 1331 |
bool all_valid_entries = true; |
| 1332 |
|
| 1333 |
for (; def; def = (VarDef *) def->common.next) { |
| 1334 |
const char *field; |
| 1335 |
ExprDef *arrayNdx; |
| 1336 |
bool ok = true; |
| 1337 |
|
| 1338 |
if (!def->name) { |
| 1339 |
if (unlikely(!def->value) || def->value->common.type != STMT_EXPR_ACTION_LIST) |
| 1340 |
field = "symbols"; /* Default to symbols field */ |
| 1341 |
else |
| 1342 |
field = "actions"; |
| 1343 |
arrayNdx = NULL; |
| 1344 |
} |
| 1345 |
else { |
| 1346 |
const char *elem; |
| 1347 |
ok = ExprResolveLhs(info->ctx, def->name, &elem, &field, |
| 1348 |
&arrayNdx); |
| 1349 |
if (ok && elem) { |
| 1350 |
log_err(info->ctx, XKB_ERROR_GLOBAL_DEFAULTS_WRONG_SCOPE, |
| 1351 |
"Cannot set global defaults for \"%s\" element within " |
| 1352 |
"a key statement: move statements to the global file " |
| 1353 |
"scope. Assignment to \"%s.%s\" ignored.\n", |
| 1354 |
elem, elem, field); |
| 1355 |
ok = false; |
| 1356 |
} |
| 1357 |
} |
| 1358 |
|
| 1359 |
if (unlikely(!def->value)) { |
| 1360 |
log_err(info->ctx, XKB_ERROR_ALLOCATION_ERROR, |
| 1361 |
"Could not allocate the value of field \"%s\". " |
| 1362 |
"Statement ignored.\n", field); |
| 1363 |
ok = false; |
| 1364 |
} |
| 1365 |
|
| 1366 |
if (!ok || !SetSymbolsField(info, keyi, field, arrayNdx, def->value)) |
| 1367 |
all_valid_entries = false; |
| 1368 |
} |
| 1369 |
|
| 1370 |
return all_valid_entries; |
| 1371 |
} |
| 1372 |
|
| 1373 |
static bool |
| 1374 |
SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi) |
| 1375 |
{ |
| 1376 |
xkb_layout_index_t i; |
| 1377 |
GroupInfo *groupi; |
| 1378 |
bool warn = false; |
| 1379 |
|
| 1380 |
if (info->explicit_group == XKB_LAYOUT_INVALID) |
| 1381 |
return true; |
| 1382 |
|
| 1383 |
darray_enumerate_from(i, groupi, keyi->groups, 1) { |
| 1384 |
if (groupi->defined) { |
| 1385 |
warn = true; |
| 1386 |
ClearGroupInfo(groupi); |
| 1387 |
InitGroupInfo(groupi); |
| 1388 |
} |
| 1389 |
} |
| 1390 |
|
| 1391 |
if (warn) { |
| 1392 |
log_warn(info->ctx, XKB_WARNING_MULTIPLE_GROUPS_AT_ONCE, |
| 1393 |
"For the map %s the explicit group %"PRIu32" is specified, " |
| 1394 |
"but key %s has more than one group defined; " |
| 1395 |
"All groups except first one will be ignored\n", |
| 1396 |
info->name, info->explicit_group + 1, KeyInfoText(info, keyi)); |
| 1397 |
} |
| 1398 |
|
| 1399 |
darray_resize0(keyi->groups, info->explicit_group + 1); |
| 1400 |
if (info->explicit_group > 0) { |
| 1401 |
darray_item(keyi->groups, info->explicit_group) = |
| 1402 |
darray_item(keyi->groups, 0); |
| 1403 |
InitGroupInfo(&darray_item(keyi->groups, 0)); |
| 1404 |
} |
| 1405 |
|
| 1406 |
return true; |
| 1407 |
} |
| 1408 |
|
| 1409 |
static bool |
| 1410 |
HandleSymbolsDef(SymbolsInfo *info, SymbolsDef *stmt) |
| 1411 |
{ |
| 1412 |
KeyInfo keyi; |
| 1413 |
|
| 1414 |
keyi = info->default_key; |
| 1415 |
darray_init(keyi.groups); |
| 1416 |
darray_copy(keyi.groups, info->default_key.groups); |
| 1417 |
for (xkb_layout_index_t i = 0; i < darray_size(keyi.groups); i++) |
| 1418 |
CopyGroupInfo(&darray_item(keyi.groups, i), |
| 1419 |
&darray_item(info->default_key.groups, i)); |
| 1420 |
keyi.merge = stmt->merge; |
| 1421 |
keyi.name = stmt->keyName; |
| 1422 |
|
| 1423 |
if (HandleSymbolsBody(info, stmt->symbols, &keyi) && |
| 1424 |
SetExplicitGroup(info, &keyi) && |
| 1425 |
AddKeySymbols(info, &keyi, true)) { |
| 1426 |
return true; |
| 1427 |
} |
| 1428 |
|
| 1429 |
ClearKeyInfo(&keyi); |
| 1430 |
info->errorCount++; |
| 1431 |
return false; |
| 1432 |
} |
| 1433 |
|
| 1434 |
static bool |
| 1435 |
HandleModMapDef(SymbolsInfo *info, ModMapDef *def) |
| 1436 |
{ |
| 1437 |
ModMapEntry tmp; |
| 1438 |
xkb_mod_index_t ndx; |
| 1439 |
bool ok; |
| 1440 |
struct xkb_context *ctx = info->ctx; |
| 1441 |
const char *modifier_name = xkb_atom_text(ctx, def->modifier); |
| 1442 |
|
| 1443 |
if (istreq(modifier_name, "none")) { |
| 1444 |
/* Handle special "None" entry */ |
| 1445 |
ndx = XKB_MOD_NONE; |
| 1446 |
} else { |
| 1447 |
/* Handle normal entry */ |
| 1448 |
ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL); |
| 1449 |
if (ndx == XKB_MOD_INVALID) { |
| 1450 |
log_err(info->ctx, XKB_ERROR_INVALID_REAL_MODIFIER, |
| 1451 |
"Illegal modifier map definition; " |
| 1452 |
"Ignoring map for non-modifier \"%s\"\n", |
| 1453 |
xkb_atom_text(ctx, def->modifier)); |
| 1454 |
return false; |
| 1455 |
} |
| 1456 |
} |
| 1457 |
|
| 1458 |
ok = true; |
| 1459 |
tmp.modifier = ndx; |
| 1460 |
tmp.merge = def->merge; |
| 1461 |
|
| 1462 |
for (ExprDef *key = def->keys; key; key = (ExprDef *) key->common.next) { |
| 1463 |
if (key->common.type == STMT_EXPR_KEYNAME_LITERAL) { |
| 1464 |
tmp.haveSymbol = false; |
| 1465 |
tmp.u.keyName = key->key_name.key_name; |
| 1466 |
} |
| 1467 |
else if (key->common.type == STMT_EXPR_KEYSYM_LITERAL) { |
| 1468 |
if (key->keysym.keysym == XKB_KEY_NoSymbol) { |
| 1469 |
/* Invalid keysym: ignore. Error message already printed */ |
| 1470 |
continue; |
| 1471 |
} else { |
| 1472 |
tmp.haveSymbol = true; |
| 1473 |
tmp.u.keySym = key->keysym.keysym; |
| 1474 |
} |
| 1475 |
} |
| 1476 |
else { |
| 1477 |
log_err(info->ctx, XKB_ERROR_INVALID_MODMAP_ENTRY, |
| 1478 |
"Modmap entries may contain only key names or keysyms; " |
| 1479 |
"Illegal definition for %s modifier ignored\n", |
| 1480 |
ModIndexText(info->ctx, &info->mods, tmp.modifier)); |
| 1481 |
continue; |
| 1482 |
} |
| 1483 |
|
| 1484 |
ok = AddModMapEntry(info, &tmp) && ok; |
| 1485 |
} |
| 1486 |
return ok; |
| 1487 |
} |
| 1488 |
|
| 1489 |
static void |
| 1490 |
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file) |
| 1491 |
{ |
| 1492 |
bool ok; |
| 1493 |
|
| 1494 |
free(info->name); |
| 1495 |
info->name = strdup_safe(file->name); |
| 1496 |
|
| 1497 |
for (ParseCommon *stmt = file->defs; stmt; stmt = stmt->next) { |
| 1498 |
switch (stmt->type) { |
| 1499 |
case STMT_INCLUDE: |
| 1500 |
ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt); |
| 1501 |
break; |
| 1502 |
case STMT_SYMBOLS: |
| 1503 |
ok = HandleSymbolsDef(info, (SymbolsDef *) stmt); |
| 1504 |
break; |
| 1505 |
case STMT_VAR: |
| 1506 |
ok = HandleGlobalVar(info, (VarDef *) stmt); |
| 1507 |
break; |
| 1508 |
case STMT_VMOD: |
| 1509 |
ok = HandleVModDef(info->ctx, &info->mods, (VModDef *) stmt); |
| 1510 |
break; |
| 1511 |
case STMT_MODMAP: |
| 1512 |
ok = HandleModMapDef(info, (ModMapDef *) stmt); |
| 1513 |
break; |
| 1514 |
default: |
| 1515 |
log_err(info->ctx, XKB_ERROR_WRONG_STATEMENT_TYPE, |
| 1516 |
"Symbols files may not include other types; " |
| 1517 |
"Ignoring %s\n", stmt_type_to_string(stmt->type)); |
| 1518 |
ok = false; |
| 1519 |
break; |
| 1520 |
} |
| 1521 |
|
| 1522 |
if (!ok) |
| 1523 |
info->errorCount++; |
| 1524 |
|
| 1525 |
if (info->errorCount > 10) { |
| 1526 |
log_err(info->ctx, XKB_ERROR_INVALID_XKB_SYNTAX, |
| 1527 |
"Abandoning symbols file \"%s\"\n", |
| 1528 |
safe_map_name(file)); |
| 1529 |
break; |
| 1530 |
} |
| 1531 |
} |
| 1532 |
} |
| 1533 |
|
| 1534 |
/** |
| 1535 |
* Given a keysym @sym, return a key which generates it, or NULL. |
| 1536 |
* This is used for example in a modifier map definition, such as: |
| 1537 |
* modifier_map Lock { Caps_Lock }; |
| 1538 |
* where we want to add the Lock modifier to the modmap of the key |
| 1539 |
* which matches the keysym Caps_Lock. |
| 1540 |
* Since there can be many keys which generates the keysym, the key |
| 1541 |
* is chosen first by lowest group in which the keysym appears, than |
| 1542 |
* by lowest level and than by lowest key code. |
| 1543 |
*/ |
| 1544 |
static struct xkb_key * |
| 1545 |
FindKeyForSymbol(struct xkb_keymap *keymap, xkb_keysym_t sym) |
| 1546 |
{ |
| 1547 |
bool got_one_group; |
| 1548 |
xkb_layout_index_t group = 0; |
| 1549 |
do { |
| 1550 |
xkb_level_index_t level = 0; |
| 1551 |
got_one_group = false; |
| 1552 |
bool got_one_level; |
| 1553 |
do { |
| 1554 |
got_one_level = false; |
| 1555 |
struct xkb_key *key; |
| 1556 |
xkb_keys_foreach(key, keymap) { |
| 1557 |
if (group < key->num_groups && |
| 1558 |
level < XkbKeyNumLevels(key, group)) { |
| 1559 |
got_one_group = got_one_level = true; |
| 1560 |
const xkb_keysym_count_t num_syms = |
| 1561 |
key->groups[group].levels[level].num_syms; |
| 1562 |
if (num_syms > 1) { |
| 1563 |
for (xkb_keysym_count_t k = 0; k < num_syms; k++) { |
| 1564 |
if (key->groups[group].levels[level].s.syms[k] == sym) |
| 1565 |
return key; |
| 1566 |
} |
| 1567 |
} else if (num_syms && |
| 1568 |
key->groups[group].levels[level].s.sym == sym) { |
| 1569 |
return key; |
| 1570 |
} |
| 1571 |
} |
| 1572 |
} |
| 1573 |
level++; |
| 1574 |
} while (got_one_level); |
| 1575 |
group++; |
| 1576 |
} while (got_one_group); |
| 1577 |
|
| 1578 |
return NULL; |
| 1579 |
} |
| 1580 |
|
| 1581 |
/* |
| 1582 |
* Find an appropriate type for a group and return its name. |
| 1583 |
* |
| 1584 |
* Simple recipe: |
| 1585 |
* - ONE_LEVEL for width 0/1 |
| 1586 |
* - ALPHABETIC for 2 shift levels, with lower/upercase keysyms |
| 1587 |
* - KEYPAD for keypad keys. |
| 1588 |
* - TWO_LEVEL for other 2 shift level keys. |
| 1589 |
* and the same for four level keys. |
| 1590 |
* |
| 1591 |
* FIXME: Decide how to handle multiple-syms-per-level, and do it. |
| 1592 |
*/ |
| 1593 |
static xkb_atom_t |
| 1594 |
FindAutomaticType(struct xkb_context *ctx, GroupInfo *groupi) |
| 1595 |
{ |
| 1596 |
xkb_keysym_t sym0, sym1; |
| 1597 |
const xkb_level_index_t width = darray_size(groupi->levels); |
| 1598 |
|
| 1599 |
#define GET_SYM(level) \ |
| 1600 |
(darray_item(groupi->levels, level).num_syms == 0 ? \ |
| 1601 |
XKB_KEY_NoSymbol : \ |
| 1602 |
darray_item(groupi->levels, level).num_syms == 1 ? \ |
| 1603 |
darray_item(groupi->levels, level).s.sym : \ |
| 1604 |
/* num_syms > 1 */ \ |
| 1605 |
darray_item(groupi->levels, level).s.syms[0]) |
| 1606 |
|
| 1607 |
if (width == 1 || width <= 0) |
| 1608 |
return xkb_atom_intern_literal(ctx, "ONE_LEVEL"); |
| 1609 |
|
| 1610 |
sym0 = GET_SYM(0); |
| 1611 |
sym1 = GET_SYM(1); |
| 1612 |
|
| 1613 |
if (width == 2) { |
| 1614 |
if (xkb_keysym_is_lower(sym0) && xkb_keysym_is_upper_or_title(sym1)) |
| 1615 |
return xkb_atom_intern_literal(ctx, "ALPHABETIC"); |
| 1616 |
|
| 1617 |
if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1)) |
| 1618 |
return xkb_atom_intern_literal(ctx, "KEYPAD"); |
| 1619 |
|
| 1620 |
return xkb_atom_intern_literal(ctx, "TWO_LEVEL"); |
| 1621 |
} |
| 1622 |
|
| 1623 |
if (width <= 4) { |
| 1624 |
if (xkb_keysym_is_lower(sym0) && xkb_keysym_is_upper_or_title(sym1)) { |
| 1625 |
xkb_keysym_t sym2, sym3; |
| 1626 |
sym2 = GET_SYM(2); |
| 1627 |
sym3 = (width == 4 ? GET_SYM(3) : XKB_KEY_NoSymbol); |
| 1628 |
|
| 1629 |
if (xkb_keysym_is_lower(sym2) && xkb_keysym_is_upper_or_title(sym3)) |
| 1630 |
return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_ALPHABETIC"); |
| 1631 |
|
| 1632 |
return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_SEMIALPHABETIC"); |
| 1633 |
} |
| 1634 |
|
| 1635 |
if (xkb_keysym_is_keypad(sym0) || xkb_keysym_is_keypad(sym1)) |
| 1636 |
return xkb_atom_intern_literal(ctx, "FOUR_LEVEL_KEYPAD"); |
| 1637 |
|
| 1638 |
return xkb_atom_intern_literal(ctx, "FOUR_LEVEL"); |
| 1639 |
} |
| 1640 |
|
| 1641 |
return XKB_ATOM_NONE; |
| 1642 |
|
| 1643 |
#undef GET_SYM |
| 1644 |
} |
| 1645 |
|
| 1646 |
static const struct xkb_key_type * |
| 1647 |
FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi, |
| 1648 |
xkb_layout_index_t group, bool *explicit_type) |
| 1649 |
{ |
| 1650 |
GroupInfo *groupi = &darray_item(keyi->groups, group); |
| 1651 |
xkb_atom_t type_name = groupi->type; |
| 1652 |
|
| 1653 |
*explicit_type = true; |
| 1654 |
|
| 1655 |
if (type_name == XKB_ATOM_NONE) { |
| 1656 |
if (keyi->default_type != XKB_ATOM_NONE) { |
| 1657 |
type_name = keyi->default_type; |
| 1658 |
} |
| 1659 |
else { |
| 1660 |
type_name = FindAutomaticType(keymap->ctx, groupi); |
| 1661 |
if (type_name != XKB_ATOM_NONE) |
| 1662 |
*explicit_type = false; |
| 1663 |
} |
| 1664 |
} |
| 1665 |
|
| 1666 |
if (type_name == XKB_ATOM_NONE) { |
| 1667 |
log_warn(keymap->ctx, XKB_WARNING_CANNOT_INFER_KEY_TYPE, |
| 1668 |
"Couldn't find an automatic type for key '%s' " |
| 1669 |
"group %"PRIu32" with %u levels; Using the default type\n", |
| 1670 |
KeyNameText(keymap->ctx, keyi->name), group + 1, |
| 1671 |
darray_size(groupi->levels)); |
| 1672 |
goto use_default; |
| 1673 |
} |
| 1674 |
|
| 1675 |
darray_size_t i; |
| 1676 |
for (i = 0; i < keymap->num_types; i++) |
| 1677 |
if (keymap->types[i].name == type_name) |
| 1678 |
break; |
| 1679 |
|
| 1680 |
if (i >= keymap->num_types) { |
| 1681 |
log_warn(keymap->ctx, XKB_WARNING_UNDEFINED_KEY_TYPE, |
| 1682 |
"The type \"%s\" for key '%s' group %"PRIu32" " |
| 1683 |
"was not previously defined; Using the default type\n", |
| 1684 |
xkb_atom_text(keymap->ctx, type_name), |
| 1685 |
KeyNameText(keymap->ctx, keyi->name), group + 1); |
| 1686 |
goto use_default; |
| 1687 |
} |
| 1688 |
|
| 1689 |
keymap->types[i].required = true; |
| 1690 |
return &keymap->types[i]; |
| 1691 |
|
| 1692 |
use_default: |
| 1693 |
/* |
| 1694 |
* Index 0 is guaranteed to contain something, usually |
| 1695 |
* ONE_LEVEL or at least some default one-level type. |
| 1696 |
*/ |
| 1697 |
keymap->types[0].required = true; |
| 1698 |
return &keymap->types[0]; |
| 1699 |
} |
| 1700 |
|
| 1701 |
static bool |
| 1702 |
CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, |
| 1703 |
KeyInfo *keyi) |
| 1704 |
{ |
| 1705 |
struct xkb_key *key; |
| 1706 |
GroupInfo *groupi; |
| 1707 |
const GroupInfo *group0; |
| 1708 |
xkb_layout_index_t i; |
| 1709 |
|
| 1710 |
/* |
| 1711 |
* The name is guaranteed to be real and not an alias (see |
| 1712 |
* AddKeySymbols), so 'false' is safe here. |
| 1713 |
*/ |
| 1714 |
key = XkbKeyByName(keymap, keyi->name, false); |
| 1715 |
if (!key) { |
| 1716 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_DETAILED, |
| 1717 |
XKB_WARNING_UNDEFINED_KEYCODE, |
| 1718 |
"Key %s not found in keycodes; Symbols ignored\n", |
| 1719 |
KeyInfoText(info, keyi)); |
| 1720 |
return false; |
| 1721 |
} |
| 1722 |
|
| 1723 |
/* Find the range of groups we need. */ |
| 1724 |
key->num_groups = 0; |
| 1725 |
darray_enumerate(i, groupi, keyi->groups) { |
| 1726 |
/* Skip groups that have no levels and no explicit type. |
| 1727 |
* Such group would be filled with `NoSymbol` anyway. */ |
| 1728 |
const bool has_explicit_type = (keyi->defined & KEY_FIELD_DEFAULT_TYPE) |
| 1729 |
|| (groupi->defined & GROUP_FIELD_TYPE); |
| 1730 |
if (darray_size(groupi->levels) > 0 || has_explicit_type) |
| 1731 |
key->num_groups = i + 1; |
| 1732 |
if (has_explicit_type) |
| 1733 |
key->explicit |= EXPLICIT_TYPES; |
| 1734 |
} |
| 1735 |
|
| 1736 |
if (key->num_groups <= 0) { |
| 1737 |
/* A key with no group may still have other fields defined */ |
| 1738 |
if (keyi->defined) |
| 1739 |
goto key_fields; |
| 1740 |
else |
| 1741 |
return false; |
| 1742 |
} |
| 1743 |
|
| 1744 |
darray_resize(keyi->groups, key->num_groups); |
| 1745 |
|
| 1746 |
/* |
| 1747 |
* If there are empty groups between non-empty ones, fill them with data |
| 1748 |
* from the first group. |
| 1749 |
* We can make a wrong assumption here. But leaving gaps is worse. |
| 1750 |
*/ |
| 1751 |
group0 = &darray_item(keyi->groups, 0); |
| 1752 |
darray_foreach_from(groupi, keyi->groups, 1) { |
| 1753 |
if (groupi->defined) |
| 1754 |
continue; |
| 1755 |
|
| 1756 |
CopyGroupInfo(groupi, group0); |
| 1757 |
} |
| 1758 |
|
| 1759 |
key->groups = calloc(key->num_groups, sizeof(*key->groups)); |
| 1760 |
|
| 1761 |
/* Find and assign the groups' types in the keymap. */ |
| 1762 |
darray_enumerate(i, groupi, keyi->groups) { |
| 1763 |
bool explicit_type = false; |
| 1764 |
const struct xkb_key_type * const type = |
| 1765 |
FindTypeForGroup(keymap, keyi, i, &explicit_type); |
| 1766 |
|
| 1767 |
/* Always have as many levels as the type specifies. */ |
| 1768 |
if (type->num_levels < darray_size(groupi->levels)) { |
| 1769 |
struct xkb_level *leveli; |
| 1770 |
|
| 1771 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_BRIEF, |
| 1772 |
XKB_WARNING_EXTRA_SYMBOLS_IGNORED, |
| 1773 |
"Type \"%s\" has %"PRIu32" levels, but %s has %u levels; " |
| 1774 |
"Ignoring extra symbols\n", |
| 1775 |
xkb_atom_text(keymap->ctx, type->name), type->num_levels, |
| 1776 |
KeyInfoText(info, keyi), |
| 1777 |
darray_size(groupi->levels)); |
| 1778 |
|
| 1779 |
darray_foreach_from(leveli, groupi->levels, type->num_levels) |
| 1780 |
clear_level(leveli); |
| 1781 |
} |
| 1782 |
darray_resize0(groupi->levels, type->num_levels); |
| 1783 |
|
| 1784 |
key->groups[i].explicit_type = explicit_type; |
| 1785 |
key->groups[i].type = type; |
| 1786 |
} |
| 1787 |
|
| 1788 |
/* Copy levels. */ |
| 1789 |
darray_enumerate(i, groupi, keyi->groups) { |
| 1790 |
/* |
| 1791 |
* Compute the capitalization transformation of the keysyms. |
| 1792 |
* This is necessary because `xkb_state_key_get_syms()` returns an |
| 1793 |
* immutable array and does not use a buffer, so we must store them. |
| 1794 |
* We apply only simple capitalization rules, so the keysyms count is |
| 1795 |
* unchanged. |
| 1796 |
*/ |
| 1797 |
struct xkb_level *leveli; |
| 1798 |
darray_foreach(leveli, groupi->levels) { |
| 1799 |
switch (leveli->num_syms) { |
| 1800 |
case 0: |
| 1801 |
leveli->upper = XKB_KEY_NoSymbol; |
| 1802 |
break; |
| 1803 |
case 1: |
| 1804 |
leveli->upper = xkb_keysym_to_upper(leveli->s.sym); |
| 1805 |
break; |
| 1806 |
default: |
| 1807 |
/* Multiple keysyms: check if there is any cased keysym */ |
| 1808 |
leveli->has_upper = false; |
| 1809 |
for (xkb_keysym_count_t k = 0; k < leveli->num_syms; k++) { |
| 1810 |
const xkb_keysym_t upper = |
| 1811 |
xkb_keysym_to_upper(leveli->s.syms[k]); |
| 1812 |
if (upper != leveli->s.syms[k]) { |
| 1813 |
leveli->has_upper = true; |
| 1814 |
break; |
| 1815 |
} |
| 1816 |
} |
| 1817 |
if (leveli->has_upper) { |
| 1818 |
/* |
| 1819 |
* Some cased keysyms: store the transformation result in |
| 1820 |
* the same array, right after the original keysyms. |
| 1821 |
*/ |
| 1822 |
leveli->s.syms = realloc(leveli->s.syms, |
| 1823 |
(size_t) 2 * leveli->num_syms * |
| 1824 |
sizeof(*leveli->s.syms)); |
| 1825 |
if (!leveli->s.syms) |
| 1826 |
return false; /* FIXME: better handling? */ |
| 1827 |
for (xkb_keysym_count_t k = 0; k < leveli->num_syms; k++) { |
| 1828 |
leveli->s.syms[leveli->num_syms + k] = |
| 1829 |
xkb_keysym_to_upper(leveli->s.syms[k]); |
| 1830 |
} |
| 1831 |
} |
| 1832 |
} |
| 1833 |
} |
| 1834 |
|
| 1835 |
/* Copy the level */ |
| 1836 |
darray_steal(groupi->levels, &key->groups[i].levels, NULL); |
| 1837 |
if (key->groups[i].type->num_levels > 1 || |
| 1838 |
key->groups[i].levels[0].num_syms > 0) |
| 1839 |
key->explicit |= EXPLICIT_SYMBOLS; |
| 1840 |
if (groupi->defined & GROUP_FIELD_ACTS) { // FIXME |
| 1841 |
key->groups[i].explicit_actions = true; |
| 1842 |
key->explicit |= EXPLICIT_INTERP; |
| 1843 |
} |
| 1844 |
if (key->groups[i].explicit_type) |
| 1845 |
key->explicit |= EXPLICIT_TYPES; |
| 1846 |
} |
| 1847 |
|
| 1848 |
key->out_of_range_group_number = keyi->out_of_range_group_number; |
| 1849 |
key->out_of_range_group_action = keyi->out_of_range_group_action; |
| 1850 |
|
| 1851 |
key_fields: |
| 1852 |
if (keyi->defined & KEY_FIELD_VMODMAP) { |
| 1853 |
key->vmodmap = keyi->vmodmap; |
| 1854 |
key->explicit |= EXPLICIT_VMODMAP; |
| 1855 |
} |
| 1856 |
|
| 1857 |
if (keyi->repeat != KEY_REPEAT_UNDEFINED) { |
| 1858 |
key->repeats = (keyi->repeat == KEY_REPEAT_YES); |
| 1859 |
key->explicit |= EXPLICIT_REPEAT; |
| 1860 |
} |
| 1861 |
|
| 1862 |
return true; |
| 1863 |
} |
| 1864 |
|
| 1865 |
static bool |
| 1866 |
CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, |
| 1867 |
ModMapEntry *entry) |
| 1868 |
{ |
| 1869 |
struct xkb_key *key; |
| 1870 |
|
| 1871 |
if (!entry->haveSymbol) { |
| 1872 |
key = XkbKeyByName(keymap, entry->u.keyName, true); |
| 1873 |
if (!key) { |
| 1874 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_DETAILED, |
| 1875 |
XKB_WARNING_UNDEFINED_KEYCODE, |
| 1876 |
"Key %s not found in keycodes; " |
| 1877 |
"Modifier map entry for %s not updated\n", |
| 1878 |
KeyNameText(info->ctx, entry->u.keyName), |
| 1879 |
ModIndexText(info->ctx, &info->mods, entry->modifier)); |
| 1880 |
return false; |
| 1881 |
} |
| 1882 |
} |
| 1883 |
else { |
| 1884 |
key = FindKeyForSymbol(keymap, entry->u.keySym); |
| 1885 |
if (!key) { |
| 1886 |
log_vrb(info->ctx, XKB_LOG_VERBOSITY_DETAILED, |
| 1887 |
XKB_WARNING_UNRESOLVED_KEYMAP_SYMBOL, |
| 1888 |
"Key \"%s\" not found in symbol map; " |
| 1889 |
"Modifier map entry for %s not updated\n", |
| 1890 |
KeysymText(info->ctx, entry->u.keySym), |
| 1891 |
ModIndexText(info->ctx, &info->mods, entry->modifier)); |
| 1892 |
return false; |
| 1893 |
} |
| 1894 |
} |
| 1895 |
|
| 1896 |
/* Skip modMap None */ |
| 1897 |
if (entry->modifier != XKB_MOD_NONE) { |
| 1898 |
/* Convert modifier index to modifier mask */ |
| 1899 |
key->modmap |= (UINT32_C(1) << entry->modifier); |
| 1900 |
} |
| 1901 |
|
| 1902 |
return true; |
| 1903 |
} |
| 1904 |
|
| 1905 |
static bool |
| 1906 |
CopySymbolsToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info) |
| 1907 |
{ |
| 1908 |
KeyInfo *keyi; |
| 1909 |
ModMapEntry *mm; |
| 1910 |
|
| 1911 |
keymap->symbols_section_name = strdup_safe(info->name); |
| 1912 |
XkbEscapeMapName(keymap->symbols_section_name); |
| 1913 |
|
| 1914 |
keymap->mods = info->mods; |
| 1915 |
|
| 1916 |
keymap->num_group_names = (xkb_layout_index_t)darray_size(info->group_names); |
| 1917 |
darray_steal(info->group_names, &keymap->group_names, NULL); |
| 1918 |
|
| 1919 |
darray_foreach(keyi, info->keys) |
| 1920 |
if (!CopySymbolsDefToKeymap(keymap, info, keyi)) |
| 1921 |
info->errorCount++; |
| 1922 |
|
| 1923 |
if (xkb_context_get_log_verbosity(keymap->ctx) > 3) { |
| 1924 |
struct xkb_key *key; |
| 1925 |
|
| 1926 |
xkb_keys_foreach(key, keymap) { |
| 1927 |
if (key->name == XKB_ATOM_NONE) |
| 1928 |
continue; |
| 1929 |
|
| 1930 |
if (key->num_groups < 1) |
| 1931 |
log_info(info->ctx, XKB_LOG_MESSAGE_NO_ID, |
| 1932 |
"No symbols defined for %s\n", |
| 1933 |
KeyNameText(info->ctx, key->name)); |
| 1934 |
} |
| 1935 |
} |
| 1936 |
|
| 1937 |
darray_foreach(mm, info->modmaps) |
| 1938 |
if (!CopyModMapDefToKeymap(keymap, info, mm)) |
| 1939 |
info->errorCount++; |
| 1940 |
|
| 1941 |
/* XXX: If we don't ignore errorCount, things break. */ |
| 1942 |
return true; |
| 1943 |
} |
| 1944 |
|
| 1945 |
bool |
| 1946 |
CompileSymbols(XkbFile *file, struct xkb_keymap *keymap) |
| 1947 |
{ |
| 1948 |
SymbolsInfo info; |
| 1949 |
|
| 1950 |
InitSymbolsInfo(&info, keymap, 0, &keymap->mods); |
| 1951 |
|
| 1952 |
if (file !=NULL) |
| 1953 |
HandleSymbolsFile(&info, file); |
| 1954 |
|
| 1955 |
if (info.errorCount != 0) |
| 1956 |
goto err_info; |
| 1957 |
|
| 1958 |
if (!CopySymbolsToKeymap(keymap, &info)) |
| 1959 |
goto err_info; |
| 1960 |
|
| 1961 |
ClearSymbolsInfo(&info); |
| 1962 |
return true; |
| 1963 |
|
| 1964 |
err_info: |
| 1965 |
ClearSymbolsInfo(&info); |
| 1966 |
return false; |
| 1967 |
} |