diff options
author | Ran Benita <ran234@gmail.com> | 2012-10-05 22:46:21 +0200 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2012-10-06 21:41:59 +0200 |
commit | 424de613af4c0a8121213bbee8c4fdd8364612e5 (patch) | |
tree | 60ccce13d87c24cf7bd1411bf1889bed0830472a /src/text.c | |
parent | 1005b320f14339236ff53a07b13d6dcbad52bf19 (diff) | |
download | libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.tar.gz libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.tar.bz2 libxkbcommon-424de613af4c0a8121213bbee8c4fdd8364612e5.zip |
Keep real and virtual mods in the same table in the keymap
We change the keymap->vmods array into keymap->mods, and change it's
member type from struct xkb_vmod to struct xkb_mod. This table now
includes the real modifiers in the first 8 places. To distinguish
between them, we add an enum mod_type to struct xkb_mod.
Besides being a more reasonable approach, this enables us to share
some code later, remove XKB_NUM_CORE_MODS (though the 0xff mask still
appears in a few places), and prepares us to flat out remove the
distinction in the future. This commit just does the conversion.
Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/text.c')
-rw-r--r-- | src/text.c | 94 |
1 files changed, 40 insertions, 54 deletions
@@ -233,7 +233,7 @@ GetBuffer(size_t size) /* 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) +VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask) { xkb_mod_index_t i; xkb_mod_mask_t rmask, vmask; @@ -241,15 +241,16 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) const char *mm = NULL; char *rtrn, *str; char buf[BUFFER_SIZE]; + const struct xkb_mod *mod; - rmask = cmask & 0xff; - vmask = cmask & (~0xff); + rmask = mask & 0xff; + vmask = mask & (~0xff); if (rmask == 0 && vmask == 0) return "none"; if (rmask != 0) - mm = ModMaskText(rmask); + mm = ModMaskText(keymap, rmask); if (vmask == 0) return mm; @@ -258,16 +259,18 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) buf[0] = '\0'; rem = BUFFER_SIZE; - for (i = 0; i < darray_size(keymap->vmods) && rem > 1; i++) { - const char *name; - - if (!(vmask & (1 << (i + XKB_NUM_CORE_MODS)))) + darray_enumerate(i, mod, keymap->mods) { + if (mod->type != MOD_VIRT || !(vmask & (1 << i))) continue; - name = xkb_atom_text(keymap->ctx, darray_item(keymap->vmods, i).name); - len = snprintf(str, rem, "%s%s", (str != buf) ? "+" : "", name); + len = snprintf(str, rem, "%s%s", + (str != buf) ? "+" : "", + xkb_atom_text(keymap->ctx, mod->name)); rem -= len; str += len; + + if (rem <= 1) + break; } str = buf; @@ -286,70 +289,51 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t cmask) return rtrn; } -/* - * IMPORTATNT - * The indices used for the legacy core modifiers is derived from - * the order of the names in this table. It matches the values - * ShiftMapIndex, LockMapIndex, etc. from X11/X.h. Take note before - * changing. - */ -static const char *modNames[XKB_NUM_CORE_MODS] = { - "Shift", - "Lock", - "Control", - "Mod1", - "Mod2", - "Mod3", - "Mod4", - "Mod5", -}; - xkb_mod_index_t -ModNameToIndex(const char *name) +ModNameToIndex(const struct xkb_keymap *keymap, xkb_atom_t name) { xkb_mod_index_t i; + const struct xkb_mod *mod; - for (i = 0; i < XKB_NUM_CORE_MODS; i++) - if (istreq(name, modNames[i])) + darray_enumerate(i, mod, keymap->mods) + if (mod->type == MOD_REAL && name == mod->name) return i; return XKB_MOD_INVALID; } -const char * -ModIndexToName(xkb_mod_index_t ndx) +xkb_atom_t +ModIndexToName(struct xkb_keymap *keymap, xkb_mod_index_t ndx) { - if (ndx < XKB_NUM_CORE_MODS) - return modNames[ndx]; - return NULL; + if (ndx >= darray_size(keymap->mods) || + darray_item(keymap->mods, ndx).type != MOD_REAL) + return XKB_ATOM_NONE; + + return darray_item(keymap->mods, ndx).name; } const char * -ModIndexText(xkb_mod_index_t ndx) +ModIndexText(struct xkb_keymap *keymap, xkb_mod_index_t ndx) { - const char *name; - char *buf; + xkb_atom_t name; - name = ModIndexToName(ndx); + name = ModIndexToName(keymap, ndx); if (name) - return name; + return xkb_atom_text(keymap->ctx, name); if (ndx == XKB_MOD_INVALID) return "none"; - buf = GetBuffer(32); - snprintf(buf, 32, "ILLEGAL_%02x", ndx); - - return buf; + return "illegal"; } -/* Gets the text for the real modifiers only. */ const char * -ModMaskText(xkb_mod_mask_t mask) +ModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t mask) { - int i, rem; - xkb_mod_index_t bit; + xkb_mod_index_t i; + int len, rem; char *str, *buf; + const struct xkb_mod *mod; if ((mask & 0xff) == 0xff) return "all"; @@ -361,16 +345,18 @@ ModMaskText(xkb_mod_mask_t mask) buf = GetBuffer(rem); str = buf; buf[0] = '\0'; - for (i = 0, bit = 1; i < XKB_NUM_CORE_MODS && rem > 1; i++, bit <<= 1) { - int len; - - if (!(mask & bit)) + darray_enumerate(i, mod, keymap->mods) { + if (mod->type != MOD_REAL || !(mask & (1 << i))) continue; len = snprintf(str, rem, "%s%s", - (str != buf ? "+" : ""), modNames[i]); + (str != buf ? "+" : ""), + ModIndexText(keymap, i)); rem -= len; str += len; + + if (rem <= 1) + break; } return buf; |