dix: replace wClient() macro by dixClientForWindow() inline function

Hide internals (drop the need to include windowstr.h), make it typesafe
as well as the naming easier to understand.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-09-04 18:42:15 +02:00
parent 261c49b4c2
commit d697618c16
13 changed files with 80 additions and 33 deletions

View File

@ -32,6 +32,7 @@ in this Software without prior written authorization from The Open Group.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/registry_priv.h" #include "dix/registry_priv.h"
#include "dix/resource_priv.h"
#include "include/extinit_priv.h" #include "include/extinit_priv.h"
#include "os/audit.h" #include "os/audit.h"
#include "os/auth.h" #include "os/auth.h"
@ -856,13 +857,13 @@ SecurityProperty(CallbackListPtr *pcbl, void *unused, void *calldata)
Mask allowed = SecurityResourceMask | DixReadAccess; Mask allowed = SecurityResourceMask | DixReadAccess;
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey);
if (SecurityDoCheck(subj, obj, requested, allowed) != Success) { if (SecurityDoCheck(subj, obj, requested, allowed) != Success) {
SecurityAudit("Security: denied client %d access to property %s " SecurityAudit("Security: denied client %d access to property %s "
"(atom 0x%x) window 0x%lx of client %d on request %s\n", "(atom 0x%x) window 0x%lx of client %d on request %s\n",
rec->client->index, NameForAtom(name), name, rec->client->index, NameForAtom(name), name,
(unsigned long)rec->pWin->drawable.id, wClient(rec->pWin)->index, (unsigned long)rec->pWin->drawable.id, dixClientForWindow(rec->pWin)->index,
SecurityLookupRequestName(rec->client)); SecurityLookupRequestName(rec->client));
rec->status = BadAccess; rec->status = BadAccess;
} }
@ -878,7 +879,7 @@ SecuritySend(CallbackListPtr *pcbl, void *unused, void *calldata)
int i; int i;
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey);
if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success) if (SecurityDoCheck(subj, obj, DixSendAccess, 0) == Success)
return; return;
@ -893,7 +894,7 @@ SecuritySend(CallbackListPtr *pcbl, void *unused, void *calldata)
rec->client->index, rec->client->index,
LookupEventName(rec->events[i].u.u.type), LookupEventName(rec->events[i].u.u.type),
(unsigned long)rec->pWin->drawable.id, (unsigned long)rec->pWin->drawable.id,
wClient(rec->pWin)->index); dixClientForWindow(rec->pWin)->index);
rec->status = BadAccess; rec->status = BadAccess;
return; return;
} }
@ -907,7 +908,7 @@ SecurityReceive(CallbackListPtr *pcbl, void *unused, void *calldata)
SecurityStateRec *subj, *obj; SecurityStateRec *subj, *obj;
subj = dixLookupPrivate(&rec->client->devPrivates, stateKey); subj = dixLookupPrivate(&rec->client->devPrivates, stateKey);
obj = dixLookupPrivate(&wClient(rec->pWin)->devPrivates, stateKey); obj = dixLookupPrivate(&dixClientForWindow(rec->pWin)->devPrivates, stateKey);
if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success) if (SecurityDoCheck(subj, obj, DixReceiveAccess, 0) == Success)
return; return;
@ -915,7 +916,7 @@ SecurityReceive(CallbackListPtr *pcbl, void *unused, void *calldata)
SecurityAudit("Security: denied client %d from receiving an event " SecurityAudit("Security: denied client %d from receiving an event "
"sent to window 0x%lx of client %d\n", "sent to window 0x%lx of client %d\n",
rec->client->index, (unsigned long)rec->pWin->drawable.id, rec->client->index, (unsigned long)rec->pWin->drawable.id,
wClient(rec->pWin)->index); dixClientForWindow(rec->pWin)->index);
rec->status = BadAccess; rec->status = BadAccess;
} }

View File

@ -34,6 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/registry_priv.h" #include "dix/registry_priv.h"
#include "dix/resource_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "selection.h" #include "selection.h"
@ -772,7 +773,7 @@ SELinuxResourceState(CallbackListPtr *pcbl, void *unused, void *calldata)
return; return;
pWin = (WindowPtr) rec->value; pWin = (WindowPtr) rec->value;
subj = dixLookupPrivate(&wClient(pWin)->devPrivates, subjectKey); subj = dixLookupPrivate(&dixClientForWindow(pWin)->devPrivates, subjectKey);
if (subj->sid) { if (subj->sid) {
char *ctx; char *ctx;

View File

@ -96,6 +96,7 @@ SOFTWARE.
#include "dix/eventconvert.h" #include "dix/eventconvert.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/resource_priv.h"
#include "mi/mi_priv.h" #include "mi/mi_priv.h"
#include "inputstr.h" #include "inputstr.h"
@ -1427,7 +1428,7 @@ RetrieveTouchDeliveryData(DeviceIntPtr dev, TouchPointInfoPtr ti,
break; break;
/* if owner selected, oclients is NULL */ /* if owner selected, oclients is NULL */
*client = oclients ? rClient(oclients) : wClient(*win); *client = oclients ? rClient(oclients) : dixClientForWindow(*win);
} }
*grab = NULL; *grab = NULL;

View File

@ -44,6 +44,7 @@
#include <dix-config.h> #include <dix-config.h>
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "os/osdep.h" #include "os/osdep.h"
#include "compint.h" #include "compint.h"
@ -216,7 +217,7 @@ updateOverlayWindow(ScreenPtr pScreen)
/* Let's resize the overlay window. */ /* Let's resize the overlay window. */
vlist[0] = w; vlist[0] = w;
vlist[1] = h; vlist[1] = h;
return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, wClient(pWin)); return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, dixClientForWindow(pWin));
} }
/* Let's be on the safe side and not assume an overlay window is /* Let's be on the safe side and not assume an overlay window is

View File

@ -125,6 +125,7 @@ Equipment Corporation.
#include "dix/eventconvert.h" #include "dix/eventconvert.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/reqhandlers_priv.h" #include "dix/reqhandlers_priv.h"
#include "dix/resource_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "os/fmt.h" #include "os/fmt.h"
@ -2199,11 +2200,11 @@ DeliverToWindowOwner(DeviceIntPtr dev, WindowPtr win,
!((wOtherEventMasks(win) | win->eventMask) & filter)) !((wOtherEventMasks(win) | win->eventMask) & filter))
return EVENT_SKIP; return EVENT_SKIP;
if (IsInterferingGrab(wClient(win), dev, events)) if (IsInterferingGrab(dixClientForWindow(win), dev, events))
return EVENT_SKIP; return EVENT_SKIP;
if (!XaceHookReceiveAccess(wClient(win), win, events, count)) { if (!XaceHookReceiveAccess(dixClientForWindow(win), win, events, count)) {
int attempt = TryClientEvents(wClient(win), dev, events, int attempt = TryClientEvents(dixClientForWindow(win), dev, events,
count, win->eventMask, count, win->eventMask,
filter, grab); filter, grab);
@ -2377,7 +2378,7 @@ DeliverEventsToWindow(DeviceIntPtr pDev, WindowPtr pWin, xEvent
case EVENT_DELIVERED: case EVENT_DELIVERED:
/* We delivered to the owner, with our event mask */ /* We delivered to the owner, with our event mask */
deliveries++; deliveries++;
client = wClient(pWin); client = dixClientForWindow(pWin);
deliveryMask = pWin->eventMask; deliveryMask = pWin->eventMask;
break; break;
case EVENT_NOT_DELIVERED: case EVENT_NOT_DELIVERED:
@ -2551,16 +2552,16 @@ Bool MaybeDeliverEventToClient(WindowPtr pWin, xEvent *pEvents,
OtherClients *other; OtherClients *other;
if (pWin->eventMask & filter) { if (pWin->eventMask & filter) {
if (wClient(pWin) == dontClient) if (dixClientForWindow(pWin) == dontClient)
return FALSE; return FALSE;
#ifdef XINERAMA #ifdef XINERAMA
if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum) if (!noPanoramiXExtension && pWin->drawable.pScreen->myNum)
return XineramaTryClientEventsResult(wClient(pWin), NullGrab, return XineramaTryClientEventsResult(dixClientForWindow(pWin), NullGrab,
pWin->eventMask, filter); pWin->eventMask, filter);
#endif /* XINERAMA */ #endif /* XINERAMA */
if (XaceHookReceiveAccess(wClient(pWin), pWin, pEvents, 1)) if (XaceHookReceiveAccess(dixClientForWindow(pWin), pWin, pEvents, 1))
return TRUE; /* don't send, but pretend we did */ return TRUE; /* don't send, but pretend we did */
return TryClientEvents(wClient(pWin), NULL, pEvents, 1, return TryClientEvents(dixClientForWindow(pWin), NULL, pEvents, 1,
pWin->eventMask, filter, NullGrab) == 1; pWin->eventMask, filter, NullGrab) == 1;
} }
for (other = wOtherClients(pWin); other; other = other->next) { for (other = wOtherClients(pWin); other; other = other->next) {
@ -4560,14 +4561,14 @@ XRetCode EventSelectForWindow(WindowPtr pWin, ClientPtr client, Mask mask)
/* It is illegal for two different clients to select on any of the /* It is illegal for two different clients to select on any of the
events for AtMostOneClient. However, it is OK, for some client to events for AtMostOneClient. However, it is OK, for some client to
continue selecting on one of those events. */ continue selecting on one of those events. */
if ((wClient(pWin) != client) && (check & pWin->eventMask)) if ((dixClientForWindow(pWin) != client) && (check & pWin->eventMask))
return BadAccess; return BadAccess;
for (others = wOtherClients(pWin); others; others = others->next) { for (others = wOtherClients(pWin); others; others = others->next) {
if (!SameClient(others, client) && (check & others->mask)) if (!SameClient(others, client) && (check & others->mask))
return BadAccess; return BadAccess;
} }
} }
if (wClient(pWin) == client) { if (dixClientForWindow(pWin) == client) {
check = pWin->eventMask; check = pWin->eventMask;
pWin->eventMask = mask; pWin->eventMask = mask;
} }
@ -4721,7 +4722,7 @@ CoreEnterLeaveEvent(DeviceIntPtr mouse,
xKeymapEvent ke = { xKeymapEvent ke = {
.type = KeymapNotify .type = KeymapNotify
}; };
ClientPtr client = grab ? rClient(grab) : wClient(pWin); ClientPtr client = grab ? rClient(grab) : dixClientForWindow(pWin);
int rc; int rc;
rc = XaceHookDeviceAccess(client, keybd, DixReadAccess); rc = XaceHookDeviceAccess(client, keybd, DixReadAccess);
@ -4834,7 +4835,7 @@ CoreFocusEvent(DeviceIntPtr dev, int type, int mode, int detail, WindowPtr pWin)
xKeymapEvent ke = { xKeymapEvent ke = {
.type = KeymapNotify .type = KeymapNotify
}; };
ClientPtr client = wClient(pWin); ClientPtr client = dixClientForWindow(pWin);
int rc; int rc;
rc = XaceHookDeviceAccess(client, dev, DixReadAccess); rc = XaceHookDeviceAccess(client, dev, DixReadAccess);
@ -5895,7 +5896,7 @@ DeleteWindowFromAnyEvents(WindowPtr pWin, Bool freeResources)
of ending up reverting to a dying window and thence of ending up reverting to a dying window and thence
to None */ to None */
#ifdef NOTDEF #ifdef NOTDEF
|| wClient(parent)->clientGone || dixClientForWindow(parent)->clientGone
#endif #endif
); );
if (!ActivateFocusInGrab(keybd, pWin, parent)) if (!ActivateFocusInGrab(keybd, pWin, parent))
@ -5967,7 +5968,7 @@ EventMaskForClient(WindowPtr pWin, ClientPtr client)
{ {
OtherClientsPtr other; OtherClientsPtr other;
if (wClient(pWin) == client) if (dixClientForWindow(pWin) == client)
return pWin->eventMask; return pWin->eventMask;
for (other = wOtherClients(pWin); other; other = other->next) { for (other = wOtherClients(pWin); other; other = other->next) {
if (SameClient(other, client)) if (SameClient(other, client))

17
dix/lookup.c Normal file
View File

@ -0,0 +1,17 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*
* @brief DIX lookup functions
*/
#include <dix-config.h>
#include "dix/dix_priv.h"
#include "include/windowstr.h"
ClientPtr dixClientForWindow(WindowPtr pWin) {
if (!pWin)
return NullClient;
return clients[CLIENT_ID(pWin->drawable.id)];
}

View File

@ -20,6 +20,7 @@ srcs_dix = [
'glyphcurs.c', 'glyphcurs.c',
'grabs.c', 'grabs.c',
'inpututils.c', 'inpututils.c',
'lookup.c',
'pixmap.c', 'pixmap.c',
'privates.c', 'privates.c',
'property.c', 'property.c',

21
dix/resource_priv.h Normal file
View File

@ -0,0 +1,21 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#ifndef _XSERVER_DIX_RESOURCE_PRIV_H
#define _XSERVER_DIX_RESOURCE_PRIV_H
#include "include/dix.h"
/*
* @brief retrieve client that owns given window
*
* 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 WindowPtr to the window whose client shall be retrieved
* @return pointer to ClientRec structure or NullClient (NULL)
*/
ClientPtr dixClientForWindow(WindowPtr pWin);
#endif /* _XSERVER_DIX_RESOURCE_PRIV_H */

View File

@ -104,6 +104,7 @@ Equipment Corporation.
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/property_priv.h" #include "dix/property_priv.h"
#include "dix/resource_priv.h"
#include "mi/mi_priv.h" /* miPaintWindow */ #include "mi/mi_priv.h" /* miPaintWindow */
#include "os/auth.h" #include "os/auth.h"
#include "os/client_priv.h" #include "os/client_priv.h"
@ -921,7 +922,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
RecalculateDeliverableEvents(pWin); RecalculateDeliverableEvents(pWin);
if (vmask) if (vmask)
*error = ChangeWindowAttributes(pWin, vmask, vlist, wClient(pWin)); *error = ChangeWindowAttributes(pWin, vmask, vlist, dixClientForWindow(pWin));
else else
*error = Success; *error = Success;
@ -2940,7 +2941,7 @@ HandleSaveSet(ClientPtr client)
else else
{ {
pParent = pWin->parent; pParent = pWin->parent;
while (pParent && (wClient(pParent) == client)) while (pParent && (dixClientForWindow(pParent) == client))
pParent = pParent->parent; pParent = pParent->parent;
} }
if (pParent) { if (pParent) {

View File

@ -31,6 +31,7 @@
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/resource_priv.h"
#include "randr/randrstr_priv.h" #include "randr/randrstr_priv.h"
#include "xwayland-cvt.h" #include "xwayland-cvt.h"
@ -574,7 +575,7 @@ xwl_output_set_window_randr_emu_props(struct xwl_screen *xwl_screen,
{ {
struct xwl_output_randr_emu_prop prop = {}; struct xwl_output_randr_emu_prop prop = {};
xwl_output_randr_emu_prop(xwl_screen, wClient(window), &prop); xwl_output_randr_emu_prop(xwl_screen, dixClientForWindow(window), &prop);
xwl_output_set_randr_emu_prop(window, &prop); xwl_output_set_randr_emu_prop(window, &prop);
} }

View File

@ -34,6 +34,7 @@
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/property_priv.h" #include "dix/property_priv.h"
#include "dix/resource_priv.h"
#include "compositeext.h" #include "compositeext.h"
#include "compint.h" #include "compint.h"
@ -570,7 +571,7 @@ xwl_window_should_enable_viewport(struct xwl_window *xwl_window,
if (!window) if (!window)
return FALSE; return FALSE;
owner = wClient(window); owner = dixClientForWindow(window);
drawable = &window->drawable; drawable = &window->drawable;
/* 1. Test if the window matches the emulated mode on one of the outputs /* 1. Test if the window matches the emulated mode on one of the outputs

View File

@ -36,6 +36,7 @@
#include <xwin-config.h> #include <xwin-config.h>
#endif #endif
#include "dix/resource_priv.h"
#include "mi/mi_priv.h" #include "mi/mi_priv.h"
#include "win.h" #include "win.h"
@ -662,7 +663,7 @@ XID
winGetWindowID(WindowPtr pWin) winGetWindowID(WindowPtr pWin)
{ {
WindowIDPairRec wi = { pWin, 0 }; WindowIDPairRec wi = { pWin, 0 };
ClientPtr c = wClient(pWin); ClientPtr c = dixClientForWindow(pWin);
/* */ /* */
FindClientResourcesByType(c, X11_RESTYPE_WINDOW, winFindWindow, &wi); FindClientResourcesByType(c, X11_RESTYPE_WINDOW, winFindWindow, &wi);
@ -732,14 +733,14 @@ winReorderWindowsMultiWindow(void)
if (!pWinSib) { /* 1st window - raise to the top */ if (!pWinSib) { /* 1st window - raise to the top */
vlist[0] = Above; vlist[0] = Above;
ConfigureWindow(pWin, CWStackMode, vlist, wClient(pWin)); ConfigureWindow(pWin, CWStackMode, vlist, dixClientForWindow(pWin));
} }
else { /* 2nd or deeper windows - just below the previous one */ else { /* 2nd or deeper windows - just below the previous one */
vlist[0] = winGetWindowID(pWinSib); vlist[0] = winGetWindowID(pWinSib);
vlist[1] = Below; vlist[1] = Below;
ConfigureWindow(pWin, CWSibling | CWStackMode, ConfigureWindow(pWin, CWSibling | CWStackMode,
vlist, wClient(pWin)); vlist, dixClientForWindow(pWin));
} }
} }
} }
@ -798,7 +799,7 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
*/ */
vlist[0] = 0; vlist[0] = 0;
vlist[1] = 0; vlist[1] = 0;
return ConfigureWindow(pWin, CWX | CWY, vlist, wClient(pWin)); return ConfigureWindow(pWin, CWX | CWY, vlist, dixClientForWindow(pWin));
} }
pDraw = &pWin->drawable; pDraw = &pWin->drawable;
@ -860,7 +861,7 @@ winAdjustXWindow(WindowPtr pWin, HWND hwnd)
(unsigned int)vlist[2], (unsigned int)vlist[3]); (unsigned int)vlist[2], (unsigned int)vlist[3]);
#endif #endif
return ConfigureWindow(pWin, CWX | CWY | CWWidth | CWHeight, return ConfigureWindow(pWin, CWX | CWY | CWWidth | CWHeight,
vlist, wClient(pWin)); vlist, dixClientForWindow(pWin));
#undef WIDTH #undef WIDTH
#undef HEIGHT #undef HEIGHT

View File

@ -193,7 +193,6 @@ extern _X_EXPORT Mask DontPropagateMasks[];
#define wBoundingShape(w) wUseDefault(w, boundingShape, NULL) #define wBoundingShape(w) wUseDefault(w, boundingShape, NULL)
#define wClipShape(w) wUseDefault(w, clipShape, NULL) #define wClipShape(w) wUseDefault(w, clipShape, NULL)
#define wInputShape(w) wUseDefault(w, inputShape, NULL) #define wInputShape(w) wUseDefault(w, inputShape, NULL)
#define wClient(w) (clients[CLIENT_ID((w)->drawable.id)])
#define wBorderWidth(w) ((int) (w)->borderWidth) #define wBorderWidth(w) ((int) (w)->borderWidth)
static inline PropertyPtr wUserProps(WindowPtr pWin) { return pWin->properties; } static inline PropertyPtr wUserProps(WindowPtr pWin) { return pWin->properties; }