summaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-10-05 22:07:04 +0200
committerRan Benita <ran234@gmail.com>2012-10-06 21:41:59 +0200
commit1005b320f14339236ff53a07b13d6dcbad52bf19 (patch)
tree57bbf751a4daaca29fbef2faecf1403d471964f9 /src/text.c
parent6974e1f9acc42a946203a48c3a57d8bbb19e3316 (diff)
downloadlibxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.tar.gz
libxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.tar.bz2
libxkbcommon-1005b320f14339236ff53a07b13d6dcbad52bf19.zip
Don't use shifted virtual modifier masks
Modifier masks can be confusing in some places. For example, key->vmodmap only contains virtual modifiers, where the first is in position 0, the second in 1 etc., while normally in a xkb_mod_mask_t the virtual modifiers start from the 8th (XKB_NUM_CORE_MODS) position. This happens in some other places as well. Change all of the masks to be in the usual real+virtual format, and when we need to access e.g. keymap->vmods we just adjust by XKB_NUM_CORE_MODS. (This also goes for indexes, e.g. interpret->virtual_modifier). This makes this stuff easier to reason about. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/text.c b/src/text.c
index 118820b..c9f5cf9 100644
--- a/src/text.c
+++ b/src/text.c
@@ -231,16 +231,6 @@ GetBuffer(size_t size)
return rtrn;
}
-/* Get a vmod name's text, where the vmod index is zero based. */
-static const char *
-VModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx)
-{
- if (ndx >= darray_size(keymap->vmods))
- return "illegal";
- return xkb_atom_text(keymap->ctx,
- darray_item(keymap->vmods, ndx).name);
-}
-
/* Get a mod mask's text, where the mask is in rmods+vmods format. */
const char *
VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
@@ -253,7 +243,7 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
char buf[BUFFER_SIZE];
rmask = cmask & 0xff;
- vmask = cmask >> XKB_NUM_CORE_MODS;
+ vmask = cmask & (~0xff);
if (rmask == 0 && vmask == 0)
return "none";
@@ -261,26 +251,26 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask)
if (rmask != 0)
mm = ModMaskText(rmask);
+ if (vmask == 0)
+ return mm;
+
str = buf;
buf[0] = '\0';
rem = BUFFER_SIZE;
- if (vmask != 0) {
- for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) {
- if (!(vmask & (1 << i)))
- continue;
+ for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) {
+ const char *name;
- len = snprintf(str, rem, "%s%s",
- (str != buf) ? "+" : "",
- VModIndexText(keymap, i));
- rem -= len;
- str += len;
- }
+ if (!(vmask & (1 << (i + XKB_NUM_CORE_MODS))))
+ continue;
- str = buf;
+ name = xkb_atom_text(keymap->ctx, darray_item(keymap->vmods, i).name);
+ len = snprintf(str, rem, "%s%s", (str != buf) ? "+" : "", name);
+ rem -= len;
+ str += len;
}
- else
- str = NULL;
+
+ str = buf;
len = (str ? strlen(str) : 0) + (mm ? strlen(mm) : 0) +
(str && mm ? 1 : 0);