From 83d5ba42f8a98fc0df177efef4333f74a0481f61 Mon Sep 17 00:00:00 2001 From: pants Date: Mon, 21 Sep 2026 14:18:06 -0700 Subject: init --- src/canvas/x11/x11.hpp | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 src/canvas/x11/x11.hpp (limited to 'src/canvas/x11/x11.hpp') diff --git a/src/canvas/x11/x11.hpp b/src/canvas/x11/x11.hpp new file mode 100644 index 0000000..09d99a3 --- /dev/null +++ b/src/canvas/x11/x11.hpp @@ -0,0 +1,93 @@ +// Display images inside a terminal +// Copyright (C) 2023 JustKidding +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef X11_CANVAS_H +#define X11_CANVAS_H + +#include "canvas.hpp" +#include "image.hpp" +#include "window.hpp" +#include "dimensions.hpp" +#include "util/x11.hpp" + +#include +#include +#include +#include +#include + +#include +#include + +#ifdef ENABLE_XCB_ERRORS +# include +#endif + +#ifdef ENABLE_OPENGL +# include "util/egl.hpp" +#endif + +class Flags; + +class X11Canvas : public Canvas +{ +public: + explicit X11Canvas(); + ~X11Canvas() override; + + void add_image(const std::string& identifier, std::unique_ptr new_image) override; + void remove_image(const std::string& identifier) override; + void hide() override; + void show() override; + +private: + xcb_connection_t *connection; + xcb_screen_t *screen; + +#ifdef ENABLE_XCB_ERRORS + xcb_errors_context_t *err_ctx; +#endif + + std::unique_ptr xutil; + + // map for event handler + std::unordered_map> windows; + + // windows per image + std::unordered_map>> image_windows; + + std::unordered_map> images; + std::unordered_map draw_threads; + + std::thread event_handler; + std::mutex windows_mutex; + + std::shared_ptr logger; + std::shared_ptr flags; + +#ifdef ENABLE_OPENGL + std::unique_ptr> egl; + bool egl_available = true; +#endif + + void draw(const std::string& identifier); + void handle_events(); + void get_tmux_window_ids(std::unordered_set& windows); + void print_xcb_error(const xcb_generic_error_t* err); +}; + +#endif -- cgit v1.2.3