diff options
| author | Lukasz Kasprzak <lukasz@arcofasiagroup.com> | 2026-08-21 09:49:33 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukasz@arcofasiagroup.com> | 2026-08-21 09:49:33 +0200 |
| commit | 7459e218fa8b5b86c059762519447cb8863d3e75 (patch) | |
| tree | 413f960c8543a0d8016c2ce45132648c61e25b6e /mu_x11.c | |
| parent | d58ac7945a97b4029772022550775ab834c81b97 (diff) | |
| download | colitur-x-7459e218fa8b5b86c059762519447cb8863d3e75.tar.gz colitur-x-7459e218fa8b5b86c059762519447cb8863d3e75.zip | |
debug: MUX_DUMP writes one frame from the pixmap, then exits
Verifying what the program actually draws by screenshotting its window is
unreliable: X does not retain a window's contents while it is obscured or
on an unfocused tag, so import and xwd can both return solid black while
the rendering is correct. Reading back the off-screen pixmap always
works.
Used to confirm the XRectangle clip-truncation fix: rows now run
unbroken from 2027-01-01 to 2027-01-29 with every column populated,
where before the twelfth row lost everything but its name.
Diffstat (limited to 'mu_x11.c')
| -rw-r--r-- | mu_x11.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -11,6 +11,7 @@ #include <X11/Xlib.h> #include <X11/Xft/Xft.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "vendor/microui.h" #include "mu_x11.h" @@ -145,4 +146,32 @@ void mux_present(mu_Context *ctx, int w, int h, mu_Color bg) XftDrawSetClip(xd, NULL); XCopyArea(dpy, buf, win, gc, 0, 0, w, h, 0, 0); XFlush(dpy); + + /* MUX_DUMP=path writes the frame out as a PPM and exits. Reading back + the off-screen PIXMAP rather than the window is what makes this + reliable: a window's contents are not retained when it is obscured or + on an unfocused tag, so screenshotting one can return black even + though the program is drawing perfectly. A pixmap is always there. */ + { + const char *path = getenv("MUX_DUMP"); + if (!path) return; + XImage *im = XGetImage(dpy, buf, 0, 0, w, h, AllPlanes, ZPixmap); + if (!im) { fprintf(stderr, "MUX_DUMP: XGetImage failed\n"); exit(1); } + FILE *f = fopen(path, "wb"); + if (!f) { fprintf(stderr, "MUX_DUMP: cannot write %s\n", path); exit(1); } + fprintf(f, "P6\n%d %d\n255\n", w, h); + for (int yy = 0; yy < h; yy++) + for (int xx = 0; xx < w; xx++) { + unsigned long px = XGetPixel(im, xx, yy); + unsigned char rgb[3] = { + (unsigned char)((px >> 16) & 0xff), + (unsigned char)((px >> 8) & 0xff), + (unsigned char)(px & 0xff) }; + fwrite(rgb, 1, 3, f); + } + fclose(f); + XDestroyImage(im); + fprintf(stderr, "MUX_DUMP: wrote %s (%dx%d)\n", path, w, h); + exit(0); + } } |
