summaryrefslogtreecommitdiff
path: root/src/text.c
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-08-01 11:25:34 +0300
committerRan Benita <ran234@gmail.com>2012-08-07 11:09:42 +0300
commit7c7e43415128229c97b2f9efa756c485774caa3b (patch)
tree4b55cb05215f268b644f8d52d74d02f294880cd3 /src/text.c
parentc6dee4640a6eff283bc868fbc4aca33aa48ddb42 (diff)
downloadxorg-lib-libxkbcommon-7c7e43415128229c97b2f9efa756c485774caa3b.tar.gz
Use only one set of core mod name-to-index functions
These were repeated 5 times. Note that this changes the ABI slightly: XKB_MOD_NAME_CAPS is changed from "Caps Lock" to "Lock", which is the ordinary legacy mod name for it. Since its hidden behind a #define, it's best to stay compatible with the old names (as I think was intended, given that "Mod1", etc. are the same). Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'src/text.c')
-rw-r--r--src/text.c45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/text.c b/src/text.c
index 022d284..5286ba9 100644
--- a/src/text.c
+++ b/src/text.c
@@ -129,24 +129,47 @@ VModMaskText(struct xkb_keymap *keymap, xkb_mod_mask_t modMask,
}
static const char *modNames[XkbNumModifiers] = {
- "Shift",
- "Lock",
- "Control",
- "Mod1",
- "Mod2",
- "Mod3",
- "Mod4",
- "Mod5"
+ [ShiftMapIndex] = "Shift",
+ [LockMapIndex] = "Lock",
+ [ControlMapIndex] = "Control",
+ [Mod1MapIndex] = "Mod1",
+ [Mod2MapIndex] = "Mod2",
+ [Mod3MapIndex] = "Mod3",
+ [Mod4MapIndex] = "Mod4",
+ [Mod5MapIndex] = "Mod5",
};
+xkb_mod_index_t
+ModNameToIndex(const char *name)
+{
+ xkb_mod_index_t i;
+
+ for (i = 0; i < XkbNumModifiers; i++)
+ if (istreq(name, modNames[i]))
+ return i;
+
+ return XKB_MOD_INVALID;
+}
+
+const char *
+ModIndexToName(xkb_mod_index_t ndx)
+{
+ if (ndx < XkbNumModifiers)
+ return modNames[ndx];
+ return NULL;
+}
+
const char *
ModIndexText(xkb_mod_index_t ndx)
{
+ const char *name;
char *buf;
- if (ndx < XkbNumModifiers)
- return modNames[ndx];
- else if (ndx == XkbNoModifier)
+ name = ModIndexToName(ndx);
+ if (name)
+ return name;
+
+ if (ndx == XkbNoModifier)
return "none";
buf = GetBuffer(32);