xnest: introduce Xnest screen private structure

Since we've got lots of per-screen information spread across several arrays,
and for future features (eg. mult-upstream support) yet more to come, it's
time to consolidate into a per-screen private structure.

Initially just moving the upstream root window ID into it - others follwing
by subsequent patches. Leaving it as a global array and not assigning
private data to Screen structure yet.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-06-29 14:25:54 +02:00
parent 44f33ec12c
commit 4e81519e99
13 changed files with 87 additions and 31 deletions

View File

@ -32,6 +32,7 @@ is" without express or implied warranty.
#include "Visual.h" #include "Visual.h"
#include "XNWindow.h" #include "XNWindow.h"
#include "Args.h" #include "Args.h"
#include "multiscreen.h"
DevPrivateKeyRec xnestColormapPrivateKeyRec; DevPrivateKeyRec xnestColormapPrivateKeyRec;
@ -54,9 +55,11 @@ xnestCreateColormap(ColormapPtr pCmap)
pVisual = pCmap->pVisual; pVisual = pCmap->pVisual;
ncolors = pVisual->ColormapEntries; ncolors = pVisual->ColormapEntries;
XnestScreenPtr xnscr = xnestScreenPriv(pCmap->pScreen);
xnestColormapPriv(pCmap)->colormap = xnestColormapPriv(pCmap)->colormap =
XCreateColormap(xnestDisplay, XCreateColormap(xnestDisplay,
xnestDefaultWindows[pCmap->pScreen->myNum], xnscr->rootWindow,
xnestVisual(pVisual), xnestVisual(pVisual),
(pVisual->class & DynamicClass) ? AllocAll : AllocNone); (pVisual->class & DynamicClass) ? AllocAll : AllocNone);
@ -193,6 +196,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
{ {
xnestInstalledColormapWindows icws; xnestInstalledColormapWindows icws;
int numWindows; int numWindows;
XnestScreenPtr xnscr = xnestScreenPriv(pScreen);
icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap)); icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap));
icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs); icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs);
@ -202,7 +206,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window)); icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window));
icws.index = 0; icws.index = 0;
WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws); WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws);
icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum]; icws.windows[icws.numWindows] = xnscr->rootWindow;
numWindows = icws.numWindows + 1; numWindows = icws.numWindows + 1;
} }
else { else {
@ -215,7 +219,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) { if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) {
free(xnestOldInstalledColormapWindows); free(xnestOldInstalledColormapWindows);
XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], XSetWMColormapWindows(xnestDisplay, xnscr->rootWindow,
icws.windows, numWindows); icws.windows, numWindows);
xnestOldInstalledColormapWindows = icws.windows; xnestOldInstalledColormapWindows = icws.windows;
@ -243,9 +247,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
pScreen->defColormap, X11_RESTYPE_COLORMAP, pScreen->defColormap, X11_RESTYPE_COLORMAP,
serverClient, DixUseAccess); serverClient, DixUseAccess);
XSetWindowColormap(xnestDisplay, XSetWindowColormap(xnestDisplay, xnscr->rootWindow, xnestColormap(pCmap));
xnestDefaultWindows[pScreen->myNum],
xnestColormap(pCmap));
} }
#endif /* DUMB_WINDOW_MANAGERS */ #endif /* DUMB_WINDOW_MANAGERS */
} }
@ -256,9 +258,11 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen)
void void
xnestSetScreenSaverColormapWindow(ScreenPtr pScreen) xnestSetScreenSaverColormapWindow(ScreenPtr pScreen)
{ {
XnestScreenPtr xnscr = xnestScreenPriv(pScreen);
free(xnestOldInstalledColormapWindows); free(xnestOldInstalledColormapWindows);
XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], XSetWMColormapWindows(xnestDisplay, xnscr->rootWindow,
&xnestScreenSaverWindows[pScreen->myNum], 1); &xnestScreenSaverWindows[pScreen->myNum], 1);
xnestOldInstalledColormapWindows = NULL; xnestOldInstalledColormapWindows = NULL;

View File

@ -32,6 +32,7 @@ is" without express or implied warranty.
#include "Visual.h" #include "Visual.h"
#include "Keyboard.h" #include "Keyboard.h"
#include "Args.h" #include "Args.h"
#include "multiscreen.h"
xnestCursorFuncRec xnestCursorFuncs = { NULL }; xnestCursorFuncRec xnestCursorFuncs = { NULL };
@ -43,6 +44,7 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
XColor fg_color, bg_color; XColor fg_color, bg_color;
unsigned long valuemask; unsigned long valuemask;
XGCValues values; XGCValues values;
XnestScreenPtr xscr = xnestScreenPriv(pScreen);
valuemask = GCFunction | valuemask = GCFunction |
GCPlaneMask | GCForeground | GCBackground | GCClipMask; GCPlaneMask | GCForeground | GCBackground | GCClipMask;
@ -56,11 +58,11 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor)
XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values); XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values);
source = XCreatePixmap(xnestDisplay, source = XCreatePixmap(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xscr->rootWindow,
pCursor->bits->width, pCursor->bits->height, 1); pCursor->bits->width, pCursor->bits->height, 1);
mask = XCreatePixmap(xnestDisplay, mask = XCreatePixmap(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xscr->rootWindow,
pCursor->bits->width, pCursor->bits->height, 1); pCursor->bits->width, pCursor->bits->height, 1);
ximage = XCreateImage(xnestDisplay, ximage = XCreateImage(xnestDisplay,
@ -136,8 +138,9 @@ xnestSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x,
int y) int y)
{ {
if (pCursor) { if (pCursor) {
XnestScreenPtr xnscr = xnestScreenPriv(pScreen);
XDefineCursor(xnestDisplay, XDefineCursor(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xnscr->rootWindow,
xnestCursor(pCursor, pScreen)); xnestCursor(pCursor, pScreen));
} }
} }

View File

@ -34,6 +34,7 @@ is" without express or implied warranty.
#include "GCOps.h" #include "GCOps.h"
#include "Drawable.h" #include "Drawable.h"
#include "Visual.h" #include "Visual.h"
#include "multiscreen.h"
void void
xnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint * pPoints, xnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint * pPoints,
@ -61,12 +62,13 @@ xnestQueryBestSize(int class, unsigned short *pWidth, unsigned short *pHeight,
ScreenPtr pScreen) ScreenPtr pScreen)
{ {
unsigned int width, height; unsigned int width, height;
XnestScreenPtr xnscr = xnestScreenPriv(pScreen);
width = *pWidth; width = *pWidth;
height = *pHeight; height = *pHeight;
XQueryBestSize(xnestDisplay, class, XQueryBestSize(xnestDisplay, class,
xnestDefaultWindows[pScreen->myNum], xnscr->rootWindow,
width, height, &width, &height); width, height, &width, &height);
*pWidth = width; *pWidth = width;

View File

@ -34,6 +34,7 @@ is" without express or implied warranty.
#include "Keyboard.h" #include "Keyboard.h"
#include "Args.h" #include "Args.h"
#include "Events.h" #include "Events.h"
#include "multiscreen.h"
#include <X11/extensions/XKB.h> #include <X11/extensions/XKB.h>
#include "xkbsrv.h" #include "xkbsrv.h"
@ -175,13 +176,17 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff)
break; break;
case DEVICE_ON: case DEVICE_ON:
xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK;
for (i = 0; i < xnestNumScreens; i++) for (i = 0; i < xnestNumScreens; i++) {
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); XnestScreenPtr xnscr = xnestScreenByIdx(i);
XSelectInput(xnestDisplay, xnscr->rootWindow, xnestEventMask);
}
break; break;
case DEVICE_OFF: case DEVICE_OFF:
xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK; xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK;
for (i = 0; i < xnestNumScreens; i++) for (i = 0; i < xnestNumScreens; i++) {
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); XnestScreenPtr xnscr = xnestScreenByIdx(i);
XSelectInput(xnestDisplay, xnscr->rootWindow, xnestEventMask);
}
break; break;
case DEVICE_CLOSE: case DEVICE_CLOSE:
break; break;

View File

@ -29,6 +29,7 @@ is" without express or implied warranty.
#include "Display.h" #include "Display.h"
#include "Screen.h" #include "Screen.h"
#include "XNPixmap.h" #include "XNPixmap.h"
#include "multiscreen.h"
DevPrivateKeyRec xnestPixmapPrivateKeyRec; DevPrivateKeyRec xnestPixmapPrivateKeyRec;
@ -58,7 +59,7 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
if (width && height) if (width && height)
xnestPixmapPriv(pPixmap)->pixmap = xnestPixmapPriv(pPixmap)->pixmap =
XCreatePixmap(xnestDisplay, XCreatePixmap(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xnestScreenPriv(pScreen)->rootWindow,
width, height, depth); width, height, depth);
else else
xnestPixmapPriv(pPixmap)->pixmap = 0; xnestPixmapPriv(pPixmap)->pixmap = 0;
@ -83,7 +84,7 @@ xnestModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth,
if(!xnestPixmapPriv(pPixmap)->pixmap && width > 0 && height > 0) { if(!xnestPixmapPriv(pPixmap)->pixmap && width > 0 && height > 0) {
xnestPixmapPriv(pPixmap)->pixmap = xnestPixmapPriv(pPixmap)->pixmap =
XCreatePixmap(xnestDisplay, XCreatePixmap(xnestDisplay,
xnestDefaultWindows[pPixmap->drawable.pScreen->myNum], xnestScreenPriv(pPixmap->drawable.pScreen)->rootWindow,
width, height, depth); width, height, depth);
} }

View File

@ -28,6 +28,7 @@ is" without express or implied warranty.
#include "Screen.h" #include "Screen.h"
#include "Pointer.h" #include "Pointer.h"
#include "Args.h" #include "Args.h"
#include "multiscreen.h"
#include "xserver-properties.h" #include "xserver-properties.h"
#include "exevents.h" /* For XIGetKnownProperty */ #include "exevents.h" /* For XIGetKnownProperty */
@ -78,12 +79,12 @@ xnestPointerProc(DeviceIntPtr pDev, int onoff)
case DEVICE_ON: case DEVICE_ON:
xnestEventMask |= XNEST_POINTER_EVENT_MASK; xnestEventMask |= XNEST_POINTER_EVENT_MASK;
for (i = 0; i < xnestNumScreens; i++) for (i = 0; i < xnestNumScreens; i++)
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); XSelectInput(xnestDisplay, xnestScreenByIdx(i)->rootWindow, xnestEventMask);
break; break;
case DEVICE_OFF: case DEVICE_OFF:
xnestEventMask &= ~XNEST_POINTER_EVENT_MASK; xnestEventMask &= ~XNEST_POINTER_EVENT_MASK;
for (i = 0; i < xnestNumScreens; i++) for (i = 0; i < xnestNumScreens; i++)
XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); XSelectInput(xnestDisplay, xnestScreenByIdx(i)->rootWindow, xnestEventMask);
break; break;
case DEVICE_CLOSE: case DEVICE_CLOSE:
break; break;

View File

@ -41,8 +41,8 @@ is" without express or implied warranty.
#include "mipointer.h" #include "mipointer.h"
#include "Args.h" #include "Args.h"
#include "mipointrst.h" #include "mipointrst.h"
#include "multiscreen.h"
Window xnestDefaultWindows[MAXSCREENS];
Window xnestScreenSaverWindows[MAXSCREENS]; Window xnestScreenSaverWindows[MAXSCREENS];
DevPrivateKeyRec xnestScreenCursorFuncKeyRec; DevPrivateKeyRec xnestScreenCursorFuncKeyRec;
DevScreenPrivateKeyRec xnestScreenCursorPrivKeyRec; DevScreenPrivateKeyRec xnestScreenCursorPrivKeyRec;
@ -53,7 +53,7 @@ xnestScreen(Window window)
int i; int i;
for (i = 0; i < xnestNumScreens; i++) for (i = 0; i < xnestNumScreens; i++)
if (xnestDefaultWindows[i] == window) if (xnestScreenByIdx(i)->rootWindow == window)
return screenInfo.screens[i]; return screenInfo.screens[i];
return NULL; return NULL;
@ -340,6 +340,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
#define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32) #define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32)
if (xnestDoFullGeneration) { if (xnestDoFullGeneration) {
XnestScreenPtr xnscr = xnestScreenPriv(pScreen);
valuemask = CWBackPixel | CWEventMask | CWColormap; valuemask = CWBackPixel | CWEventMask | CWColormap;
attributes.background_pixel = xnestWhitePixel; attributes.background_pixel = xnestWhitePixel;
@ -348,12 +349,11 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
xnestDefaultVisualColormap(xnestDefaultVisual(pScreen)); xnestDefaultVisualColormap(xnestDefaultVisual(pScreen));
if (xnestParentWindow != 0) { if (xnestParentWindow != 0) {
xnestDefaultWindows[pScreen->myNum] = xnestParentWindow; xnscr->rootWindow = xnestParentWindow;
XSelectInput(xnestDisplay, xnestDefaultWindows[pScreen->myNum], XSelectInput(xnestDisplay, xnestParentWindow, xnestEventMask);
xnestEventMask);
} }
else else
xnestDefaultWindows[pScreen->myNum] = xnscr->rootWindow =
XCreateWindow(xnestDisplay, XCreateWindow(xnestDisplay,
DefaultRootWindow(xnestDisplay), DefaultRootWindow(xnestDisplay),
xnestX + POSITION_OFFSET, xnestX + POSITION_OFFSET,
@ -378,12 +378,12 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue) if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue)
sizeHints.flags |= USSize; sizeHints.flags |= USSize;
XSetStandardProperties(xnestDisplay, XSetStandardProperties(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xnscr->rootWindow,
xnestWindowName, xnestWindowName,
xnestWindowName, xnestWindowName,
xnestIconBitmap, argv, argc, &sizeHints); xnestIconBitmap, argv, argc, &sizeHints);
XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]); XMapWindow(xnestDisplay, xnscr->rootWindow);
valuemask = CWBackPixmap | CWColormap; valuemask = CWBackPixmap | CWColormap;
attributes.background_pixmap = xnestScreenSaverPixmap; attributes.background_pixmap = xnestScreenSaverPixmap;
@ -391,7 +391,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[])
DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay)); DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay));
xnestScreenSaverWindows[pScreen->myNum] = xnestScreenSaverWindows[pScreen->myNum] =
XCreateWindow(xnestDisplay, XCreateWindow(xnestDisplay,
xnestDefaultWindows[pScreen->myNum], xnscr->rootWindow,
0, 0, xnestWidth, xnestHeight, 0, 0, 0, xnestWidth, xnestHeight, 0,
DefaultDepth(xnestDisplay, DefaultDepth(xnestDisplay,
DefaultScreen(xnestDisplay)), DefaultScreen(xnestDisplay)),

View File

@ -18,7 +18,6 @@ is" without express or implied warranty.
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xdefs.h> #include <X11/Xdefs.h>
extern Window xnestDefaultWindows[MAXSCREENS];
extern Window xnestScreenSaverWindows[MAXSCREENS]; extern Window xnestScreenSaverWindows[MAXSCREENS];
ScreenPtr xnestScreen(Window window); ScreenPtr xnestScreen(Window window);

View File

@ -36,6 +36,7 @@ is" without express or implied warranty.
#include "Visual.h" #include "Visual.h"
#include "Events.h" #include "Events.h"
#include "Args.h" #include "Args.h"
#include "multiscreen.h"
DevPrivateKeyRec xnestWindowPrivateKeyRec; DevPrivateKeyRec xnestWindowPrivateKeyRec;

View File

@ -47,7 +47,7 @@ extern DevPrivateKeyRec xnestWindowPrivateKeyRec;
#define xnestWindowParent(pWin) \ #define xnestWindowParent(pWin) \
((pWin)->parent ? \ ((pWin)->parent ? \
xnestWindow((pWin)->parent) : \ xnestWindow((pWin)->parent) : \
xnestDefaultWindows[pWin->drawable.pScreen->myNum]) xnestScreenPriv(pWin->drawable.pScreen)->rootWindow)
#define xnestWindowSiblingAbove(pWin) \ #define xnestWindowSiblingAbove(pWin) \
((pWin)->prevSib ? xnestWindow((pWin)->prevSib) : None) ((pWin)->prevSib ? xnestWindow((pWin)->prevSib) : None)

View File

@ -15,6 +15,7 @@ srcs = [
'Screen.c', 'Screen.c',
'Visual.c', 'Visual.c',
'Window.c', 'Window.c',
'multiscreen.c',
'../../mi/miinitext.c', '../../mi/miinitext.c',
'../../mi/miinitext.h', '../../mi/miinitext.h',
] ]

15
hw/xnest/multiscreen.c Normal file
View File

@ -0,0 +1,15 @@
#include "multiscreen.h"
#include "scrnintstr.h"
XnestScreenRec xnestScreens[MAXSCREENS] = { 0 };
XnestScreenPtr xnestScreenPriv(ScreenPtr pScreen)
{
return &xnestScreens[pScreen->myNum];
}
XnestScreenPtr xnestScreenByIdx(int idx)
{
return &xnestScreens[idx];
}

24
hw/xnest/multiscreen.h Normal file
View File

@ -0,0 +1,24 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#ifndef _XNEST_MULTISCREEN_H
#define _XNEST_MULTISCREEN_H
#include <X11/X.h>
#include <X11/Xdefs.h>
#include <X11/Xlib.h>
#include "screenint.h"
typedef struct xnest_screen {
Window rootWindow;
} XnestScreenRec, *XnestScreenPtr;
/* retrieve private screen structure by ScreenPtr */
XnestScreenPtr xnestScreenPriv(ScreenPtr pScreen);
/* retrieve private screen structure by global index */
XnestScreenPtr xnestScreenByIdx(int idx);
#endif /* _XSERVER_CALLBACK_PRIV_H */