Skip to content

Commit

Permalink
hide xcb-errors behind compile flag
Browse files Browse the repository at this point in the history
some distros don't package this, also, bump version
  • Loading branch information
jstkdng committed Jun 23, 2023
1 parent 76a6d71 commit 61b445c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type.")

project(ueberzugpp LANGUAGES CXX C VERSION 2.8.7)
project(ueberzugpp LANGUAGES CXX C VERSION 2.8.8)
add_executable(ueberzug)

option(ENABLE_X11 "Enable X11 canvas." ON)
option(ENABLE_XCB_ERRORS "Enable useful logging of XCB errors." OFF)
option(ENABLE_WAYLAND "Enable wayland canvas" OFF)
option(ENABLE_OPENCV "Enable OpenCV image processing." ON)
option(ENABLE_TURBOBASE64 "Enable Turbo-Base64 for base64 encoding." OFF)
option(ENABLE_OPENGL "Enable window rendering with OpenGL." OFF)
option(ENABLE_OPENGL "Enable canvas rendering with OpenGL." OFF)

include(FetchContent)
include(GNUInstallDirs)
Expand Down Expand Up @@ -107,18 +108,22 @@ if(ENABLE_X11)
pkg_check_modules(XCB REQUIRED IMPORTED_TARGET xcb)
pkg_check_modules(XCBIMAGE REQUIRED IMPORTED_TARGET xcb-image)
pkg_check_modules(XCBRES REQUIRED IMPORTED_TARGET xcb-res)
pkg_check_modules(XCBERRORS REQUIRED IMPORTED_TARGET xcb-errors)
list(APPEND UEBERZUG_SOURCES
"src/util/x11.cpp"
"src/canvas/x11/x11.cpp"
"src/canvas/x11/window.cpp"
)
list(APPEND UEBERZUG_LIBRARIES
PkgConfig::XCB
PkgConfig::XCBERRORS
PkgConfig::XCBIMAGE
PkgConfig::XCBRES
)

if(ENABLE_XCB_ERRORS)
target_compile_definitions(ueberzug PRIVATE ENABLE_XCB_ERRORS)
pkg_check_modules(XCBERRORS REQUIRED IMPORTED_TARGET xcb-errors)
list(APPEND UEBERZUG_LIBRARIES PkgConfig::XCBERRORS)
endif()
endif()

if(ENABLE_WAYLAND)
Expand Down
1 change: 1 addition & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Build-Depends:
libsixel-dev,
libssl-dev,
libxcb-image0-dev,
libxcb-res0-dev,
wayland-protocols,
libwayland-dev,
extra-cmake-modules
Expand Down
14 changes: 13 additions & 1 deletion src/canvas/x11/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ connection(xcb_connect(nullptr, nullptr))
if (xcb_connection_has_error(connection) > 0) {
throw std::runtime_error("Can't connect to X11 server");
}
xcb_errors_context_new(connection, &err_ctx);
screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;

#ifdef ENABLE_XCB_ERRORS
xcb_errors_context_new(connection, &err_ctx);
#endif

#ifdef ENABLE_OPENGL
egl_display = eglGetPlatformDisplay(EGL_PLATFORM_XCB_EXT, connection, nullptr);
eglInitialize(egl_display, nullptr, nullptr);
Expand All @@ -57,10 +60,15 @@ X11Canvas::~X11Canvas()
if (draw_thread.joinable()) {
draw_thread.join();
}

#ifdef ENABLE_OPENGL
eglTerminate(egl_display);
#endif

#ifdef ENABLE_XCB_ERRORS
xcb_errors_context_free(err_ctx);
#endif

xcb_disconnect(connection);
}

Expand Down Expand Up @@ -179,6 +187,7 @@ void X11Canvas::get_tmux_window_ids(std::unordered_set<xcb_window_t>& windows)

void X11Canvas::print_xcb_error(const xcb_generic_error_t* err)
{
#ifdef ENABLE_XCB_ERRORS
const char *extension = nullptr;
const char *major = xcb_errors_get_name_for_major_code(err_ctx, err->major_code);
const char *minor = xcb_errors_get_name_for_minor_code(err_ctx, err->major_code, err->minor_code);
Expand All @@ -187,6 +196,9 @@ void X11Canvas::print_xcb_error(const xcb_generic_error_t* err)
error, extension != nullptr ? extension : "no_extension",
major, minor != nullptr ? minor : "no_minor",
err->resource_id, err->sequence);
#else
logger->error("XCB: resource {} sequence {}", err->resource_id, err->sequence);
#endif
}

void X11Canvas::clear()
Expand Down
13 changes: 11 additions & 2 deletions src/canvas/x11/x11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@
#include <atomic>
#include <mutex>

#include <xcb/xcb_errors.h>
#include <xcb/xcb.h>
#include <spdlog/spdlog.h>

#ifdef ENABLE_XCB_ERRORS
# include <xcb/xcb_errors.h>
#endif

#ifdef ENABLE_OPENGL
# include <EGL/egl.h>
#endif
Expand All @@ -51,8 +55,12 @@ class X11Canvas : public Canvas

private:
xcb_connection_t *connection;
xcb_errors_context_t *err_ctx;
xcb_screen_t *screen;

#ifdef ENABLE_XCB_ERRORS
xcb_errors_context_t *err_ctx;
#endif

std::unique_ptr<X11Util> xutil;

std::unordered_map<xcb_window_t, std::unique_ptr<X11Window>> windows;
Expand All @@ -68,6 +76,7 @@ class X11Canvas : public Canvas
#ifdef ENABLE_OPENGL
EGLDisplay egl_display;
#endif

void handle_events();
void get_tmux_window_ids(std::unordered_set<xcb_window_t>& windows);
void print_xcb_error(const xcb_generic_error_t* err);
Expand Down

0 comments on commit 61b445c

Please sign in to comment.