From d3a108b3db8732e01bfb3970f7e5772fc5d0008d Mon Sep 17 00:00:00 2001 From: Maxim Solovyov Date: Thu, 1 Feb 2024 02:31:29 +0300 Subject: [PATCH] x: add the x_get_visual_for_depth function it returns the first found visual for the given depth (cherry picked from commit 4401666cfb06f9d76a1bf109feda42730a6da9aa) Signed-off-by: Yuxuan Shui --- src/x.c | 15 +++++++++++++++ src/x.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/x.c b/src/x.c index 85913da4..d885c66e 100644 --- a/src/x.c +++ b/src/x.c @@ -321,6 +321,21 @@ xcb_visualid_t x_get_visual_for_standard(struct x_connection *c, xcb_pict_standa return x_get_visual_for_pictfmt(g_pictfmts, pictfmt->id); } +xcb_visualid_t x_get_visual_for_depth(struct x_connection *c, uint8_t depth) { + xcb_screen_iterator_t screen_it = xcb_setup_roots_iterator(xcb_get_setup(c->c)); + for (; screen_it.rem; xcb_screen_next(&screen_it)) { + xcb_depth_iterator_t depth_it = + xcb_screen_allowed_depths_iterator(screen_it.data); + for (; depth_it.rem; xcb_depth_next(&depth_it)) { + if (depth_it.data->depth == depth) { + return xcb_depth_visuals_iterator(depth_it.data).data->visual_id; + } + } + } + + return XCB_NONE; +} + xcb_render_pictformat_t x_get_pictfmt_for_standard(struct x_connection *c, xcb_pict_standard_t std) { x_get_server_pictfmts(c); diff --git a/src/x.h b/src/x.h index 3027c84c..c811d382 100644 --- a/src/x.h +++ b/src/x.h @@ -411,6 +411,8 @@ struct xvisual_info x_get_visual_info(struct x_connection *c, xcb_visualid_t vis xcb_visualid_t x_get_visual_for_standard(struct x_connection *c, xcb_pict_standard_t std); +xcb_visualid_t x_get_visual_for_depth(struct x_connection *c, uint8_t depth); + xcb_render_pictformat_t x_get_pictfmt_for_standard(struct x_connection *c, xcb_pict_standard_t std);