diff --git a/src/picom.c b/src/picom.c index fedcf55..9d2e93b 100644 --- a/src/picom.c +++ b/src/picom.c @@ -1355,9 +1355,7 @@ static void handle_pending_updates(EV_P_ struct session *ps) { log_debug("Delayed handling of events, entering critical section"); auto e = xcb_request_check(ps->c, xcb_grab_server_checked(ps->c)); if (e) { - log_fatal("failed to grab x server"); - x_print_error(e->full_sequence, e->major_code, e->minor_code, - e->error_code); + log_fatal_x_error(e, "failed to grab x server"); return quit(ps); } @@ -1389,9 +1387,7 @@ static void handle_pending_updates(EV_P_ struct session *ps) { e = xcb_request_check(ps->c, xcb_ungrab_server_checked(ps->c)); if (e) { - log_fatal("failed to ungrab x server"); - x_print_error(e->full_sequence, e->major_code, e->minor_code, - e->error_code); + log_fatal_x_error(e, "failed to ungrab x server"); return quit(ps); } @@ -1701,8 +1697,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE})); if (e) { - log_error("Failed to setup root window event mask"); - free(e); + log_error_x_error(e, "Failed to setup root window event mask"); } xcb_prefetch_extension_data(ps->c, &xcb_render_id); @@ -1903,8 +1898,8 @@ static session_t *session_init(int argc, char **argv, Display *dpy, e = xcb_request_check( ps->c, xcb_sync_create_fence(ps->c, ps->root, ps->sync_fence, 0)); if (e) { - log_error("Failed to create a XSync fence. xrender-sync-fence " - "will be disabled"); + log_error_x_error(e, "Failed to create a XSync fence. " + "xrender-sync-fence will be disabled"); ps->o.xrender_sync_fence = false; ps->sync_fence = XCB_NONE; free(e); @@ -2118,7 +2113,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy, e = xcb_request_check(ps->c, xcb_ungrab_server(ps->c)); if (e) { - log_error("Failed to ungrab server"); + log_error_x_error(e, "Failed to ungrab server"); free(e); } diff --git a/src/x.c b/src/x.c index ce331e4..5af873b 100644 --- a/src/x.c +++ b/src/x.c @@ -205,8 +205,7 @@ x_create_picture_with_pictfmt_and_pixmap(xcb_connection_t *c, c, tmp_picture, pixmap, pictfmt->id, valuemask, buf)); free(buf); if (e) { - x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code); - log_error("failed to create picture"); + log_error_x_error(e, "failed to create picture"); return XCB_NONE; } return tmp_picture; @@ -265,7 +264,7 @@ bool x_fetch_region(xcb_connection_t *c, xcb_xfixes_region_t r, pixman_region32_ xcb_xfixes_fetch_region_reply_t *xr = xcb_xfixes_fetch_region_reply(c, xcb_xfixes_fetch_region(c, r), &e); if (!xr) { - log_error("Failed to fetch rectangles"); + log_error_x_error(e, "Failed to fetch rectangles"); return false; } @@ -301,9 +300,10 @@ void x_set_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict, xcb_generic_error_t *e = xcb_request_check( c, xcb_render_set_picture_clip_rectangles_checked( c, pict, clip_x_origin, clip_y_origin, to_u32_checked(nrects), xrects)); - if (e) - log_error("Failed to set clip region"); - free(e); + if (e) { + log_error_x_error(e, "Failed to set clip region"); + free(e); + } free(xrects); return; } @@ -312,9 +312,10 @@ void x_clear_picture_clip_region(xcb_connection_t *c, xcb_render_picture_t pict) xcb_render_change_picture_value_list_t v = {.clipmask = XCB_NONE}; xcb_generic_error_t *e = xcb_request_check( c, xcb_render_change_picture(c, pict, XCB_RENDER_CP_CLIP_MASK, &v)); - if (e) - log_error("failed to clear clip region"); - free(e); + if (e) { + log_error_x_error(e, "failed to clear clip region"); + free(e); + } return; } @@ -436,8 +437,7 @@ xcb_pixmap_t x_create_pixmap(xcb_connection_t *c, uint8_t depth, xcb_drawable_t if (err == NULL) return pix; - log_error("Failed to create pixmap:"); - x_print_error(err->sequence, err->major_code, err->minor_code, err->error_code); + log_error_x_error(err, "Failed to create pixmap"); free(err); return XCB_NONE; } @@ -508,25 +508,26 @@ bool x_fence_sync(xcb_connection_t *c, xcb_sync_fence_t f) { auto e = xcb_request_check(c, xcb_sync_trigger_fence_checked(c, f)); if (e) { - log_error("Failed to trigger the fence."); - free(e); - return false; + log_error_x_error(e, "Failed to trigger the fence"); + goto err; } e = xcb_request_check(c, xcb_sync_await_fence_checked(c, 1, &f)); if (e) { - log_error("Failed to await on a fence."); - free(e); - return false; + log_error_x_error(e, "Failed to await on a fence"); + goto err; } e = xcb_request_check(c, xcb_sync_reset_fence_checked(c, f)); if (e) { - log_error("Failed to reset the fence."); - free(e); - return false; + log_error_x_error(e, "Failed to reset the fence"); + goto err; } return true; + +err: + free(e); + return false; } // xcb-render specific macros diff --git a/src/x.h b/src/x.h index 9ee33cd..e408428 100644 --- a/src/x.h +++ b/src/x.h @@ -73,6 +73,11 @@ struct xvisual_info { __r; \ }) +#define log_error_x_error(e, fmt, ...) \ + LOG(ERROR, fmt " (%s)", ##__VA_ARGS__, x_strerror(e)) +#define log_fatal_x_error(e, fmt, ...) \ + LOG(FATAL, fmt " (%s)", ##__VA_ARGS__, x_strerror(e)) + /// 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);