(!1714) dix: add per-screen window position notify hook

Right now, extension specific actions on window positioning are implemented
by wrapping the ScreenRec's PositionWindow() proc pointer: the extensions are
storing the original pointer in their private data and putting in their own one.
On each call, their proc restores the original one, calls it, and switches back
again. When multiple extensions doing so, they're forming a kind of daisy chain.
(the same is done for lots of other procs)

While that approach is looking nice and elegant on the drawing board, it's
complicated, dangerous like a chainsaw and makes debugging hard, leading to
pretty blurred API borders.

This commit introduces a simple approach for letting extension hook into the
window positioning path safely, w/o having to care much about side effects
with the call chain. Extensions now can simply register their hook proc
(and an opaque pointer) and get called back - w/o ever having to mess with
the ScreenRec's internal structures. These hooks are called before the original
vector (usually handled by DDX/screen driver directly) is called.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2024-09-24 17:58:33 +02:00
parent 9f99daa8dd
commit 5a69235013
7 changed files with 80 additions and 12 deletions

View File

@@ -72,4 +72,40 @@ _X_EXPORT void dixScreenUnhookWindowDestroy(ScreenPtr pScreen,
XorgWindowDestroyProcPtr func,
void *arg);
/* prototype of a window move notification handler */
typedef void (*XorgWindowPositionProcPtr)(ScreenPtr pScreen,
WindowPtr pWindow,
void *arg,
int32_t x,
int32_t y);
/**
* @brief register a position notify hook on the given screen
*
* @param pScreen pointer to the screen to register the notify hook into
* @param func pointer to the window hook function
* @param arg opaque pointer passed to the hook
*
* When registration fails, the server aborts.
*
**/
_X_EXPORT void dixScreenHookWindowPosition(ScreenPtr pScreen,
XorgWindowPositionProcPtr func,
void *arg);
/**
* @brief unregister a window position notify hook on the given screen
*
* @param pScreen pointer to the screen to unregister the hook from
* @param func pointer to the hook function
* @param arg opaque pointer passed to the destructor
*
* @see dixScreenHookWindowPosition
*
* Unregister a window position notify hook registered via @ref dixScreenHookWindowPosition
**/
_X_EXPORT void dixScreenUnhookWindowPosition(ScreenPtr pScreen,
XorgWindowPositionProcPtr func,
void *arg);
#endif /* DIX_SCREEN_HOOKS_H */

View File

@@ -561,6 +561,10 @@ typedef struct _Screen {
should NOT be touched outside of DIX core */
_SCREEN_HOOK_TYPE(_notify_window_destroy, XorgWindowDestroyProcPtr, 8);
/* additional window position notify hooks (replaces wrapping PositionWindow)
should NOT be touched outside of DIX core */
_SCREEN_HOOK_TYPE(_notify_window_position, XorgWindowPositionProcPtr, 4);
/* Pixmap procedures */
CreatePixmapProcPtr CreatePixmap;

View File

@@ -216,5 +216,6 @@
/* announce server API features */
#define XORG_API_DIX_SCREEN_HOOK_WINDOW_DESTROY 1
#define XORG_API_DIX_SCREEN_HOOK_WINDOW_POSITION 1
#endif /* _XORG_SERVER_H_ */