/** * 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; }
int ProcXUngrabDeviceButton(ClientPtr client) { DeviceIntPtr dev; DeviceIntPtr mdev; WindowPtr pWin; GrabPtr temporaryGrab; int rc; REQUEST(xUngrabDeviceButtonReq); REQUEST_SIZE_MATCH(xUngrabDeviceButtonReq); rc = dixLookupDevice(&dev, stuff->grabbed_device, client, DixGrabAccess); if (rc != Success) return rc; if (dev->button == NULL) return BadMatch; if (stuff->modifier_device != UseXKeyboard) { rc = dixLookupDevice(&mdev, stuff->modifier_device, client, DixReadAccess); if (rc != Success) return BadDevice; if (mdev->key == NULL) return BadMatch; } else mdev = PickKeyboard(client); rc = dixLookupWindow(&pWin, stuff->grabWindow, client, DixSetAttrAccess); if (rc != Success) return rc; if ((stuff->modifiers != AnyModifier) && (stuff->modifiers & ~AllModifiersMask)) return BadValue; temporaryGrab = AllocGrab(); if (!temporaryGrab) return BadAlloc; temporaryGrab->resource = client->clientAsMask; temporaryGrab->device = dev; temporaryGrab->window = pWin; temporaryGrab->type = DeviceButtonPress; temporaryGrab->grabtype = XI; temporaryGrab->modifierDevice = mdev; temporaryGrab->modifiersDetail.exact = stuff->modifiers; temporaryGrab->modifiersDetail.pMask = NULL; temporaryGrab->detail.exact = stuff->button; temporaryGrab->detail.pMask = NULL; DeletePassiveGrabFromList(temporaryGrab); FreeGrab(temporaryGrab); return Success; }
static void DestroyPassiveList( XtServerGrabPtr *passiveListPtr) { XtServerGrabPtr next, grab; for (next = *passiveListPtr; next; ) { grab = next; next = grab->next; /* not necessary to explicitly ungrab key or button; * window is being destroyed so server will take care of it. */ FreeGrab(grab); } }
int DeletePassiveGrab(pointer value, XID id) { GrabPtr g, prev; GrabPtr pGrab = (GrabPtr) value; /* it is OK if the grab isn't found */ prev = 0; for (g = (wPassiveGrabs(pGrab->window)); g; g = g->next) { if (pGrab == g) { if (prev) prev->next = g->next; else if (!(pGrab->window->optional->passiveGrabs = g->next)) CheckWindowOptionalNeed(pGrab->window); break; } prev = g; } FreeGrab(pGrab); return Success; }
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 }
int ProcXIPassiveUngrabDevice(ClientPtr client) { DeviceIntPtr dev, mod_dev; WindowPtr win; GrabPtr tempGrab; uint32_t *modifiers; int i, rc; REQUEST(xXIPassiveUngrabDeviceReq); REQUEST_FIXED_SIZE(xXIPassiveUngrabDeviceReq, ((uint32_t) stuff->num_modifiers) << 2); if (stuff->deviceid == XIAllDevices) dev = inputInfo.all_devices; else if (stuff->deviceid == XIAllMasterDevices) dev = inputInfo.all_master_devices; else { rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); if (rc != Success) return rc; } if (stuff->grab_type != XIGrabtypeButton && stuff->grab_type != XIGrabtypeKeycode && stuff->grab_type != XIGrabtypeEnter && stuff->grab_type != XIGrabtypeFocusIn && stuff->grab_type != XIGrabtypeTouchBegin) { client->errorValue = stuff->grab_type; return BadValue; } if ((stuff->grab_type == XIGrabtypeEnter || stuff->grab_type == XIGrabtypeFocusIn || stuff->grab_type == XIGrabtypeTouchBegin) && stuff->detail != 0) { client->errorValue = stuff->detail; return BadValue; } rc = dixLookupWindow(&win, stuff->grab_window, client, DixSetAttrAccess); if (rc != Success) return rc; mod_dev = (IsFloating(dev)) ? dev : GetMaster(dev, MASTER_KEYBOARD); tempGrab = AllocGrab(NULL); if (!tempGrab) return BadAlloc; tempGrab->resource = client->clientAsMask; tempGrab->device = dev; tempGrab->window = win; switch (stuff->grab_type) { case XIGrabtypeButton: tempGrab->type = XI_ButtonPress; break; case XIGrabtypeKeycode: tempGrab->type = XI_KeyPress; break; case XIGrabtypeEnter: tempGrab->type = XI_Enter; break; case XIGrabtypeFocusIn: tempGrab->type = XI_FocusIn; break; case XIGrabtypeTouchBegin: tempGrab->type = XI_TouchBegin; break; } tempGrab->grabtype = XI2; tempGrab->modifierDevice = mod_dev; tempGrab->modifiersDetail.pMask = NULL; tempGrab->detail.exact = stuff->detail; tempGrab->detail.pMask = NULL; modifiers = (uint32_t *) &stuff[1]; for (i = 0; i < stuff->num_modifiers; i++, modifiers++) { tempGrab->modifiersDetail.exact = *modifiers; DeletePassiveGrabFromList(tempGrab); } FreeGrab(tempGrab); return Success; }
static void DeleteServerGrabFromList( XtServerGrabPtr *passiveListPtr, XtServerGrabPtr pMinuendGrab) { register XtServerGrabPtr *next; register XtServerGrabPtr grab; register XtServerGrabExtPtr ext; for (next = passiveListPtr; (grab = *next); ) { if (GrabMatchesSecond(grab, pMinuendGrab) && (pDisplay(grab) == pDisplay(pMinuendGrab))) { if (GrabSupersedesSecond(pMinuendGrab, grab)) { /* * The entry being deleted encompasses the list entry, * so delete the list entry. */ *next = grab->next; FreeGrab(grab); continue; } if (!grab->hasExt) { grab = (XtServerGrabPtr) XtRealloc((char *)grab, (sizeof(XtServerGrabRec) + sizeof(XtServerGrabExtRec))); *next = grab; grab->hasExt = True; ext = GRABEXT(grab); ext->pKeyButMask = NULL; ext->pModifiersMask = NULL; ext->confineTo = None; ext->cursor = None; } else ext = GRABEXT(grab); if ((grab->keybut == AnyKey) && (grab->modifiers != AnyModifier)) { /* * If the list entry has the key detail of AnyKey, and * a modifier detail not set to AnyModifier, then we * simply need to turn off the key detail bit in the * list entry's key detail mask. */ DeleteDetailFromMask(&ext->pKeyButMask, pMinuendGrab->keybut); } else if ((grab->modifiers == AnyModifier) && (grab->keybut != AnyKey)) { /* * The list entry has a specific key detail, but its * modifier detail is set to AnyModifier; so, we only * need to turn off the specified modifier combination * in the list entry's modifier mask. */ DeleteDetailFromMask(&ext->pModifiersMask, pMinuendGrab->modifiers); } else if ((pMinuendGrab->keybut != AnyKey) && (pMinuendGrab->modifiers != AnyModifier)) { /* * The list entry has a key detail of AnyKey and a * modifier detail of AnyModifier; the entry being * deleted has a specific key and a specific modifier * combination. Therefore, we need to mask off the * keycode from the list entry, and also create a * new entry for this keycode, which has a modifier * mask set to AnyModifier & ~(deleted modifiers). */ XtServerGrabPtr pNewGrab; DeleteDetailFromMask(&ext->pKeyButMask, pMinuendGrab->keybut); pNewGrab = CreateGrab(grab->widget, (Boolean)grab->ownerEvents, (Modifiers)AnyModifier, pMinuendGrab->keybut, (int)grab->pointerMode, (int)grab->keyboardMode, (Mask)0, (Window)0, (Cursor)0, True); GRABEXT(pNewGrab)->pModifiersMask = CopyDetailMask(ext->pModifiersMask); DeleteDetailFromMask(&GRABEXT(pNewGrab)->pModifiersMask, pMinuendGrab->modifiers); pNewGrab->next = *passiveListPtr; *passiveListPtr = pNewGrab; } else if (pMinuendGrab->keybut == AnyKey) { /* * The list entry has keycode AnyKey and modifier * AnyModifier; the entry being deleted has * keycode AnyKey and specific modifiers. So we * simply need to mask off the specified modifier * combination. */ DeleteDetailFromMask(&ext->pModifiersMask, pMinuendGrab->modifiers); } else { /* * The list entry has keycode AnyKey and modifier * AnyModifier; the entry being deleted has a * specific keycode and modifier AnyModifier. So * we simply need to mask off the specified * keycode. */ DeleteDetailFromMask(&ext->pKeyButMask, pMinuendGrab->keybut); } } next = &(*next)->next; } }