From 56650ba8734ef30e3f5dbf37195823c6c0201433 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 2 Jul 2025 14:24:10 +0200 Subject: [PATCH 1/4] dix: add screen hook for post-close In contrast to the already existing ScreenClose hook, this one is called *after* the driver's CloseScreen() proc. That's required for some extensions (eg. damage) where drivers still need to call in inside of their CloseScreen procs. Signed-off-by: Enrico Weigelt, metux IT consult --- dix/screen.c | 1 + dix/screen_hooks.c | 3 +++ dix/screen_hooks_priv.h | 31 +++++++++++++++++++++++++++++++ include/scrnintstr.h | 4 ++++ 4 files changed, 39 insertions(+) diff --git a/dix/screen.c b/dix/screen.c index 3c3b715a7..fe39a275c 100644 --- a/dix/screen.c +++ b/dix/screen.c @@ -23,6 +23,7 @@ void dixFreeScreen(ScreenPtr pScreen) DeleteCallbackList(&pScreen->hookWindowDestroy); DeleteCallbackList(&pScreen->hookWindowPosition); DeleteCallbackList(&pScreen->hookClose); + DeleteCallbackList(&pScreen->hookPostClose); DeleteCallbackList(&pScreen->hookPixmapDestroy); free(pScreen); } diff --git a/dix/screen_hooks.c b/dix/screen_hooks.c index 1c96fa211..d3c0ab435 100644 --- a/dix/screen_hooks.c +++ b/dix/screen_hooks.c @@ -28,6 +28,7 @@ DECLARE_HOOK_PROC(WindowDestroy, hookWindowDestroy, XorgScreenWindowDestroyProcPtr); DECLARE_HOOK_PROC(WindowPosition, hookWindowPosition, XorgScreenWindowPositionProcPtr); DECLARE_HOOK_PROC(Close, hookClose, XorgScreenCloseProcPtr); +DECLARE_HOOK_PROC(PostClose, hookPostClose, XorgScreenCloseProcPtr); DECLARE_HOOK_PROC(PixmapDestroy, hookPixmapDestroy, XorgScreenPixmapDestroyProcPtr); DECLARE_HOOK_PROC(PostCreateResources, hookPostCreateResources, XorgScreenPostCreateResourcesProcPtr); @@ -71,6 +72,8 @@ void dixScreenRaiseClose(ScreenPtr pScreen) { if (pScreen->CloseScreen) pScreen->CloseScreen(pScreen); + + CallCallbacks(&pScreen->hookPostClose, NULL); } void dixScreenRaisePixmapDestroy(PixmapPtr pPixmap) diff --git a/dix/screen_hooks_priv.h b/dix/screen_hooks_priv.h index 01e4d8d9b..3ab6bfdda 100644 --- a/dix/screen_hooks_priv.h +++ b/dix/screen_hooks_priv.h @@ -147,6 +147,37 @@ _X_EXPORT void dixScreenUnhookClose(ScreenPtr pScreen, XorgScreenCloseProcPtr func); +/** + * @brief register a screen post 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 + * + * In contrast to Close hook, it's called *after* the driver's CloseScreen() + * proc had been called. + * + * When registration fails, the server aborts. + **/ +void dixScreenHookPostClose(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 dixScreenHookPostClose + * + * Unregister a screen close notify hook registered via @ref dixScreenHookPostClose + * + * In contrast to Close hook, it's called *after* the driver's CloseScreen() + * proc had been called. + **/ +void dixScreenUnhookPostClose(ScreenPtr pScreen, + XorgScreenCloseProcPtr func); + /* prototype of pixmap destroy notification handler */ typedef void (*XorgScreenPixmapDestroyProcPtr)(CallbackListPtr *pcbl, ScreenPtr pScreen, diff --git a/include/scrnintstr.h b/include/scrnintstr.h index d1f99840f..71ef762ea 100644 --- a/include/scrnintstr.h +++ b/include/scrnintstr.h @@ -696,6 +696,10 @@ typedef struct _Screen { CallbackListPtr hookPostCreateResources; SetWindowVRRModeProcPtr SetWindowVRRMode; + + /* additional screen post-close notify hooks (replaces wrapping CloseScreen) + should NOT be touched outside of DIX core */ + CallbackListPtr hookPostClose; } ScreenRec; static inline RegionPtr From 96be335fd351f55b16a0148d8d63178dce65dedb Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 2 Jul 2025 14:35:01 +0200 Subject: [PATCH 2/4] miext: damage: use dixScreenHookPostClose() instead of dixScreenHookClose() Some drivers need to call into damage from within their CloseScreen proc, so damage teardown needs to be done after that, instead of before. Signed-off-by: Enrico Weigelt, metux IT consult --- miext/damage/damage.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/miext/damage/damage.c b/miext/damage/damage.c index 56f24d756..4d146efaf 100644 --- a/miext/damage/damage.c +++ b/miext/damage/damage.c @@ -1569,7 +1569,7 @@ damageWindowDestroy(CallbackListPtr *pcbl, ScreenPtr pScreen, WindowPtr pWindow) static void damageCloseScreen(CallbackListPtr *pcbl, ScreenPtr pScreen, void *unused) { - dixScreenUnhookClose(pScreen, damageCloseScreen); + dixScreenUnhookPostClose(pScreen, damageCloseScreen); dixScreenUnhookWindowDestroy(pScreen, damageWindowDestroy); dixScreenUnhookPixmapDestroy(pScreen, damagePixmapDestroy); @@ -1667,7 +1667,7 @@ DamageSetup(ScreenPtr pScreen) pScrPriv->internalLevel = 0; pScrPriv->pScreenDamage = 0; - dixScreenHookClose(pScreen, damageCloseScreen); + dixScreenHookPostClose(pScreen, damageCloseScreen); dixScreenHookWindowDestroy(pScreen, damageWindowDestroy); dixScreenHookPixmapDestroy(pScreen, damagePixmapDestroy); From a750176ce7291ab9c591147c5c6de1de80a028a6 Mon Sep 17 00:00:00 2001 From: stefan11111 Date: Mon, 30 Jun 2025 13:50:11 +0300 Subject: [PATCH 3/4] kdrive: add KdOsInit Kdrive X servers used to do the OS-speciffic init part using KdOsInit. This was changed in modern Xorg because Xephyr is the only kdrive X server there, so there was no need to keep this generic. Since we want to eventually add Xfbdev, we need to add this back. Signed-off-by: stefan11111 --- hw/kdrive/src/kdrive.c | 21 +++++++++++++++++++++ hw/kdrive/src/kdrive.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/hw/kdrive/src/kdrive.c b/hw/kdrive/src/kdrive.c index 36bda4153..4637bb6be 100644 --- a/hw/kdrive/src/kdrive.c +++ b/hw/kdrive/src/kdrive.c @@ -91,6 +91,14 @@ const char *kdGlobalXkbLayout = NULL; const char *kdGlobalXkbVariant = NULL; const char *kdGlobalXkbOptions = NULL; + +/* + * Carry arguments from InitOutput through driver initialization + * to KdScreenInit + */ + +KdOsFuncs *kdOsFuncs = NULL; + void KdDisableScreen(ScreenPtr pScreen) { @@ -517,6 +525,19 @@ KdProcessArgument(int argc, char **argv, int i) return 0; } +void +KdOsInit(KdOsFuncs * pOsFuncs) +{ + kdOsFuncs = pOsFuncs; + if (pOsFuncs) { + if (serverGeneration == 1) { + KdDoSwitchCmd("start"); + if (pOsFuncs->Init) + (*pOsFuncs->Init) (); + } + } +} + static Bool KdAllocatePrivates(ScreenPtr pScreen) { diff --git a/hw/kdrive/src/kdrive.h b/hw/kdrive/src/kdrive.h index a4b7576d0..7ce181f42 100644 --- a/hw/kdrive/src/kdrive.h +++ b/hw/kdrive/src/kdrive.h @@ -278,6 +278,16 @@ int KdAddConfigKeyboard(char *pointer); int KdAddKeyboard(KdKeyboardInfo * ki); void KdRemoveKeyboard(KdKeyboardInfo * ki); +typedef struct _KdOsFuncs { + int (*Init) (void); /* Only called when the X server is started, when serverGeneration == 1 */ + void (*Enable) (void); + Bool (*SpecialKey) (KeySym); + void (*Disable) (void); + void (*Fini) (void); + void (*pollEvents) (void); + void (*Bell) (int, int, int); +} KdOsFuncs; + typedef struct _KdPointerMatrix { int matrix[2][3]; } KdPointerMatrix; @@ -289,6 +299,8 @@ extern DevPrivateKeyRec kdScreenPrivateKeyRec; extern Bool kdEmulateMiddleButton; extern Bool kdDisableZaphod; +extern KdOsFuncs *kdOsFuncs; + #define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \ dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey)) #define KdSetScreenPriv(pScreen,v) \ @@ -345,6 +357,9 @@ void int KdProcessArgument(int argc, char **argv, int i); +void + KdOsInit(KdOsFuncs * pOsFuncs); + void KdOsAddInputDrivers(void); From 922a22b6ef83ac312a2ff8cf79001cab83e3265e Mon Sep 17 00:00:00 2001 From: stefan11111 Date: Mon, 30 Jun 2025 14:16:23 +0300 Subject: [PATCH 4/4] kdrive: ephyr: initialize OS specific callback vectors These will be used by subsequent commits for generic Kdrive functions calling back into the OS specific parts Signed-off-by: stefan11111 --- hw/kdrive/ephyr/ephyrinit.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/kdrive/ephyr/ephyrinit.c b/hw/kdrive/ephyr/ephyrinit.c index fd5e73f82..f65cef052 100644 --- a/hw/kdrive/ephyr/ephyrinit.c +++ b/hw/kdrive/ephyr/ephyrinit.c @@ -370,6 +370,23 @@ ddxProcessArgument(int argc, char **argv, int i) return KdProcessArgument(argc, argv, i); } +static int +EphyrInit(void) +{ + /* + * make sure at least one screen + * has been added to the system. + */ + if (!KdCardInfoLast()) { + processScreenArg("640x480", NULL); + } + return hostx_init(); +} + +KdOsFuncs EphyrOsFuncs = { + .Init = EphyrInit, +}; + void OsVendorInit(void) { @@ -381,12 +398,7 @@ OsVendorInit(void) if (hostx_want_host_cursor()) ephyrFuncs.initCursor = &ephyrCursorInit; - if (serverGeneration == 1) { - if (!KdCardInfoLast()) { - processScreenArg("640x480", NULL); - } - hostx_init(); - } + KdOsInit(&EphyrOsFuncs); } KdCardFuncs ephyrFuncs = {