Add VMod Text functions from xkbfile
parent
46e5e164d6
commit
54aea7fe8b
|
@ -241,6 +241,12 @@ XkbcInternAtom(char *name, Bool onlyIfExists);
|
|||
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);
|
||||
|
||||
|
|
83
src/text.c
83
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",
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue