diff --git a/hw/xnest/Color.c b/hw/xnest/Color.c index 8fe62c1c3..bd550d280 100644 --- a/hw/xnest/Color.c +++ b/hw/xnest/Color.c @@ -96,7 +96,7 @@ xnestCreateColormap(ColormapPtr pCmap) xcb_create_colormap(xnestUpstreamInfo.conn, (pVisual->class & DynamicClass) ? XCB_COLORMAP_ALLOC_ALL : XCB_COLORMAP_ALLOC_NONE, cmap, - xnestDefaultWindows[pCmap->pScreen->myNum], + xnest_screen_priv(pCmap->pScreen)->upstream_frame_window, xnest_visual_map_to_upstream(pVisual->vid)); switch (pVisual->class) { @@ -212,6 +212,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) { xnestInstalledColormapWindows icws; int numWindows; + struct xnest_screen_info *screenPriv = xnest_screen_priv(pScreen); icws.cmapIDs = xallocarray(pScreen->maxInstalledCmaps, sizeof(Colormap)); icws.numCmapIDs = xnestListInstalledColormaps(pScreen, icws.cmapIDs); @@ -221,7 +222,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) icws.windows = xallocarray(icws.numWindows + 1, sizeof(xcb_window_t)); icws.index = 0; WalkTree(pScreen, xnestGetInstalledColormapWindows, (void *) &icws); - icws.windows[icws.numWindows] = xnestDefaultWindows[pScreen->myNum]; + icws.windows[icws.numWindows] = screenPriv->upstream_frame_window; numWindows = icws.numWindows + 1; } else { @@ -235,7 +236,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) free(xnestOldInstalledColormapWindows); xnest_wm_colormap_windows(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, icws.windows, numWindows); @@ -265,7 +266,7 @@ xnestSetInstalledColormapWindows(ScreenPtr pScreen) uint32_t cmap = xnestColormap(pCmap); xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, XCB_CW_COLORMAP, &cmap); } @@ -281,7 +282,7 @@ xnestSetScreenSaverColormapWindow(ScreenPtr pScreen) free(xnestOldInstalledColormapWindows); xnest_wm_colormap_windows(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + xnest_screen_priv(pScreen)->upstream_frame_window, &xnestScreenSaverWindows[pScreen->myNum], 1); diff --git a/hw/xnest/Cursor.c b/hw/xnest/Cursor.c index b71a5197f..1398b034d 100644 --- a/hw/xnest/Cursor.c +++ b/hw/xnest/Cursor.c @@ -54,7 +54,7 @@ xnestRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor) xcb_aux_change_gc(xnestUpstreamInfo.conn, xnestBitmapGC, valuemask, &values); - uint32_t const winId = xnestDefaultWindows[pScreen->myNum]; + uint32_t const winId = xnest_screen_priv(pScreen)->upstream_frame_window; Pixmap const source = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_pixmap(xnestUpstreamInfo.conn, 1, source, winId, pCursor->bits->width, pCursor->bits->height); @@ -134,7 +134,7 @@ xnestSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor, int x, uint32_t cursor = xnestCursor(pCursor, pScreen); xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + xnest_screen_priv(pScreen)->upstream_frame_window, XCB_CW_CURSOR, &cursor); } diff --git a/hw/xnest/GCOps.c b/hw/xnest/GCOps.c index 0fbbf6eb0..19d612274 100644 --- a/hw/xnest/GCOps.c +++ b/hw/xnest/GCOps.c @@ -71,7 +71,7 @@ xnestQueryBestSize(int class, unsigned short *pWidth, unsigned short *pHeight, xcb_query_best_size( xnestUpstreamInfo.conn, class, - xnestDefaultWindows[pScreen->myNum], + xnest_screen_priv(pScreen)->upstream_frame_window, *pWidth, *pHeight), &err); diff --git a/hw/xnest/Keyboard.c b/hw/xnest/Keyboard.c index 7714f3c9a..dcb405b32 100644 --- a/hw/xnest/Keyboard.c +++ b/hw/xnest/Keyboard.c @@ -218,7 +218,7 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff) xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[i], + xnest_screen_by_id(i)->upstream_frame_window, XCB_CW_EVENT_MASK, &xnestEventMask); break; @@ -226,7 +226,7 @@ xnestKeyboardProc(DeviceIntPtr pDev, int onoff) xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[i], + xnest_screen_by_id(i)->upstream_frame_window, XCB_CW_EVENT_MASK, &xnestEventMask); break; diff --git a/hw/xnest/Pixmap.c b/hw/xnest/Pixmap.c index 572f74e3d..4a567060d 100644 --- a/hw/xnest/Pixmap.c +++ b/hw/xnest/Pixmap.c @@ -59,7 +59,7 @@ xnestCreatePixmap(ScreenPtr pScreen, int width, int height, int depth, if (width && height) { uint32_t pixmap = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_pixmap(xnestUpstreamInfo.conn, depth, pixmap, - xnestDefaultWindows[pScreen->myNum], width, height); + xnest_screen_priv(pScreen)->upstream_frame_window, width, height); xnestPixmapPriv(pPixmap)->pixmap = pixmap; } else @@ -85,7 +85,7 @@ xnestModifyPixmapHeader(PixmapPtr pPixmap, int width, int height, int depth, if(!xnestPixmapPriv(pPixmap)->pixmap && width > 0 && height > 0) { uint32_t pixmap = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_pixmap(xnestUpstreamInfo.conn, depth, pixmap, - xnestDefaultWindows[pPixmap->drawable.pScreen->myNum], + xnest_screen_priv(pPixmap->drawable.pScreen)->upstream_frame_window, width, height); xnestPixmapPriv(pPixmap)->pixmap = pixmap; } diff --git a/hw/xnest/Pointer.c b/hw/xnest/Pointer.c index b72154f44..85bd51bbc 100644 --- a/hw/xnest/Pointer.c +++ b/hw/xnest/Pointer.c @@ -107,7 +107,7 @@ xnestPointerProc(DeviceIntPtr pDev, int onoff) xnestEventMask |= XNEST_POINTER_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[i], + xnest_screen_by_id(i)->upstream_frame_window, XCB_CW_EVENT_MASK, &xnestEventMask); break; @@ -115,7 +115,7 @@ xnestPointerProc(DeviceIntPtr pDev, int onoff) xnestEventMask &= ~XNEST_POINTER_EVENT_MASK; for (i = 0; i < xnestNumScreens; i++) xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[i], + xnest_screen_by_id(i)->upstream_frame_window, XCB_CW_EVENT_MASK, &xnestEventMask); break; diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index 411df8278..1ae631917 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -47,7 +47,6 @@ is" without express or implied warranty. #include "Args.h" #include "mipointrst.h" -xcb_window_t xnestDefaultWindows[MAXSCREENS]; xcb_window_t xnestScreenSaverWindows[MAXSCREENS]; DevPrivateKeyRec xnestScreenCursorFuncKeyRec; DevScreenPrivateKeyRec xnestScreenCursorPrivKeyRec; @@ -58,7 +57,7 @@ xnestScreen(xcb_window_t window) int i; for (i = 0; i < xnestNumScreens; i++) - if (xnestDefaultWindows[i] == window) + if (xnest_screen_by_id(i)->upstream_frame_window == window) return screenInfo.screens[i]; return NULL; @@ -415,18 +414,20 @@ breakout: valuemask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP; + struct xnest_screen_info *screenPriv = xnest_screen_priv(pScreen); + if (xnestParentWindow != 0) { - xnestDefaultWindows[pScreen->myNum] = xnestParentWindow; + screenPriv->upstream_frame_window = xnestParentWindow; xcb_change_window_attributes(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, XCB_CW_EVENT_MASK, &xnestEventMask); } else { - xnestDefaultWindows[pScreen->myNum] = xcb_generate_id(xnestUpstreamInfo.conn); + screenPriv->upstream_frame_window = xcb_generate_id(xnestUpstreamInfo.conn); xcb_aux_create_window(xnestUpstreamInfo.conn, pScreen->rootDepth, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, xnestUpstreamInfo.screenInfo->root, xnestGeometry.x + POSITION_OFFSET, xnestGeometry.y + POSITION_OFFSET, @@ -462,21 +463,21 @@ breakout: const size_t windowNameLen = strlen(xnestWindowName); xcb_icccm_set_wm_name_checked(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, XCB_ATOM_STRING, 8, windowNameLen, xnestWindowName); xcb_icccm_set_wm_icon_name_checked(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, XCB_ATOM_STRING, 8, windowNameLen, xnestWindowName); xnest_set_command(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, argv, argc); xcb_icccm_wm_hints_t wmhints = { @@ -485,10 +486,10 @@ breakout: }; xcb_icccm_set_wm_hints_checked(xnestUpstreamInfo.conn, - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, &wmhints); - xcb_map_window(xnestUpstreamInfo.conn, xnestDefaultWindows[pScreen->myNum]); + xcb_map_window(xnestUpstreamInfo.conn, screenPriv->upstream_frame_window); valuemask = XCB_CW_BACK_PIXMAP | XCB_CW_COLORMAP; attributes.back_pixmap = xnestScreenSaverPixmap; @@ -498,7 +499,7 @@ breakout: xcb_aux_create_window(xnestUpstreamInfo.conn, xnestUpstreamInfo.screenInfo->root_depth, xnestScreenSaverWindows[pScreen->myNum], - xnestDefaultWindows[pScreen->myNum], + screenPriv->upstream_frame_window, 0, 0, xnestGeometry.width, diff --git a/hw/xnest/Screen.h b/hw/xnest/Screen.h index 60312e7d9..832c76839 100644 --- a/hw/xnest/Screen.h +++ b/hw/xnest/Screen.h @@ -20,7 +20,6 @@ is" without express or implied warranty. #include -extern xcb_window_t xnestDefaultWindows[MAXSCREENS]; extern xcb_window_t xnestScreenSaverWindows[MAXSCREENS]; ScreenPtr xnestScreen(xcb_window_t window); diff --git a/hw/xnest/XNWindow.h b/hw/xnest/XNWindow.h index 79f776ef4..73c748227 100644 --- a/hw/xnest/XNWindow.h +++ b/hw/xnest/XNWindow.h @@ -48,7 +48,7 @@ extern DevPrivateKeyRec xnestWindowPrivateKeyRec; #define xnestWindowParent(pWin) \ ((pWin)->parent ? \ xnestWindow((pWin)->parent) : \ - xnestDefaultWindows[pWin->drawable.pScreen->myNum]) + xnest_screen_priv(pWin->drawable.pScreen)->upstream_frame_window) #define xnestWindowSiblingAbove(pWin) \ ((pWin)->prevSib ? xnestWindow((pWin)->prevSib) : XCB_WINDOW_NONE) diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c index 0f040c49c..61df94a3e 100644 --- a/hw/xnest/xcb.c +++ b/hw/xnest/xcb.c @@ -21,6 +21,7 @@ #include "XNGC.h" #include "Display.h" +struct xnest_screen_info xnestScreens[MAXSCREENS] = { 0 }; struct xnest_upstream_info xnestUpstreamInfo = { 0 }; xnest_visual_t *xnestVisualMap; int xnestNumVisualMap; diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h index 71a1aa4ac..9b8f480d7 100644 --- a/hw/xnest/xnest-xcb.h +++ b/hw/xnest/xnest-xcb.h @@ -8,12 +8,24 @@ #include #include "include/list.h" +#include "include/scrnintstr.h" struct xnest_event_queue { struct xorg_list entry; xcb_generic_event_t *event; }; +struct xnest_screen_info { + /* the FRAME window isn't the ROOT window - it's where the ROOT window + is created into: + + on startup the core will call xnestCreateWindow() with pWin->parent == NULL, + which means we're creating the screen's ROOT window. This approach makes + several things easier, eg. embedding Xnest into another application, or maybe + even adding some control widgets (eg. scroll bars) */ + xcb_window_t upstream_frame_window; +}; + struct xnest_upstream_info { xcb_connection_t *conn; int screenId; @@ -22,8 +34,17 @@ struct xnest_upstream_info { struct xnest_event_queue eventQueue; }; +extern struct xnest_screen_info xnestScreens[MAXSCREENS]; extern struct xnest_upstream_info xnestUpstreamInfo; +static inline struct xnest_screen_info *xnest_screen_by_id(int idx) { + return &xnestScreens[idx]; +} + +static inline struct xnest_screen_info *xnest_screen_priv(ScreenPtr pScreen) { + return xnest_screen_by_id(pScreen->myNum); // should use devPrivates +} + /* connect to upstream X server */ Bool xnest_upstream_setup(const char* displayName);