diff --git a/src/backend/backend_common.c b/src/backend/backend_common.c index 5d7b7b1b..90ad52e1 100644 --- a/src/backend/backend_common.c +++ b/src/backend/backend_common.c @@ -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); diff --git a/src/backend/xrender.c b/src/backend/xrender.c index 193f26d3..d1fe2f8d 100644 --- a/src/backend/xrender.c +++ b/src/backend/xrender.c @@ -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, diff --git a/src/compton.c b/src/compton.c index 59835444..20adf6b6 100644 --- a/src/compton.c +++ b/src/compton.c @@ -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) { diff --git a/src/event.c b/src/event.c index a196ea47..13b491c5 100644 --- a/src/event.c +++ b/src/event.c @@ -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); diff --git a/src/render.c b/src/render.c index 074a2588..2565824e 100644 --- a/src/render.c +++ b/src/render.c @@ -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); diff --git a/src/win.c b/src/win.c index 2de78c8d..ca001d4d 100644 --- a/src/win.c +++ b/src/win.c @@ -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)); diff --git a/src/x.c b/src/x.c index 7e79262a..5801d996 100644 --- a/src/x.c +++ b/src/x.c @@ -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); diff --git a/src/x.h b/src/x.h index 275bc56d..df281428 100644 --- a/src/x.h +++ b/src/x.h @@ -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