input: replace GrabRec's coreGrab field with grabtype.

Don't allow grabs of different types to override each other.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2009-04-12 16:19:45 +10:00
parent 7fbe1b7d63
commit 09f9a86077
7 changed files with 38 additions and 21 deletions

View File

@ -1415,7 +1415,7 @@ GrabButton(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
grab = CreateGrab(client->index, dev, pWin, eventMask, grab = CreateGrab(client->index, dev, pWin, eventMask,
(Bool) ownerEvents, (Bool) this_device_mode, (Bool) ownerEvents, (Bool) this_device_mode,
(Bool) other_devices_mode, modifier_device, modifiers, (Bool) other_devices_mode, modifier_device, modifiers,
DeviceButtonPress, button, confineTo, cursor); DeviceButtonPress, GRABTYPE_XI, button, confineTo, cursor);
if (!grab) if (!grab)
return BadAlloc; return BadAlloc;
return AddPassiveGrabToList(client, grab); return AddPassiveGrabToList(client, grab);
@ -1470,8 +1470,8 @@ GrabKey(ClientPtr client, DeviceIntPtr dev, BYTE this_device_mode,
grab = CreateGrab(client->index, dev, pWin, grab = CreateGrab(client->index, dev, pWin,
mask, ownerEvents, this_device_mode, other_devices_mode, mask, ownerEvents, this_device_mode, other_devices_mode,
modifier_device, modifiers, DeviceKeyPress, key, modifier_device, modifiers, DeviceKeyPress, GRABTYPE_XI,
NullWindow, NullCursor); key, NullWindow, NullCursor);
if (!grab) if (!grab)
return BadAlloc; return BadAlloc;
return AddPassiveGrabToList(client, grab); return AddPassiveGrabToList(client, grab);

View File

@ -104,7 +104,7 @@ ProcXUngrabDevice(ClientPtr client)
time = ClientTimeToServerTime(stuff->time); time = ClientTimeToServerTime(stuff->time);
if ((CompareTimeStamps(time, currentTime) != LATER) && if ((CompareTimeStamps(time, currentTime) != LATER) &&
(CompareTimeStamps(time, dev->deviceGrab.grabTime) != EARLIER) && (CompareTimeStamps(time, dev->deviceGrab.grabTime) != EARLIER) &&
(grab) && SameClient(grab, client) && !grab->coreGrab) (grab) && SameClient(grab, client) && grab->grabtype == GRABTYPE_XI)
(*dev->deviceGrab.DeactivateGrab) (dev); (*dev->deviceGrab.DeactivateGrab) (dev);
return Success; return Success;
} }

View File

@ -2057,7 +2057,12 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
tempGrab.pointerMode = GrabModeAsync; tempGrab.pointerMode = GrabModeAsync;
tempGrab.confineTo = NullWindow; tempGrab.confineTo = NullWindow;
tempGrab.cursor = NullCursor; tempGrab.cursor = NullCursor;
tempGrab.coreGrab = (type == ButtonPress); if (type == ButtonPress)
tempGrab.grabtype = GRABTYPE_CORE;
else if (type == DeviceButtonPress)
tempGrab.grabtype = GRABTYPE_XI;
else
tempGrab.grabtype = GRABTYPE_XI2;
/* get the XI and XI2 device mask */ /* get the XI and XI2 device mask */
inputMasks = wOtherInputMasks(pWin); inputMasks = wOtherInputMasks(pWin);
@ -3298,7 +3303,7 @@ CheckPassiveGrabsOnWindow(
XkbSrvInfoPtr xkbi = NULL; XkbSrvInfoPtr xkbi = NULL;
gdev= grab->modifierDevice; gdev= grab->modifierDevice;
if (grab->coreGrab) if (grab->grabtype == GRABTYPE_CORE)
{ {
if (IsPointerDevice(device)) if (IsPointerDevice(device))
gdev = GetPairedDevice(device); gdev = GetPairedDevice(device);
@ -3351,14 +3356,14 @@ CheckPassiveGrabsOnWindow(
* device. * device.
*/ */
if (grab->coreGrab) if (grab->grabtype == GRABTYPE_CORE)
{ {
DeviceIntPtr other; DeviceIntPtr other;
BOOL interfering = FALSE; BOOL interfering = FALSE;
for (other = inputInfo.devices; other; other = other->next) for (other = inputInfo.devices; other; other = other->next)
{ {
GrabPtr othergrab = other->deviceGrab.grab; GrabPtr othergrab = other->deviceGrab.grab;
if (othergrab && othergrab->coreGrab && if (othergrab && othergrab->grabtype == GRABTYPE_CORE &&
SameClient(grab, rClient(othergrab)) && SameClient(grab, rClient(othergrab)) &&
((IsPointerDevice(grab->device) && ((IsPointerDevice(grab->device) &&
IsPointerDevice(othergrab->device)) || IsPointerDevice(othergrab->device)) ||
@ -3679,7 +3684,7 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
sendCore = (thisDev->isMaster && thisDev->coreEvents); sendCore = (thisDev->isMaster && thisDev->coreEvents);
/* try core event */ /* try core event */
if (sendCore && grab->coreGrab) if (sendCore && grab->grabtype == GRABTYPE_CORE)
{ {
xEvent core; xEvent core;
@ -4428,7 +4433,7 @@ ProcGrabPointer(ClientPtr client)
rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode, rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
stuff->grabWindow, stuff->ownerEvents, stuff->time, stuff->grabWindow, stuff->ownerEvents, stuff->time,
stuff->eventMask, TRUE, stuff->cursor, stuff->eventMask, GRABTYPE_CORE, stuff->cursor,
stuff->confineTo, &rep.status); stuff->confineTo, &rep.status);
if (rc != Success) if (rc != Success)
return rc; return rc;
@ -4547,7 +4552,7 @@ int
GrabDevice(ClientPtr client, DeviceIntPtr dev, GrabDevice(ClientPtr client, DeviceIntPtr dev,
unsigned pointer_mode, unsigned keyboard_mode, Window grabWindow, unsigned pointer_mode, unsigned keyboard_mode, Window grabWindow,
unsigned ownerEvents, Time ctime, Mask mask, unsigned ownerEvents, Time ctime, Mask mask,
Bool coreGrab, Cursor curs, Window confineToWin, CARD8 *status) int grabtype, Cursor curs, Window confineToWin, CARD8 *status)
{ {
WindowPtr pWin, confineTo; WindowPtr pWin, confineTo;
GrabPtr grab; GrabPtr grab;
@ -4610,6 +4615,8 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
time = ClientTimeToServerTime(ctime); time = ClientTimeToServerTime(ctime);
grab = grabInfo->grab; grab = grabInfo->grab;
if (grab && grab->grabtype != grabtype)
*status = AlreadyGrabbed;
if (grab && !SameClient(grab, client)) if (grab && !SameClient(grab, client))
*status = AlreadyGrabbed; *status = AlreadyGrabbed;
else if ((!pWin->realized) || else if ((!pWin->realized) ||
@ -4640,7 +4647,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
tempGrab.device = dev; tempGrab.device = dev;
tempGrab.cursor = cursor; tempGrab.cursor = cursor;
tempGrab.confineTo = confineTo; tempGrab.confineTo = confineTo;
tempGrab.coreGrab = coreGrab; tempGrab.grabtype = grabtype;
(*grabInfo->ActivateGrab)(dev, &tempGrab, time, FALSE); (*grabInfo->ActivateGrab)(dev, &tempGrab, time, FALSE);
*status = GrabSuccess; *status = GrabSuccess;
} }
@ -4665,7 +4672,7 @@ ProcGrabKeyboard(ClientPtr client)
memset(&rep, 0, sizeof(xGrabKeyboardReply)); memset(&rep, 0, sizeof(xGrabKeyboardReply));
result = GrabDevice(client, keyboard, stuff->pointerMode, result = GrabDevice(client, keyboard, stuff->pointerMode,
stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents, stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents,
stuff->time, KeyPressMask | KeyReleaseMask, TRUE, None, None, stuff->time, KeyPressMask | KeyReleaseMask, GRABTYPE_CORE, None, None,
&rep.status); &rep.status);
if (result != Success) if (result != Success)
@ -4698,7 +4705,7 @@ ProcUngrabKeyboard(ClientPtr client)
time = ClientTimeToServerTime(stuff->id); time = ClientTimeToServerTime(stuff->id);
if ((CompareTimeStamps(time, currentTime) != LATER) && if ((CompareTimeStamps(time, currentTime) != LATER) &&
(CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) && (CompareTimeStamps(time, device->deviceGrab.grabTime) != EARLIER) &&
(grab) && SameClient(grab, client) && grab->coreGrab) (grab) && SameClient(grab, client) && grab->grabtype == GRABTYPE_CORE)
(*device->deviceGrab.DeactivateGrab)(device); (*device->deviceGrab.DeactivateGrab)(device);
return Success; return Success;
} }
@ -5038,7 +5045,7 @@ ProcGrabKey(ClientPtr client)
grab = CreateGrab(client->index, keybd, pWin, grab = CreateGrab(client->index, keybd, pWin,
(Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents, (Mask)(KeyPressMask | KeyReleaseMask), (Bool)stuff->ownerEvents,
(Bool)stuff->keyboardMode, (Bool)stuff->pointerMode, (Bool)stuff->keyboardMode, (Bool)stuff->pointerMode,
keybd, stuff->modifiers, KeyPress, stuff->key, keybd, stuff->modifiers, KeyPress, GRABTYPE_CORE, stuff->key,
NullWindow, NullCursor); NullWindow, NullCursor);
if (!grab) if (!grab)
return BadAlloc; return BadAlloc;
@ -5130,7 +5137,7 @@ ProcGrabButton(ClientPtr client)
grab = CreateGrab(client->index, ptr, pWin, grab = CreateGrab(client->index, ptr, pWin,
(Mask)stuff->eventMask, (Bool)stuff->ownerEvents, (Mask)stuff->eventMask, (Bool)stuff->ownerEvents,
(Bool) stuff->keyboardMode, (Bool)stuff->pointerMode, (Bool) stuff->keyboardMode, (Bool)stuff->pointerMode,
modifierDevice, stuff->modifiers, ButtonPress, modifierDevice, stuff->modifiers, ButtonPress, GRABTYPE_CORE,
stuff->button, confineTo, cursor); stuff->button, confineTo, cursor);
if (!grab) if (!grab)
return BadAlloc; return BadAlloc;
@ -5564,7 +5571,7 @@ PickPointer(ClientPtr client)
for(it = inputInfo.devices; it; it = it->next) for(it = inputInfo.devices; it; it = it->next)
{ {
GrabPtr grab = it->deviceGrab.grab; GrabPtr grab = it->deviceGrab.grab;
if (grab && grab->coreGrab && SameClient(grab, client)) if (grab && grab->grabtype == GRABTYPE_CORE && SameClient(grab, client))
{ {
if (!IsPointerDevice(it)) if (!IsPointerDevice(it))
it = GetPairedDevice(it); it = GetPairedDevice(it);

View File

@ -76,6 +76,7 @@ CreateGrab(
DeviceIntPtr modDevice, DeviceIntPtr modDevice,
unsigned short modifiers, unsigned short modifiers,
int type, int type,
int grabtype,
KeyCode keybut, /* key or button */ KeyCode keybut, /* key or button */
WindowPtr confineTo, WindowPtr confineTo,
CursorPtr cursor) CursorPtr cursor)
@ -87,7 +88,6 @@ CreateGrab(
return (GrabPtr)NULL; return (GrabPtr)NULL;
grab->resource = FakeClientID(client); grab->resource = FakeClientID(client);
grab->device = device; grab->device = device;
grab->coreGrab = (type < LASTEvent);
grab->window = window; grab->window = window;
grab->eventMask = eventMask; grab->eventMask = eventMask;
grab->deviceMask = 0; grab->deviceMask = 0;
@ -98,6 +98,7 @@ CreateGrab(
grab->modifiersDetail.pMask = NULL; grab->modifiersDetail.pMask = NULL;
grab->modifierDevice = modDevice; grab->modifierDevice = modDevice;
grab->type = type; grab->type = type;
grab->grabtype = grabtype;
grab->detail.exact = keybut; grab->detail.exact = keybut;
grab->detail.pMask = NULL; grab->detail.pMask = NULL;
grab->confineTo = confineTo; grab->confineTo = confineTo;
@ -411,7 +412,8 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
grab = grab->next) grab = grab->next)
{ {
if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) || if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) ||
!GrabMatchesSecond(grab, pMinuendGrab, (grab->coreGrab))) !GrabMatchesSecond(grab, pMinuendGrab,
(grab->grabtype == GRABTYPE_CORE)))
continue; continue;
if (GrabSupersedesSecond(pMinuendGrab, grab)) if (GrabSupersedesSecond(pMinuendGrab, grab))
{ {
@ -442,6 +444,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
(Bool)grab->pointerMode, (Bool)grab->pointerMode,
grab->modifierDevice, grab->modifierDevice,
AnyModifier, (int)grab->type, AnyModifier, (int)grab->type,
grab->grabtype,
pMinuendGrab->detail.exact, pMinuendGrab->detail.exact,
grab->confineTo, grab->cursor); grab->confineTo, grab->cursor);
if (!pNewGrab) if (!pNewGrab)

View File

@ -434,7 +434,7 @@ extern int GrabDevice(
unsigned /* ownerEvents */, unsigned /* ownerEvents */,
Time /* ctime */, Time /* ctime */,
Mask /* mask */, Mask /* mask */,
Bool /* coreGrab */, int /* grabtype */,
Cursor /* curs */, Cursor /* curs */,
Window /* confineToWin */, Window /* confineToWin */,
CARD8 * /* status */); CARD8 * /* status */);

View File

@ -37,6 +37,7 @@ extern _X_EXPORT GrabPtr CreateGrab(
DeviceIntPtr /* modDevice */, DeviceIntPtr /* modDevice */,
unsigned short /* modifiers */, unsigned short /* modifiers */,
int /* type */, int /* type */,
int /* grabtype */,
KeyCode /* keybut */, KeyCode /* keybut */,
WindowPtr /* confineTo */, WindowPtr /* confineTo */,
CursorPtr /* cursor */); CursorPtr /* cursor */);

View File

@ -150,6 +150,12 @@ typedef struct _DetailRec { /* Grab details may be bit masks */
Mask *pMask; Mask *pMask;
} DetailRec; } DetailRec;
typedef enum {
GRABTYPE_CORE,
GRABTYPE_XI,
GRABTYPE_XI2
} GrabType;
/** /**
* Central struct for device grabs. * Central struct for device grabs.
* The same struct is used for both core grabs and device grabs, with * The same struct is used for both core grabs and device grabs, with
@ -171,7 +177,7 @@ typedef struct _GrabRec {
unsigned ownerEvents:1; unsigned ownerEvents:1;
unsigned keyboardMode:1; unsigned keyboardMode:1;
unsigned pointerMode:1; unsigned pointerMode:1;
unsigned coreGrab:1; /* grab is on core device */ GrabType grabtype;
CARD8 type; /* event type */ CARD8 type; /* event type */
DetailRec modifiersDetail; DetailRec modifiersDetail;
DeviceIntPtr modifierDevice; DeviceIntPtr modifierDevice;