From c34d411adcce6b183144a174838d5da441f3b9a2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 23 Apr 2013 15:52:18 +1000 Subject: [PATCH 25/35] dix: AllocGrab can copy if an argument is passed in Signed-off-by: Peter Hutterer (cherry picked from commit 925e35122ebad877395bcf13676e9dbeb254bdfa) --- Xi/exevents.c | 2 +- Xi/ungrdevb.c | 2 +- Xi/ungrdevk.c | 2 +- Xi/xipassivegrab.c | 2 +- dix/events.c | 16 +++++++--------- dix/grabs.c | 10 ++++++++-- include/dixgrabs.h | 2 +- 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Xi/exevents.c b/Xi/exevents.c index 755a5b6..7914b89 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -2845,7 +2845,7 @@ CheckDeviceGrabAndHintWindow(WindowPtr pWin, int type, (deliveryMask & DeviceButtonGrabMask)) { GrabPtr tempGrab; - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); if (!tempGrab) return; diff --git a/Xi/ungrdevb.c b/Xi/ungrdevb.c index c4632fa..b02510e 100644 --- a/Xi/ungrdevb.c +++ b/Xi/ungrdevb.c @@ -127,7 +127,7 @@ ProcXUngrabDeviceButton(ClientPtr client) (stuff->modifiers & ~AllModifiersMask)) return BadValue; - temporaryGrab = AllocGrab(); + temporaryGrab = AllocGrab(NULL); if (!temporaryGrab) return BadAlloc; diff --git a/Xi/ungrdevk.c b/Xi/ungrdevk.c index 3273878..f981171 100644 --- a/Xi/ungrdevk.c +++ b/Xi/ungrdevk.c @@ -134,7 +134,7 @@ ProcXUngrabDeviceKey(ClientPtr client) (stuff->modifiers & ~AllModifiersMask)) return BadValue; - temporaryGrab = AllocGrab(); + temporaryGrab = AllocGrab(NULL); if (!temporaryGrab) return BadAlloc; diff --git a/Xi/xipassivegrab.c b/Xi/xipassivegrab.c index 62a3a46..eccec0a 100644 --- a/Xi/xipassivegrab.c +++ b/Xi/xipassivegrab.c @@ -307,7 +307,7 @@ ProcXIPassiveUngrabDevice(ClientPtr client) mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD); - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); if (!tempGrab) return BadAlloc; diff --git a/dix/events.c b/dix/events.c index 0216502..6a8e7a6 100644 --- a/dix/events.c +++ b/dix/events.c @@ -1489,8 +1489,7 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab, if (grab->cursor) grab->cursor->refcnt++; BUG_WARN(grabinfo->grab != NULL); - grabinfo->grab = AllocGrab(); - CopyGrab(grabinfo->grab, grab); + grabinfo->grab = AllocGrab(grab); grabinfo->fromPassiveGrab = isPassive; grabinfo->implicitGrab = autoGrab & ImplicitGrabMask; PostNewCursor(mouse); @@ -1593,8 +1592,7 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, else grabinfo->grabTime = time; BUG_WARN(grabinfo->grab != NULL); - grabinfo->grab = AllocGrab(); - CopyGrab(grabinfo->grab, grab); + grabinfo->grab = AllocGrab(grab); grabinfo->fromPassiveGrab = passive; grabinfo->implicitGrab = passive & ImplicitGrabMask; CheckGrabForSyncs(keybd, (Bool) grab->keyboardMode, @@ -1988,7 +1986,7 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win, else return FALSE; - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); if (!tempGrab) return FALSE; tempGrab->next = NULL; @@ -3895,7 +3893,7 @@ CheckPassiveGrabsOnWindow(WindowPtr pWin, if (!grab) return NULL; - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); /* Fill out the grab details, but leave the type for later before * comparing */ @@ -5084,7 +5082,7 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev, else { GrabPtr tempGrab; - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); tempGrab->next = NULL; tempGrab->window = pWin; @@ -5440,7 +5438,7 @@ ProcUngrabKey(ClientPtr client) client->errorValue = stuff->modifiers; return BadValue; } - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); if (!tempGrab) return BadAlloc; tempGrab->resource = client->clientAsMask; @@ -5634,7 +5632,7 @@ ProcUngrabButton(ClientPtr client) ptr = PickPointer(client); - tempGrab = AllocGrab(); + tempGrab = AllocGrab(NULL); if (!tempGrab) return BadAlloc; tempGrab->resource = client->clientAsMask; diff --git a/dix/grabs.c b/dix/grabs.c index 0a2111d..f46a6b2 100644 --- a/dix/grabs.c +++ b/dix/grabs.c @@ -189,7 +189,7 @@ UngrabAllDevices(Bool kill_client) } GrabPtr -AllocGrab(void) +AllocGrab(const GrabPtr src) { 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; } @@ -213,7 +219,7 @@ CreateGrab(int client, DeviceIntPtr device, DeviceIntPtr modDevice, { GrabPtr grab; - grab = AllocGrab(); + grab = AllocGrab(NULL); if (!grab) return (GrabPtr) NULL; grab->resource = FakeClientID(client); diff --git a/include/dixgrabs.h b/include/dixgrabs.h index eccec77..ca3c95b 100644 --- a/include/dixgrabs.h +++ b/include/dixgrabs.h @@ -31,7 +31,7 @@ struct _GrabParameters; extern void PrintDeviceGrabInfo(DeviceIntPtr dev); extern void UngrabAllDevices(Bool kill_client); -extern GrabPtr AllocGrab(void); +extern GrabPtr AllocGrab(const GrabPtr src); extern void FreeGrab(GrabPtr grab); extern Bool CopyGrab(GrabPtr dst, const GrabPtr src); -- 1.8.2.1