(!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:
parent
08e8e1af35
commit
c4f89e4edc
|
@ -266,4 +266,16 @@ extern Bool enableBackingStore;
|
|||
*/
|
||||
int dixScreenRaiseWindowDestroy(WindowPtr pWin);
|
||||
|
||||
/*
|
||||
* @brief call screen's window position notification hooks
|
||||
* @see dixScreenHookWindowPosition
|
||||
* @param pWin the window to notify on
|
||||
*
|
||||
* Call the pluggable window position hooks that extensions might have registered on
|
||||
* the screen, and finally call ScreenRec's PositionWindow proc.
|
||||
*
|
||||
* Should only be called by DIX itself.
|
||||
*/
|
||||
void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y);
|
||||
|
||||
#endif /* _XSERVER_DIX_PRIV_H */
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
}
|
||||
|
||||
DECLARE_HOOK_LIST(WindowDestroy, _notify_window_destroy)
|
||||
DECLARE_HOOK_LIST(WindowPosition, _notify_window_position)
|
||||
|
||||
int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
||||
{
|
||||
|
@ -55,3 +56,16 @@ int dixScreenRaiseWindowDestroy(WindowPtr pWin)
|
|||
}
|
||||
return (pScreen->DestroyWindow ? (*pScreen->DestroyWindow) (pWin) : Success);
|
||||
}
|
||||
|
||||
void dixScreenRaiseWindowPosition(WindowPtr pWin, uint32_t x, uint32_t y)
|
||||
{
|
||||
ScreenPtr pScreen = pWin->drawable.pScreen;
|
||||
|
||||
ARRAY_FOR_EACH(pScreen->_notify_window_position, walk) {
|
||||
if (walk.ptr->func)
|
||||
walk.ptr->func(pScreen, pWin, walk.ptr->arg, x, y);
|
||||
}
|
||||
|
||||
if (pScreen->PositionWindow)
|
||||
(*pScreen->PositionWindow) (pWin, x, y);
|
||||
}
|
||||
|
|
20
dix/window.c
20
dix/window.c
|
@ -670,7 +670,8 @@ InitRootWindow(WindowPtr pWin)
|
|||
|
||||
if (!(*pScreen->CreateWindow) (pWin))
|
||||
return; /* XXX */
|
||||
(*pScreen->PositionWindow) (pWin, 0, 0);
|
||||
|
||||
dixScreenRaiseWindowPosition(pWin, 0, 0);
|
||||
|
||||
pWin->cursorIsNone = FALSE;
|
||||
pWin->optional->cursor = RefCursor(rootCursor);
|
||||
|
@ -928,7 +929,7 @@ CreateWindow(Window wid, WindowPtr pParent, int x, int y, unsigned w,
|
|||
return NullWindow;
|
||||
}
|
||||
/* We SHOULD check for an error value here XXX */
|
||||
(*pScreen->PositionWindow) (pWin, pWin->drawable.x, pWin->drawable.y);
|
||||
dixScreenRaiseWindowPosition(pWin, pWin->drawable.x, pWin->drawable.y);
|
||||
|
||||
if (!(vmask & CWEventMask))
|
||||
RecalculateDeliverableEvents(pWin);
|
||||
|
@ -1848,12 +1849,9 @@ GravityTranslate(int x, int y, int oldx, int oldy,
|
|||
void
|
||||
ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
|
||||
{
|
||||
ScreenPtr pScreen;
|
||||
WindowPtr pSib, pChild;
|
||||
Bool resized = (dw || dh);
|
||||
|
||||
pScreen = pWin->drawable.pScreen;
|
||||
|
||||
for (pSib = pWin->firstChild; pSib; pSib = pSib->nextSib) {
|
||||
if (resized && (pSib->winGravity > NorthWestGravity)) {
|
||||
int cwsx, cwsy;
|
||||
|
@ -1878,7 +1876,8 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
|
|||
pSib->drawable.y = pWin->drawable.y + pSib->origin.y;
|
||||
SetWinSize(pSib);
|
||||
SetBorderSize(pSib);
|
||||
(*pScreen->PositionWindow) (pSib, pSib->drawable.x, pSib->drawable.y);
|
||||
|
||||
dixScreenRaiseWindowPosition(pSib, pSib->drawable.x, pSib->drawable.y);
|
||||
|
||||
if ((pChild = pSib->firstChild)) {
|
||||
while (1) {
|
||||
|
@ -1888,9 +1887,9 @@ ResizeChildrenWinSize(WindowPtr pWin, int dx, int dy, int dw, int dh)
|
|||
pChild->origin.y;
|
||||
SetWinSize(pChild);
|
||||
SetBorderSize(pChild);
|
||||
(*pScreen->PositionWindow) (pChild,
|
||||
pChild->drawable.x,
|
||||
pChild->drawable.y);
|
||||
dixScreenRaiseWindowPosition(pChild,
|
||||
pChild->drawable.x,
|
||||
pChild->drawable.y);
|
||||
if (pChild->firstChild) {
|
||||
pChild = pChild->firstChild;
|
||||
continue;
|
||||
|
@ -2584,7 +2583,8 @@ ReparentWindow(WindowPtr pWin, WindowPtr pParent,
|
|||
|
||||
if (pScreen->ReparentWindow)
|
||||
(*pScreen->ReparentWindow) (pWin, pPriorParent);
|
||||
(*pScreen->PositionWindow) (pWin, pWin->drawable.x, pWin->drawable.y);
|
||||
|
||||
dixScreenRaiseWindowPosition(pWin, pWin->drawable.x, pWin->drawable.y);
|
||||
ResizeChildrenWinSize(pWin, 0, 0, 0, 0);
|
||||
|
||||
CheckWindowOptionalNeed(pWin);
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -50,6 +50,7 @@ SOFTWARE.
|
|||
#include <X11/extensions/shapeconst.h>
|
||||
|
||||
#include "dix/cursor_priv.h"
|
||||
#include "dix/dix_priv.h"
|
||||
#include "dix/input_priv.h"
|
||||
#include "mi/mi_priv.h"
|
||||
|
||||
|
@ -276,7 +277,7 @@ miMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pNextSib, VTKind kind)
|
|||
SetWinSize(pWin);
|
||||
SetBorderSize(pWin);
|
||||
|
||||
(*pScreen->PositionWindow) (pWin, x, y);
|
||||
dixScreenRaiseWindowPosition(pWin, x, y);
|
||||
|
||||
windowToValidate = MoveWindowInStack(pWin, pNextSib);
|
||||
|
||||
|
@ -446,7 +447,7 @@ miResizeWindow(WindowPtr pWin, int x, int y, unsigned int w, unsigned int h,
|
|||
ResizeChildrenWinSize(pWin, x - oldx, y - oldy, dw, dh);
|
||||
|
||||
/* let the hardware adjust background and border pixmaps, if any */
|
||||
(*pScreen->PositionWindow) (pWin, x, y);
|
||||
dixScreenRaiseWindowPosition(pWin, x, y);
|
||||
|
||||
pFirstChange = MoveWindowInStack(pWin, pSib);
|
||||
|
||||
|
|
Loading…
Reference in New Issue