/** * Prepend the new grab to the list of passive grabs on the window. * Any previously existing grab that matches the new grab will be removed. * Adding a new grab that would override another client's grab will result in * a BadAccess. * * @return Success or X error code on failure. */ int AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab) { GrabPtr grab; Mask access_mode = DixGrabAccess; int rc; for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { if (GrabMatchesSecond(pGrab, grab, FALSE)) { if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource)) { FreeGrab(pGrab); return BadAccess; } } } if (pGrab->keyboardMode == GrabModeSync||pGrab->pointerMode == GrabModeSync) access_mode |= DixFreezeAccess; rc = XaceHook(XACE_DEVICE_ACCESS, client, pGrab->device, access_mode); if (rc != Success) return rc; /* Remove all grabs that match the new one exactly */ for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { if (GrabsAreIdentical(pGrab, grab)) { DeletePassiveGrabFromList(grab); break; } } if (!pGrab->window->optional && !MakeWindowOptional (pGrab->window)) { FreeGrab(pGrab); return BadAlloc; } pGrab->next = pGrab->window->optional->passiveGrabs; pGrab->window->optional->passiveGrabs = pGrab; if (AddResource(pGrab->resource, RT_PASSIVEGRAB, (pointer)pGrab)) return Success; return BadAlloc; }
void DeleteDeviceEvents(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client) { InputClientsPtr others; OtherInputMasks *pOthers; GrabPtr grab, next; if ((pOthers = wOtherInputMasks(pWin)) != 0) for (others = pOthers->inputClients; others; others = others->next) if (SameClient(others, client)) others->mask[dev->id] = NoEventMask; for (grab = wPassiveGrabs(pWin); grab; grab = next) { next = grab->next; if ((grab->device == dev) && (client->clientAsMask == CLIENT_BITS(grab->resource))) FreeResource(grab->resource, RT_NONE); } }
int ProcXFixesChangeSaveSet(ClientPtr client) { Bool toRoot, remap; int result; WindowPtr pWin; REQUEST(xXFixesChangeSaveSetReq); REQUEST_SIZE_MATCH(xXFixesChangeSaveSetReq); pWin = (WindowPtr) SecurityLookupWindow(stuff->window, client, SecurityReadAccess); if (!pWin) return (BadWindow); if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id))) return BadMatch; if ((stuff->mode != SetModeInsert) && (stuff->mode != SetModeDelete)) { client->errorValue = stuff->mode; return (BadValue); } if ((stuff->target != SaveSetNearest) && (stuff->target != SaveSetRoot)) { client->errorValue = stuff->target; return (BadValue); } if ((stuff->map != SaveSetMap) && (stuff->map != SaveSetUnmap)) { client->errorValue = stuff->map; return (BadValue); } toRoot = (stuff->target == SaveSetRoot); remap = (stuff->map == SaveSetMap); result = AlterSaveSetForClient(client, pWin, stuff->mode, toRoot, remap); if (client->noClientException != Success) return (client->noClientException); else return (result); }
Bool DeletePassiveGrabFromList(GrabPtr pMinuendGrab) { GrabPtr grab; GrabPtr *deletes, *adds; Mask ***updates, **details; int i, ndels, nadds, nups; Bool ok; unsigned int any_modifier; unsigned int any_key; #define UPDATE(mask,exact) \ if (!(details[nups] = DeleteDetailFromMask(mask, exact))) \ ok = FALSE; \ else \ updates[nups++] = &(mask) i = 0; for (grab = wPassiveGrabs(pMinuendGrab->window); grab; grab = grab->next) i++; if (!i) return TRUE; deletes = malloc(i * sizeof(GrabPtr)); adds = malloc(i * sizeof(GrabPtr)); updates = malloc(i * sizeof(Mask **)); details = malloc(i * sizeof(Mask *)); if (!deletes || !adds || !updates || !details) { free(details); free(updates); free(adds); free(deletes); return FALSE; } any_modifier = (pMinuendGrab->grabtype == XI2) ? (unsigned int) XIAnyModifier : (unsigned int) AnyModifier; any_key = (pMinuendGrab->grabtype == XI2) ? (unsigned int) XIAnyKeycode : (unsigned int) AnyKey; ndels = nadds = nups = 0; ok = TRUE; for (grab = wPassiveGrabs(pMinuendGrab->window); grab && ok; grab = grab->next) { if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) || !GrabMatchesSecond(grab, pMinuendGrab, (grab->grabtype == CORE))) continue; if (GrabSupersedesSecond(pMinuendGrab, grab)) { deletes[ndels++] = grab; } else if ((grab->detail.exact == any_key) && (grab->modifiersDetail.exact != any_modifier)) { UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); } else if ((grab->modifiersDetail.exact == any_modifier) && (grab->detail.exact != any_key)) { UPDATE(grab->modifiersDetail.pMask, pMinuendGrab->modifiersDetail.exact); } else if ((pMinuendGrab->detail.exact != any_key) && (pMinuendGrab->modifiersDetail.exact != any_modifier)) { GrabPtr pNewGrab; GrabParameters param; UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); memset(¶m, 0, sizeof(param)); param.ownerEvents = grab->ownerEvents; param.this_device_mode = grab->keyboardMode; param.other_devices_mode = grab->pointerMode; param.modifiers = any_modifier; pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device, grab->modifierDevice, grab->window, grab->grabtype, (GrabMask *) &grab->eventMask, ¶m, (int) grab->type, pMinuendGrab->detail.exact, grab->confineTo, grab->cursor); if (!pNewGrab) ok = FALSE; else if (!(pNewGrab->modifiersDetail.pMask = DeleteDetailFromMask(grab->modifiersDetail.pMask, pMinuendGrab->modifiersDetail. exact)) || (!pNewGrab->window->optional && !MakeWindowOptional(pNewGrab->window))) { FreeGrab(pNewGrab); ok = FALSE; } else if (!AddResource(pNewGrab->resource, RT_PASSIVEGRAB, (pointer) pNewGrab)) ok = FALSE; else adds[nadds++] = pNewGrab; } else if (pMinuendGrab->detail.exact == any_key) { UPDATE(grab->modifiersDetail.pMask, pMinuendGrab->modifiersDetail.exact); } else { UPDATE(grab->detail.pMask, pMinuendGrab->detail.exact); } } if (!ok) { for (i = 0; i < nadds; i++) FreeResource(adds[i]->resource, RT_NONE); for (i = 0; i < nups; i++) free(details[i]); } else { for (i = 0; i < ndels; i++) FreeResource(deletes[i]->resource, RT_NONE); for (i = 0; i < nadds; i++) { grab = adds[i]; grab->next = grab->window->optional->passiveGrabs; grab->window->optional->passiveGrabs = grab; } for (i = 0; i < nups; i++) { free(*updates[i]); *updates[i] = details[i]; } } free(details); free(updates); free(adds); free(deletes); return ok; #undef UPDATE }