Input: Remove state from KeyClassRec

We already have state fully stored within XKB, so instead of duplicating it,
just generate the values to send to clients when required.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Daniel Stone 2008-08-09 16:45:45 +03:00
parent 08363c5830
commit 6727ee9408
11 changed files with 29 additions and 61 deletions

View File

@ -220,28 +220,19 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
mk->curKeySyms.maxKeyCode = dk->curKeySyms.maxKeyCode;
SetKeySymsMap(&mk->curKeySyms, &dk->curKeySyms);
/*
* Copy state from the extended keyboard to core. If you omit this,
* holding Ctrl on keyboard one, and pressing Q on keyboard two, will
* cause your app to quit. This feels wrong to me, hence the below
* code.
*
* XXX: If you synthesise core modifier events, the state will get
* clobbered here. You'll have to work out something sensible
* to fix that. Good luck.
*/
#define KEYBOARD_MASK (ShiftMask | LockMask | ControlMask | Mod1Mask | \
Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask)
mk->state &= ~(KEYBOARD_MASK);
mk->state |= (dk->state & KEYBOARD_MASK);
#undef KEYBOARD_MASK
for (i = 0; i < 8; i++)
mk->modifierKeyCount[i] = dk->modifierKeyCount[i];
if (!XkbCopyKeymap(dk->xkbInfo->desc, mk->xkbInfo->desc, True))
FatalError("Couldn't pivot keymap from device to core!\n");
/* Copy the state here. This means we'll only have consistency
* between state and active keymap, rather than between state and
* keycodes pressed, but there's pretty much no way to win here,
* so might as well go for the one that would seem to give the
* least nonsensical result. */
mk->xkbInfo->state = dk->xkbInfo->state;
if (lastMapNotifyDevice != master) {
SendMappingNotify(master, MappingKeyboard,
mk->curKeySyms.minKeyCode,
@ -250,13 +241,6 @@ CopyKeyClass(DeviceIntPtr device, DeviceIntPtr master)
serverClient);
lastMapNotifyDevice = master;
}
/* Copy the state here. This means we'll only have consistency
* between state and active keymap, rather than between state and
* keycodes pressed, but there's pretty much no way to win here,
* so might as well go for the one that would seem to give the
* least nonsensical result. */
mk->xkbInfo->state = dk->xkbInfo->state;
}
/**
@ -879,12 +863,10 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
if (device->valuator)
device->valuator->motionHintWindow = NullWindow;
*kptr |= bit;
k->prev_state = k->state;
for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
if (mask & modifiers) {
/* This key affects modifier "i" */
k->modifierKeyCount[i]++;
k->state |= mask;
modifiers &= ~mask;
}
}
@ -899,13 +881,11 @@ UpdateDeviceState(DeviceIntPtr device, xEvent* xE, int count)
if (device->valuator)
device->valuator->motionHintWindow = NullWindow;
*kptr &= ~bit;
k->prev_state = k->state;
for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
if (mask & modifiers) {
/* This key affects modifier "i" */
if (--k->modifierKeyCount[i] <= 0) {
k->modifierKeyCount[i] = 0;
k->state &= ~mask;
}
modifiers &= ~mask;
}
@ -1003,7 +983,7 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr device, int count)
}
/* State needs to be assembled BEFORE the device is updated. */
state = (kbd) ? kbd->key->state : 0;
state = (kbd) ? XkbStateFieldFromRec(&kbd->key->xkbInfo->state) : 0;
state |= (mouse) ? (mouse->button->state) : 0;
ret = UpdateDeviceState(device, xE, count);
@ -1047,7 +1027,7 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr device, int count)
device->name);
xV->device_state = 0;
if (k)
xV->device_state |= k->state;
xV->device_state |= XkbStateFieldFromRec(&k->xkbInfo->state);
if (b)
xV->device_state |= b->state;
}

View File

@ -42,6 +42,7 @@
#include "extnsionst.h"
#include "exevents.h"
#include "exglobals.h"
#include "xkbsrv.h"
#ifdef PANORAMIX
#include "panoramiXsrv.h"
@ -105,7 +106,9 @@ ProcXQueryDevicePointer(ClientPtr client)
rep.RepType = X_QueryDevicePointer;
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.mask = pDev->button->state | (kbd && kbd->key) ? kbd->key->state : 0;
rep.mask = pDev->button->state;
if (kbd && kbd->key)
rep.mask |= XkbStateFieldFromRec(&kbd->key->xkbInfo->state);
rep.root = (GetCurrentRootWindow(pDev))->drawable.id;
rep.rootX = pSprite->hot.x;
rep.rootY = pSprite->hot.y;

View File

@ -3683,11 +3683,14 @@ CoreProcessKeyboardEvent (xEvent *xE, DeviceIntPtr keybd, int count)
CallCallbacks(&DeviceEventCallback, (pointer)&eventinfo);
}
}
/* ProcessOtherEvent already updated the keyboard's state, so we need to
* access prev_state here! */
XE_KBPTR.state = (keyc->prev_state | GetPairedDevice(keybd)->button->state);
XE_KBPTR.state = XkbStateFieldFromRec(&keybd->key->xkbInfo->prev_state);
XE_KBPTR.state |= GetPairedDevice(keybd)->button->state;
XE_KBPTR.rootX = keybd->spriteInfo->sprite->hot.x;
XE_KBPTR.rootY = keybd->spriteInfo->sprite->hot.y;
key = xE->u.u.detail;
kptr = &keyc->down[key >> 3];
bit = 1 << (key & 7);
@ -4800,7 +4803,8 @@ ProcQueryPointer(ClientPtr client)
MaybeStopHint(mouse, client);
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.mask = mouse->button->state | kbd->key->state;
rep.mask = mouse->button->state;
rep.mask |= XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state);
rep.length = 0;
rep.root = (RootWindow(mouse))->drawable.id;
rep.rootX = pSprite->hot.x;

View File

@ -67,7 +67,6 @@
#define ScrollLockMask Mod5Mask
#define KeyPressed(k) (keyc->postdown[k >> 3] & (1 << (k & 7)))
#define ModifierDown(k) ((keyc->state & (k)) == (k))
/*
* NOTE: The AT/MF keyboards can generate (via the 8042) two (MF: three)

View File

@ -1925,7 +1925,8 @@ KdCheckLock (void)
if (tmp->LockLed && tmp->dixdev && tmp->dixdev->key) {
keyc = tmp->dixdev->key;
isSet = (tmp->leds & (1 << (tmp->LockLed-1))) != 0;
shouldBeSet = (keyc->state & LockMask) != 0;
/* FIXME: Just use XKB indicators! */
shouldBeSet = !!(XkbStateFieldFromRec(&keyc->xkbInfo->state) & LockMask);
if (isSet != shouldBeSet)
KdSetLed (tmp, tmp->LockLed, shouldBeSet);
}

View File

@ -1043,7 +1043,8 @@ DGAProcessKeyboardEvent (ScreenPtr pScreen, dgaEvent *de, DeviceIntPtr keybd)
de->u.event.dx = 0;
de->u.event.dy = 0;
de->u.event.screen = pScreen->myNum;
de->u.event.state = keyc->state | pointer->button->state;
de->u.event.state = XkbStateFieldFromRec(&keyc->xkbInfo->state);
de->u.event.state |= pointer->button->state;
de->u.u.type = (IEventBase - 1) + coreEquiv; /* change to XI event */
UpdateDeviceState(keybd, (xEvent*)de, 1);
@ -1090,7 +1091,8 @@ DGAProcessPointerEvent (ScreenPtr pScreen, dgaEvent *de, DeviceIntPtr mouse)
* Fill in remaining event state
*/
de->u.event.screen = pScreen->myNum;
de->u.event.state = butc->state | GetPairedDevice(mouse)->key->state;
de->u.event.state = butc->state;
de->u.event.state |= XkbStateFieldFromRec(&GetPairedDevice(mouse)->key->xkbInfo->state);
de->u.u.type = (IEventBase - 1) + coreEquiv; /* change to XI event */
UpdateDeviceState(mouse, (xEvent*)de, 1);

View File

@ -398,7 +398,6 @@ xf86PrintBacktrace(void)
}
#define KeyPressed(k) (keyc->postdown[k >> 3] & (1 << (k & 7)))
#define ModifierDown(k) ((keyc->state & (k)) == (k))
static void
xf86ReleaseKeys(DeviceIntPtr pDev)

View File

@ -142,8 +142,6 @@ typedef struct _KeyClassRec {
int modifierKeyCount[8];
CARD8 modifierMap[MAP_LENGTH];
CARD8 maxKeysPerModifier;
unsigned short state;
unsigned short prev_state;
struct _XkbSrvInfo *xkbInfo;
} KeyClassRec, *KeyClassPtr;

View File

@ -559,7 +559,7 @@ ProcXkbGetState(ClientPtr client)
rep.sequenceNumber= client->sequence;
rep.length = 0;
rep.deviceID = dev->id;
rep.mods = dev->key->state&0xff;
rep.mods = XkbStateFieldFromRec(xkb) & 0xff;
rep.baseMods = xkb->base_mods;
rep.lockedMods = xkb->locked_mods;
rep.latchedMods = xkb->latched_mods;
@ -626,7 +626,6 @@ ProcXkbLatchLockState(ClientPtr client)
return status;
XkbComputeDerivedState(tmpd->key->xkbInfo);
tmpd->key->state = XkbStateFieldFromRec(newState);
changed = XkbStateChangedFlags(&oldState, newState);
if (changed) {

View File

@ -748,7 +748,6 @@ deviceKeyButtonPointer *kbp = xE;
XkbUpdateIndicators(dev,changed_leds,True,NULL,&cause);
}
}
dev->key->state= XkbStateFieldFromRec(&xkbi->state);
}
if (((xkbi->flags&_XkbStateNotifyInProgress)==0)&&(changed!=0)) {

View File

@ -802,7 +802,7 @@ unsigned realMods = 0;
xEvent ev;
int x,y;
XkbStateRec old;
unsigned mods,mask,oldCoreState = 0,oldCorePrevState = 0;
unsigned mods,mask;
xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(xkbi->device);
ProcessInputProc backupproc;
@ -843,8 +843,6 @@ ProcessInputProc backupproc;
if ( mask || mods ) {
old= xkbi->state;
oldCoreState= xkbi->device->key->state;
oldCorePrevState= xkbi->device->key->prev_state;
xkbi->state.base_mods&= ~mask;
xkbi->state.base_mods|= (mods&mask);
xkbi->state.latched_mods&= ~mask;
@ -852,8 +850,6 @@ ProcessInputProc backupproc;
xkbi->state.locked_mods&= ~mask;
xkbi->state.locked_mods|= (mods&mask);
XkbComputeDerivedState(xkbi);
xkbi->device->key->state= xkbi->device->key->prev_state=
xkbi->state.mods;
}
realMods = xkbi->device->key->modifierMap[ev.u.u.detail];
@ -864,11 +860,8 @@ ProcessInputProc backupproc;
backupproc,xkbUnwrapProc);
xkbi->device->key->modifierMap[ev.u.u.detail] = realMods;
if ( mask || mods ) {
xkbi->device->key->state= oldCoreState;
xkbi->device->key->prev_state= oldCorePrevState;
if ( mask || mods )
xkbi->state= old;
}
}
else if (filter->keycode==keycode) {
@ -885,8 +878,6 @@ ProcessInputProc backupproc;
if ( mask || mods ) {
old= xkbi->state;
oldCoreState= xkbi->device->key->state;
oldCorePrevState= xkbi->device->key->prev_state;
xkbi->state.base_mods&= ~mask;
xkbi->state.base_mods|= (mods&mask);
xkbi->state.latched_mods&= ~mask;
@ -894,8 +885,6 @@ ProcessInputProc backupproc;
xkbi->state.locked_mods&= ~mask;
xkbi->state.locked_mods|= (mods&mask);
XkbComputeDerivedState(xkbi);
xkbi->device->key->state= xkbi->device->key->prev_state=
xkbi->state.mods;
}
realMods = xkbi->device->key->modifierMap[ev.u.u.detail];
@ -906,11 +895,8 @@ ProcessInputProc backupproc;
backupproc,xkbUnwrapProc);
xkbi->device->key->modifierMap[ev.u.u.detail] = realMods;
if ( mask || mods ) {
xkbi->device->key->state= oldCoreState;
xkbi->device->key->prev_state= oldCorePrevState;
if ( mask || mods )
xkbi->state= old;
}
filter->keycode= 0;
filter->active= 0;
@ -1250,8 +1236,6 @@ xkbDeviceInfoPtr xkbPrivPtr = XKBDEVICEINFO(dev);
xkbi->prev_state= oldState;
XkbComputeDerivedState(xkbi);
keyc->prev_state= keyc->state;
keyc->state= XkbStateFieldFromRec(&xkbi->state);
changed = XkbStateChangedFlags(&oldState,&xkbi->state);
if (genStateNotify) {
if (changed) {