From 9969258e442a8e333b8fa0547c910166e12e07b3 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 21 Aug 2024 14:59:42 +0200 Subject: [PATCH] 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 c0ff37324..7bc3b0b4b 100644 --- a/hw/xnest/Display.c +++ b/hw/xnest/Display.c @@ -37,7 +37,6 @@ is" without express or implied warranty. #include "icon" #include "screensaver" -Display *xnestDisplay = NULL; Colormap *xnestDefaultColormaps; int xnestNumPixmapFormats; Drawable xnestDefaultDrawables[MAXDEPTH + 1]; @@ -46,15 +45,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[]) { @@ -63,16 +53,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; @@ -146,7 +130,7 @@ xnestOpenDisplay(int argc, char *argv[]) void xnestCloseDisplay(void) { - if (!xnestDoFullGeneration || !xnestDisplay) + if (!xnestDoFullGeneration || !xnestUpstreamInfo.conn) return; /* @@ -157,5 +141,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 16df73215..afda1c91e 100644 --- a/hw/xnest/Events.c +++ b/hw/xnest/Events.c @@ -257,7 +257,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);