Xnest: fetch supported pixmap formats from xcb setup data

There's even no need to keep our own copies, since we can ask XCB's
copy any time.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-08-09 13:01:57 +02:00
parent e172253272
commit a05b912d06
3 changed files with 15 additions and 17 deletions

View File

@ -44,7 +44,6 @@ int xnestNumVisuals;
int xnestDefaultVisualIndex; int xnestDefaultVisualIndex;
Colormap *xnestDefaultColormaps; Colormap *xnestDefaultColormaps;
static uint16_t xnestNumDefaultColormaps; static uint16_t xnestNumDefaultColormaps;
XPixmapFormatValues *xnestPixmapFormats;
int xnestNumPixmapFormats; int xnestNumPixmapFormats;
Drawable xnestDefaultDrawables[MAXDEPTH + 1]; Drawable xnestDefaultDrawables[MAXDEPTH + 1];
Pixmap xnestIconBitmap; Pixmap xnestIconBitmap;
@ -126,9 +125,6 @@ xnestOpenDisplay(int argc, char *argv[])
xnestVisuals[i].visual->visualid); xnestVisuals[i].visual->visualid);
} }
xnestPixmapFormats = XListPixmapFormats(xnestDisplay,
&xnestNumPixmapFormats);
if (xnestParentWindow != (Window) 0) if (xnestParentWindow != (Window) 0)
xnestEventMask = XCB_EVENT_MASK_STRUCTURE_NOTIFY; xnestEventMask = XCB_EVENT_MASK_STRUCTURE_NOTIFY;
else else
@ -137,21 +133,22 @@ xnestOpenDisplay(int argc, char *argv[])
for (i = 0; i <= MAXDEPTH; i++) for (i = 0; i <= MAXDEPTH; i++)
xnestDefaultDrawables[i] = XCB_WINDOW_NONE; xnestDefaultDrawables[i] = XCB_WINDOW_NONE;
for (i = 0; i < xnestNumPixmapFormats; i++) { xcb_format_t *fmt = xcb_setup_pixmap_formats(xnestUpstreamInfo.setup);
const xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length(xnestUpstreamInfo.setup);
for(; fmt != fmtend; ++fmt) {
xcb_depth_iterator_t depth_iter; xcb_depth_iterator_t depth_iter;
for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo); for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo);
depth_iter.rem; depth_iter.rem;
xcb_depth_next(&depth_iter)) xcb_depth_next(&depth_iter))
{ {
if (xnestPixmapFormats[i].depth == 1 || if (fmt->depth == 1 || fmt->depth == depth_iter.data->depth) {
xnestPixmapFormats[i].depth == depth_iter.data->depth) {
uint32_t pixmap = xcb_generate_id(xnestUpstreamInfo.conn); uint32_t pixmap = xcb_generate_id(xnestUpstreamInfo.conn);
xcb_create_pixmap(xnestUpstreamInfo.conn, xcb_create_pixmap(xnestUpstreamInfo.conn,
xnestPixmapFormats[i].depth, fmt->depth,
pixmap, pixmap,
xnestUpstreamInfo.screenInfo->root, xnestUpstreamInfo.screenInfo->root,
1, 1); 1, 1);
xnestDefaultDrawables[xnestPixmapFormats[i].depth] = pixmap; xnestDefaultDrawables[fmt->depth] = pixmap;
} }
} }
} }
@ -210,6 +207,5 @@ xnestCloseDisplay(void)
free(xnestDefaultColormaps); free(xnestDefaultColormaps);
XFree(xnestVisuals); XFree(xnestVisuals);
XFree(xnestPixmapFormats);
XCloseDisplay(xnestDisplay); XCloseDisplay(xnestDisplay);
} }

View File

@ -28,7 +28,6 @@ extern int xnestNumVisuals;
extern int xnestDefaultVisualIndex; extern int xnestDefaultVisualIndex;
extern Colormap *xnestDefaultColormaps; extern Colormap *xnestDefaultColormaps;
extern int xnestNumDefaultClormaps; extern int xnestNumDefaultClormaps;
extern XPixmapFormatValues *xnestPixmapFormats;
extern int xnestNumPixmapFormats; extern int xnestNumPixmapFormats;
extern Drawable xnestDefaultDrawables[MAXDEPTH + 1]; extern Drawable xnestDefaultDrawables[MAXDEPTH + 1];
extern Pixmap xnestIconBitmap; extern Pixmap xnestIconBitmap;

View File

@ -77,20 +77,23 @@ InitOutput(ScreenInfo * screen_info, int argc, char *argv[])
screen_info->bitmapScanlinePad = xnestUpstreamInfo.setup->bitmap_format_scanline_pad; screen_info->bitmapScanlinePad = xnestUpstreamInfo.setup->bitmap_format_scanline_pad;
screen_info->bitmapBitOrder = xnestUpstreamInfo.setup->bitmap_format_bit_order; screen_info->bitmapBitOrder = xnestUpstreamInfo.setup->bitmap_format_bit_order;
screen_info->numPixmapFormats = 0; screen_info->numPixmapFormats = 0;
for (i = 0; i < xnestNumPixmapFormats; i++) {
xcb_format_t *fmt = xcb_setup_pixmap_formats(xnestUpstreamInfo.setup);
const xcb_format_t *fmtend = fmt + xcb_setup_pixmap_formats_length(xnestUpstreamInfo.setup);
for(; fmt != fmtend; ++fmt) {
xcb_depth_iterator_t depth_iter; xcb_depth_iterator_t depth_iter;
for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo); for (depth_iter = xcb_screen_allowed_depths_iterator(xnestUpstreamInfo.screenInfo);
depth_iter.rem; depth_iter.rem;
xcb_depth_next(&depth_iter)) xcb_depth_next(&depth_iter))
{ {
if ((xnestPixmapFormats[i].depth == 1) || if ((fmt->depth == 1) ||
(xnestPixmapFormats[i].depth == depth_iter.data->depth)) { (fmt->depth == depth_iter.data->depth)) {
screen_info->formats[screen_info->numPixmapFormats].depth = screen_info->formats[screen_info->numPixmapFormats].depth =
xnestPixmapFormats[i].depth; fmt->depth;
screen_info->formats[screen_info->numPixmapFormats].bitsPerPixel = screen_info->formats[screen_info->numPixmapFormats].bitsPerPixel =
xnestPixmapFormats[i].bits_per_pixel; fmt->bits_per_pixel;
screen_info->formats[screen_info->numPixmapFormats].scanlinePad = screen_info->formats[screen_info->numPixmapFormats].scanlinePad =
xnestPixmapFormats[i].scanline_pad; fmt->scanline_pad;
screen_info->numPixmapFormats++; screen_info->numPixmapFormats++;
break; break;
} }