dix: add dixClientForGrab()

Helper function for retrieving the owning client of a grab.

It's an actual function, so callers don't need access to internal
knowledge (definition of GrabRec, clients[] array, ...)

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-03-06 12:37:59 +01:00
parent d697618c16
commit 0ca0c334d8
4 changed files with 35 additions and 14 deletions

View File

@ -1119,7 +1119,7 @@ ActivateEarlyAccept(DeviceIntPtr dev, TouchPointInfoPtr ti)
ti->listeners[0].type != TOUCH_LISTENER_POINTER_GRAB);
BUG_RETURN(!grab);
client = rClient(grab);
client = dixClientForGrab(grab);
if (TouchAcceptReject(client, dev, XIAcceptTouch, ti->client_id,
ti->listeners[0].window->drawable.id, &error) != Success)
@ -1371,7 +1371,7 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
BUG_RETURN_VAL(!*grab, FALSE);
*client = rClient(*grab);
*client = dixClientForGrab(*grab);
*win = (*grab)->window;
*mask = (*grab)->xi2mask;
}
@ -1454,7 +1454,7 @@ DeliverTouchEmulatedEvent(DeviceIntPtr dev, TouchPointInfoPtr ti,
if (grab) {
win = grab->window;
xi2mask = grab->xi2mask;
client = rClient(grab);
client = dixClientForGrab(grab);
}
}
@ -2284,7 +2284,7 @@ RetrieveGestureDeliveryData(DeviceIntPtr dev, InternalEvent *ev, GestureListener
BUG_RETURN_VAL(!*grab, FALSE);
*client = rClient(*grab);
*client = dixClientForGrab(*grab);
*win = (*grab)->window;
}
else {

View File

@ -3827,7 +3827,7 @@ ActivatePassiveGrab(DeviceIntPtr device, GrabPtr grab, InternalEvent *event,
FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
/* XXX: XACE? */
TryClientEvents(rClient(grab), device, xE, count,
TryClientEvents(dixClientForGrab(grab), device, xE, count,
GetEventFilter(device, xE),
GetEventFilter(device, xE), grab);
}
@ -3867,7 +3867,7 @@ CoreGrabInterferes(DeviceIntPtr device, GrabPtr grab)
GrabPtr othergrab = other->deviceGrab.grab;
if (othergrab && othergrab->grabtype == CORE &&
SameClient(grab, rClient(othergrab)) &&
SameClient(grab, dixClientForGrab(othergrab)) &&
((IsPointerDevice(grab->device) &&
IsPointerDevice(othergrab->device)) ||
(IsKeyboardDevice(grab->device) &&
@ -4326,10 +4326,10 @@ DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev,
if (rc == Success) {
FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
if (XaceHookSendAccess(NullClient, dev, grab->window, xE, count) ||
XaceHookReceiveAccess(rClient(grab), grab->window, xE, count))
XaceHookReceiveAccess(dixClientForGrab(grab), grab->window, xE, count))
deliveries = 1; /* don't send, but pretend we did */
else if (level != CORE || !IsInterferingGrab(rClient(grab), dev, xE)) {
deliveries = TryClientEvents(rClient(grab), dev,
else if (level != CORE || !IsInterferingGrab(dixClientForGrab(grab), dev, xE)) {
deliveries = TryClientEvents(dixClientForGrab(grab), dev,
xE, count, mask, filter, grab);
}
}
@ -4683,7 +4683,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
if (grab) {
mask = (pWin == grab->window) ? grab->eventMask : 0;
if (grab->ownerEvents)
mask |= EventMaskForClient(pWin, rClient(grab));
mask |= EventMaskForClient(pWin, dixClientForGrab(grab));
}
else {
mask = pWin->eventMask | wOtherEventMasks(pWin);
@ -4711,7 +4711,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
if ((mask & GetEventFilter(mouse, &event))) {
if (grab)
TryClientEvents(rClient(grab), mouse, &event, 1, mask,
TryClientEvents(dixClientForGrab(grab), mouse, &event, 1, mask,
GetEventFilter(mouse, &event), grab);
else
DeliverEventsToWindow(mouse, pWin, &event, 1,
@ -4722,7 +4722,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
xKeymapEvent ke = {
.type = KeymapNotify
};
ClientPtr client = grab ? rClient(grab) : dixClientForWindow(pWin);
ClientPtr client = grab ? dixClientForGrab(grab) : dixClientForWindow(pWin);
int rc;
rc = XaceHookDeviceAccess(client, keybd, DixReadAccess);
@ -4730,7 +4730,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
memcpy((char *) &ke.map[0], (char *) &keybd->key->down[1], 31);
if (grab)
TryClientEvents(rClient(grab), keybd, (xEvent *) &ke, 1,
TryClientEvents(dixClientForGrab(grab), keybd, (xEvent *) &ke, 1,
mask, KeymapStateMask, grab);
else
DeliverEventsToWindow(mouse, pWin, (xEvent *) &ke, 1,
@ -4804,7 +4804,7 @@ DeviceEnterLeaveEvent(DeviceIntPtr mouse,
Mask mask;
mask = xi2mask_isset(grab->xi2mask, mouse, type);
TryClientEvents(rClient(grab), mouse, (xEvent *) event, 1, mask, 1,
TryClientEvents(dixClientForGrab(grab), mouse, (xEvent *) event, 1, mask, 1,
grab);
}
else {

View File

@ -7,6 +7,9 @@
#include <dix-config.h>
#include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "include/input.h"
#include "include/inputstr.h"
#include "include/windowstr.h"
ClientPtr dixClientForWindow(WindowPtr pWin) {
@ -15,3 +18,10 @@ ClientPtr dixClientForWindow(WindowPtr pWin) {
return clients[CLIENT_ID(pWin->drawable.id)];
}
ClientPtr dixClientForGrab(GrabPtr pGrab) {
if (!pGrab)
return NullClient;
return clients[CLIENT_ID(pGrab->resource)];
}

View File

@ -18,4 +18,15 @@
*/
ClientPtr dixClientForWindow(WindowPtr pWin);
/*
* @brief retrieve client that owns given grab
*
* XIDs carry the ID of the client who created/owns the resource in upper bits.
* (every client so is assigned a range of XIDs it may use for resource creation)
*
* @param GrabPtr to the grab whose owning client shall be retrieved
* @return pointer to ClientRec structure or NullClient (NULL)
*/
ClientPtr dixClientForGrab(GrabPtr pGrab);
#endif /* _XSERVER_DIX_RESOURCE_PRIV_H */