dix: Get the state from the paired device and the real device to fill the

state field in the event, rather than using the virtual devices.
        ProcessPointerEvent: name argument "device" instead of "other".
        Add GetPairedKeyboard().
This commit is contained in:
Peter Hutterer 2007-03-13 19:16:56 +10:30
parent 577464af43
commit ce9409aceb
4 changed files with 75 additions and 46 deletions

View File

@ -113,29 +113,46 @@ RegisterOtherDevice(DeviceIntPtr device)
} }
/*ARGSUSED*/ void /*ARGSUSED*/ void
ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count) ProcessOtherEvent(xEventPtr xE, DeviceIntPtr device, int count)
{ {
BYTE *kptr; BYTE *kptr;
int i; int i;
CARD16 modifiers; CARD16 modifiers;
CARD16 mask; CARD16 mask;
GrabPtr grab = other->deviceGrab.grab; GrabPtr grab = device->deviceGrab.grab;
Bool deactivateDeviceGrab = FALSE; Bool deactivateDeviceGrab = FALSE;
int key = 0, bit = 0, rootX, rootY; int key = 0, bit = 0, rootX, rootY;
ButtonClassPtr b = other->button; ButtonClassPtr b = device->button;
KeyClassPtr k = other->key; KeyClassPtr k = device->key;
ValuatorClassPtr v = other->valuator; ValuatorClassPtr v = device->valuator;
deviceValuator *xV = (deviceValuator *) xE; deviceValuator *xV = (deviceValuator *) xE;
if (xE->u.u.type != DeviceValuator) { if (xE->u.u.type != DeviceValuator) {
GetSpritePosition(other, &rootX, &rootY); DeviceIntPtr mouse = NULL, kbd = NULL;
GetSpritePosition(device, &rootX, &rootY);
xE->u.keyButtonPointer.rootX = rootX; xE->u.keyButtonPointer.rootX = rootX;
xE->u.keyButtonPointer.rootY = rootY; xE->u.keyButtonPointer.rootY = rootY;
key = xE->u.u.detail; key = xE->u.u.detail;
NoticeEventTime(xE); NoticeEventTime(xE);
xE->u.keyButtonPointer.state = inputInfo.keyboard->key->state |
inputInfo.pointer->button->state; /* FIXME: change for MPX */ /* If 'device' is a pointer device, we need to get the paired keyboard
* for the state. If there is none, the kbd bits of state are 0.
* If 'device' is a keyboard device, get the paired pointer and use the
* pointer's state for the button bits.
*/
if (IsPointerDevice(device))
{
kbd = GetPairedKeyboard(device);
mouse = device;
}
else
{
mouse = GetPairedPointer(device);
kbd = device;
}
xE->u.keyButtonPointer.state = (kbd) ? (kbd->key->state) : 0;
xE->u.keyButtonPointer.state |= (mouse) ? (mouse->button->state) : 0;
bit = 1 << (key & 7); bit = 1 << (key & 7);
} }
if (DeviceEventCallback) { if (DeviceEventCallback) {
@ -155,7 +172,7 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
|| (xV->num_valuators || (xV->num_valuators
&& (first + xV->num_valuators > v->numAxes)))) && (first + xV->num_valuators > v->numAxes))))
FatalError("Bad valuators reported for device %s\n", FatalError("Bad valuators reported for device %s\n",
other->name); device->name);
xV->device_state = 0; xV->device_state = 0;
if (k) if (k)
xV->device_state |= k->state; xV->device_state |= k->state;
@ -192,15 +209,15 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
if (*kptr & bit) { /* allow ddx to generate multiple downs */ if (*kptr & bit) { /* allow ddx to generate multiple downs */
if (!modifiers) { if (!modifiers) {
xE->u.u.type = DeviceKeyRelease; xE->u.u.type = DeviceKeyRelease;
ProcessOtherEvent(xE, other, count); ProcessOtherEvent(xE, device, count);
xE->u.u.type = DeviceKeyPress; xE->u.u.type = DeviceKeyPress;
/* release can have side effects, don't fall through */ /* release can have side effects, don't fall through */
ProcessOtherEvent(xE, other, count); ProcessOtherEvent(xE, device, count);
} }
return; return;
} }
if (other->valuator) if (device->valuator)
other->valuator->motionHintWindow = NullWindow; device->valuator->motionHintWindow = NullWindow;
*kptr |= bit; *kptr |= bit;
k->prev_state = k->state; k->prev_state = k->state;
for (i = 0, mask = 1; modifiers; i++, mask <<= 1) { for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
@ -211,8 +228,8 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
modifiers &= ~mask; modifiers &= ~mask;
} }
} }
if (!grab && CheckDeviceGrabs(other, xE, 0, count)) { if (!grab && CheckDeviceGrabs(device, xE, 0, count)) {
other->deviceGrab.activatingKey = key; device->deviceGrab.activatingKey = key;
return; return;
} }
} else if (xE->u.u.type == DeviceKeyRelease) { } else if (xE->u.u.type == DeviceKeyRelease) {
@ -223,8 +240,8 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
if (!(*kptr & bit)) /* guard against duplicates */ if (!(*kptr & bit)) /* guard against duplicates */
return; return;
modifiers = k->modifierMap[key]; modifiers = k->modifierMap[key];
if (other->valuator) if (device->valuator)
other->valuator->motionHintWindow = NullWindow; device->valuator->motionHintWindow = NullWindow;
*kptr &= ~bit; *kptr &= ~bit;
k->prev_state = k->state; k->prev_state = k->state;
for (i = 0, mask = 1; modifiers; i++, mask <<= 1) { for (i = 0, mask = 1; modifiers; i++, mask <<= 1) {
@ -238,9 +255,9 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
} }
} }
if (other->deviceGrab.fromPassiveGrab && if (device->deviceGrab.fromPassiveGrab &&
!other->deviceGrab.grab->coreGrab && !device->deviceGrab.grab->coreGrab &&
(key == other->deviceGrab.activatingKey)) (key == device->deviceGrab.activatingKey))
deactivateDeviceGrab = TRUE; deactivateDeviceGrab = TRUE;
} else if (xE->u.u.type == DeviceButtonPress) { } else if (xE->u.u.type == DeviceButtonPress) {
if (!b) if (!b)
@ -248,8 +265,8 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
kptr = &b->down[key >> 3]; kptr = &b->down[key >> 3];
*kptr |= bit; *kptr |= bit;
if (other->valuator) if (device->valuator)
other->valuator->motionHintWindow = NullWindow; device->valuator->motionHintWindow = NullWindow;
b->buttonsDown++; b->buttonsDown++;
b->motionMask = DeviceButtonMotionMask; b->motionMask = DeviceButtonMotionMask;
xE->u.u.detail = b->map[key]; xE->u.u.detail = b->map[key];
@ -259,7 +276,7 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
b->state |= (Button1Mask >> 1) << xE->u.u.detail; b->state |= (Button1Mask >> 1) << xE->u.u.detail;
SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify); SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify);
if (!grab) if (!grab)
if (CheckDeviceGrabs(other, xE, 0, count)) if (CheckDeviceGrabs(device, xE, 0, count))
return; return;
} else if (xE->u.u.type == DeviceButtonRelease) { } else if (xE->u.u.type == DeviceButtonRelease) {
@ -268,8 +285,8 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
kptr = &b->down[key >> 3]; kptr = &b->down[key >> 3];
*kptr &= ~bit; *kptr &= ~bit;
if (other->valuator) if (device->valuator)
other->valuator->motionHintWindow = NullWindow; device->valuator->motionHintWindow = NullWindow;
if (!--b->buttonsDown) if (!--b->buttonsDown)
b->motionMask = 0; b->motionMask = 0;
xE->u.u.detail = b->map[key]; xE->u.u.detail = b->map[key];
@ -279,24 +296,24 @@ ProcessOtherEvent(xEventPtr xE, DeviceIntPtr other, int count)
b->state &= ~((Button1Mask >> 1) << xE->u.u.detail); b->state &= ~((Button1Mask >> 1) << xE->u.u.detail);
SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify); SetMaskForEvent(Motion_Filter(b), DeviceMotionNotify);
if (!b->state if (!b->state
&& other->deviceGrab.fromPassiveGrab && device->deviceGrab.fromPassiveGrab
&& !other->deviceGrab.grab->coreGrab) && !device->deviceGrab.grab->coreGrab)
deactivateDeviceGrab = TRUE; deactivateDeviceGrab = TRUE;
} else if (xE->u.u.type == ProximityIn) } else if (xE->u.u.type == ProximityIn)
other->valuator->mode &= ~OutOfProximity; device->valuator->mode &= ~OutOfProximity;
else if (xE->u.u.type == ProximityOut) else if (xE->u.u.type == ProximityOut)
other->valuator->mode |= OutOfProximity; device->valuator->mode |= OutOfProximity;
if (grab) if (grab)
DeliverGrabbedEvent(xE, other, deactivateDeviceGrab, count); DeliverGrabbedEvent(xE, device, deactivateDeviceGrab, count);
else if (other->focus) else if (device->focus)
DeliverFocusedEvent(other, xE, GetSpriteWindow(other), count); DeliverFocusedEvent(device, xE, GetSpriteWindow(device), count);
else else
DeliverDeviceEvents(GetSpriteWindow(other), xE, NullGrab, NullWindow, DeliverDeviceEvents(GetSpriteWindow(device), xE, NullGrab, NullWindow,
other, count); device, count);
if (deactivateDeviceGrab == TRUE) if (deactivateDeviceGrab == TRUE)
(*other->deviceGrab.DeactivateGrab) (other); (*device->deviceGrab.DeactivateGrab) (device);
} }
_X_EXPORT int _X_EXPORT int

View File

@ -2030,6 +2030,23 @@ GetPairedPointer(DeviceIntPtr kbd)
return inputInfo.pointer; return inputInfo.pointer;
} }
/* Find the keyboard device that is paired with the given pointer. If none is
* found, return NULL.
*/
_X_EXPORT DeviceIntPtr
GetPairedKeyboard(DeviceIntPtr ptr)
{
DeviceIntPtr dev = inputInfo.devices;
while(dev)
{
if (ptr->pSprite == dev->pSprite)
return dev;
dev = dev->next;
}
return dev;
}
/* /*
* Register a client to be able to pair devices. * Register a client to be able to pair devices.
*/ */

View File

@ -4913,18 +4913,12 @@ PickPointer(ClientPtr client)
_X_EXPORT DeviceIntPtr _X_EXPORT DeviceIntPtr
PickKeyboard(ClientPtr client) PickKeyboard(ClientPtr client)
{ {
DeviceIntPtr ptr; DeviceIntPtr ptr = PickPointer(client);
DeviceIntPtr dev = inputInfo.devices; DeviceIntPtr kbd;
ptr = PickPointer(client);
while(dev) kbd = GetPairedKeyboard(ptr);
{
if (ptr->pSprite == dev->pSprite)
return dev;
dev = dev->next;
}
return inputInfo.keyboard; return (kbd) ? kbd : inputInfo.keyboard;
} }
/* A client that has one or more core grabs does not get core events from /* A client that has one or more core grabs does not get core events from

View File

@ -451,6 +451,7 @@ extern int PairDevices(ClientPtr client,
DeviceIntPtr keyboard); DeviceIntPtr keyboard);
extern DeviceIntPtr GetPairedPointer(DeviceIntPtr kbd); extern DeviceIntPtr GetPairedPointer(DeviceIntPtr kbd);
extern DeviceIntPtr GetPairedKeyboard(DeviceIntPtr ptr);
extern Bool RegisterPairingClient(ClientPtr client); extern Bool RegisterPairingClient(ClientPtr client);
extern Bool UnregisterPairingClient(ClientPtr client); extern Bool UnregisterPairingClient(ClientPtr client);