diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c index 5fdfba8cc..0bc9ffc7f 100644 --- a/hw/xnest/Color.c +++ b/hw/xnest/Color.c @@ -32,6 +32,7 @@ is" without express or implied warranty. #include "Visual.h" #include "XNWindow.h" #include "Args.h" +#include "multiscreen.h" DevPrivateKeyRec xnestColormapPrivateKeyRec; @@ -54,9 +55,11 @@ xnestCreateColormap(ColormapPtr pCmap) pVisual = pCmap->pVisual; ncolors = pVisual->ColormapEntries; + XnestScreenPtr xnscr = xnestScreenPriv(pCmap->pScreen); + xnestColormapPriv(pCmap)->colormap = XCreateColormap(xnestDisplay, - xnestDefaultWindows[pCmap->pScreen->myNum], + xnscr->rootWindow, xnestVisual(pVisual), (pVisual->class & DynamicClass) ? AllocAll : AllocNone); @@ -193,6 +196,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) { xnestInstalledColormapWindows icws; int numWindows; + XnestScreenPtr xnscr = xnestScreenPriv(pScreen); icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap)); icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs); @@ -202,7 +206,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) icws.windows = xallocarray(icws.numWindows + 1, sizeof(Window)); icws.index = 0; WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws); - icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum]; + icws.windows[icws.numWindows] = xnscr->rootWindow; numWindows = icws.numWindows + 1; } else { @@ -215,7 +219,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) if (!xnestSameInstalledColormapWindows(icws.windows, icws.numWindows)) { free(xnestOldInstalledColormapWindows); - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + XSetWMColormapWindows(xnestDisplay, xnscr->rootWindow, icws.windows, numWindows); xnestOldInstalledColormapWindows = icws.windows; @@ -243,9 +247,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) pScreen->defColormap, X11_RESTYPE_COLORMAP, serverClient, DixUseAccess); - XSetWindowColormap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - xnestColormap(pCmap)); + XSetWindowColormap(xnestDisplay, xnscr->rootWindow, xnestColormap(pCmap)); } #endif /* DUMB_WINDOW_MANAGERS */ } @@ -256,9 +258,11 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) void xnestSetScreenSaverColormapWindow(ScreenPtr pScreen) { + XnestScreenPtr xnscr = xnestScreenPriv(pScreen); + free(xnestOldInstalledColormapWindows); - XSetWMColormapWindows(xnestDisplay, xnestDefaultWindows[pScreen->myNum], + XSetWMColormapWindows(xnestDisplay, xnscr->rootWindow, &xnestScreenSaverWindows[pScreen->myNum], 1); xnestOldInstalledColormapWindows = NULL; diff --git a/hw/xnest/Cursor.c b/hw/xnest/Cursor.c index b26302219..ddedf098b 100644 --- a/hw/xnest/Cursor.c +++ b/hw/xnest/Cursor.c @@ -32,6 +32,7 @@ is" without express or implied warranty. #include "Visual.h" #include "Keyboard.h" #include "Args.h" +#include "multiscreen.h" xnestCursorFuncRec xnestCursorFuncs = { NULL }; @@ -43,6 +44,7 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) XColor fg_color, bg_color; unsigned long valuemask; XGCValues values; + XnestScreenPtr xscr = xnestScreenPriv(pScreen); valuemask = GCFunction | GCPlaneMask | GCForeground | GCBackground | GCClipMask; @@ -56,11 +58,11 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) XChangeGC(xnestDisplay, xnestBitmapGC, valuemask, &values); source = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], + xscr->rootWindow, pCursor->bits->width, pCursor->bits->height, 1); mask = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], + xscr->rootWindow, pCursor->bits->width, pCursor->bits->height, 1); ximage = XCreateImage(xnestDisplay, @@ -136,8 +138,9 @@ xnestSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, int y) { if (pCursor) { + XnestScreenPtr xnscr = xnestScreenPriv(pScreen); XDefineCursor(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], + xnscr->rootWindow, xnestCursor(pCursor, pScreen)); } } diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c index 398a634f2..8d74012fa 100644 --- a/hw/xnest/GCOps.c +++ b/hw/xnest/GCOps.c @@ -34,6 +34,7 @@ is" without express or implied warranty. #include "GCOps.h" #include "Drawable.h" #include "Visual.h" +#include "multiscreen.h" void xnestFillSpans(DrawablePtr pDrawable, GCPtr pGC, int nSpans, xPoint * pPoints, @@ -61,12 +62,13 @@ xnestQueryBestSize(int class, unsigned short *pWidth, unsigned short *pHeight, ScreenPtr pScreen) { unsigned int width, height; + XnestScreenPtr xnscr = xnestScreenPriv(pScreen); width = *pWidth; height = *pHeight; XQueryBestSize(xnestDisplay, class, - xnestDefaultWindows[pScreen->myNum], + xnscr->rootWindow, width, height, &width, &height); *pWidth = width; diff --git a/hw/xnest/Keyboard.c b/hw/xnest/Keyboard.c index fe8f750ad..64beaa2bc 100644 --- a/hw/xnest/Keyboard.c +++ b/hw/xnest/Keyboard.c @@ -34,6 +34,7 @@ is" without express or implied warranty. #include "Keyboard.h" #include "Args.h" #include "Events.h" +#include "multiscreen.h" #include #include "xkbsrv.h" @@ -175,13 +176,17 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff) break; case DEVICE_ON: xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; - for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + for (i = 0; i < xnestNumScreens; i++) { + XnestScreenPtr xnscr = xnestScreenByIdx(i); + XSelectInput(xnestDisplay, xnscr->rootWindow, xnestEventMask); + } break; case DEVICE_OFF: xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK; - for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + for (i = 0; i < xnestNumScreens; i++) { + XnestScreenPtr xnscr = xnestScreenByIdx(i); + XSelectInput(xnestDisplay, xnscr->rootWindow, xnestEventMask); + } break; case DEVICE_CLOSE: break; diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c index c78c98102..d4ddd62ae 100644 --- a/hw/xnest/Pixmap.c +++ b/hw/xnest/Pixmap.c @@ -29,6 +29,7 @@ is" without express or implied warranty. #include "Display.h" #include "Screen.h" #include "XNPixmap.h" +#include "multiscreen.h" DevPrivateKeyRec xnestPixmapPrivateKeyRec; @@ -58,8 +59,8 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth, if (width && height) xnestPixmapPriv(pPixmap)->pixmap = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], - width, height, depth); + xnestScreenPriv(pScreen)->rootWindow, + width, height, depth); else 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) { xnestPixmapPriv(pPixmap)->pixmap = XCreatePixmap(xnestDisplay, - xnestDefaultWindows[pPixmap->drawable.pScreen->myNum], + xnestScreenPriv(pPixmap->drawable.pScreen)->rootWindow, width, height, depth); } diff --git a/hw/xnest/Pointer.c b/hw/xnest/Pointer.c index c813a6521..35190d47b 100644 --- a/hw/xnest/Pointer.c +++ b/hw/xnest/Pointer.c @@ -28,6 +28,7 @@ is" without express or implied warranty. #include "Screen.h" #include "Pointer.h" #include "Args.h" +#include "multiscreen.h" #include "xserver-properties.h" #include "exevents.h" /* For XIGetKnownProperty */ @@ -78,12 +79,12 @@ xnestPointerProc(DeviceIntPtr pDev, int onoff) case DEVICE_ON: xnestEventMask |= XNEST_POINTER_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + XSelectInput(xnestDisplay, xnestScreenByIdx(i)->rootWindow, xnestEventMask); break; case DEVICE_OFF: xnestEventMask &= ~XNEST_POINTER_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) - XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask); + XSelectInput(xnestDisplay, xnestScreenByIdx(i)->rootWindow, xnestEventMask); break; case DEVICE_CLOSE: break; diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index 133031098..c55f00410 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -41,8 +41,8 @@ is" without express or implied warranty. #include "mipointer.h" #include "Args.h" #include "mipointrst.h" +#include "multiscreen.h" -Window xnestDefaultWindows[MAXSCREENS]; Window xnestScreenSaverWindows[MAXSCREENS]; DevPrivateKeyRec xnestScreenCursorFuncKeyRec; DevScreenPrivateKeyRec xnestScreenCursorPrivKeyRec; @@ -53,7 +53,7 @@ xnestScreen(Window window) int i; for (i = 0; i < xnestNumScreens; i++) - if (xnestDefaultWindows[i] == window) + if (xnestScreenByIdx(i)->rootWindow == window) return screenInfo.screens[i]; return NULL; @@ -340,6 +340,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) #define POSITION_OFFSET (pScreen->myNum * (xnestWidth + xnestHeight) / 32) if (xnestDoFullGeneration) { + XnestScreenPtr xnscr = xnestScreenPriv(pScreen); valuemask = CWBackPixel | CWEventMask | CWColormap; attributes.background_pixel = xnestWhitePixel; @@ -348,12 +349,11 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) xnestDefaultVisualColormap(xnestDefaultVisual(pScreen)); if (xnestParentWindow != 0) { - xnestDefaultWindows[pScreen->myNum] = xnestParentWindow; - XSelectInput(xnestDisplay, xnestDefaultWindows[pScreen->myNum], - xnestEventMask); + xnscr->rootWindow = xnestParentWindow; + XSelectInput(xnestDisplay, xnestParentWindow, xnestEventMask); } else - xnestDefaultWindows[pScreen->myNum] = + xnscr->rootWindow = XCreateWindow(xnestDisplay, DefaultRootWindow(xnestDisplay), xnestX + POSITION_OFFSET, @@ -378,12 +378,12 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) if (xnestUserGeometry & WidthValue || xnestUserGeometry & HeightValue) sizeHints.flags |= USSize; XSetStandardProperties(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], + xnscr->rootWindow, xnestWindowName, xnestWindowName, xnestIconBitmap, argv, argc, &sizeHints); - XMapWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum]); + XMapWindow(xnestDisplay, xnscr->rootWindow); valuemask = CWBackPixmap | CWColormap; attributes.background_pixmap = xnestScreenSaverPixmap; @@ -391,7 +391,7 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay)); xnestScreenSaverWindows[pScreen->myNum] = XCreateWindow(xnestDisplay, - xnestDefaultWindows[pScreen->myNum], + xnscr->rootWindow, 0, 0, xnestWidth, xnestHeight, 0, DefaultDepth(xnestDisplay, DefaultScreen(xnestDisplay)), diff --git a/hw/xnest/Screen.h b/hw/xnest/Screen.h index d06338f5a..e4c746626 100644 --- a/hw/xnest/Screen.h +++ b/hw/xnest/Screen.h @@ -18,7 +18,6 @@ is" without express or implied warranty. #include #include -extern Window xnestDefaultWindows[MAXSCREENS]; extern Window xnestScreenSaverWindows[MAXSCREENS]; ScreenPtr xnestScreen(Window window); diff --git a/hw/xnest/Window.c b/hw/xnest/Window.c index e58df9f0e..9f398aa2b 100644 --- a/hw/xnest/Window.c +++ b/hw/xnest/Window.c @@ -36,6 +36,7 @@ is" without express or implied warranty. #include "Visual.h" #include "Events.h" #include "Args.h" +#include "multiscreen.h" DevPrivateKeyRec xnestWindowPrivateKeyRec; diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h index 59dba01c0..76f4ab83b 100644 --- a/hw/xnest/XNWindow.h +++ b/hw/xnest/XNWindow.h @@ -47,7 +47,7 @@ extern DevPrivateKeyRec xnestWindowPrivateKeyRec; #define xnestWindowParent(pWin) \ ((pWin)->parent ? \ xnestWindow((pWin)->parent) : \ - xnestDefaultWindows[pWin->drawable.pScreen->myNum]) + xnestScreenPriv(pWin->drawable.pScreen)->rootWindow) #define xnestWindowSiblingAbove(pWin) \ ((pWin)->prevSib ? xnestWindow((pWin)->prevSib) : None) diff --git a/hw/xnest/meson.build b/hw/xnest/meson.build index 36489b1d8..c85c095a1 100644 --- a/hw/xnest/meson.build +++ b/hw/xnest/meson.build @@ -15,6 +15,7 @@ srcs = [ 'Screen.c', 'Visual.c', 'Window.c', + 'multiscreen.c', '../../mi/miinitext.c', '../../mi/miinitext.h', ] diff --git a/hw/xnest/multiscreen.c b/hw/xnest/multiscreen.c new file mode 100644 index 000000000..fc96a22cf --- /dev/null +++ b/hw/xnest/multiscreen.c @@ -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]; +} diff --git a/hw/xnest/multiscreen.h b/hw/xnest/multiscreen.h new file mode 100644 index 000000000..2cd931fe9 --- /dev/null +++ b/hw/xnest/multiscreen.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef _XNEST_MULTISCREEN_H +#define _XNEST_MULTISCREEN_H + +#include +#include +#include + +#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 */