/* SPDX-License-Identifier: MIT OR X11 * * Copyright © 2024 Enrico Weigelt, metux IT consult */ #include #include #include #include #include #include #include "include/gc.h" #include "include/servermd.h" #include "Xnest.h" #include "xnest-xcb.h" #include "XNGC.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; } /* retrieve upstream GC XID for our xserver GC */ uint32_t xnest_upstream_gc(GCPtr pGC) { if (pGC == NULL) return 0; xnestPrivGC *priv = dixLookupPrivate(&(pGC)->devPrivates, xnestGCPrivateKey); if (priv == NULL) return 0; return priv->gc; } const char WM_COLORMAP_WINDOWS[] = "WM_COLORMAP_WINDOWS"; void xnest_wm_colormap_windows( xcb_connection_t *conn, xcb_window_t w, xcb_window_t *windows, int count) { xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply( conn, xcb_intern_atom( conn, 0, sizeof(WM_COLORMAP_WINDOWS)-1, WM_COLORMAP_WINDOWS), NULL); if (!reply) return; xcb_icccm_set_wm_colormap_windows_checked( conn, w, reply->atom, count, (xcb_window_t*)windows); free(reply); } uint32_t xnest_create_bitmap_from_data( xcb_connection_t *conn, uint32_t drawable, const char *data, uint32_t width, uint32_t height) { uint32_t pix = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_pixmap(conn, 1, pix, drawable, width, height); uint32_t gc = xcb_generate_id(xnestUpstreamInfo.conn); xcb_create_gc(conn, gc, pix, 0, NULL); const int leftPad = 0; xcb_put_image(conn, XYPixmap, pix, gc, width, height, 0 /* dst_x */, 0 /* dst_y */, leftPad, 1 /* depth */, BitmapBytePad(width + leftPad) * height, (uint8_t*)data); xcb_free_gc(conn, gc); return pix; }