From 7a8ba94a49986d88e16c81433364a13072c04c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Tue, 15 Jan 2019 19:26:02 +0100 Subject: [PATCH] bar: xcb-errors is optional With it available, we get better (more descriptive) X error messages. But it's not fatal, and we don't require it. --- CMakeLists.txt | 10 +++++++++- bar.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ede29a..87aab6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,8 @@ set(CMAKE_C_FLAGS "-Wall -Werror ${CMAKE_C_FLAGS}") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) -pkg_check_modules(XCB REQUIRED xcb xcb-errors xcb-randr xcb-render xcb-cursor) +pkg_check_modules(XCB REQUIRED xcb 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) pkg_check_modules(YAML REQUIRED yaml-0.1) @@ -47,8 +48,13 @@ add_executable(f00bar # Make global symbols in f00bar visible to dlopen:ed plugins set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic") +if (XCB_ERRORS_FOUND) + target_compile_definitions(f00bar PRIVATE HAVE_XCB_ERRORS) +endif () + target_compile_options(f00bar PRIVATE ${XCB_CFLAGS_OTHER} + ${XCB_ERRORS_CFLAGS_OTHER} ${FONTCONFIG_CFLAGS_OTHER} ${CAIRO_CFLAGS_OTHER} ${YAML_CFLAGS_OTHER} @@ -56,6 +62,7 @@ target_compile_options(f00bar PRIVATE target_include_directories(f00bar PRIVATE ${XCB_INCLUDE_DIRS} + ${XCB_ERRORS_INCLUDE_DIRS} ${FONTCONFIG_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS} ${YAML_INCLUDE_DIRS} @@ -66,6 +73,7 @@ target_link_libraries(f00bar ${CMAKE_DL_LIBS} ${XCB_LIBRARIES} + ${XCB_ERRORS_LIBRARIES} ${FONTCONFIG_LIBRARIES} ${CAIRO_LIBRARIES} ${YAML_LIBRARIES} diff --git a/bar.c b/bar.c index c2c5921..71deef6 100644 --- a/bar.c +++ b/bar.c @@ -18,7 +18,10 @@ #include #include #include -#include + +#if defined(HAVE_XCB_ERRORS) + #include +#endif #include #include @@ -555,8 +558,10 @@ run(struct bar_run_context *run_ctx) LOG_DBG("all modules started"); +#if defined(HAVE_XCB_ERRORS) xcb_errors_context_t *err_context; xcb_errors_context_new(bar->conn, &err_context); +#endif int fd = xcb_get_file_descriptor(bar->conn); @@ -583,6 +588,7 @@ run(struct bar_run_context *run_ctx) { switch (XCB_EVENT_RESPONSE_TYPE(e)) { case 0: { +#if defined(HAVE_XCB_ERRORS) const xcb_value_error_t *error = (void *)e; const char *major = xcb_errors_get_name_for_major_code( err_context, error->major_opcode); @@ -597,6 +603,9 @@ run(struct bar_run_context *run_ctx) major, minor != NULL ? minor : "no minor", name, extension != NULL ? extension : "no extension", error->sequence, error->bad_value); +#else + LOG_ERR(" XCB error: TODO"); +#endif break; } @@ -705,7 +714,10 @@ run(struct bar_run_context *run_ctx) bar->cursor_name = NULL; } +#if defined(HAVE_XCB_ERRORS) xcb_errors_context_free(err_context); +#endif + xcb_free_gc(bar->conn, bar->gc); xcb_free_pixmap(bar->conn, bar->pixmap); xcb_destroy_window(bar->conn, bar->win);