diff --git a/CMakeLists.txt b/CMakeLists.txt index 87aab6b..fc39f00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -pkg_check_modules(XCB REQUIRED xcb xcb-randr xcb-render xcb-cursor) +pkg_check_modules(XCB REQUIRED xcb xcb-aux xcb-randr xcb-render xcb-cursor) pkg_check_modules(XCB_ERRORS xcb-errors) pkg_check_modules(FONTCONFIG REQUIRED fontconfig) pkg_check_modules(CAIRO REQUIRED cairo cairo-xcb cairo-ft) diff --git a/bar.c b/bar.c index 8012d35..c5a556c 100644 --- a/bar.c +++ b/bar.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -332,9 +333,7 @@ run(struct bar *_bar) return 1; } - const xcb_setup_t *setup = xcb_get_setup(bar->conn); - - xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data; + xcb_screen_t *screen = xcb_aux_get_screen(bar->conn, default_screen); xcb_randr_get_monitors_reply_t *monitors = xcb_randr_get_monitors_reply( bar->conn, @@ -371,43 +370,20 @@ run(struct bar *_bar) } free(monitors); - /* Find a 32-bit visual (TODO: fallback to 24-bit) */ - const uint8_t wanted_depth = 32; - const uint8_t wanted_class = 0; - uint8_t depth = 0; - xcb_visualtype_t *vis = NULL; + xcb_visualtype_t *vis = xcb_aux_find_visual_by_attrs(screen, -1, 32); - for (xcb_depth_iterator_t it = xcb_screen_allowed_depths_iterator(screen); - it.rem > 0; - xcb_depth_next(&it)) - { - const xcb_depth_t *_depth = it.data; - - if (!(wanted_depth == 0 || _depth->depth == wanted_depth)) - continue; - - for (xcb_visualtype_iterator_t vis_it = - xcb_depth_visuals_iterator(_depth); - vis_it.rem > 0; - xcb_visualtype_next(&vis_it)) - { - xcb_visualtype_t *_vis = vis_it.data; - if (!(wanted_class == 0 || _vis->_class == wanted_class)) - continue; - - vis = _vis; - break; - } - - if (vis != NULL) { - depth = _depth->depth; - break; - } + if (vis != NULL) + depth = 32; + else { + vis = xcb_aux_find_visual_by_attrs(screen, -1, 24); + if (vis != NULL) + depth = 24; } assert(depth == 32 || depth == 24); assert(vis != NULL); + LOG_DBG("using a %hhu-bit visual", depth); bar->colormap = xcb_generate_id(bar->conn); xcb_create_colormap(bar->conn, 0, bar->colormap, screen->root, vis->visual_id); diff --git a/modules/i3.c b/modules/i3.c index d02da17..033f73e 100644 --- a/modules/i3.c +++ b/modules/i3.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -384,8 +385,7 @@ run(struct module *mod) return 1; } - const xcb_setup_t *setup = xcb_get_setup(conn); - xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data; + xcb_screen_t *screen = xcb_aux_get_screen(conn, default_screen); xcb_atom_t atom = get_atom(conn, "I3_SOCKET_PATH"); assert(atom != XCB_ATOM_NONE); diff --git a/modules/xkb.c b/modules/xkb.c index 9df8cad..603b3cf 100644 --- a/modules/xkb.c +++ b/modules/xkb.c @@ -614,8 +614,9 @@ static int run(struct module *mod) { 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 server"); + xcb_disconnect(conn); return EXIT_FAILURE; } diff --git a/modules/xwindow.c b/modules/xwindow.c index ec9a1a4..0579f05 100644 --- a/modules/xwindow.c +++ b/modules/xwindow.c @@ -10,6 +10,7 @@ #include #include +#include #include #define LOG_MODULE "xwindow" @@ -204,8 +205,7 @@ run(struct module *mod) return 1; } - const xcb_setup_t *setup = xcb_get_setup(m->conn); - xcb_screen_t *screen = xcb_setup_roots_iterator(setup).data; + xcb_screen_t *screen = xcb_aux_get_screen(m->conn, default_screen); m->root_win = screen->root; /* Need a window(?) to be able to process events */