From 31bc28a36e9f9cae9b61a0d7e079b6e44fbb261f Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 4 Sep 2024 18:42:15 +0200 Subject: [PATCH] dix: lookup function for WindowPtr by XID This new lookup function retrieves a pointer to WindowRec structure by associated XID. Unlike dixLookupWindow(), this one works globally, instead of just on one specific client, and it doesn't do any XACE calls. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dix_priv.h | 11 +++++++++++ dix/lookup.c | 42 ++++++++++++++++++++++++++++++++++++++++++ dix/meson.build | 1 + 3 files changed, 54 insertions(+) create mode 100644 dix/lookup.c diff --git a/dix/dix_priv.h b/dix/dix_priv.h index 8a85ed35d..485b14886 100644 --- a/dix/dix_priv.h +++ b/dix/dix_priv.h @@ -253,4 +253,15 @@ extern Bool explicit_display; extern Bool disableBackingStore; extern Bool enableBackingStore; +/* + * @brief lookup window by XID + * + * This globally looks for Window with given XID (all screens, all clients) + * and returns a pointer to it. If not found, returns NULL. + * + * Unlike ::dixLookupWindow() it doesn't scan only one given client, nor does + * it do any XACE calls. + */ +WindowPtr dixLookupWindowByXID(Window window); + #endif /* _XSERVER_DIX_PRIV_H */ diff --git a/dix/lookup.c b/dix/lookup.c new file mode 100644 index 000000000..0aca0a4fe --- /dev/null +++ b/dix/lookup.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + * + * @brief DIX lookup functions + */ +#include + +#include "dix/dix_priv.h" +#include "include/windowstr.h" + +struct window_xid_match { + WindowPtr pWin; + Window id; +}; + +static int dix_match_window_xid(WindowPtr pWin, void *ptr) +{ + struct window_xid_match *walk = (struct window_xid_match*) ptr; + + if (walk->id == pWin->drawable.id) { + walk->pWin = pWin; + return WT_STOPWALKING; + } + else + return WT_WALKCHILDREN; +} + +WindowPtr dixLookupWindowByXID(Window window) +{ + struct window_xid_match walk = { + .id = window, + }; + + for (int i = 0; i < screenInfo.numScreens; i++) { + WalkTree(screenInfo.screens[i], dix_match_window_xid, &walk); + if (walk.pWin) + break; + } + + return walk.pWin; +} diff --git a/dix/meson.build b/dix/meson.build index aa0c908dc..b586e91ea 100644 --- a/dix/meson.build +++ b/dix/meson.build @@ -19,6 +19,7 @@ srcs_dix = [ 'glyphcurs.c', 'grabs.c', 'inpututils.c', + 'lookup.c', 'pixmap.c', 'privates.c', 'property.c',