Commit ae127b28 authored by Adam Sampson's avatar Adam Sampson
Browse files

xkb: Fix off-by-one error in XKeycodeToKeysym



The code here that made indexes greater than 3 refer to XKB symbol
groups had an off-by-one error, so it would always leave out the symbol
that should have been at index 4. Rewrite the code to fix this and
simplify the logic a bit.
Signed-off-by: Adam Sampson's avatarAdam Sampson <ats@offog.org>
parent d01d2337
Pipeline #353086 passed with stages
in 11 minutes and 18 seconds
...@@ -113,36 +113,24 @@ XKeycodeToKeysym(Display *dpy, ...@@ -113,36 +113,24 @@ XKeycodeToKeysym(Display *dpy,
return NoSymbol; return NoSymbol;
if (col > 3) { if (col > 3) {
int lastSym, tmp, nGrp; int firstSym, nGrp, grp;
lastSym = 3; firstSym = 4;
nGrp = XkbKeyNumGroups(xkb, kc); nGrp = XkbKeyNumGroups(xkb, kc);
if ((nGrp > 0) && for (grp = 0; grp < nGrp; grp++) {
((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup1Index)) > 2)) { int width = XkbKeyGroupWidth(xkb, kc, grp);
if (col <= (lastSym + tmp - 2)) int skip = 0;
return XkbKeycodeToKeysym(dpy, kc, XkbGroup1Index, if (grp < 2) {
col - lastSym + 2); /* Skip the first two symbols in the first two groups, since we
lastSym += tmp - 2; * return them below for indexes 0-3. */
} skip = 2;
if ((nGrp > 1) && width -= skip;
((tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup2Index)) > 2)) { if (width < 0)
if (col <= (lastSym + tmp - 2)) width = 0;
return XkbKeycodeToKeysym(dpy, kc, XkbGroup2Index, }
col - lastSym + 2); if (col < firstSym + width)
lastSym += tmp - 2; return XkbKeycodeToKeysym(dpy, kc, grp, col - firstSym + skip);
} firstSym += width;
if (nGrp > 2) {
tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup3Index);
if (col <= lastSym + tmp)
return XkbKeycodeToKeysym(dpy, kc, XkbGroup3Index,
col - lastSym);
lastSym += tmp;
}
if (nGrp > 3) {
tmp = XkbKeyGroupWidth(xkb, kc, XkbGroup4Index);
if (col <= lastSym + tmp)
return XkbKeycodeToKeysym(dpy, kc, XkbGroup4Index,
col - lastSym);
} }
return NoSymbol; return NoSymbol;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment