x: add the x_set_region function

it sets an x region to a pixman region
This commit is contained in:
Maxim Solovyov 2024-01-28 03:46:55 +03:00
parent d111e1640a
commit efb7a1430f
No known key found for this signature in database
2 changed files with 31 additions and 0 deletions

28
src/x.c
View File

@ -459,6 +459,34 @@ bool x_fetch_region(struct x_connection *c, xcb_xfixes_region_t r, pixman_region
return ret;
}
bool x_set_region(struct x_connection *c, xcb_xfixes_region_t dst, const region_t *src) {
if (!src || dst == XCB_NONE) {
return false;
}
int32_t nrects = 0;
const rect_t *rects = pixman_region32_rectangles((region_t *)src, &nrects);
if (!rects || nrects < 1) {
return false;
}
xcb_rectangle_t *xrects = ccalloc(nrects, xcb_rectangle_t);
for (int32_t i = 0; i < nrects; i++) {
xrects[i] =
(xcb_rectangle_t){.x = to_i16_checked(rects[i].x1),
.y = to_i16_checked(rects[i].y1),
.width = to_u16_checked(rects[i].x2 - rects[i].x1),
.height = to_u16_checked(rects[i].y2 - rects[i].y1)};
}
bool success =
XCB_AWAIT_VOID(xcb_xfixes_set_region, c->c, dst, to_u32_checked(nrects), xrects);
free(xrects);
return success;
}
uint32_t x_create_region(struct x_connection *c, const region_t *reg) {
if (!reg) {
return XCB_NONE;

View File

@ -321,6 +321,9 @@ x_create_picture_with_visual(struct x_connection *, int w, int h, xcb_visualid_t
/// Fetch a X region and store it in a pixman region
bool x_fetch_region(struct x_connection *, xcb_xfixes_region_t r, region_t *res);
/// Set an X region to a pixman region
bool x_set_region(struct x_connection *c, xcb_xfixes_region_t dst, const region_t *src);
/// Create a X region from a pixman region
uint32_t x_create_region(struct x_connection *c, const region_t *reg);