Split the mods, layout, leds parts of xkb_state_components Note first: This commits breaks the ABI somewhat. If an application is run against this commit without recompiling against the updated header, these break: - xkb_state_layout_*_is_active always retuns false. - xkb_state_serialize_mods always returns 0. So it might break layout switching in some applications. However, xkbcommon-compat.h provides the necessary fixes, so recompiling should work (though updating the application is even better). Split the enum to its individual components, which enables us to refer to them individually. We will use that later for reporting which components of the state have changed after update. 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 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
diff --git a/src/compat.c b/src/compat.c
index 244a723..3cc3ab3 100644
--- a/src/compat.c
+++ b/src/compat.c
@@ -29,7 +29,6 @@
#include "utils.h"
/* We don't carry any prototypes for these functions, as we #define them
-<<<<<<< HEAD
* to their newer versions so people link against those. */
#pragma GCC diagnostic ignored "-Wmissing-prototypes"
diff --git a/src/keymap-dump.c b/src/keymap-dump.c
index 357ba42..4306a7d 100644
--- a/src/keymap-dump.c
+++ b/src/keymap-dump.c
@@ -255,7 +255,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf,
xkb_atom_text(keymap->ctx, led->name));
if (led->which_groups) {
- if (led->which_groups != XKB_STATE_EFFECTIVE) {
+ if (led->which_groups != XKB_STATE_LAYOUT_EFFECTIVE) {
write_buf(buf, "\t\t\twhichGroupState= %s;\n",
IndicatorStateText(keymap->ctx, led->which_groups));
}
@@ -264,7 +264,7 @@ write_indicator_map(struct xkb_keymap *keymap, struct buf *buf,
}
if (led->which_mods) {
- if (led->which_mods != XKB_STATE_EFFECTIVE) {
+ if (led->which_mods != XKB_STATE_MODS_EFFECTIVE) {
write_buf(buf, "\t\t\twhichModState= %s;\n",
IndicatorStateText(keymap->ctx, led->which_mods));
}
diff --git a/src/state.c b/src/state.c
index 4c159fc..06e5334 100644
--- a/src/state.c
+++ b/src/state.c
@@ -114,7 +114,7 @@ get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
unsigned int i;
type = key->groups[group].type;
- active_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
+ active_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
active_mods &= type->mods.mask;
for (i = 0; i < type->num_entries; i++)
@@ -191,7 +191,7 @@ XKB_EXPORT xkb_layout_index_t
xkb_state_key_get_layout(struct xkb_state *state, xkb_keycode_t kc)
{
xkb_layout_index_t group =
- xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
+ xkb_state_serialize_layout(state, XKB_STATE_LAYOUT_EFFECTIVE);
const struct xkb_key *key = XkbKey(state->keymap, kc);
if (!key)
@@ -598,20 +598,24 @@ xkb_state_led_update_all(struct xkb_state *state)
xkb_mod_mask_t mod_mask = 0;
xkb_layout_mask_t group_mask = 0;
- if (map->which_mods & XKB_STATE_DEPRESSED)
+ if (map->which_mods & XKB_STATE_MODS_EFFECTIVE)
+ mod_mask |= state->mods;
+ if (map->which_mods & XKB_STATE_MODS_DEPRESSED)
mod_mask |= state->base_mods;
- if (map->which_mods & XKB_STATE_LATCHED)
+ if (map->which_mods & XKB_STATE_MODS_LATCHED)
mod_mask |= state->latched_mods;
- if (map->which_mods & XKB_STATE_LOCKED)
+ if (map->which_mods & XKB_STATE_MODS_LOCKED)
mod_mask |= state->locked_mods;
if (map->mods.mask & mod_mask)
state->leds |= (1 << led);
- if (map->which_groups & XKB_STATE_DEPRESSED)
+ if (map->which_groups & XKB_STATE_LAYOUT_EFFECTIVE)
+ group_mask |= (1 << state->group);
+ if (map->which_groups & XKB_STATE_LAYOUT_DEPRESSED)
group_mask |= (1 << state->base_group);
- if (map->which_groups & XKB_STATE_LATCHED)
+ if (map->which_groups & XKB_STATE_LAYOUT_LATCHED)
group_mask |= (1 << state->latched_group);
- if (map->which_groups & XKB_STATE_LOCKED)
+ if (map->which_groups & XKB_STATE_LAYOUT_LOCKED)
group_mask |= (1 << state->locked_group);
if (map->groups & group_mask)
state->leds |= (1 << led);
@@ -785,14 +789,14 @@ xkb_state_serialize_mods(struct xkb_state *state,
{
xkb_mod_mask_t ret = 0;
- if (type == XKB_STATE_EFFECTIVE)
+ if (type & XKB_STATE_MODS_EFFECTIVE)
return state->mods;
- if (type & XKB_STATE_DEPRESSED)
+ if (type & XKB_STATE_MODS_DEPRESSED)
ret |= state->base_mods;
- if (type & XKB_STATE_LATCHED)
+ if (type & XKB_STATE_MODS_LATCHED)
ret |= state->latched_mods;
- if (type & XKB_STATE_LOCKED)
+ if (type & XKB_STATE_MODS_LOCKED)
ret |= state->locked_mods;
return ret;
@@ -808,14 +812,14 @@ xkb_state_serialize_layout(struct xkb_state *state,
{
xkb_layout_index_t ret = 0;
- if (type == XKB_STATE_EFFECTIVE)
+ if (type & XKB_STATE_LAYOUT_EFFECTIVE)
return state->group;
- if (type & XKB_STATE_DEPRESSED)
+ if (type & XKB_STATE_LAYOUT_DEPRESSED)
ret += state->base_group;
- if (type & XKB_STATE_LATCHED)
+ if (type & XKB_STATE_LAYOUT_LATCHED)
ret += state->latched_group;
- if (type & XKB_STATE_LOCKED)
+ if (type & XKB_STATE_LAYOUT_LOCKED)
ret += state->locked_group;
return ret;
@@ -960,15 +964,13 @@ xkb_state_layout_index_is_active(struct xkb_state *state,
if (idx >= xkb_keymap_num_layouts(state->keymap))
return -1;
- /* Can only have one effective group. */
- if (type == XKB_STATE_EFFECTIVE)
- return state->group == idx;
-
- if (type & XKB_STATE_DEPRESSED)
+ if (type & XKB_STATE_LAYOUT_EFFECTIVE)
+ ret |= (state->group == idx);
+ if (type & XKB_STATE_LAYOUT_DEPRESSED)
ret |= (state->base_group == idx);
- if (type & XKB_STATE_LATCHED)
+ if (type & XKB_STATE_LAYOUT_LATCHED)
ret |= (state->latched_group == idx);
- if (type & XKB_STATE_LOCKED)
+ if (type & XKB_STATE_LAYOUT_LOCKED)
ret |= (state->locked_group == idx);
return ret;
diff --git a/src/text.c b/src/text.c
index cc9b0f3..bb56b12 100644
--- a/src/text.c
+++ b/src/text.c
@@ -80,22 +80,22 @@ const LookupEntry ctrlMaskNames[] = {
};
const LookupEntry modComponentMaskNames[] = {
- {"base", XKB_STATE_DEPRESSED},
- {"latched", XKB_STATE_LATCHED},
- {"locked", XKB_STATE_LOCKED},
- {"effective", XKB_STATE_EFFECTIVE},
- {"compat", XKB_STATE_EFFECTIVE},
- {"any", XKB_STATE_EFFECTIVE},
+ {"base", XKB_STATE_MODS_DEPRESSED},
+ {"latched", XKB_STATE_MODS_LATCHED},
+ {"locked", XKB_STATE_MODS_LOCKED},
+ {"effective", XKB_STATE_MODS_EFFECTIVE},
+ {"compat", XKB_STATE_MODS_EFFECTIVE},
+ {"any", XKB_STATE_MODS_EFFECTIVE},
{"none", 0},
{NULL, 0}
};
const LookupEntry groupComponentMaskNames[] = {
- {"base", XKB_STATE_DEPRESSED},
- {"latched", XKB_STATE_LATCHED},
- {"locked", XKB_STATE_LOCKED},
- {"effective", XKB_STATE_EFFECTIVE},
- {"any", XKB_STATE_EFFECTIVE},
+ {"base", XKB_STATE_LAYOUT_DEPRESSED},
+ {"latched", XKB_STATE_LAYOUT_LATCHED},
+ {"locked", XKB_STATE_LAYOUT_LOCKED},
+ {"effective", XKB_STATE_LAYOUT_EFFECTIVE},
+ {"any", XKB_STATE_LAYOUT_EFFECTIVE},
{"none", 0},
{NULL, 0}
};
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index fb654a6..ddd7583 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -1037,9 +1037,9 @@ CopyIndicatorMapDefs(CompatInfo *info)
*im = led->im;
if (im->groups != 0 && im->which_groups == 0)
- im->which_groups = XKB_STATE_EFFECTIVE;
+ im->which_groups = XKB_STATE_LAYOUT_EFFECTIVE;
if (im->mods.mods != 0 && im->which_mods == 0)
- im->which_mods = XKB_STATE_EFFECTIVE;
+ im->which_mods = XKB_STATE_MODS_EFFECTIVE;
}
}
diff --git a/test/interactive.c b/test/interactive.c
index 15442c9..333f2ff 100644
--- a/test/interactive.c
+++ b/test/interactive.c
@@ -256,7 +256,8 @@ print_keycode(struct keyboard *kbd, xkb_keycode_t keycode)
printf("groups [ ");
for (group = 0; group < xkb_keymap_num_layouts(keymap); group++) {
- if (!xkb_state_layout_index_is_active(state, group, XKB_STATE_EFFECTIVE))
+ if (xkb_state_layout_index_is_active(state, group,
+ XKB_STATE_LAYOUT_EFFECTIVE) <= 0)
continue;
printf("%s (%d) ", xkb_keymap_layout_get_name(keymap, group), group);
}
@@ -264,7 +265,8 @@ print_keycode(struct keyboard *kbd, xkb_keycode_t keycode)
printf("mods [ ");
for (mod = 0; mod < xkb_keymap_num_mods(keymap); mod++) {
- if (!xkb_state_mod_index_is_active(state, mod, XKB_STATE_EFFECTIVE))
+ if (xkb_state_mod_index_is_active(state, mod,
+ XKB_STATE_MODS_EFFECTIVE) <= 0)
continue;
if (xkb_state_mod_index_is_consumed(state, keycode, mod))
printf("-%s ", xkb_keymap_mod_get_name(keymap, mod));
diff --git a/test/state.c b/test/state.c
index cafc264..d23b94c 100644
--- a/test/state.c
+++ b/test/state.c
@@ -42,9 +42,9 @@ print_state(struct xkb_state *state)
xkb_mod_index_t mod;
xkb_led_index_t led;
- group = xkb_state_serialize_layout(state, XKB_STATE_EFFECTIVE);
- mod = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
- /* led = xkb_state_serialize_leds(state, XKB_STATE_EFFECTIVE); */
+ group = xkb_state_serialize_layout(state, XKB_STATE_LAYOUT_EFFECTIVE);
+ mod = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
+ /* led = xkb_state_serialize_leds(state, XKB_STATE_LEDS); */
if (!group && !mod /* && !led */) {
fprintf(stderr, "\tno state\n");
return;
@@ -53,32 +53,42 @@ print_state(struct xkb_state *state)
keymap = xkb_state_get_keymap(state);
for (group = 0; group < xkb_keymap_num_layouts(keymap); group++) {
- if (xkb_state_layout_index_is_active(state, group, XKB_STATE_EFFECTIVE) != 1)
+ if (xkb_state_layout_index_is_active(state, group,
+ XKB_STATE_LAYOUT_EFFECTIVE |
+ XKB_STATE_LAYOUT_DEPRESSED |
+ XKB_STATE_LAYOUT_LATCHED |
+ XKB_STATE_LAYOUT_LOCKED) <= 0)
continue;
fprintf(stderr, "\tgroup %s (%d): %s%s%s%s\n",
xkb_keymap_layout_get_name(keymap, group),
group,
- xkb_state_layout_index_is_active(state, group, XKB_STATE_EFFECTIVE) > 0 ?
+ xkb_state_layout_index_is_active(state, group, XKB_STATE_LAYOUT_EFFECTIVE) > 0 ?
"effective " : "",
- xkb_state_layout_index_is_active(state, group, XKB_STATE_DEPRESSED) > 0 ?
+ xkb_state_layout_index_is_active(state, group, XKB_STATE_LAYOUT_DEPRESSED) > 0 ?
"depressed " : "",
- xkb_state_layout_index_is_active(state, group, XKB_STATE_LATCHED) > 0 ?
+ xkb_state_layout_index_is_active(state, group, XKB_STATE_LAYOUT_LATCHED) > 0 ?
"latched " : "",
- xkb_state_layout_index_is_active(state, group, XKB_STATE_LOCKED) > 0 ?
+ xkb_state_layout_index_is_active(state, group, XKB_STATE_LAYOUT_LOCKED) > 0 ?
"locked " : "");
}
for (mod = 0; mod < xkb_keymap_num_mods(keymap); mod++) {
- if (!xkb_state_mod_index_is_active(state, mod, XKB_STATE_EFFECTIVE))
+ if (xkb_state_mod_index_is_active(state, mod,
+ XKB_STATE_MODS_EFFECTIVE |
+ XKB_STATE_MODS_DEPRESSED |
+ XKB_STATE_MODS_LATCHED |
+ XKB_STATE_MODS_LOCKED) <= 0)
continue;
- fprintf(stderr, "\tmod %s (%d): %s%s%s\n",
+ fprintf(stderr, "\tmod %s (%d): %s%s%s%s\n",
xkb_keymap_mod_get_name(keymap, mod),
mod,
- xkb_state_mod_index_is_active(state, mod, XKB_STATE_DEPRESSED) > 0 ?
+ xkb_state_mod_index_is_active(state, mod, XKB_STATE_MODS_EFFECTIVE) > 0 ?
+ "effective " : "",
+ xkb_state_mod_index_is_active(state, mod, XKB_STATE_MODS_DEPRESSED) > 0 ?
"depressed " : "",
- xkb_state_mod_index_is_active(state, mod, XKB_STATE_LATCHED) > 0 ?
+ xkb_state_mod_index_is_active(state, mod, XKB_STATE_MODS_LATCHED) > 0 ?
"latched " : "",
- xkb_state_mod_index_is_active(state, mod, XKB_STATE_LOCKED) > 0 ?
+ xkb_state_mod_index_is_active(state, mod, XKB_STATE_MODS_LOCKED) > 0 ?
"locked " : "");
}
@@ -106,31 +116,31 @@ test_update_key(struct xkb_keymap *keymap)
fprintf(stderr, "dumping state for LCtrl down:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
- XKB_STATE_DEPRESSED) > 0);
+ XKB_STATE_MODS_DEPRESSED) > 0);
/* LCtrl + RAlt down */
xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_DOWN);
fprintf(stderr, "dumping state for LCtrl + RAlt down:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
- XKB_STATE_DEPRESSED) > 0);
+ XKB_STATE_MODS_DEPRESSED) > 0);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
- XKB_STATE_DEPRESSED) > 0);
- assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
+ XKB_STATE_MODS_DEPRESSED) > 0);
+ assert(xkb_state_mod_names_are_active(state, XKB_STATE_MODS_DEPRESSED,
XKB_STATE_MATCH_ALL,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
NULL) > 0);
- assert(xkb_state_mod_indices_are_active(state, XKB_STATE_DEPRESSED,
+ assert(xkb_state_mod_indices_are_active(state, XKB_STATE_MODS_DEPRESSED,
XKB_STATE_MATCH_ALL,
xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CTRL),
xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_ALT),
XKB_MOD_INVALID) > 0);
- assert(!xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
+ assert(!xkb_state_mod_names_are_active(state, XKB_STATE_MODS_DEPRESSED,
XKB_STATE_MATCH_ALL,
XKB_MOD_NAME_ALT,
NULL) > 0);
- assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
+ assert(xkb_state_mod_names_are_active(state, XKB_STATE_MODS_DEPRESSED,
(XKB_STATE_MATCH_ANY |
XKB_STATE_MATCH_NON_EXCLUSIVE),
XKB_MOD_NAME_ALT,
@@ -141,15 +151,15 @@ test_update_key(struct xkb_keymap *keymap)
fprintf(stderr, "dumping state for RAlt down:\n");
print_state(state);
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
- XKB_STATE_EFFECTIVE) > 0);
+ XKB_STATE_MODS_EFFECTIVE) > 0);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
- XKB_STATE_DEPRESSED) > 0);
- assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
+ XKB_STATE_MODS_DEPRESSED) > 0);
+ assert(xkb_state_mod_names_are_active(state, XKB_STATE_MODS_DEPRESSED,
XKB_STATE_MATCH_ANY,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
NULL) > 0);
- assert(xkb_state_mod_names_are_active(state, XKB_STATE_LATCHED,
+ assert(xkb_state_mod_names_are_active(state, XKB_STATE_MODS_LATCHED,
XKB_STATE_MATCH_ANY,
XKB_MOD_NAME_CTRL,
XKB_MOD_NAME_ALT,
@@ -158,19 +168,19 @@ test_update_key(struct xkb_keymap *keymap)
/* none down */
xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_UP);
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
- XKB_STATE_EFFECTIVE));
+ XKB_STATE_MODS_EFFECTIVE));
/* Caps locked */
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
- XKB_STATE_DEPRESSED) > 0);
+ XKB_STATE_MODS_DEPRESSED) > 0);
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
fprintf(stderr, "dumping state for Caps Lock:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
- XKB_STATE_DEPRESSED) == 0);
+ XKB_STATE_MODS_DEPRESSED) == 0);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
- XKB_STATE_LOCKED) > 0);
+ XKB_STATE_MODS_LOCKED) > 0);
assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_CAPS) > 0);
num_syms = xkb_state_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
assert(num_syms == 1 && syms[0] == XKB_KEY_Q);
@@ -181,9 +191,9 @@ test_update_key(struct xkb_keymap *keymap)
fprintf(stderr, "dumping state for Caps Lock + Num Lock:\n");
print_state(state);
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
- XKB_STATE_LOCKED) > 0);
+ XKB_STATE_MODS_LOCKED) > 0);
assert(xkb_state_mod_name_is_active(state, "Mod2",
- XKB_STATE_LOCKED) > 0);
+ XKB_STATE_MODS_LOCKED) > 0);
num_syms = xkb_state_key_get_syms(state, KEY_KP1 + EVDEV_OFFSET, &syms);
assert(num_syms == 1 && syms[0] == XKB_KEY_KP_1);
assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_NUM) > 0);
@@ -206,7 +216,7 @@ test_update_key(struct xkb_keymap *keymap)
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
- XKB_STATE_EFFECTIVE) > 0);
+ XKB_STATE_MODS_EFFECTIVE) > 0);
assert(!xkb_state_led_name_is_active(state, XKB_LED_NAME_CAPS) > 0);
num_syms = xkb_state_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
assert(num_syms == 1 && syms[0] == XKB_KEY_q);
@@ -252,31 +262,31 @@ test_serialisation(struct xkb_keymap *keymap)
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
- base_mods = xkb_state_serialize_mods(state, XKB_STATE_DEPRESSED);
+ base_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED);
assert(base_mods == 0);
- latched_mods = xkb_state_serialize_mods(state, XKB_STATE_LATCHED);
+ latched_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED);
assert(latched_mods == 0);
- locked_mods = xkb_state_serialize_mods(state, XKB_STATE_LOCKED);
+ locked_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED);
assert(locked_mods == (1 << caps));
- effective_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
+ effective_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
assert(effective_mods == locked_mods);
xkb_state_update_key(state, KEY_LEFTSHIFT + EVDEV_OFFSET, XKB_KEY_DOWN);
- base_mods = xkb_state_serialize_mods(state, XKB_STATE_DEPRESSED);
+ base_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED);
assert(base_mods == (1 << shift));
- latched_mods = xkb_state_serialize_mods(state, XKB_STATE_LATCHED);
+ latched_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED);
assert(latched_mods == 0);
- locked_mods = xkb_state_serialize_mods(state, XKB_STATE_LOCKED);
+ locked_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED);
assert(locked_mods == (1 << caps));
- effective_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
+ effective_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
assert(effective_mods == (base_mods | locked_mods));
base_mods |= (1 << ctrl);
xkb_state_update_mask(state, base_mods, latched_mods, locked_mods,
base_group, latched_group, locked_group);
- assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_DEPRESSED));
- assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_EFFECTIVE));
+ assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_MODS_DEPRESSED));
+ assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_MODS_EFFECTIVE));
xkb_state_unref(state);
}
@@ -312,7 +322,7 @@ test_consume(struct xkb_keymap *keymap)
fprintf(stderr, "dumping state for Alt-Shift-+\n");
print_state(state);
- mask = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
+ mask = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
assert(mask == ((1 << alt) | (1 << shift)));
mask = xkb_state_mod_mask_remove_consumed(state, KEY_EQUAL + EVDEV_OFFSET,
mask);
diff --git a/xkbcommon/xkbcommon-compat.h b/xkbcommon/xkbcommon-compat.h
index 0142bca..f96e4c8 100644
--- a/xkbcommon/xkbcommon-compat.h
+++ b/xkbcommon/xkbcommon-compat.h
@@ -34,6 +34,16 @@
#define xkb_map_compile_flags xkb_keymap_compile_flags
#define XKB_GROUP_INVALID XKB_LAYOUT_INVALID
+#define XKB_STATE_DEPRESSED \
+ (XKB_STATE_MODS_DEPRESSED | XKB_STATE_LAYOUT_DEPRESSED)
+#define XKB_STATE_LATCHED \
+ (XKB_STATE_MODS_LATCHED | XKB_STATE_LAYOUT_LATCHED)
+#define XKB_STATE_LOCKED \
+ (XKB_STATE_MODS_LOCKED | XKB_STATE_LAYOUT_LOCKED)
+#define XKB_STATE_EFFECTIVE \
+ (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED | \
+ XKB_STATE_MODS_EFFECTIVE | XKB_STATE_LAYOUT_EFFECTIVE)
+
#define xkb_map_new_from_names(context, names, flags) \
xkb_keymap_new_from_names(context, names, flags)
#define xkb_map_new_from_file(context, file, format, flags) \
diff --git a/xkbcommon/xkbcommon.h b/xkbcommon/xkbcommon.h
index 6387f92..846b619 100644
--- a/xkbcommon/xkbcommon.h
+++ b/xkbcommon/xkbcommon.h
@@ -1102,22 +1102,36 @@ xkb_keymap_key_get_syms_by_level(struct xkb_keymap *keymap,
/**
* Modifier and layout types for state objects. This enum is bitmaskable,
- * e.g. (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED) is valid to exclude
- * locked modifiers.
+ * e.g. (XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_LATCHED) is valid to
+ * exclude locked modifiers.
+ *
+ * In XKB, the DEPRESSED states are also known as 'base'.
*/
enum xkb_state_component {
- /** A key holding this modifier or layout is currently physically
- * depressed; also known as 'base'. */
- XKB_STATE_DEPRESSED = (1 << 0),
- /** Modifier or layout is latched, i.e. will be unset after the next
- * non-modifier key press. */
- XKB_STATE_LATCHED = (1 << 1),
- /** Modifier or layout is locked, i.e. will be unset after the key
- * provoking the lock has been pressed again. */
- XKB_STATE_LOCKED = (1 << 2),
- /** Combinatination of depressed, latched, and locked. */
- XKB_STATE_EFFECTIVE =
- (XKB_STATE_DEPRESSED | XKB_STATE_LATCHED | XKB_STATE_LOCKED),
+ /** Depressed modifiers, i.e. a key is physically holding them. */
+ XKB_STATE_MODS_DEPRESSED = (1 << 0),
+ /** Latched modifiers, i.e. will be unset after the next non-modifier
+ * key press. */
+ XKB_STATE_MODS_LATCHED = (1 << 1),
+ /** Locked modifiers, i.e. will be unset after the key provoking the
+ * lock has been pressed again. */
+ XKB_STATE_MODS_LOCKED = (1 << 2),
+ /** Effective modifiers, i.e. currently active and affect key
+ * processing (derived from the other state components). */
+ XKB_STATE_MODS_EFFECTIVE = (1 << 3),
+ /** Depressed layout, i.e. a key is physically holding it. */
+ XKB_STATE_LAYOUT_DEPRESSED = (1 << 4),
+ /** Latched layout, i.e. will be unset after the next non-modifier
+ * key press. */
+ XKB_STATE_LAYOUT_LATCHED = (1 << 5),
+ /** Locked layout, i.e. will be unset after the key provoking the lock
+ * has been pressed again. */
+ XKB_STATE_LAYOUT_LOCKED = (1 << 6),
+ /** Effective layout, i.e. currently active and affects key processing
+ * (derived from the other state components). */
+ XKB_STATE_LAYOUT_EFFECTIVE = (1 << 7),
+ /** LEDs (derived from the other state components). */
+ XKB_STATE_LEDS = (1 << 8),
};
/**
@@ -1163,30 +1177,48 @@ xkb_state_update_mask(struct xkb_state *state, xkb_mod_mask_t base_mods,
xkb_layout_index_t locked_layout);
/**
- * The counterpart to xkb_state_update_mask, to be used on the server side
- * of serialization.
+ * The counterpart to xkb_state_update_mask for modifiers, to be used on
+ * the server side of serialization.
*
- * @returns A xkb_mod_mask_t representing the given component(s) of the
- * state.
+ * @param state The keyboard state.
+ * @param components A mask of the modifier state components to serialize.
+ * State components other than XKB_STATE_MODS_* are ignored.
+ * If XKB_STATE_MODS_EFFECTIVE is included, all other state components are
+ * ignored.
+ *
+ * @returns A xkb_mod_mask_t representing the given components of the
+ * modifier state.
*
* This function should not be used in regular clients; please use the
- * xkb_state_mod_*_is_active or xkb_state_foreach_active_mod API instead.
+ * xkb_state_mod_*_is_active API instead.
*
* @memberof xkb_state
*/
xkb_mod_mask_t
xkb_state_serialize_mods(struct xkb_state *state,
- enum xkb_state_component component);
+ enum xkb_state_component components);
/**
- * The layout equivalent of xkb_state_serialize_mods.
+ * The counterpart to xkb_state_update_mask for layouts, to be used on
+ * the server side of serialization.
+ *
+ * @param state The keyboard state.
+ * @param components A mask of the layout state components to serialize.
+ * State components other than XKB_STATE_LAYOUT_* are ignored.
+ * If XKB_STATE_LAYOUT_EFFECTIVE is included, all other state components are
+ * ignored.
+ *
+ * @returns A xkb_layout_mask_t representing the given components of the
+ * layout state.
+ *
+ * This function should not be used in regular clients; please use the
+ * xkb_state_layout_*_is_active API instead.
*
- * @sa xkb_state_serialize_mods
* @memberof xkb_state
*/
xkb_layout_index_t
xkb_state_serialize_layout(struct xkb_state *state,
- enum xkb_state_component component);
+ enum xkb_state_component components);
/**
* Test whether a modifier is active in a given keyboard state by name.