Add VMod Text functions from xkbfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
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;