Xnest: use XCB for upstream connection

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-08-21 14:59:42 +02:00
parent 540043413b
commit 6e4914ffd0
5 changed files with 18 additions and 28 deletions

View File

@ -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;
@ -147,7 +131,7 @@ xnestOpenDisplay(int argc, char *argv[])
void
xnestCloseDisplay(void)
{
if (!xnestDoFullGeneration || !xnestDisplay)
if (!xnestDoFullGeneration || !xnestUpstreamInfo.conn)
return;
/*
@ -158,5 +142,8 @@ xnestCloseDisplay(void)
xnestVisualMap = NULL;
xnestNumVisualMap = 0;
XCloseDisplay(xnestDisplay);
xcb_disconnect(xnestUpstreamInfo.conn);
xnestUpstreamInfo.conn = NULL;
xnestUpstreamInfo.screenInfo = NULL;
xnestUpstreamInfo.setup = NULL;
}

View File

@ -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;

View File

@ -259,7 +259,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);
}

View File

@ -25,11 +25,13 @@ xnestUpstreamInfoRec xnestUpstreamInfo = { 0 };
XnestVisualRec *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);
@ -38,6 +40,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 */

View File

@ -16,7 +16,7 @@ typedef struct {
typedef struct {
xcb_connection_t *conn;
uint32_t screenId;
int screenId;
const xcb_screen_t *screenInfo;
const xcb_setup_t *setup;
xnestEventQueue eventQueue;
@ -24,8 +24,8 @@ typedef struct {
extern xnestUpstreamInfoRec 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 xnestUpstreamGC(GCPtr pGC);