Commit 54aea7fe8bb5455040b836d09fae7fb0d352a08b

Dan Nicholson 2009-03-28T15:12:30

Add VMod Text functions from xkbfile

diff --git a/include/X11/extensions/XKBcommon.h b/include/X11/extensions/XKBcommon.h
index 5e37ea4..d857ff2 100644
--- a/include/X11/extensions/XKBcommon.h
+++ b/include/X11/extensions/XKBcommon.h
@@ -242,6 +242,12 @@ extern char *
 XkbcAtomText(Atom atm);
 
 extern char *
+XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx);
+
+extern char *
+XkbcVModMaskText(XkbcDescPtr xkb, unsigned modMask, unsigned mask);
+
+extern char *
 XkbcModMaskText(unsigned mask, Bool cFormat);
 
 extern char *
diff --git a/src/text.c b/src/text.c
index 0180747..1b24cf6 100644
--- a/src/text.c
+++ b/src/text.c
@@ -153,6 +153,89 @@ XkbcAtomText(Atom atm)
     return XkbStringText(rtrn);
 }
 
+char *
+XkbcVModIndexText(XkbcDescPtr xkb, unsigned ndx)
+{
+    int len;
+    Atom *vmodNames;
+    char *rtrn, *tmp = NULL;
+
+    if (xkb && xkb->names)
+        vmodNames = xkb->names->vmods;
+    else
+        vmodNames = NULL;
+
+    if (ndx >= XkbNumVirtualMods)
+         tmp = strdup("illegal");
+    else if (vmodNames && (vmodNames[ndx] != None))
+         tmp = XkbcAtomGetString(vmodNames[ndx]);
+
+    if (!tmp) {
+        tmp = _XkbAlloc(20 * sizeof(char));
+        snprintf(tmp, 20, "%d", ndx);
+    }
+
+    len = strlen(tmp) + 1;
+    if (len >= BUFFER_SIZE)
+        len = BUFFER_SIZE - 1;
+
+    rtrn = tbGetBuffer(len);
+    strncpy(rtrn, tmp, len);
+
+    _XkbFree(tmp);
+
+    return rtrn;
+}
+
+char *
+XkbcVModMaskText(XkbcDescPtr xkb, unsigned modMask, unsigned mask)
+{
+    int i, bit, len, rem;
+    char *mm = NULL, *rtrn, *str;
+    char buf[BUFFER_SIZE];
+
+    if ((modMask == 0) && (mask == 0))
+        return "none";
+
+    if (modMask != 0)
+        mm = XkbcModMaskText(modMask, False);
+
+    str = buf;
+    buf[0]= '\0';
+    rem = BUFFER_SIZE;
+
+    if (mask) {
+        for (i = 0, bit = 1; i < XkbNumVirtualMods && rem > 1; i++, bit <<= 1)
+        {
+            if (!(mask & bit))
+                continue;
+
+            len = snprintf(str, rem, "%s%s",
+                           (str != buf) ? "+" : "",
+                           XkbcVModIndexText(xkb, i));
+            rem -= len;
+            str += len;
+        }
+
+        str = buf;
+    }
+    else
+        str = NULL;
+
+    len = ((str) ? strlen(str) : 0) + ((mm) ? strlen(mm) : 0) +
+          ((str && mm) ? 1 : 0);
+    if (len >= BUFFER_SIZE)
+        len = BUFFER_SIZE - 1;
+
+    rtrn = tbGetBuffer(len + 1);
+    rtrn[0] = '\0';
+
+    snprintf(rtrn, len + 1, "%s%s%s", (mm) ? mm : "",
+             (mm && str) ? "+" : "", (str) ? str : "");
+
+    return rtrn;
+}
+
 static char *modNames[XkbNumModifiers] = {
     "Shift",
     "Lock",
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index b8f97b0..080bb31 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -112,15 +112,15 @@ extern Bool AddLevelName(KeyTypeInfo * /* type */ ,
     );
 
 #define MapEntryTxt(x, e) \
-    XkbVModMaskText((x), (e)->mods.real_mods, (e)->mods.vmods, XkbMessage)
+    XkbcVModMaskText((x), (e)->mods.real_mods, (e)->mods.vmods)
 #define PreserveIndexTxt(x, p) \
-    XkbVModMaskText((x), (p)->indexMods, (p)->indexVMods, XkbMessage)
+    XkbcVModMaskText((x), (p)->indexMods, (p)->indexVMods)
 #define PreserveTxt(x, p) \
-    XkbVModMaskText((x), (p)->preMods, (p)->preVMods, XkbMessage)
+    XkbcVModMaskText((x), (p)->preMods, (p)->preVMods)
 #define TypeTxt(t) \
     XkbcAtomText((t)->name)
 #define TypeMaskTxt(t, x) \
-    XkbVModMaskText((x), (t)->mask, (t)->vmask, XkbMessage)
+    XkbcVModMaskText((x), (t)->mask, (t)->vmask)
 
 /***====================================================================***/
 
@@ -695,10 +695,9 @@ SetMapEntry(KeyTypeInfo * type,
         {
             WARN1("Map entry for unused modifiers in %s\n", TypeTxt(type));
             ACTION1("Using %s instead of ",
-                    XkbVModMaskText(xkb,
+                    XkbcVModMaskText(xkb,
                                     entry.mods.real_mods & type->mask,
-                                    entry.mods.vmods & type->vmask,
-                                    XkbMessage));
+                                    entry.mods.vmods & type->vmask));
             INFO1("%s\n", MapEntryTxt(xkb, &entry));
         }
         entry.mods.real_mods &= type->mask;
@@ -900,8 +899,7 @@ SetKeyTypeField(KeyTypeInfo * type,
             WARN1("Multiple modifier mask definitions for key type %s\n",
                   XkbcAtomText(type->name));
             ACTION1("Using %s, ", TypeMaskTxt(type, xkb));
-            INFO1("ignoring %s\n", XkbVModMaskText(xkb, mods, vmods,
-                                                   XkbMessage));
+            INFO1("ignoring %s\n", XkbcVModMaskText(xkb, mods, vmods));
             return False;
         }
         type->mask = mods;