dix: AllocGrab can copy if an argument is passed in

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2013-04-23 15:52:18 +10:00
parent 4980bcef99
commit 925e35122e
7 changed files with 20 additions and 16 deletions

View File

@ -2844,7 +2844,7 @@ CheckDeviceGrabAndHintWindow(WindowPtr pWin, int type,
(deliveryMask & DeviceButtonGrabMask)) { (deliveryMask & DeviceButtonGrabMask)) {
GrabPtr tempGrab; GrabPtr tempGrab;
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
if (!tempGrab) if (!tempGrab)
return; return;

View File

@ -127,7 +127,7 @@ ProcXUngrabDeviceButton(ClientPtr client)
(stuff->modifiers & ~AllModifiersMask)) (stuff->modifiers & ~AllModifiersMask))
return BadValue; return BadValue;
temporaryGrab = AllocGrab(); temporaryGrab = AllocGrab(NULL);
if (!temporaryGrab) if (!temporaryGrab)
return BadAlloc; return BadAlloc;

View File

@ -134,7 +134,7 @@ ProcXUngrabDeviceKey(ClientPtr client)
(stuff->modifiers & ~AllModifiersMask)) (stuff->modifiers & ~AllModifiersMask))
return BadValue; return BadValue;
temporaryGrab = AllocGrab(); temporaryGrab = AllocGrab(NULL);
if (!temporaryGrab) if (!temporaryGrab)
return BadAlloc; return BadAlloc;

View File

@ -307,7 +307,7 @@ ProcXIPassiveUngrabDevice(ClientPtr client)
mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD); mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD);
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
if (!tempGrab) if (!tempGrab)
return BadAlloc; return BadAlloc;

View File

@ -1492,8 +1492,7 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab,
if (grab->cursor) if (grab->cursor)
grab->cursor->refcnt++; grab->cursor->refcnt++;
BUG_WARN(grabinfo->grab != NULL); BUG_WARN(grabinfo->grab != NULL);
grabinfo->grab = AllocGrab(); grabinfo->grab = AllocGrab(grab);
CopyGrab(grabinfo->grab, grab);
grabinfo->fromPassiveGrab = isPassive; grabinfo->fromPassiveGrab = isPassive;
grabinfo->implicitGrab = autoGrab & ImplicitGrabMask; grabinfo->implicitGrab = autoGrab & ImplicitGrabMask;
PostNewCursor(mouse); PostNewCursor(mouse);
@ -1596,8 +1595,7 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time,
else else
grabinfo->grabTime = time; grabinfo->grabTime = time;
BUG_WARN(grabinfo->grab != NULL); BUG_WARN(grabinfo->grab != NULL);
grabinfo->grab = AllocGrab(); grabinfo->grab = AllocGrab(grab);
CopyGrab(grabinfo->grab, grab);
grabinfo->fromPassiveGrab = passive; grabinfo->fromPassiveGrab = passive;
grabinfo->implicitGrab = passive & ImplicitGrabMask; grabinfo->implicitGrab = passive & ImplicitGrabMask;
CheckGrabForSyncs(keybd, (Bool) grab->keyboardMode, CheckGrabForSyncs(keybd, (Bool) grab->keyboardMode,
@ -1991,7 +1989,7 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
else else
return FALSE; return FALSE;
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
if (!tempGrab) if (!tempGrab)
return FALSE; return FALSE;
tempGrab->next = NULL; tempGrab->next = NULL;
@ -3898,7 +3896,7 @@ CheckPassiveGrabsOnWindow(WindowPtr pWin,
if (!grab) if (!grab)
return NULL; return NULL;
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
/* Fill out the grab details, but leave the type for later before /* Fill out the grab details, but leave the type for later before
* comparing */ * comparing */
@ -5087,7 +5085,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
else { else {
GrabPtr tempGrab; GrabPtr tempGrab;
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
tempGrab->next = NULL; tempGrab->next = NULL;
tempGrab->window = pWin; tempGrab->window = pWin;
@ -5443,7 +5441,7 @@ ProcUngrabKey(ClientPtr client)
client->errorValue = stuff->modifiers; client->errorValue = stuff->modifiers;
return BadValue; return BadValue;
} }
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
if (!tempGrab) if (!tempGrab)
return BadAlloc; return BadAlloc;
tempGrab->resource = client->clientAsMask; tempGrab->resource = client->clientAsMask;
@ -5637,7 +5635,7 @@ ProcUngrabButton(ClientPtr client)
ptr = PickPointer(client); ptr = PickPointer(client);
tempGrab = AllocGrab(); tempGrab = AllocGrab(NULL);
if (!tempGrab) if (!tempGrab)
return BadAlloc; return BadAlloc;
tempGrab->resource = client->clientAsMask; tempGrab->resource = client->clientAsMask;

View File

@ -189,7 +189,7 @@ UngrabAllDevices(Bool kill_client)
} }
GrabPtr GrabPtr
AllocGrab(void) AllocGrab(const GrabPtr src)
{ {
GrabPtr grab = calloc(1, sizeof(GrabRec)); GrabPtr grab = calloc(1, sizeof(GrabRec));
@ -201,6 +201,12 @@ AllocGrab(void)
} }
} }
if (src && !CopyGrab(grab, src)) {
free(grab->xi2mask);
free(grab);
grab = NULL;
}
return grab; return grab;
} }
@ -213,7 +219,7 @@ CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice,
{ {
GrabPtr grab; GrabPtr grab;
grab = AllocGrab(); grab = AllocGrab(NULL);
if (!grab) if (!grab)
return (GrabPtr) NULL; return (GrabPtr) NULL;
grab->resource = FakeClientID(client); grab->resource = FakeClientID(client);

View File

@ -31,7 +31,7 @@ struct _GrabParameters;
extern void PrintDeviceGrabInfo(DeviceIntPtr dev); extern void PrintDeviceGrabInfo(DeviceIntPtr dev);
extern void UngrabAllDevices(Bool kill_client); extern void UngrabAllDevices(Bool kill_client);
extern GrabPtr AllocGrab(void); extern GrabPtr AllocGrab(const GrabPtr src);
extern void FreeGrab(GrabPtr grab); extern void FreeGrab(GrabPtr grab);
extern Bool CopyGrab(GrabPtr dst, const GrabPtr src); extern Bool CopyGrab(GrabPtr dst, const GrabPtr src);