mirror of
https://github.com/X11Libre/xserver.git
synced 2026-03-26 08:15:24 +00:00
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>
70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
/* SPDX-License-Identifier: MIT OR X11
|
|
*
|
|
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
|
|
*/
|
|
|
|
#include <dix-config.h>
|
|
|
|
#include "dix/dix_priv.h"
|
|
#include "dix/screen_hooks_priv.h"
|
|
#include "include/dix.h"
|
|
#include "include/os.h"
|
|
#include "include/scrnintstr.h"
|
|
#include "include/windowstr.h"
|
|
|
|
#define DECLARE_HOOK_PROC(NAME, FIELD, TYPE) \
|
|
void dixScreenHook##NAME(ScreenPtr pScreen, TYPE func) \
|
|
{ \
|
|
AddCallback(&pScreen->FIELD, (CallbackProcPtr)func, pScreen); \
|
|
} \
|
|
\
|
|
void dixScreenUnhook##NAME(ScreenPtr pScreen, TYPE func) \
|
|
{ \
|
|
DeleteCallback(&pScreen->FIELD, (CallbackProcPtr)func, pScreen); \
|
|
}
|
|
|
|
DECLARE_HOOK_PROC(WindowDestroy, hookWindowDestroy, XorgScreenWindowDestroyProcPtr);
|
|
DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr);
|
|
DECLARE_HOOK_PROC(Close, hookClose, XorgScreenCloseProcPtr);
|
|
|
|
int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
|
{
|
|
if (!pWin)
|
|
return Success;
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
CallCallbacks(&pScreen->hookWindowDestroy, pWin);
|
|
|
|
return (pScreen->DestroyWindow ? pScreen->DestroyWindow(pWin) : Success);
|
|
}
|
|
|
|
void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y)
|
|
{
|
|
if (!pWin)
|
|
return;
|
|
|
|
ScreenPtr pScreen = pWin->drawable.pScreen;
|
|
|
|
XorgScreenWindowPositionParamRec param = {
|
|
.window = pWin,
|
|
.x = x,
|
|
.y = y,
|
|
};
|
|
|
|
CallCallbacks(&pScreen->hookWindowPosition, ¶m);
|
|
|
|
if (pScreen->PositionWindow)
|
|
pScreen->PositionWindow(pWin, x, y);
|
|
}
|
|
|
|
void dixScreenRaiseClose(ScreenPtr pScreen) {
|
|
if (!pScreen)
|
|
return;
|
|
|
|
CallCallbacks(&pScreen->hookClose, NULL);
|
|
|
|
if (pScreen->CloseScreen)
|
|
pScreen->CloseScreen(pScreen);
|
|
}
|