dix: add per-screen close notify hook

Right now, extension specific actions on screen closing 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
screen closing 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-27 19:01:23 +02:00
parent 242d11e338
commit 8e43be7a3a
6 changed files with 62 additions and 0 deletions

View File

@ -282,4 +282,16 @@ int dixScreenRaiseWindowDestroy(WindowPtr pWin);
*/ */
void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y); void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y);
/*
* @brief call screen's close hooks
* @see dixScreenHookClose
* @param pScreen the screen being closed
*
* Call the pluggable screen close hooks that extensions might have registered on
* the screen, and finally call ScreenRec's CloseScreen proc.
*
* Should only be called by DIX itself.
*/
void dixScreenRaiseClose(ScreenPtr pScreen);
#endif /* _XSERVER_DIX_PRIV_H */ #endif /* _XSERVER_DIX_PRIV_H */

View File

@ -22,5 +22,6 @@ void dixFreeScreen(ScreenPtr pScreen)
dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN); dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
DeleteCallbackList(&pScreen->hookWindowDestroy); DeleteCallbackList(&pScreen->hookWindowDestroy);
DeleteCallbackList(&pScreen->hookWindowPosition); DeleteCallbackList(&pScreen->hookWindowPosition);
DeleteCallbackList(&pScreen->hookClose);
free(pScreen); free(pScreen);
} }

View File

@ -24,6 +24,7 @@
DECLARE_HOOK_PROC(WindowDestroy, hookWindowDestroy, XorgScreenWindowDestroyProcPtr); DECLARE_HOOK_PROC(WindowDestroy, hookWindowDestroy, XorgScreenWindowDestroyProcPtr);
DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr); DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr);
DECLARE_HOOK_PROC(Close, hookClose, XorgScreenCloseProcPtr);
int dixScreenRaiseWindowDestroy(WindowPtr pWin) int dixScreenRaiseWindowDestroy(WindowPtr pWin)
{ {
@ -55,3 +56,13 @@ void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y)
if (pScreen->PositionWindow) if (pScreen->PositionWindow)
pScreen->PositionWindow(pWin, x, y); pScreen->PositionWindow(pWin, x, y);
} }
void dixScreenRaiseClose(ScreenPtr pScreen) {
if (!pScreen)
return;
CallCallbacks(&pScreen->hookClose, NULL);
if (pScreen->CloseScreen)
pScreen->CloseScreen(pScreen);
}

View File

@ -22,6 +22,8 @@
#include <X11/Xfuncproto.h> #include <X11/Xfuncproto.h>
#include "include/callback.h"
#include "screenint.h" /* ScreenPtr */ #include "screenint.h" /* ScreenPtr */
#include "window.h" /* WindowPtr */ #include "window.h" /* WindowPtr */
@ -108,4 +110,35 @@ _X_EXPORT void dixScreenHookWindowPosition(ScreenPtr pScreen,
_X_EXPORT void dixScreenUnhookWindowPosition(ScreenPtr pScreen, _X_EXPORT void dixScreenUnhookWindowPosition(ScreenPtr pScreen,
XorgScreenWindowPositionProcPtr func); XorgScreenWindowPositionProcPtr func);
/* prototype of screen close notification handler */
typedef void (*XorgScreenCloseProcPtr)(CallbackListPtr *pcbl,
ScreenPtr pScreen,
void *unused);
/**
* @brief register a screen close notify hook on the given screen
*
* @param pScreen pointer to the screen to register the notify hook into
* @param func pointer to the hook function
*
* When registration fails, the server aborts.
*
**/
_X_EXPORT void dixScreenHookClose(ScreenPtr pScreen,
XorgScreenCloseProcPtr func);
/**
* @brief unregister a screen close 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 dixScreenHookClose
*
* Unregister a screen close notify hook registered via @ref dixScreenHookClose
**/
_X_EXPORT void dixScreenUnhookClose(ScreenPtr pScreen,
XorgScreenCloseProcPtr func);
#endif /* DIX_SCREEN_HOOKS_H */ #endif /* DIX_SCREEN_HOOKS_H */

View File

@ -677,6 +677,10 @@ typedef struct _Screen {
/* additional window position notify hooks (replaces wrapping PositionWindow) /* additional window position notify hooks (replaces wrapping PositionWindow)
should NOT be touched outside of DIX core */ should NOT be touched outside of DIX core */
CallbackListPtr hookWindowPosition; CallbackListPtr hookWindowPosition;
/* additional screen close notify hooks (replaces wrapping CloseScreen)
should NOT be touched outside of DIX core */
CallbackListPtr hookClose;
} ScreenRec; } ScreenRec;
static inline RegionPtr static inline RegionPtr

View File

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