From 3818fab9287bde3acaf0bcc11e6c014f1fcab0ad Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 30 Jul 2024 17:19:05 +0200 Subject: [PATCH] (!1654) Xnest: fetch xcb setup data Fetching the setup data from xcb instead of Xlib, storing in our own struct, holding all information needed for one particular upstream connection. For now, there's only one, but future multi-upstream implementation will change this to an array (and storing pointers to particular upstream in various places). Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xnest/Display.c | 23 +++++++++++------------ hw/xnest/Screen.c | 19 +++++++++---------- hw/xnest/meson.build | 1 + hw/xnest/xcb.c | 31 +++++++++++++++++++++++++++++++ hw/xnest/xnest-xcb.h | 22 ++++++++++++++++++++++ 5 files changed, 74 insertions(+), 22 deletions(-) create mode 100644 hw/xnest/xcb.c create mode 100644 hw/xnest/xnest-xcb.h diff --git a/hw/xnest/Display.c b/hw/xnest/Display.c index 7466848b1..af6335c72 100644 --- a/hw/xnest/Display.c +++ b/hw/xnest/Display.c @@ -31,6 +31,7 @@ is" without express or implied warranty. #include "servermd.h" #include "Xnest.h" +#include "xnest-xcb.h" #include "Display.h" #include "Init.h" @@ -88,8 +89,10 @@ xnestOpenDisplay(int argc, char *argv[]) if (xnestSynchronize) XSynchronize(xnestDisplay, TRUE); + xnest_upstream_setup(); + mask = VisualScreenMask; - vi.screen = DefaultScreen(xnestDisplay); + vi.screen = xnestUpstreamInfo.screenId; xnestVisuals = XGetVisualInfo(xnestDisplay, mask, &vi, &xnestNumVisuals); if (xnestNumVisuals == 0 || xnestVisuals == NULL) FatalError("Unable to find any visuals.\n"); @@ -110,8 +113,7 @@ xnestOpenDisplay(int argc, char *argv[]) } else { vi.visualid = XVisualIDFromVisual(DefaultVisual(xnestDisplay, - DefaultScreen - (xnestDisplay))); + xnestUpstreamInfo.screenId)); xnestDefaultVisualIndex = 0; for (i = 0; i < xnestNumVisuals; i++) if (vi.visualid == xnestVisuals[i].visualid) @@ -128,14 +130,14 @@ xnestOpenDisplay(int argc, char *argv[]) xnestVisuals[i].visual, AllocNone); - xnestDepths = XListDepths(xnestDisplay, DefaultScreen(xnestDisplay), + xnestDepths = XListDepths(xnestDisplay, xnestUpstreamInfo.screenId, &xnestNumDepths); xnestPixmapFormats = XListPixmapFormats(xnestDisplay, &xnestNumPixmapFormats); - xnestBlackPixel = BlackPixel(xnestDisplay, DefaultScreen(xnestDisplay)); - xnestWhitePixel = WhitePixel(xnestDisplay, DefaultScreen(xnestDisplay)); + xnestBlackPixel = BlackPixel(xnestDisplay, xnestUpstreamInfo.screenId); + xnestWhitePixel = WhitePixel(xnestDisplay, xnestUpstreamInfo.screenId); if (xnestParentWindow != (Window) 0) xnestEventMask = XCB_EVENT_MASK_STRUCTURE_NOTIFY; @@ -164,12 +166,10 @@ xnestOpenDisplay(int argc, char *argv[]) if (xnestParentWindow == 0) { if (!(xnestUserGeometry & WidthValue)) - xnestWidth = 3 * DisplayWidth(xnestDisplay, - DefaultScreen(xnestDisplay)) / 4; + xnestWidth = 3 * DisplayWidth(xnestDisplay, xnestUpstreamInfo.screenId) / 4; if (!(xnestUserGeometry & HeightValue)) - xnestHeight = 3 * DisplayHeight(xnestDisplay, - DefaultScreen(xnestDisplay)) / 4; + xnestHeight = 3 * DisplayHeight(xnestDisplay, xnestUpstreamInfo.screenId) / 4; } if (!xnestUserBorderWidth) @@ -188,8 +188,7 @@ xnestOpenDisplay(int argc, char *argv[]) screensaver_height, xnestWhitePixel, xnestBlackPixel, - DefaultDepth(xnestDisplay, - DefaultScreen(xnestDisplay))); + DefaultDepth(xnestDisplay, xnestUpstreamInfo.screenId)); } void diff --git a/hw/xnest/Screen.c b/hw/xnest/Screen.c index e518628cb..a7300d909 100644 --- a/hw/xnest/Screen.c +++ b/hw/xnest/Screen.c @@ -30,6 +30,7 @@ is" without express or implied warranty. #include "resource.h" #include "Xnest.h" +#include "xnest-xcb.h" #include "Display.h" #include "Screen.h" @@ -325,13 +326,12 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) &xnestCursorFuncs); PointPriv->spriteFuncs = &xnestPointerSpriteFuncs; - pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay, - DefaultScreen(xnestDisplay)) - / DisplayWidth(xnestDisplay, DefaultScreen(xnestDisplay)); + pScreen->mmWidth = xnestWidth * DisplayWidthMM(xnestDisplay, xnestUpstreamInfo.screenId) + / DisplayWidth(xnestDisplay, xnestUpstreamInfo.screenId); pScreen->mmHeight = xnestHeight * DisplayHeightMM(xnestDisplay, - DefaultScreen(xnestDisplay)) / - DisplayHeight(xnestDisplay, DefaultScreen(xnestDisplay)); + xnestUpstreamInfo.screenId) / + DisplayHeight(xnestDisplay, xnestUpstreamInfo.screenId); /* overwrite miCloseScreen with our own */ pScreen->CloseScreen = xnestCloseScreen; @@ -392,16 +392,15 @@ xnestOpenScreen(ScreenPtr pScreen, int argc, char *argv[]) valuemask = XCB_CW_BACK_PIXMAP | XCB_CW_COLORMAP; attributes.background_pixmap = xnestScreenSaverPixmap; attributes.colormap = - DefaultColormap(xnestDisplay, DefaultScreen(xnestDisplay)); + DefaultColormap(xnestDisplay, xnestUpstreamInfo.screenId); xnestScreenSaverWindows[pScreen->myNum] = XCreateWindow(xnestDisplay, xnestDefaultWindows[pScreen->myNum], 0, 0, xnestWidth, xnestHeight, 0, - DefaultDepth(xnestDisplay, - DefaultScreen(xnestDisplay)), + DefaultDepth(xnestDisplay, xnestUpstreamInfo.screenId), InputOutput, DefaultVisual(xnestDisplay, - DefaultScreen - (xnestDisplay)), valuemask, + xnestUpstreamInfo.screenId), + valuemask, &attributes); } diff --git a/hw/xnest/meson.build b/hw/xnest/meson.build index 8c4d2aa17..4428e6851 100644 --- a/hw/xnest/meson.build +++ b/hw/xnest/meson.build @@ -17,6 +17,7 @@ srcs = [ 'Window.c', '../../mi/miinitext.c', '../../mi/miinitext.h', + 'xcb.c', ] x11_xcb_dep = dependency('x11-xcb', required: true) diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c new file mode 100644 index 000000000..a93628886 --- /dev/null +++ b/hw/xnest/xcb.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#include + +#include + +#include +#include +#include + +#include "Xnest.h" +#include "xnest-xcb.h" + +#include "Display.h" + +struct xnest_upstream_info xnestUpstreamInfo = { 0 }; + +void xnest_upstream_setup(void) { + xnestUpstreamInfo.screenId = DefaultScreen(xnestDisplay); + + /* retrieve setup data for our screen */ + xnestUpstreamInfo.conn = XGetXCBConnection(xnestDisplay); + xnestUpstreamInfo.setup = xcb_get_setup(xnestUpstreamInfo.conn); + xcb_screen_iterator_t iter = xcb_setup_roots_iterator (xnestUpstreamInfo.setup); + + for (int i = 0; i < xnestUpstreamInfo.screenId; ++i) + xcb_screen_next (&iter); + xnestUpstreamInfo.screenInfo = iter.data; +} diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h new file mode 100644 index 000000000..391e84d22 --- /dev/null +++ b/hw/xnest/xnest-xcb.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: MIT OR X11 + * + * Copyright © 2024 Enrico Weigelt, metux IT consult + */ +#ifndef __XNEST__XCB_H +#define __XNEST__XCB_H + +#include + +struct xnest_upstream_info { + xcb_connection_t *conn; + uint32_t screenId; + const xcb_screen_t *screenInfo; + const xcb_setup_t *setup; +}; + +extern struct xnest_upstream_info xnestUpstreamInfo; + +/* fetch upstream connection's xcb setup data */ +void xnest_upstream_setup(void); + +#endif /* __XNEST__XCB_H */