x: wrap xcb_generate_id to check for errors

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-04-08 05:49:39 +01:00
parent 83941c5612
commit a28f5f584b
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
8 changed files with 24 additions and 12 deletions

View File

@ -221,7 +221,7 @@ bool build_shadow(xcb_connection_t *c, xcb_drawable_t d, double opacity, const i
goto shadow_picture_err;
}
gc = xcb_generate_id(c);
gc = x_new_id(c);
xcb_create_gc(c, gc, shadow_pixmap, 0, NULL);
xcb_image_put(c, shadow_pixmap, gc, shadow_image, 0, 0, 0);

View File

@ -510,7 +510,7 @@ backend_t *backend_xrender_init(session_t *ps) {
xd->vsync = ps->o.vsync;
if (ps->present_exists) {
auto eid = xcb_generate_id(ps->c);
auto eid = x_new_id(ps->c);
auto e =
xcb_request_check(ps->c, xcb_present_select_input_checked(
ps->c, eid, xd->target_win,

View File

@ -1064,7 +1064,7 @@ void update_ewmh_active_win(session_t *ps) {
static bool register_cm(session_t *ps) {
assert(!ps->reg_win);
ps->reg_win = xcb_generate_id(ps->c);
ps->reg_win = x_new_id(ps->c);
auto e = xcb_request_check(
ps->c, xcb_create_window_checked(ps->c, XCB_COPY_FROM_PARENT, ps->reg_win, ps->root,
0, 0, 1, 1, 0, XCB_NONE, ps->vis, 0, NULL));
@ -1956,7 +1956,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
}
if (ps->o.xrender_sync_fence) {
ps->sync_fence = xcb_generate_id(ps->c);
ps->sync_fence = x_new_id(ps->c);
e = xcb_request_check(
ps->c, xcb_sync_create_fence(ps->c, ps->root, ps->sync_fence, 0));
if (e) {

View File

@ -438,7 +438,7 @@ static inline void repair_win(session_t *ps, win *w) {
set_ignore_cookie(
ps, xcb_damage_subtract(ps->c, w->damage, XCB_NONE, XCB_NONE));
} else {
xcb_xfixes_region_t tmp = xcb_generate_id(ps->c);
xcb_xfixes_region_t tmp = x_new_id(ps->c);
xcb_xfixes_create_region(ps->c, tmp, 0, NULL);
set_ignore_cookie(ps, xcb_damage_subtract(ps->c, w->damage, XCB_NONE, tmp));
x_fetch_region(ps->c, tmp, &parts);

View File

@ -240,7 +240,7 @@ static inline bool paint_isvalid(session_t *ps, const paint_t *ppaint) {
void paint_one(session_t *ps, win *w, const region_t *reg_paint) {
// Fetch Pixmap
if (!w->paint.pixmap) {
w->paint.pixmap = xcb_generate_id(ps->c);
w->paint.pixmap = x_new_id(ps->c);
set_ignore_cookie(
ps, xcb_composite_name_window_pixmap(ps->c, w->id, w->paint.pixmap));
}
@ -537,7 +537,7 @@ static bool win_build_shadow(session_t *ps, win *w, double opacity) {
if (!shadow_picture || !shadow_picture_argb)
goto shadow_picture_err;
gc = xcb_generate_id(ps->c);
gc = x_new_id(ps->c);
xcb_create_gc(ps->c, gc, shadow_pixmap, 0, NULL);
xcb_image_put(ps->c, shadow_pixmap, gc, shadow_image, 0, 0, 0);

View File

@ -200,7 +200,7 @@ void win_release_image(backend_t *base, win *w) {
static inline bool
_win_bind_image(session_t *ps, win *w, void **win_image, void **shadow_image) {
auto pixmap = xcb_generate_id(ps->c);
auto pixmap = x_new_id(ps->c);
auto e = xcb_request_check(
ps->c, xcb_composite_name_window_pixmap_checked(ps->c, w->id, pixmap));
if (e) {
@ -1011,7 +1011,7 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
// Create Damage for window (if not Input Only)
if (new->a._class != XCB_WINDOW_CLASS_INPUT_ONLY) {
new->damage = xcb_generate_id(ps->c);
new->damage = x_new_id(ps->c);
xcb_generic_error_t *e = xcb_request_check(
ps->c, xcb_damage_create_checked(ps->c, new->damage, id,
XCB_DAMAGE_REPORT_LEVEL_NON_EMPTY));

View File

@ -196,7 +196,7 @@ x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *c,
}
}
xcb_render_picture_t tmp_picture = xcb_generate_id(c);
xcb_render_picture_t tmp_picture = x_new_id(c);
xcb_generic_error_t *e =
xcb_request_check(c, xcb_render_create_picture_checked(
c, tmp_picture, pixmap, pictfmt->id, valuemask, buf));
@ -410,7 +410,7 @@ void x_print_error(unsigned long serial, uint8_t major, uint16_t minor, uint8_t
*/
xcb_pixmap_t x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t drawable,
int width, int height) {
xcb_pixmap_t pix = xcb_generate_id(c);
xcb_pixmap_t pix = x_new_id(c);
xcb_void_cookie_t cookie = xcb_create_pixmap_checked(
c, depth, pix, drawable, to_u16_checked(width), to_u16_checked(height));
xcb_generic_error_t *err = xcb_request_check(c, cookie);

14
src/x.h
View File

@ -61,6 +61,18 @@ struct xvisual_info {
r; \
})
/// Wraps x_new_id. abort the program if x_new_id returns error
static inline uint32_t x_new_id(xcb_connection_t *c) {
auto ret = xcb_generate_id(c);
if (ret == (uint32_t)-1) {
log_fatal("We seems to have run of XIDs. This is either a bug in the X "
"server, or a resource leakage in compton. Please open an "
"issue about this problem. compton will die.");
abort();
}
return ret;
}
/**
* Send a request to X server and get the reply to make sure all previous
* requests are processed, and their replies received
@ -203,7 +215,7 @@ bool x_fence_sync(xcb_connection_t *, xcb_sync_fence_t);
* @param[inout] size size of the array pointed to by `ret`.
*/
int x_picture_filter_from_conv(const conv *kernel, double center,
xcb_render_fixed_t **ret, size_t *size);
xcb_render_fixed_t **ret, size_t *size);
/// Generate a search criteria for fbconfig from a X visual.
/// Returns {-1, -1, -1, -1, -1, -1} on failure