summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-10-22 20:49:44 +0200
committerRan Benita <ran234@gmail.com>2012-10-22 21:48:40 +0200
commit6a94b122a4dde3e8f59d69f9a388e9a77c343326 (patch)
treea8ac8a9f103ffe866c29f666408ab8849ae48a19
parent3a5f87b8e9856a69c8978f8baf0954e08679c974 (diff)
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>
-rw-r--r--src/compat.c1
-rw-r--r--src/keymap-dump.c4
-rw-r--r--src/state.c48
-rw-r--r--src/text.c22
-rw-r--r--src/xkbcomp/compat.c4
-rw-r--r--test/interactive.c6
-rw-r--r--test/state.c94
-rw-r--r--xkbcommon/xkbcommon-compat.h10
-rw-r--r--xkbcommon/xkbcommon.h78
9 files changed, 161 insertions, 106 deletions
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.