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 }
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; } }