aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/dix/events.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-12-12 14:26:41 +0100
committermarha <marha@users.sourceforge.net>2011-12-12 14:26:41 +0100
commit2b5652fc7742c5ac57aca701214b046626a729e9 (patch)
treea994b9e63a32a7c061bcfb563aa22369c217e49c /xorg-server/dix/events.c
parent2331d6e4ac699e775ccee07a8a461cae0a98033a (diff)
parent5efb0a5e19b75137b7294b27f4e7878aeb8f0927 (diff)
downloadvcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.tar.gz
vcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.tar.bz2
vcxsrv-2b5652fc7742c5ac57aca701214b046626a729e9.zip
Merge remote-tracking branch 'origin/released'
Diffstat (limited to 'xorg-server/dix/events.c')
-rw-r--r--xorg-server/dix/events.c288
1 files changed, 146 insertions, 142 deletions
diff --git a/xorg-server/dix/events.c b/xorg-server/dix/events.c
index 12b601449..3d75104b3 100644
--- a/xorg-server/dix/events.c
+++ b/xorg-server/dix/events.c
@@ -420,12 +420,6 @@ GetXI2EventFilterMask(int evtype)
return (1 << (evtype % 8));
}
-static inline int
-GetXI2EventFilterOffset(int evtype)
-{
- return (evtype / 8);
-}
-
/**
* For the given event, return the matching event filter. This filter may then
* be AND'ed with the selected event mask.
@@ -459,12 +453,15 @@ GetEventFilter(DeviceIntPtr dev, xEvent *event)
* for the event_type.
*/
static int
-GetXI2MaskByte(unsigned char xi2mask[][XI2MASKSIZE], DeviceIntPtr dev, int event_type)
+GetXI2MaskByte(XI2Mask *mask, DeviceIntPtr dev, int event_type)
{
- int byte = GetXI2EventFilterOffset(event_type);
- return xi2mask[dev->id][byte] |
- xi2mask[XIAllDevices][byte] |
- (IsMaster(dev) ? xi2mask[XIAllMasterDevices][byte] : 0);
+ /* we just return the matching filter because that's the only use
+ * for this mask anyway.
+ */
+ if (xi2mask_isset(mask, dev, event_type))
+ return GetXI2EventFilterMask(event_type);
+ else
+ return 0;
}
@@ -476,16 +473,14 @@ Bool
WindowXI2MaskIsset(DeviceIntPtr dev, WindowPtr win, xEvent* ev)
{
OtherInputMasks *inputMasks = wOtherInputMasks(win);
- int filter;
int evtype;
if (!inputMasks || xi2_get_type(ev) == 0)
return 0;
evtype = ((xGenericEvent*)ev)->evtype;
- filter = GetEventFilter(dev, ev);
- return !!(GetXI2MaskByte(inputMasks->xi2mask, dev, evtype) & filter);
+ return xi2mask_isset(inputMasks->xi2mask, dev, evtype);
}
Mask
@@ -1135,12 +1130,14 @@ NoticeEventTime(InternalEvent *ev)
void
EnqueueEvent(InternalEvent *ev, DeviceIntPtr device)
{
- QdEventPtr tail = *syncEvents.pendtail;
+ QdEventPtr tail;
QdEventPtr qe;
SpritePtr pSprite = device->spriteInfo->sprite;
int eventlen;
DeviceEvent *event = &ev->device_event;
+ tail = list_last_entry(&syncEvents.pending, QdEventRec, next);
+
NoticeTime((InternalEvent*)event);
/* Fix for key repeating bug. */
@@ -1199,15 +1196,13 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device)
qe = malloc(sizeof(QdEventRec) + eventlen);
if (!qe)
return;
- qe->next = (QdEventPtr)NULL;
+ list_init(&qe->next);
qe->device = device;
qe->pScreen = pSprite->hotPhys.pScreen;
qe->months = currentTime.months;
qe->event = (InternalEvent *)(qe + 1);
memcpy(qe->event, event, eventlen);
- if (tail)
- syncEvents.pendtail = &tail->next;
- *syncEvents.pendtail = qe;
+ list_append(&qe->next, &syncEvents.pending);
}
/**
@@ -1219,22 +1214,20 @@ EnqueueEvent(InternalEvent *ev, DeviceIntPtr device)
* If there is none, we're done. If there is at least one device that is not
* frozen, then re-run from the beginning of the event queue.
*/
-static void
+void
PlayReleasedEvents(void)
{
- QdEventPtr *prev, qe;
+ QdEventPtr tmp;
+ QdEventPtr qe;
DeviceIntPtr dev;
DeviceIntPtr pDev;
- prev = &syncEvents.pending;
- while ( (qe = *prev) )
- {
+restart:
+ list_for_each_entry_safe(qe, tmp, &syncEvents.pending, next) {
if (!qe->device->deviceGrab.sync.frozen)
{
- *prev = qe->next;
- pDev = qe->device;
- if (*syncEvents.pendtail == *prev)
- syncEvents.pendtail = prev;
+ list_del(&qe->next);
+ pDev = qe->device;
if (qe->event->any.type == ET_Motion)
CheckVirtualMotion(pDev, qe, NullWindow);
syncEvents.time.months = qe->months;
@@ -1271,12 +1264,11 @@ PlayReleasedEvents(void)
;
if (!dev)
break;
+
/* Playing the event may have unfrozen another device. */
/* So to play it safe, restart at the head of the queue */
- prev = &syncEvents.pending;
+ goto restart;
}
- else
- prev = &qe->next;
}
}
@@ -1317,7 +1309,8 @@ ComputeFreezes(void)
for (dev = inputInfo.devices; dev; dev = dev->next)
FreezeThaw(dev, dev->deviceGrab.sync.other ||
(dev->deviceGrab.sync.state >= FROZEN));
- if (syncEvents.playingEvents || (!replayDev && !syncEvents.pending))
+ if (syncEvents.playingEvents ||
+ (!replayDev && list_is_empty(&syncEvents.pending)))
return;
syncEvents.playingEvents = TRUE;
if (replayDev)
@@ -1514,8 +1507,8 @@ ActivatePointerGrab(DeviceIntPtr mouse, GrabPtr grab,
grabinfo->grabTime = time;
if (grab->cursor)
grab->cursor->refcnt++;
- grabinfo->activeGrab = *grab;
- grabinfo->grab = &grabinfo->activeGrab;
+ CopyGrab(grabinfo->activeGrab, grab);
+ grabinfo->grab = grabinfo->activeGrab;
grabinfo->fromPassiveGrab = isPassive;
grabinfo->implicitGrab = autoGrab & ImplicitGrabMask;
PostNewCursor(mouse);
@@ -1591,8 +1584,8 @@ ActivateKeyboardGrab(DeviceIntPtr keybd, GrabPtr grab, TimeStamp time, Bool pass
grabinfo->grabTime = syncEvents.time;
else
grabinfo->grabTime = time;
- grabinfo->activeGrab = *grab;
- grabinfo->grab = &grabinfo->activeGrab;
+ CopyGrab(grabinfo->activeGrab, grab);
+ grabinfo->grab = grabinfo->activeGrab;
grabinfo->fromPassiveGrab = passive;
grabinfo->implicitGrab = passive & ImplicitGrabMask;
CheckGrabForSyncs(keybd, (Bool)grab->keyboardMode, (Bool)grab->pointerMode);
@@ -1981,7 +1974,7 @@ static BOOL
ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
xEvent *event, Mask deliveryMask)
{
- GrabRec tempGrab;
+ GrabPtr tempGrab;
OtherInputMasks *inputMasks;
CARD8 type = event->u.u.type;
GrabType grabtype;
@@ -1995,30 +1988,32 @@ ActivateImplicitGrab(DeviceIntPtr dev, ClientPtr client, WindowPtr win,
else
return FALSE;
- memset(&tempGrab, 0, sizeof(GrabRec));
- tempGrab.next = NULL;
- tempGrab.device = dev;
- tempGrab.resource = client->clientAsMask;
- tempGrab.window = win;
- tempGrab.ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE;
- tempGrab.eventMask = deliveryMask;
- tempGrab.keyboardMode = GrabModeAsync;
- tempGrab.pointerMode = GrabModeAsync;
- tempGrab.confineTo = NullWindow;
- tempGrab.cursor = NullCursor;
- tempGrab.type = type;
- tempGrab.grabtype = grabtype;
+ tempGrab = AllocGrab();
+ if (!tempGrab)
+ return FALSE;
+ tempGrab->next = NULL;
+ tempGrab->device = dev;
+ tempGrab->resource = client->clientAsMask;
+ tempGrab->window = win;
+ tempGrab->ownerEvents = (deliveryMask & OwnerGrabButtonMask) ? TRUE : FALSE;
+ tempGrab->eventMask = deliveryMask;
+ tempGrab->keyboardMode = GrabModeAsync;
+ tempGrab->pointerMode = GrabModeAsync;
+ tempGrab->confineTo = NullWindow;
+ tempGrab->cursor = NullCursor;
+ tempGrab->type = type;
+ tempGrab->grabtype = grabtype;
/* get the XI and XI2 device mask */
inputMasks = wOtherInputMasks(win);
- tempGrab.deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id]: 0;
+ tempGrab->deviceMask = (inputMasks) ? inputMasks->inputEvents[dev->id]: 0;
if (inputMasks)
- memcpy(tempGrab.xi2mask, inputMasks->xi2mask,
- sizeof(tempGrab.xi2mask));
+ xi2mask_merge(tempGrab->xi2mask, inputMasks->xi2mask);
- (*dev->deviceGrab.ActivateGrab)(dev, &tempGrab,
+ (*dev->deviceGrab.ActivateGrab)(dev, tempGrab,
currentTime, TRUE | ImplicitGrabMask);
+ FreeGrab(tempGrab);
return TRUE;
}
@@ -2563,10 +2558,7 @@ EventIsDeliverable(DeviceIntPtr dev, InternalEvent* event, WindowPtr win)
if ((type = GetXI2Type(event)) != 0)
{
- filter = GetXI2EventFilterMask(type);
-
- if (inputMasks &&
- (GetXI2MaskByte(inputMasks->xi2mask, dev, type) & filter))
+ if (inputMasks && xi2mask_isset(inputMasks->xi2mask, dev, type))
rc |= EVENT_XI2_MASK;
}
@@ -3665,7 +3657,7 @@ CheckPassiveGrabsOnWindow(
{
SpritePtr pSprite = device->spriteInfo->sprite;
GrabPtr grab = wPassiveGrabs(pWin);
- GrabRec tempGrab;
+ GrabPtr tempGrab;
GrabInfoPtr grabinfo;
#define CORE_MATCH 0x1
#define XI_MATCH 0x2
@@ -3674,27 +3666,30 @@ CheckPassiveGrabsOnWindow(
if (!grab)
return NULL;
+
+ tempGrab = AllocGrab();
+
/* Fill out the grab details, but leave the type for later before
* comparing */
switch (event->any.type)
{
case ET_KeyPress:
case ET_KeyRelease:
- tempGrab.detail.exact = event->device_event.detail.key;
+ tempGrab->detail.exact = event->device_event.detail.key;
break;
case ET_ButtonPress:
case ET_ButtonRelease:
- tempGrab.detail.exact = event->device_event.detail.button;
+ tempGrab->detail.exact = event->device_event.detail.button;
break;
default:
- tempGrab.detail.exact = 0;
+ tempGrab->detail.exact = 0;
break;
}
- tempGrab.window = pWin;
- tempGrab.device = device;
- tempGrab.detail.pMask = NULL;
- tempGrab.modifiersDetail.pMask = NULL;
- tempGrab.next = NULL;
+ tempGrab->window = pWin;
+ tempGrab->device = device;
+ tempGrab->detail.pMask = NULL;
+ tempGrab->modifiersDetail.pMask = NULL;
+ tempGrab->next = NULL;
for (; grab; grab = grab->next)
{
DeviceIntPtr gdev;
@@ -3719,29 +3714,29 @@ CheckPassiveGrabsOnWindow(
if (gdev && gdev->key)
xkbi= gdev->key->xkbInfo;
- tempGrab.modifierDevice = grab->modifierDevice;
- tempGrab.modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
+ tempGrab->modifierDevice = grab->modifierDevice;
+ tempGrab->modifiersDetail.exact = xkbi ? xkbi->state.grab_mods : 0;
/* Check for XI2 and XI grabs first */
- tempGrab.type = GetXI2Type(event);
- tempGrab.grabtype = GRABTYPE_XI2;
- if (GrabMatchesSecond(&tempGrab, grab, FALSE))
+ tempGrab->type = GetXI2Type(event);
+ tempGrab->grabtype = GRABTYPE_XI2;
+ if (GrabMatchesSecond(tempGrab, grab, FALSE))
match = XI2_MATCH;
if (!match)
{
- tempGrab.grabtype = GRABTYPE_XI;
- if ((tempGrab.type = GetXIType(event)) &&
- (GrabMatchesSecond(&tempGrab, grab, FALSE)))
+ tempGrab->grabtype = GRABTYPE_XI;
+ if ((tempGrab->type = GetXIType(event)) &&
+ (GrabMatchesSecond(tempGrab, grab, FALSE)))
match = XI_MATCH;
}
/* Check for a core grab (ignore the device when comparing) */
if (!match && checkCore)
{
- tempGrab.grabtype = GRABTYPE_CORE;
- if ((tempGrab.type = GetCoreType(event)) &&
- (GrabMatchesSecond(&tempGrab, grab, TRUE)))
+ tempGrab->grabtype = GRABTYPE_CORE;
+ if ((tempGrab->type = GetCoreType(event)) &&
+ (GrabMatchesSecond(tempGrab, grab, TRUE)))
match = CORE_MATCH;
}
@@ -3769,7 +3764,7 @@ CheckPassiveGrabsOnWindow(
Since XGrabDeviceButton requires to specify the
modifierDevice explicitly, we don't override this choice.
*/
- if (tempGrab.type < GenericEvent)
+ if (tempGrab->type < GenericEvent)
{
grab->device = device;
grab->modifierDevice = GetMaster(device, MASTER_KEYBOARD);
@@ -3808,7 +3803,7 @@ CheckPassiveGrabsOnWindow(
if (match & (XI_MATCH | CORE_MATCH))
{
event->device_event.corestate &= 0x1f00;
- event->device_event.corestate |= tempGrab.modifiersDetail.exact &
+ event->device_event.corestate |= tempGrab->modifiersDetail.exact &
(~0x1f00);
}
@@ -3869,6 +3864,7 @@ CheckPassiveGrabsOnWindow(
break;
}
+ FreeGrab(tempGrab);
return grab;
#undef CORE_MATCH
#undef XI_MATCH
@@ -4156,12 +4152,11 @@ DeliverGrabbedEvent(InternalEvent *event, DeviceIntPtr thisDev,
if (rc == Success)
{
int evtype = xi2_get_type(xi2);
- mask = GetXI2MaskByte(grab->xi2mask, thisDev, evtype);
+ mask = xi2mask_isset(grab->xi2mask, thisDev, evtype);
/* try XI2 event */
FixUpEventFromWindow(pSprite, xi2, grab->window, None, TRUE);
/* XXX: XACE */
- deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask,
- GetEventFilter(thisDev, xi2), grab);
+ deliveries = TryClientEvents(rClient(grab), thisDev, xi2, 1, mask, 1, grab);
} else if (rc != BadMatch)
ErrorF("[dix] %s: XI2 conversion failed in DGE (%d, %d). Skipping delivery.\n",
thisDev->name, event->any.type, rc);
@@ -4635,9 +4630,8 @@ DeviceEnterLeaveEvent(
if (grab)
{
Mask mask;
- mask = GetXI2MaskByte(grab->xi2mask, mouse, type);
- TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask,
- filter, grab);
+ mask = xi2mask_isset(grab->xi2mask, mouse, type);
+ TryClientEvents(rClient(grab), mouse, (xEvent*)event, 1, mask, 1, grab);
} else {
if (!WindowXI2MaskIsset(mouse, pWin, (xEvent*)event))
goto out;
@@ -5086,29 +5080,30 @@ GrabDevice(ClientPtr client, DeviceIntPtr dev,
*status = GrabFrozen;
else
{
- GrabRec tempGrab;
+ GrabPtr tempGrab;
- /* Otherwise segfaults happen on grabbed MPX devices */
- memset(&tempGrab, 0, sizeof(GrabRec));
+ tempGrab = AllocGrab();
- tempGrab.next = NULL;
- tempGrab.window = pWin;
- tempGrab.resource = client->clientAsMask;
- tempGrab.ownerEvents = ownerEvents;
- tempGrab.keyboardMode = keyboard_mode;
- tempGrab.pointerMode = pointer_mode;
+ tempGrab->next = NULL;
+ tempGrab->window = pWin;
+ tempGrab->resource = client->clientAsMask;
+ tempGrab->ownerEvents = ownerEvents;
+ tempGrab->keyboardMode = keyboard_mode;
+ tempGrab->pointerMode = pointer_mode;
if (grabtype == GRABTYPE_CORE)
- tempGrab.eventMask = mask->core;
+ tempGrab->eventMask = mask->core;
else if (grabtype == GRABTYPE_XI)
- tempGrab.eventMask = mask->xi;
+ tempGrab->eventMask = mask->xi;
else
- memcpy(tempGrab.xi2mask, mask->xi2mask, sizeof(tempGrab.xi2mask));
- tempGrab.device = dev;
- tempGrab.cursor = cursor;
- tempGrab.confineTo = confineTo;
- tempGrab.grabtype = grabtype;
- (*grabInfo->ActivateGrab)(dev, &tempGrab, time, FALSE);
+ xi2mask_merge(tempGrab->xi2mask, mask->xi2mask);
+ tempGrab->device = dev;
+ tempGrab->cursor = cursor;
+ tempGrab->confineTo = confineTo;
+ tempGrab->grabtype = grabtype;
+ (*grabInfo->ActivateGrab)(dev, tempGrab, time, FALSE);
*status = GrabSuccess;
+
+ FreeGrab(tempGrab);
}
return Success;
}
@@ -5264,6 +5259,7 @@ void
InitEvents(void)
{
int i;
+ QdEventPtr qe, tmp;
inputInfo.numDevices = 0;
inputInfo.devices = (DeviceIntPtr)NULL;
@@ -5277,13 +5273,10 @@ InitEvents(void)
syncEvents.replayDev = (DeviceIntPtr)NULL;
syncEvents.replayWin = NullWindow;
- while (syncEvents.pending)
- {
- QdEventPtr next = syncEvents.pending->next;
- free(syncEvents.pending);
- syncEvents.pending = next;
- }
- syncEvents.pendtail = &syncEvents.pending;
+ if (syncEvents.pending.next)
+ list_for_each_entry_safe(qe, tmp, &syncEvents.pending, next)
+ free(qe);
+ list_init(&syncEvents.pending);
syncEvents.playingEvents = FALSE;
syncEvents.time.months = 0;
syncEvents.time.milliseconds = 0; /* hardly matters */
@@ -5429,7 +5422,7 @@ ProcUngrabKey(ClientPtr client)
{
REQUEST(xUngrabKeyReq);
WindowPtr pWin;
- GrabRec tempGrab;
+ GrabPtr tempGrab;
DeviceIntPtr keybd = PickKeyboard(client);
int rc;
@@ -5451,21 +5444,27 @@ ProcUngrabKey(ClientPtr client)
client->errorValue = stuff->modifiers;
return BadValue;
}
- tempGrab.resource = client->clientAsMask;
- tempGrab.device = keybd;
- tempGrab.window = pWin;
- tempGrab.modifiersDetail.exact = stuff->modifiers;
- tempGrab.modifiersDetail.pMask = NULL;
- tempGrab.modifierDevice = keybd;
- tempGrab.type = KeyPress;
- tempGrab.grabtype = GRABTYPE_CORE;
- tempGrab.detail.exact = stuff->key;
- tempGrab.detail.pMask = NULL;
- tempGrab.next = NULL;
-
- if (!DeletePassiveGrabFromList(&tempGrab))
- return BadAlloc;
- return Success;
+ tempGrab = AllocGrab();
+ if (!tempGrab)
+ return BadAlloc;
+ tempGrab->resource = client->clientAsMask;
+ tempGrab->device = keybd;
+ tempGrab->window = pWin;
+ tempGrab->modifiersDetail.exact = stuff->modifiers;
+ tempGrab->modifiersDetail.pMask = NULL;
+ tempGrab->modifierDevice = keybd;
+ tempGrab->type = KeyPress;
+ tempGrab->grabtype = GRABTYPE_CORE;
+ tempGrab->detail.exact = stuff->key;
+ tempGrab->detail.pMask = NULL;
+ tempGrab->next = NULL;
+
+ if (!DeletePassiveGrabFromList(tempGrab))
+ rc = BadAlloc;
+
+ FreeGrab(tempGrab);
+
+ return rc;
}
/**
@@ -5629,7 +5628,7 @@ ProcUngrabButton(ClientPtr client)
{
REQUEST(xUngrabButtonReq);
WindowPtr pWin;
- GrabRec tempGrab;
+ GrabPtr tempGrab;
int rc;
DeviceIntPtr ptr;
@@ -5646,21 +5645,26 @@ ProcUngrabButton(ClientPtr client)
ptr = PickPointer(client);
- tempGrab.resource = client->clientAsMask;
- tempGrab.device = ptr;
- tempGrab.window = pWin;
- tempGrab.modifiersDetail.exact = stuff->modifiers;
- tempGrab.modifiersDetail.pMask = NULL;
- tempGrab.modifierDevice = GetMaster(ptr, MASTER_KEYBOARD);
- tempGrab.type = ButtonPress;
- tempGrab.detail.exact = stuff->button;
- tempGrab.grabtype = GRABTYPE_CORE;
- tempGrab.detail.pMask = NULL;
- tempGrab.next = NULL;
-
- if (!DeletePassiveGrabFromList(&tempGrab))
- return BadAlloc;
- return Success;
+ tempGrab = AllocGrab();
+ if (!tempGrab)
+ return BadAlloc;
+ tempGrab->resource = client->clientAsMask;
+ tempGrab->device = ptr;
+ tempGrab->window = pWin;
+ tempGrab->modifiersDetail.exact = stuff->modifiers;
+ tempGrab->modifiersDetail.pMask = NULL;
+ tempGrab->modifierDevice = GetMaster(ptr, MASTER_KEYBOARD);
+ tempGrab->type = ButtonPress;
+ tempGrab->detail.exact = stuff->button;
+ tempGrab->grabtype = GRABTYPE_CORE;
+ tempGrab->detail.pMask = NULL;
+ tempGrab->next = NULL;
+
+ if (!DeletePassiveGrabFromList(tempGrab))
+ rc = BadAlloc;
+
+ FreeGrab(tempGrab);
+ return rc;
}
/**