forked from external/yambar
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.
This commit is contained in:
parent
b0e384b2f3
commit
7a8ba94a49
2 changed files with 22 additions and 2 deletions
|
@ -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}
|
||||
|
|
14
bar.c
14
bar.c
|
@ -18,7 +18,10 @@
|
|||
#include <xcb/xcb_cursor.h>
|
||||
#include <xcb/xcb_event.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xcb_errors.h>
|
||||
|
||||
#if defined(HAVE_XCB_ERRORS)
|
||||
#include <xcb/xcb_errors.h>
|
||||
#endif
|
||||
|
||||
#include <cairo.h>
|
||||
#include <cairo-xcb.h>
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue