region.h: helper functions for converting rect types
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
a7d50ffdb2
commit
82e63593ae
22
src/region.h
22
src/region.h
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <xcb/xcb.h>
|
||||
#include <pixman.h>
|
||||
#include <stdio.h>
|
||||
#include "utils.h"
|
||||
|
@ -23,3 +24,24 @@ dump_region(const region_t *x) {
|
|||
for (int i = 0; i < nrects; i++)
|
||||
fprintf(stderr, "(%d, %d) - (%d, %d)\n", rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);
|
||||
}
|
||||
|
||||
/// Convert one xcb rectangle to our rectangle type
|
||||
static inline rect_t
|
||||
from_x_rect(const xcb_rectangle_t *rect) {
|
||||
return (rect_t) {
|
||||
.x1 = rect->x,
|
||||
.y1 = rect->y,
|
||||
.x2 = rect->x + rect->width,
|
||||
.y2 = rect->y + rect->height,
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert an array of xcb rectangles to our rectangle type
|
||||
/// Returning an array that needs to be freed
|
||||
static inline rect_t *
|
||||
from_x_rects(int nrects, const xcb_rectangle_t *rects) {
|
||||
rect_t *ret = calloc(nrects, sizeof *ret);
|
||||
for (int i = 0; i < nrects; i++)
|
||||
ret[i] = from_x_rect(rects+i);
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue