diff --git a/bar.c b/bar.c index b68ca70..8012d35 100644 --- a/bar.c +++ b/bar.c @@ -324,8 +324,13 @@ run(struct bar *_bar) /* TODO: a lot of this (up to mapping the window) could be done in bar_new() */ xcb_generic_error_t *e; - bar->conn = xcb_connect(NULL, NULL); - assert(bar->conn != NULL); + int default_screen; + bar->conn = xcb_connect(NULL, &default_screen); + if (xcb_connection_has_error(bar->conn) > 0) { + LOG_ERR("failed to connect to X"); + xcb_disconnect(bar->conn); + return 1; + } const xcb_setup_t *setup = xcb_get_setup(bar->conn); diff --git a/main.c b/main.c index f80a30a..5fc1a55 100644 --- a/main.c +++ b/main.c @@ -119,6 +119,15 @@ main(int argc, const char *const *argv) return 1; } + /* Connect to XCB, to be able to detect a disconnect (allowing us + * to exit) */ + xcb_connection_t *xcb = xcb_connect(NULL, NULL); + if (xcb_connection_has_error(xcb) > 0) { + LOG_ERR("failed to connect to X"); + xcb_disconnect(xcb); + return 1; + } + xcb_init(); bar->abort_fd = abort_fd; @@ -129,11 +138,6 @@ main(int argc, const char *const *argv) /* Now unblock. We should be only thread receiving SIGINT */ pthread_sigmask(SIG_UNBLOCK, &signal_mask, NULL); - /* Connect to XCB, to be able to detect a disconnect (allowing us - * to exit) */ - xcb_connection_t *xcb = xcb_connect(NULL, NULL); - assert(xcb != NULL); - /* Wait for SIGINT, or XCB disconnect */ while (!aborted) { struct pollfd fds[] = { diff --git a/modules/i3.c b/modules/i3.c index acf6a98..d02da17 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -376,7 +376,13 @@ run(struct module *mod) struct sockaddr_un addr = {.sun_family = AF_UNIX}; { - xcb_connection_t *conn = xcb_connect(NULL, NULL); + int default_screen; + xcb_connection_t *conn = xcb_connect(NULL, &default_screen); + if (xcb_connection_has_error(conn) > 0) { + LOG_ERR("failed to connect to X"); + xcb_disconnect(conn); + return 1; + } const xcb_setup_t *setup = xcb_get_setup(conn); xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data; diff --git a/modules/xwindow.c b/modules/xwindow.c index 3114056..ec9a1a4 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -196,9 +196,11 @@ run(struct module *mod) { struct private *m = mod->private; - m->conn = xcb_connect(NULL, NULL); - if (m->conn == NULL) { + int default_screen; + m->conn = xcb_connect(NULL, &default_screen); + if (xcb_connection_has_error(m->conn) > 0) { LOG_ERR("failed to connect to X"); + xcb_disconnect(m->conn); return 1; } diff --git a/xcb.c b/xcb.c index 3f2539f..a157c1a 100644 --- a/xcb.c +++ b/xcb.c @@ -48,8 +48,9 @@ bool xcb_init(void) { xcb_connection_t *conn = xcb_connect(NULL, NULL); - if (conn == NULL) { + if (xcb_connection_has_error(conn) > 0) { LOG_ERR("failed to connect to X"); + xcb_disconnect(conn); return false; }