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 "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;

View File

@ -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));
}
}

View File

@ -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;

View File

@ -34,6 +34,7 @@ is" without express or implied warranty.
#include "Keyboard.h"
#include "Args.h"
#include "Events.h"
#include "multiscreen.h"
#include <X11/extensions/XKB.h>
#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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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)),

View File

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

View File

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

View File

@ -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)

View File

@ -15,6 +15,7 @@ srcs = [
'Screen.c',
'Visual.c',
'Window.c',
'multiscreen.c',
'../../mi/miinitext.c',
'../../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 */