xkb: split effectiveGroup calculation into separate utility function.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2009-09-08 16:30:36 +10:00
parent 8fb3fa28a5
commit 4da59f4786
3 changed files with 45 additions and 24 deletions

View File

@ -945,6 +945,11 @@ extern void XkbFilterEvents(
int /* nEvents */, int /* nEvents */,
xEvent* /* xE */); xEvent* /* xE */);
extern int XkbGetEffectiveGroup(
XkbSrvInfoPtr /* xkbi */,
XkbStatePtr /* xkbstate */,
CARD8 /* keycode */);
#include "xkbfile.h" #include "xkbfile.h"
#include "xkbrules.h" #include "xkbrules.h"

View File

@ -124,30 +124,11 @@ static XkbAction fake;
} }
pActs= XkbKeyActionsPtr(xkb,key); pActs= XkbKeyActionsPtr(xkb,key);
col= 0; col= 0;
effectiveGroup= xkbState->group;
if (effectiveGroup!=XkbGroup1Index) { effectiveGroup = XkbGetEffectiveGroup(xkbi, xkbState, key);
if (XkbKeyNumGroups(xkb,key)>(unsigned)1) { if (effectiveGroup != XkbGroup1Index)
if (effectiveGroup>=XkbKeyNumGroups(xkb,key)) { col += (effectiveGroup * XkbKeyGroupsWidth(xkb, key));
unsigned gi= XkbKeyGroupInfo(xkb,key);
switch (XkbOutOfRangeGroupAction(gi)) {
default:
case XkbWrapIntoRange:
effectiveGroup %= XkbKeyNumGroups(xkb,key);
break;
case XkbClampIntoRange:
effectiveGroup = XkbKeyNumGroups(xkb,key)-1;
break;
case XkbRedirectIntoRange:
effectiveGroup= XkbOutOfRangeGroupInfo(gi);
if (effectiveGroup>=XkbKeyNumGroups(xkb,key))
effectiveGroup= 0;
break;
}
}
}
else effectiveGroup= XkbGroup1Index;
col+= (effectiveGroup*XkbKeyGroupsWidth(xkb,key));
}
type= XkbKeyKeyType(xkb,key,effectiveGroup); type= XkbKeyKeyType(xkb,key,effectiveGroup);
if (type->map!=NULL) { if (type->map!=NULL) {
register unsigned i,mods; register unsigned i,mods;

View File

@ -2118,3 +2118,38 @@ XkbCopyDeviceKeymap(DeviceIntPtr dst, DeviceIntPtr src)
return ret; return ret;
} }
int
XkbGetEffectiveGroup(XkbSrvInfoPtr xkbi, XkbStatePtr xkbState, CARD8 keycode)
{
XkbDescPtr xkb = xkbi->desc;
int effectiveGroup = xkbState->group;
if (!XkbKeycodeInRange(xkb, keycode))
return -1;
if (effectiveGroup == XkbGroup1Index)
return effectiveGroup;
if (XkbKeyNumGroups(xkb,keycode) > 1U) {
if (effectiveGroup >= XkbKeyNumGroups(xkb,keycode)) {
unsigned int gi = XkbKeyGroupInfo(xkb,keycode);
switch (XkbOutOfRangeGroupAction(gi)) {
default:
case XkbWrapIntoRange:
effectiveGroup %= XkbKeyNumGroups(xkb, keycode);
break;
case XkbClampIntoRange:
effectiveGroup = XkbKeyNumGroups(xkb, keycode) - 1;
break;
case XkbRedirectIntoRange:
effectiveGroup = XkbOutOfRangeGroupInfo(gi);
if (effectiveGroup >= XkbKeyNumGroups(xkb, keycode))
effectiveGroup = 0;
break;
}
}
}
else effectiveGroup = XkbGroup1Index;
return effectiveGroup;
}