win32

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 355f19114ce3c7f696618cf6142560571884305c
parent 84cdd1cd5529c9ebfb073f1b561550e92d32a73b
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Thu, 18 Dec 2025 22:16:17 +0900

find pictformats

Diffstat:
MMakefile | 2+-
Mxcb.c | 46++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -4,7 +4,7 @@ xlib: xlib.c $(CC) -Wall -Wpedantic -Wextra -I/usr/X11R6/include xlib.c -L/usr/X11R6/lib -lX11 -lXrender -o xlib xcb: xcb.c - $(CC) -Wall -Wpedantic -Wextra -I/usr/X11R6/include xcb.c -L/usr/X11R6/lib -lxcb -o xcb + $(CC) -Wall -Wpedantic -Wextra -I/usr/X11R6/include xcb.c -L/usr/X11R6/lib -lxcb -lxcb-render -o xcb clean: rm -f xlib xcb diff --git a/xcb.c b/xcb.c @@ -3,8 +3,10 @@ #include <unistd.h> // for pause(void) #include <xcb/xcb.h> #include <xcb/xproto.h> +#include <xcb/render.h> void fatal(char *msg); +int findPictFormat(xcb_connection_t *conn, int dept, xcb_render_pictformat_t *return_pictformat); int main(void) { xcb_connection_t *conn = xcb_connect(NULL, NULL); @@ -23,6 +25,21 @@ int main(void) { XCB_CW_EVENT_MASK, &attr); xcb_map_window(conn, window); + xcb_render_pictformat_t pictformat, pictformat24, pictformat32; + if (findPictFormat(conn, 32, &pictformat32) < 0) { + fatal("32bit pictformat not found"); + } + if (findPictFormat(conn, 24, &pictformat24) < 0) { + fatal("24bit pictformat not found"); + } + if (screen->root_depth == 32) { + pictformat = pictformat32; + } else if (screen->root_depth == 24) { + pictformat = pictformat24; + } else { + fatal("unsupported depth"); + } + xcb_flush(conn); pause(); @@ -35,3 +52,32 @@ void fatal(char *msg) { fprintf(stderr, "%s\n", msg); exit(1); } + +int findPictFormat(xcb_connection_t *conn, int depth, xcb_render_pictformat_t *return_pictformat) { + xcb_generic_error_t *error; + xcb_render_query_pict_formats_cookie_t cookie = xcb_render_query_pict_formats(conn); + xcb_render_query_pict_formats_reply_t *reply = xcb_render_query_pict_formats_reply(conn, cookie, &error); + if (error != NULL) { + fatal("render_query_pict_formats"); + } + xcb_render_pictforminfo_iterator_t iter = xcb_render_query_pict_formats_formats_iterator(reply); + while (iter.rem > 0) { + if (depth == 24 && iter.data->type == XCB_RENDER_PICT_TYPE_DIRECT && iter.data->depth == 24 && + iter.data->direct.red_shift == 16 && iter.data->direct.red_mask == 0xff && + iter.data->direct.green_shift == 8 && iter.data->direct.green_mask == 0xff && + iter.data->direct.blue_shift == 0 && iter.data->direct.blue_mask == 0xff) { + *return_pictformat = iter.data->id; + return 0; + } + if (depth == 32 && iter.data->type == XCB_RENDER_PICT_TYPE_DIRECT && iter.data->depth == 32 && + iter.data->direct.alpha_shift == 24 && iter.data->direct.alpha_mask == 0xff && + iter.data->direct.red_shift == 16 && iter.data->direct.red_mask == 0xff && + iter.data->direct.green_shift == 8 && iter.data->direct.green_mask == 0xff && + iter.data->direct.blue_shift == 0 && iter.data->direct.blue_mask == 0xff) { + *return_pictformat = iter.data->id; + return 0; + } + xcb_render_pictforminfo_next(&iter); + } + return -1; +}