Add helper function x_get_visual_depth

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-03 16:48:52 +00:00
parent 386f5fb8c6
commit b061789a84
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
1 changed files with 16 additions and 0 deletions

16
src/x.c
View File

@ -143,6 +143,22 @@ xcb_render_pictforminfo_t *x_get_pictform_for_visual(xcb_connection_t *c, xcb_vi
return NULL;
}
int x_get_visual_depth(xcb_connection_t *c, xcb_visualid_t visual) {
auto setup = xcb_get_setup(c);
for (auto screen = xcb_setup_roots_iterator(setup); screen.rem; xcb_screen_next(&screen)) {
for (auto depth = xcb_screen_allowed_depths_iterator(screen.data); depth.rem; xcb_depth_next(&depth)) {
const int len = xcb_depth_visuals_length(depth.data);
const xcb_visualtype_t *visuals = xcb_depth_visuals(depth.data);
for (int i = 0; i < len; i++) {
if (visual == visuals[i].visual_id) {
return depth.data->depth;
}
}
}
}
return -1;
}
xcb_render_picture_t
x_create_picture_with_pictfmt_and_pixmap(
xcb_connection_t *c, xcb_render_pictforminfo_t * pictfmt,