dix: move ProcGrabPointer guts into GrabDevice.

Yes, this means we have even more arguments to GrabDevice. But it beats having
a copy of most but not all of GrabDevice in ProcGrabPointer.
Also, reshuffle the order of parameters, the CARD* status is a return value
and should be last.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2009-03-19 09:33:02 +10:00
parent dc153271b6
commit 111ef10375
3 changed files with 81 additions and 117 deletions

View File

@ -126,10 +126,11 @@ ProcXGrabDevice(ClientPtr client)
X_GrabDevice)) != Success) X_GrabDevice)) != Success)
return rc; return rc;
rc = GrabDevice(client, dev, stuff->this_device_mode, rc = GrabDevice(client, dev, stuff->other_devices_mode,
stuff->other_devices_mode, stuff->grabWindow, stuff->this_device_mode, stuff->grabWindow,
stuff->ownerEvents, stuff->time, stuff->ownerEvents, stuff->time,
tmp[stuff->deviceid].mask, &rep.status, FALSE); tmp[stuff->deviceid].mask, FALSE, None, None,
&rep.status);
if (rc != Success) if (rc != Success)
return rc; return rc;

View File

@ -4390,40 +4390,21 @@ ProcGrabPointer(ClientPtr client)
xGrabPointerReply rep; xGrabPointerReply rep;
DeviceIntPtr device = PickPointer(client); DeviceIntPtr device = PickPointer(client);
GrabPtr grab; GrabPtr grab;
WindowPtr pWin, confineTo; WindowPtr confineTo;
CursorPtr cursor, oldCursor; CursorPtr oldCursor;
REQUEST(xGrabPointerReq); REQUEST(xGrabPointerReq);
TimeStamp time; TimeStamp time;
Mask access_mode = DixGrabAccess;
int rc; int rc;
REQUEST_SIZE_MATCH(xGrabPointerReq); REQUEST_SIZE_MATCH(xGrabPointerReq);
UpdateCurrentTime(); UpdateCurrentTime();
if ((stuff->pointerMode != GrabModeSync) &&
(stuff->pointerMode != GrabModeAsync))
{
client->errorValue = stuff->pointerMode;
return BadValue;
}
if ((stuff->keyboardMode != GrabModeSync) &&
(stuff->keyboardMode != GrabModeAsync))
{
client->errorValue = stuff->keyboardMode;
return BadValue;
}
if ((stuff->ownerEvents != xFalse) && (stuff->ownerEvents != xTrue))
{
client->errorValue = stuff->ownerEvents;
return BadValue;
}
if (stuff->eventMask & ~PointerGrabMask) if (stuff->eventMask & ~PointerGrabMask)
{ {
client->errorValue = stuff->eventMask; client->errorValue = stuff->eventMask;
return BadValue; return BadValue;
} }
rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess);
if (rc != Success)
return rc;
if (stuff->confineTo == None) if (stuff->confineTo == None)
confineTo = NullWindow; confineTo = NullWindow;
else else
@ -4433,81 +4414,32 @@ ProcGrabPointer(ClientPtr client)
if (rc != Success) if (rc != Success)
return rc; return rc;
} }
if (stuff->cursor == None)
cursor = NullCursor;
else
{
rc = dixLookupResourceByType((pointer *)&cursor, stuff->cursor, RT_CURSOR,
client, DixUseAccess);
if (rc != Success)
{
client->errorValue = stuff->cursor;
return (rc == BadValue) ? BadCursor : rc;
}
access_mode |= DixForceAccess;
}
if (stuff->pointerMode == GrabModeSync ||
stuff->keyboardMode == GrabModeSync)
access_mode |= DixFreezeAccess;
rc = XaceHook(XACE_DEVICE_ACCESS, client, device, access_mode);
if (rc != Success)
return rc;
/* at this point, some sort of reply is guaranteed. */
time = ClientTimeToServerTime(stuff->time);
memset(&rep, 0, sizeof(xGrabPointerReply)); memset(&rep, 0, sizeof(xGrabPointerReply));
oldCursor = NullCursor;
grab = device->deviceGrab.grab;
if (grab)
{
if (grab->confineTo && !confineTo)
ConfineCursorToWindow(device, RootWindow(device), FALSE, FALSE);
oldCursor = grab->cursor;
}
rc = GrabDevice(client, device, stuff->pointerMode, stuff->keyboardMode,
stuff->grabWindow, stuff->ownerEvents, stuff->time,
stuff->eventMask, TRUE, stuff->cursor,
stuff->confineTo, &rep.status);
if (rc != Success)
return rc;
if (oldCursor)
FreeCursor (oldCursor, (Cursor)0);
time = ClientTimeToServerTime(stuff->time);
rep.type = X_Reply; rep.type = X_Reply;
rep.sequenceNumber = client->sequence; rep.sequenceNumber = client->sequence;
rep.length = 0; rep.length = 0;
grab = device->deviceGrab.grab;
/* check for
1. other client has a grab on the device already.
2. window is viewable
3. other client has this device as frozen "other" device
4. times are screwed.
*/
if ((grab) && !SameClient(grab, client))
rep.status = AlreadyGrabbed;
else if ((!pWin->realized) ||
(confineTo &&
!(confineTo->realized
&& BorderSizeNotEmpty(device, confineTo))))
rep.status = GrabNotViewable;
else if (device->deviceGrab.sync.frozen &&
device->deviceGrab.sync.other &&
!SameClient(device->deviceGrab.sync.other, client))
rep.status = GrabFrozen;
else if ((CompareTimeStamps(time, currentTime) == LATER) ||
(CompareTimeStamps(time, device->deviceGrab.grabTime) == EARLIER))
rep.status = GrabInvalidTime;
else
{
GrabRec tempGrab;
oldCursor = NullCursor;
if (grab)
{
if (grab->confineTo && !confineTo)
ConfineCursorToWindow(device, RootWindow(device), FALSE, FALSE);
oldCursor = grab->cursor;
}
tempGrab.next = NULL;
tempGrab.cursor = cursor;
tempGrab.resource = client->clientAsMask;
tempGrab.ownerEvents = stuff->ownerEvents;
tempGrab.eventMask = stuff->eventMask;
tempGrab.confineTo = confineTo;
tempGrab.window = pWin;
tempGrab.keyboardMode = stuff->keyboardMode;
tempGrab.pointerMode = stuff->pointerMode;
tempGrab.device = device;
tempGrab.coreGrab = True;
(*device->deviceGrab.ActivateGrab)(device, &tempGrab, time, FALSE);
if (oldCursor)
FreeCursor (oldCursor, (Cursor)0);
rep.status = GrabSuccess;
}
WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep); WriteReplyToClient(client, sizeof(xGrabPointerReply), &rep);
return Success; return Success;
} }
@ -4613,26 +4545,27 @@ ProcUngrabPointer(ClientPtr client)
*/ */
int int
GrabDevice(ClientPtr client, DeviceIntPtr dev, GrabDevice(ClientPtr client, DeviceIntPtr dev,
unsigned this_mode, unsigned other_mode, Window grabWindow, unsigned pointer_mode, unsigned keyboard_mode, Window grabWindow,
unsigned ownerEvents, Time ctime, Mask mask, CARD8 *status, unsigned ownerEvents, Time ctime, Mask mask,
Bool coreGrab) Bool coreGrab, Cursor curs, Window confineToWin, CARD8 *status)
{ {
WindowPtr pWin; WindowPtr pWin, confineTo;
GrabPtr grab; GrabPtr grab;
TimeStamp time; TimeStamp time;
Mask access_mode = DixGrabAccess; Mask access_mode = DixGrabAccess;
int rc; int rc;
GrabInfoPtr grabInfo = &dev->deviceGrab; GrabInfoPtr grabInfo = &dev->deviceGrab;
CursorPtr cursor;
UpdateCurrentTime(); UpdateCurrentTime();
if ((this_mode != GrabModeSync) && (this_mode != GrabModeAsync)) if ((keyboard_mode != GrabModeSync) && (keyboard_mode != GrabModeAsync))
{ {
client->errorValue = this_mode; client->errorValue = keyboard_mode;
return BadValue; return BadValue;
} }
if ((other_mode != GrabModeSync) && (other_mode != GrabModeAsync)) if ((pointer_mode != GrabModeSync) && (pointer_mode != GrabModeAsync))
{ {
client->errorValue = other_mode; client->errorValue = pointer_mode;
return BadValue; return BadValue;
} }
if ((ownerEvents != xFalse) && (ownerEvents != xTrue)) if ((ownerEvents != xFalse) && (ownerEvents != xTrue))
@ -4644,7 +4577,32 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess); rc = dixLookupWindow(&pWin, grabWindow, client, DixSetAttrAccess);
if (rc != Success) if (rc != Success)
return rc; return rc;
if (this_mode == GrabModeSync || other_mode == GrabModeSync)
if (confineToWin == None)
confineTo = NullWindow;
else
{
rc = dixLookupWindow(&confineTo, confineToWin, client,
DixSetAttrAccess);
if (rc != Success)
return rc;
}
if (curs == None)
cursor = NullCursor;
else
{
rc = dixLookupResourceByType((pointer *)&cursor, curs, RT_CURSOR,
client, DixUseAccess);
if (rc != Success)
{
client->errorValue = curs;
return (rc == BadValue) ? BadCursor : rc;
}
access_mode |= DixForceAccess;
}
if (keyboard_mode == GrabModeSync || pointer_mode == GrabModeSync)
access_mode |= DixFreezeAccess; access_mode |= DixFreezeAccess;
rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode); rc = XaceHook(XACE_DEVICE_ACCESS, client, dev, access_mode);
if (rc != Success) if (rc != Success)
@ -4654,7 +4612,10 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
grab = grabInfo->grab; grab = grabInfo->grab;
if (grab && !SameClient(grab, client)) if (grab && !SameClient(grab, client))
*status = AlreadyGrabbed; *status = AlreadyGrabbed;
else if (!pWin->realized) else if ((!pWin->realized) ||
(confineTo &&
!(confineTo->realized
&& BorderSizeNotEmpty(dev, confineTo))))
*status = GrabNotViewable; *status = GrabNotViewable;
else if ((CompareTimeStamps(time, currentTime) == LATER) || else if ((CompareTimeStamps(time, currentTime) == LATER) ||
(CompareTimeStamps(time, grabInfo->grabTime) == EARLIER)) (CompareTimeStamps(time, grabInfo->grabTime) == EARLIER))
@ -4673,13 +4634,13 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
tempGrab.window = pWin; tempGrab.window = pWin;
tempGrab.resource = client->clientAsMask; tempGrab.resource = client->clientAsMask;
tempGrab.ownerEvents = ownerEvents; tempGrab.ownerEvents = ownerEvents;
tempGrab.keyboardMode = this_mode; tempGrab.keyboardMode = keyboard_mode;
tempGrab.pointerMode = other_mode; tempGrab.pointerMode = pointer_mode;
tempGrab.eventMask = mask; tempGrab.eventMask = mask;
tempGrab.device = dev; tempGrab.device = dev;
tempGrab.cursor = NULL; tempGrab.cursor = cursor;
tempGrab.coreGrab = coreGrab; tempGrab.confineTo = confineTo;
tempGrab.coreGrab = coreGrab;
(*grabInfo->ActivateGrab)(dev, &tempGrab, time, FALSE); (*grabInfo->ActivateGrab)(dev, &tempGrab, time, FALSE);
*status = GrabSuccess; *status = GrabSuccess;
} }
@ -4702,10 +4663,10 @@ ProcGrabKeyboard(ClientPtr client)
REQUEST_SIZE_MATCH(xGrabKeyboardReq); REQUEST_SIZE_MATCH(xGrabKeyboardReq);
memset(&rep, 0, sizeof(xGrabKeyboardReply)); memset(&rep, 0, sizeof(xGrabKeyboardReply));
result = GrabDevice(client, keyboard, stuff->keyboardMode, result = GrabDevice(client, keyboard, stuff->pointerMode,
stuff->pointerMode, stuff->grabWindow, stuff->keyboardMode, stuff->grabWindow, stuff->ownerEvents,
stuff->ownerEvents, stuff->time, stuff->time, KeyPressMask | KeyReleaseMask, TRUE, None, None,
KeyPressMask | KeyReleaseMask, &rep.status, TRUE); &rep.status);
if (result != Success) if (result != Success)
return result; return result;

View File

@ -434,8 +434,10 @@ extern _X_EXPORT int GrabDevice(
unsigned /* ownerEvents */, unsigned /* ownerEvents */,
Time /* ctime */, Time /* ctime */,
Mask /* mask */, Mask /* mask */,
CARD8 * /* status */, Bool /* coreGrab */,
Bool /* coreGrab */); Cursor /* curs */,
Window /* confineToWin */,
CARD8 * /* status */);
extern _X_EXPORT void InitEvents(void); extern _X_EXPORT void InitEvents(void);