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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-30 17:19:05 +02:00
parent 9df6c7a542
commit 467ee9eba7
5 changed files with 74 additions and 22 deletions

View File

@ -29,6 +29,7 @@ is" without express or implied warranty.
#include "servermd.h"
#include "Xnest.h"
#include "xnest-xcb.h"
#include "Display.h"
#include "Init.h"
@ -86,8 +87,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");
@ -108,8 +111,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)
@ -126,14 +128,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;
@ -162,12 +164,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)
@ -186,8 +186,7 @@ xnestOpenDisplay(int argc, char *argv[])
screensaver_height,
xnestWhitePixel,
xnestBlackPixel,
DefaultDepth(xnestDisplay,
DefaultScreen(xnestDisplay)));
DefaultDepth(xnestDisplay, xnestUpstreamInfo.screenId));
}
void

View File

@ -26,6 +26,7 @@ is" without express or implied warranty.
#include "resource.h"
#include "Xnest.h"
#include "xnest-xcb.h"
#include "Display.h"
#include "Screen.h"
@ -321,13 +322,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;
@ -388,16 +388,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);
}

View File

@ -17,6 +17,7 @@ srcs = [
'Window.c',
'../../mi/miinitext.c',
'../../mi/miinitext.h',
'xcb.c',
]
x11_xcb_dep = dependency('x11-xcb', required: true)

31
hw/xnest/xcb.c Normal file
View File

@ -0,0 +1,31 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#include <dix-config.h>
#include <xcb/xcb.h>
#include <X11/X.h>
#include <X11/Xdefs.h>
#include <X11/Xproto.h>
#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;
}

22
hw/xnest/xnest-xcb.h Normal file
View File

@ -0,0 +1,22 @@
/* SPDX-License-Identifier: MIT OR X11
*
* Copyright © 2024 Enrico Weigelt, metux IT consult <info@metux.net>
*/
#ifndef __XNEST__XCB_H
#define __XNEST__XCB_H
#include <xcb/xcb.h>
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 */