2018-10-03 21:14:51 +00:00
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
// Copyright (c) 2018 Yuxuan Shui <yshuiv7@gmail.com>
|
2018-09-29 22:36:53 +00:00
|
|
|
#pragma once
|
|
|
|
#include <pixman.h>
|
|
|
|
#include <stdio.h>
|
2019-03-27 15:33:55 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <xcb/xcb.h>
|
2018-12-20 02:49:29 +00:00
|
|
|
|
|
|
|
#include "log.h"
|
2019-03-27 15:33:55 +00:00
|
|
|
#include "utils.h"
|
2018-10-21 01:56:50 +00:00
|
|
|
|
2018-09-29 22:36:53 +00:00
|
|
|
typedef struct pixman_region32 pixman_region32_t;
|
|
|
|
typedef struct pixman_box32 pixman_box32_t;
|
|
|
|
typedef pixman_region32_t region_t;
|
|
|
|
typedef pixman_box32_t rect_t;
|
|
|
|
|
|
|
|
RC_TYPE(region_t, rc_region, pixman_region32_init, pixman_region32_fini, static inline)
|
|
|
|
|
2019-03-27 15:33:55 +00:00
|
|
|
static inline void dump_region(const region_t *x) {
|
|
|
|
if (log_get_level_tls() < LOG_LEVEL_TRACE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int nrects;
|
|
|
|
const rect_t *rects = pixman_region32_rectangles((region_t *)x, &nrects);
|
|
|
|
log_trace("nrects: %d", nrects);
|
|
|
|
for (int i = 0; i < nrects; i++)
|
|
|
|
log_trace("(%d, %d) - (%d, %d)", rects[i].x1, rects[i].y1, rects[i].x2,
|
|
|
|
rects[i].y2);
|
2018-09-29 22:36:53 +00:00
|
|
|
}
|
2018-09-30 13:11:10 +00:00
|
|
|
|
|
|
|
/// Convert one xcb rectangle to our rectangle type
|
2019-03-27 15:33:55 +00:00
|
|
|
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,
|
|
|
|
};
|
2018-09-30 13:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Convert an array of xcb rectangles to our rectangle type
|
|
|
|
/// Returning an array that needs to be freed
|
2019-03-27 15:33:55 +00:00
|
|
|
static inline rect_t *from_x_rects(int nrects, const xcb_rectangle_t *rects) {
|
|
|
|
rect_t *ret = ccalloc(nrects, rect_t);
|
2019-03-30 09:07:21 +00:00
|
|
|
for (int i = 0; i < nrects; i++) {
|
2019-03-27 15:33:55 +00:00
|
|
|
ret[i] = from_x_rect(rects + i);
|
2019-03-30 09:07:21 +00:00
|
|
|
}
|
2019-03-27 15:33:55 +00:00
|
|
|
return ret;
|
2018-09-30 13:11:10 +00:00
|
|
|
}
|