From 070a9b2318de85ac2f7638d9b5edd5f56a711a95 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 21 Aug 2024 14:59:42 +0200 Subject: [PATCH] (!1654) Xnest: use XCB for upstream connection Now that no Xlib operations (besides opening and closing connection) aren't used anymore, we can move over the last pieces and use XCB instead of Xlib for connecting the upstream Xserver. Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xnest/Display.c | 27 +++++++-------------------- hw/xnest/Display.h | 1 - hw/xnest/Events.c | 2 +- hw/xnest/xcb.c | 10 +++++++--- hw/xnest/xnest-xcb.h | 6 +++--- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/hw/xnest/Display.c b/hw/xnest/Display.c index e6184ad8b..fc25c725d 100644 --- a/hw/xnest/Display.c +++ b/hw/xnest/Display.c @@ -39,7 +39,6 @@ is" without express or implied warranty. #include "icon" #include "screensaver" -Display *xnestDisplay = NULL; Colormap *xnestDefaultColormaps; int xnestNumPixmapFormats; Drawable xnestDefaultDrawables[MAXDEPTH + 1]; @@ -48,15 +47,6 @@ Pixmap xnestScreenSaverPixmap; uint32_t xnestBitmapGC; uint32_t xnestEventMask; -static int _X_NORETURN -x_io_error_handler(Display * dpy) -{ - ErrorF("Lost connection to X server: %s\n", strerror(errno)); - CloseWellKnownConnections(); - OsCleanup(1); - exit(1); -} - void xnestOpenDisplay(int argc, char *argv[]) { @@ -65,16 +55,10 @@ xnestOpenDisplay(int argc, char *argv[]) if (!xnestDoFullGeneration) return; - XSetIOErrorHandler(x_io_error_handler); - xnestCloseDisplay(); - xnestDisplay = XOpenDisplay(xnestDisplayName); - if (xnestDisplay == NULL) - FatalError("Unable to open display \"%s\".\n", - XDisplayName(xnestDisplayName)); - - xnest_upstream_setup(); + if (!xnest_upstream_setup(xnestDisplayName)) + FatalError("Unable to open display \"%s\".\n", xnestDisplayName); if (xnestParentWindow != (Window) 0) xnestEventMask = XCB_EVENT_MASK_STRUCTURE_NOTIFY; @@ -148,7 +132,7 @@ xnestOpenDisplay(int argc, char *argv[]) void xnestCloseDisplay(void) { - if (!xnestDoFullGeneration || !xnestDisplay) + if (!xnestDoFullGeneration || !xnestUpstreamInfo.conn) return; /* @@ -159,5 +143,8 @@ xnestCloseDisplay(void) xnestVisualMap = NULL; xnestNumVisualMap = 0; - XCloseDisplay(xnestDisplay); + xcb_disconnect(xnestUpstreamInfo.conn); + xnestUpstreamInfo.conn = NULL; + xnestUpstreamInfo.screenInfo = NULL; + xnestUpstreamInfo.setup = NULL; } diff --git a/hw/xnest/Display.h b/hw/xnest/Display.h index 70f18b3de..25b2d819e 100644 --- a/hw/xnest/Display.h +++ b/hw/xnest/Display.h @@ -24,7 +24,6 @@ is" without express or implied warranty. #define MAXDEPTH 32 #define MAXVISUALSPERDEPTH 256 -extern Display *xnestDisplay; extern int xnestNumPixmapFormats; extern Drawable xnestDefaultDrawables[MAXDEPTH + 1]; extern Pixmap xnestIconBitmap; diff --git a/hw/xnest/Events.c b/hw/xnest/Events.c index d3fb7c85f..e775e8391 100644 --- a/hw/xnest/Events.c +++ b/hw/xnest/Events.c @@ -260,7 +260,7 @@ xnestCollectEvents(void) int err = xcb_connection_has_error(xnestUpstreamInfo.conn); if (err) { - ErrorF("Xnest: upsream connection error: %d\n", err); + ErrorF("Xnest: upstream connection error: %d\n", err); exit(0); } diff --git a/hw/xnest/xcb.c b/hw/xnest/xcb.c index e6beefca0..75d13af62 100644 --- a/hw/xnest/xcb.c +++ b/hw/xnest/xcb.c @@ -26,11 +26,13 @@ struct xnest_upstream_info xnestUpstreamInfo = { 0 }; xnest_visual_t *xnestVisualMap; int xnestNumVisualMap; -void xnest_upstream_setup(void) { - xnestUpstreamInfo.screenId = DefaultScreen(xnestDisplay); +Bool xnest_upstream_setup(const char* displayName) +{ + xnestUpstreamInfo.conn = xcb_connect(displayName, &xnestUpstreamInfo.screenId); + if (!xnestUpstreamInfo.conn) + return FALSE; /* 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); @@ -39,6 +41,8 @@ void xnest_upstream_setup(void) { xnestUpstreamInfo.screenInfo = iter.data; xorg_list_init(&xnestUpstreamInfo.eventQueue.entry); + + return TRUE; } /* retrieve upstream GC XID for our xserver GC */ diff --git a/hw/xnest/xnest-xcb.h b/hw/xnest/xnest-xcb.h index 87ccc7fb8..71a1aa4ac 100644 --- a/hw/xnest/xnest-xcb.h +++ b/hw/xnest/xnest-xcb.h @@ -16,7 +16,7 @@ struct xnest_event_queue { struct xnest_upstream_info { xcb_connection_t *conn; - uint32_t screenId; + int screenId; const xcb_screen_t *screenInfo; const xcb_setup_t *setup; struct xnest_event_queue eventQueue; @@ -24,8 +24,8 @@ struct xnest_upstream_info { extern struct xnest_upstream_info xnestUpstreamInfo; -/* fetch upstream connection's xcb setup data */ -void xnest_upstream_setup(void); +/* connect to upstream X server */ +Bool xnest_upstream_setup(const char* displayName); /* retrieve upstream GC XID for our xserver GC */ uint32_t xnest_upstream_gc(GCPtr pGC);