diff options
| author | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
|---|---|---|
| committer | pants <niklasjo2004@gmail.com> | 2026-09-21 14:18:06 -0700 |
| commit | 83d5ba42f8a98fc0df177efef4333f74a0481f61 (patch) | |
| tree | 6f1fcff64ec9adb2fc51a7cfcc451eb22a103fb3 /include | |
Diffstat (limited to 'include')
| -rw-r--r-- | include/application.hpp | 66 | ||||
| -rw-r--r-- | include/canvas.hpp | 38 | ||||
| -rw-r--r-- | include/dimensions.hpp | 51 | ||||
| -rw-r--r-- | include/flags.hpp | 68 | ||||
| -rw-r--r-- | include/image.hpp | 54 | ||||
| -rw-r--r-- | include/os.hpp | 41 | ||||
| -rw-r--r-- | include/process.hpp | 38 | ||||
| -rw-r--r-- | include/terminal.hpp | 89 | ||||
| -rw-r--r-- | include/tmux.hpp | 46 | ||||
| -rw-r--r-- | include/util.hpp | 67 | ||||
| -rw-r--r-- | include/util/dbus.hpp | 33 | ||||
| -rw-r--r-- | include/util/egl.hpp | 54 | ||||
| -rw-r--r-- | include/util/ptr.hpp | 53 | ||||
| -rw-r--r-- | include/util/socket.hpp | 46 | ||||
| -rw-r--r-- | include/util/x11.hpp | 49 | ||||
| -rw-r--r-- | include/version.hpp.in | 19 | ||||
| -rw-r--r-- | include/window.hpp | 36 |
17 files changed, 848 insertions, 0 deletions
diff --git a/include/application.hpp b/include/application.hpp new file mode 100644 index 0000000..24291ac --- /dev/null +++ b/include/application.hpp @@ -0,0 +1,66 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef APPLICATION_H +#define APPLICATION_H + +#include "canvas.hpp" +#include "flags.hpp" +#include "os.hpp" +#include "terminal.hpp" +#include "util/ptr.hpp" + +#include <atomic> +#include <cstdlib> +#include <string> +#include <string_view> +#include <thread> + +#include <spdlog/spdlog.h> + +class Application +{ + public: + explicit Application(const char *executable); + ~Application(); + + void execute(std::string_view cmd); + void command_loop(); + void handle_tmux_hook(std::string_view hook); + + inline static std::atomic<bool> stop_flag = false; // NOLINT + inline static const int parent_pid = os::get_ppid(); + + static void print_version(); + static void print_header(); + + private: + std::unique_ptr<Terminal> terminal; + std::unique_ptr<Canvas> canvas; + + std::shared_ptr<Flags> flags; + std::shared_ptr<spdlog::logger> logger; + + cn_unique_ptr<std::FILE, std::fclose> f_stderr; + std::thread socket_thread; + + void setup_logger(); + void set_silent(); + void socket_loop(); + void daemonize(); +}; + +#endif diff --git a/include/canvas.hpp b/include/canvas.hpp new file mode 100644 index 0000000..8e0c15e --- /dev/null +++ b/include/canvas.hpp @@ -0,0 +1,38 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef CANVAS_H +#define CANVAS_H + +#include "image.hpp" + +#include <memory> + +class Canvas +{ + public: + static auto create() -> std::unique_ptr<Canvas>; + virtual ~Canvas() = default; + + virtual void add_image(const std::string &identifier, std::unique_ptr<Image> new_image) = 0; + virtual void remove_image(const std::string &identifier) = 0; + + virtual void show() {} + virtual void hide() {} + virtual void toggle() {} +}; + +#endif diff --git a/include/dimensions.hpp b/include/dimensions.hpp new file mode 100644 index 0000000..a69ee27 --- /dev/null +++ b/include/dimensions.hpp @@ -0,0 +1,51 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef DIMENSIONS_H +#define DIMENSIONS_H + +#include <cstdint> +#include <string> + +#include "terminal.hpp" + +class Dimensions +{ + public: + Dimensions(const Terminal *terminal, uint16_t xcoord, uint16_t ycoord, int max_w, int max_h, std::string scaler); + + [[nodiscard]] auto xpixels() const -> int; + [[nodiscard]] auto ypixels() const -> int; + [[nodiscard]] auto max_wpixels() const -> int; + [[nodiscard]] auto max_hpixels() const -> int; + + uint16_t x; + uint16_t y; + uint16_t max_w; + uint16_t max_h; + uint16_t padding_horizontal; + uint16_t padding_vertical; + std::string scaler; + const Terminal *terminal; + + private: + uint16_t orig_x; + uint16_t orig_y; + + void read_offsets(); +}; + +#endif diff --git a/include/flags.hpp b/include/flags.hpp new file mode 100644 index 0000000..bf2c0cb --- /dev/null +++ b/include/flags.hpp @@ -0,0 +1,68 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef FLAGS_H +#define FLAGS_H + +#include <filesystem> +#include <memory> +#include <string> + +// singleton +class Flags +{ + public: + static auto instance() -> std::shared_ptr<Flags> + { + static std::shared_ptr<Flags> instance{new Flags}; + return instance; + } + + Flags(const Flags &) = delete; + Flags(Flags &) = delete; + auto operator=(const Flags &) -> Flags & = delete; + auto operator=(Flags &) -> Flags & = delete; + + bool no_stdin = false; + bool silent = false; + bool use_escape_codes = false; + bool print_version = false; + bool no_cache = false; + bool no_opencv = false; + bool use_opengl = false; + std::string output; + std::string pid_file; + bool origin_center = false; + int32_t scale_factor = 1; + bool needs_scaling = false; + + std::string cmd_id; + std::string cmd_action; + std::string cmd_socket; + std::string cmd_x; + std::string cmd_y; + std::string cmd_max_width; + std::string cmd_max_height; + std::string cmd_file_path; + + private: + Flags(); + std::filesystem::path config_file; + + void read_config_file(); +}; + +#endif diff --git a/include/image.hpp b/include/image.hpp new file mode 100644 index 0000000..3124b58 --- /dev/null +++ b/include/image.hpp @@ -0,0 +1,54 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef IMAGE_H +#define IMAGE_H + +#include <filesystem> +#include <memory> +#include <nlohmann/json.hpp> +#include <string> + +#include "dimensions.hpp" +#include "terminal.hpp" + +class Image +{ + public: + static auto load(const nlohmann::json &command, const Terminal *terminal) -> std::unique_ptr<Image>; + static auto check_cache(const Dimensions &dimensions, const std::filesystem::path &orig_path) -> std::string; + static auto get_dimensions(const nlohmann::json &json, const Terminal *terminal) -> std::shared_ptr<Dimensions>; + + virtual ~Image() = default; + + [[nodiscard]] virtual auto dimensions() const -> const Dimensions & = 0; + [[nodiscard]] virtual auto width() const -> int = 0; + [[nodiscard]] virtual auto height() const -> int = 0; + [[nodiscard]] virtual auto size() const -> size_t = 0; + [[nodiscard]] virtual auto data() const -> const unsigned char * = 0; + [[nodiscard]] virtual auto channels() const -> int = 0; + + [[nodiscard]] virtual auto frame_delay() const -> int { return -1; } + [[nodiscard]] virtual auto is_animated() const -> bool { return false; } + [[nodiscard]] virtual auto filename() const -> std::string = 0; + virtual auto next_frame() -> void {} + + protected: + [[nodiscard]] auto get_new_sizes(double max_width, double max_height, std::string_view scaler, + int scale_factor = 0) const -> std::pair<int, int>; +}; + +#endif diff --git a/include/os.hpp b/include/os.hpp new file mode 100644 index 0000000..2268d94 --- /dev/null +++ b/include/os.hpp @@ -0,0 +1,41 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef NAMESPACE_OS_H +#define NAMESPACE_OS_H + +#include <optional> +#include <string> + +namespace os +{ + +auto exec(const std::string &cmd) -> std::string; +auto getenv(const std::string &var) -> std::optional<std::string>; +auto read_data_from_fd(int filde, char sep = '\n') -> std::string; +auto read_data_from_stdin(char sep = '\n') -> std::string; +auto wait_for_data_on_fd(int filde, int waitms) -> bool; +auto wait_for_data_on_stdin(int waitms) -> bool; + +auto get_pid() -> int; +auto get_ppid() -> int; + +void get_process_info(int pid); +void daemonize(); + +} // namespace os + +#endif diff --git a/include/process.hpp b/include/process.hpp new file mode 100644 index 0000000..3817f1e --- /dev/null +++ b/include/process.hpp @@ -0,0 +1,38 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef PROCESS_INFO_H +#define PROCESS_INFO_H + +#include <string> + +class Process +{ + public: + explicit Process(int pid); + ~Process() = default; + + int pid; + char state; + int ppid; + int process_group_id; + int session_id; + int tty_nr; + int minor_dev; + std::string pty_path; +}; + +#endif diff --git a/include/terminal.hpp b/include/terminal.hpp new file mode 100644 index 0000000..8aec512 --- /dev/null +++ b/include/terminal.hpp @@ -0,0 +1,89 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef TERMINAL_H +#define TERMINAL_H + +#include <memory> +#include <string> +#include <string_view> + +#include <spdlog/fwd.h> +#include <termios.h> + +#include "flags.hpp" +#include "os.hpp" + +class Terminal +{ + public: + Terminal(); + ~Terminal(); + + uint16_t font_width; + uint16_t font_height; + uint16_t padding_horizontal; + uint16_t padding_vertical; + uint16_t rows; + uint16_t cols; + int pid = os::get_pid(); + int terminal_pid; + unsigned int x11_wid; + std::string term; + std::string term_program; + std::string detected_output; + + private: + auto get_terminal_size() -> void; + static auto guess_padding(uint16_t chars, double pixels) -> double; + static auto guess_font_size(uint16_t chars, float pixels, float padding) -> float; + static auto read_raw_str(std::string_view esc) -> std::string; + + void init_termios(); + void reset_termios() const; + + void check_sixel_support(); + void check_kitty_support(); + void check_iterm2_support(); + + void get_terminal_size_escape_code(); + void get_terminal_size_xtsm(); + void get_fallback_x11_terminal_sizes(); + void get_fallback_wayland_terminal_sizes(); + + void open_first_pty(); + void set_detected_output(); + + int pty_fd; + int xpixel = 0; + int ypixel = 0; + uint16_t fallback_xpixel = 0; + uint16_t fallback_ypixel = 0; + + bool supports_sixel = false; + bool supports_kitty = false; + bool supports_x11 = false; + bool supports_iterm2 = false; + bool supports_wayland = false; + + std::shared_ptr<Flags> flags; + std::shared_ptr<spdlog::logger> logger; + + struct termios old_term; + struct termios new_term; +}; + +#endif diff --git a/include/tmux.hpp b/include/tmux.hpp new file mode 100644 index 0000000..5652660 --- /dev/null +++ b/include/tmux.hpp @@ -0,0 +1,46 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef NAMESPACE_TMUX_H +#define NAMESPACE_TMUX_H + +#include <string> +#include <vector> +#include <optional> +#include <string_view> + +namespace tmux +{ + auto get_session_id() -> std::string; + auto get_pane() -> std::string; + + auto is_used() -> bool; + auto is_window_focused() -> bool; + + auto get_client_pids() -> std::optional<std::vector<int>>; + + auto get_offset() -> std::pair<int, int>; + + auto get_pane_offset() -> std::pair<int, int>; + + auto get_statusbar_offset() -> int; + + void handle_hook(std::string_view hook, int pid); + void register_hooks(); + void unregister_hooks(); +} // namespace tmux + +#endif diff --git a/include/util.hpp b/include/util.hpp new file mode 100644 index 0000000..9a0d3a7 --- /dev/null +++ b/include/util.hpp @@ -0,0 +1,67 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef NAMESPACE_UTIL_H +#define NAMESPACE_UTIL_H + +#include <filesystem> +#include <functional> +#include <limits> +#include <optional> +#include <random> +#include <string> +#include <string_view> +#include <vector> + +#include "flags.hpp" +#include "os.hpp" +#include "process.hpp" + +namespace util +{ +auto str_split(std::string_view str, std::string_view delim) -> std::vector<std::string>; +auto get_process_tree(int pid) -> std::vector<int>; +auto get_process_tree_v2(int pid) -> std::vector<Process>; +auto get_b2_hash_ssl(std::string_view str) -> std::string; +auto get_cache_path() -> std::string; +auto get_cache_file_save_location(const std::filesystem::path &path) -> std::string; +auto get_log_filename() -> std::string; +auto get_socket_path(int pid = os::get_pid()) -> std::string; +void send_socket_message(std::string_view msg, std::string_view endpoint); +auto base64_encode(const unsigned char *input, size_t length) -> std::string; +void base64_encode_v2(const unsigned char *input, size_t length, unsigned char *out); +void move_cursor(int row, int col); +void save_cursor_position(); +void restore_cursor_position(); +void benchmark(const std::function<void(void)> &func); +void send_command(const Flags &flags); +void clear_terminal_area(int xcoord, int ycoord, int width, int height); +auto generate_random_string(std::size_t length) -> std::string; +auto round_up(int num_to_round, int multiple) -> int; +auto temp_directory_path() -> std::filesystem::path; + +auto read_exif_rotation(const std::filesystem::path &path) -> std::optional<std::uint16_t>; +template <typename T> +auto generate_random_number(T min, T max = std::numeric_limits<T>::max()) -> T +{ + std::random_device dev; + std::mt19937 rng(dev()); + std::uniform_int_distribution<T> dist(min, max); + return dist(rng); +} +} // namespace util + +#endif diff --git a/include/util/dbus.hpp b/include/util/dbus.hpp new file mode 100644 index 0000000..ae10773 --- /dev/null +++ b/include/util/dbus.hpp @@ -0,0 +1,33 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef UEBERZUGPP_DBUS_HPP +#define UEBERZUGPP_DBUS_HPP + +#include <dbus/dbus.h> +#include <string> + +class DbusUtil +{ + public: + explicit DbusUtil(const std::string &address); + ~DbusUtil(); + + private: + DBusConnection *connection = nullptr; +}; + +#endif // UEBERZUGPP_DBUS_HPP diff --git a/include/util/egl.hpp b/include/util/egl.hpp new file mode 100644 index 0000000..05a1373 --- /dev/null +++ b/include/util/egl.hpp @@ -0,0 +1,54 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef UTIL_EGL_H +#define UTIL_EGL_H + +#include "image.hpp" + +#include <functional> +#include <memory> + +#include <spdlog/fwd.h> + +#include <EGL/egl.h> +#define GL_GLEXT_PROTOTYPES +#include <GL/gl.h> + +template <class T, class V> +class EGLUtil +{ + public: + EGLUtil(EGLenum platform, T *native_display, const EGLAttrib *attrib = nullptr); + ~EGLUtil(); + + void get_texture_from_image(const Image &image, GLuint texture) const; + void run_contained(EGLSurface surface, EGLContext context, const std::function<void()> &func) const; + void make_current(EGLSurface surface, EGLContext context) const; + void restore() const; + [[nodiscard]] auto create_surface(V *native_window) const -> EGLSurface; + [[nodiscard]] auto create_context(EGLSurface surface) const -> EGLContext; + + EGLDisplay display; + + private: + EGLConfig config; + std::shared_ptr<spdlog::logger> logger; + + [[nodiscard]] auto error_to_string() const -> std::string; +}; + +#endif diff --git a/include/util/ptr.hpp b/include/util/ptr.hpp new file mode 100644 index 0000000..0e8be3f --- /dev/null +++ b/include/util/ptr.hpp @@ -0,0 +1,53 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef UTIL_PTR_H +#define UTIL_PTR_H + +#include <memory> + +template <auto fn> +struct deleter_from_fn { + template <typename T> + constexpr void operator()(T *arg) const + { + fn(const_cast<std::remove_const_t<T> *>(arg)); + } +}; + +template <auto fn> +struct deleter_from_fn_null { + template <typename T> + constexpr void operator()(T *arg) const + { + if (arg != nullptr) { + fn(const_cast<std::remove_const_t<T> *>(arg)); + } + } +}; + +// custom unique pointer +template <typename T, auto fn> +using c_unique_ptr = std::unique_ptr<T, deleter_from_fn<fn>>; + +// custom unique pointer that checks for null before deleting +template <typename T, auto fn> +using cn_unique_ptr = std::unique_ptr<T, deleter_from_fn_null<fn>>; + +template <typename T> +using unique_C_ptr = std::unique_ptr<T, deleter_from_fn<std::free>>; + +#endif diff --git a/include/util/socket.hpp b/include/util/socket.hpp new file mode 100644 index 0000000..14859ae --- /dev/null +++ b/include/util/socket.hpp @@ -0,0 +1,46 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef UTIL_SOCKET_H +#define UTIL_SOCKET_H + +#include <cstdint> +#include <string> +#include <string_view> +#include <vector> + +class UnixSocket +{ + public: + UnixSocket(); + explicit UnixSocket(std::string_view endpoint); + ~UnixSocket(); + + void connect_to_endpoint(std::string_view endpoint); + void bind_to_endpoint(std::string_view endpoint) const; + [[nodiscard]] auto wait_for_connections(int waitms) const -> int; + [[nodiscard]] auto read_data_from_connection(int filde) -> std::vector<std::string>; + void write(const void *data, std::size_t len) const; + void read(void *data, std::size_t len) const; + [[nodiscard]] auto read_until_empty() const -> std::string; + + private: + int fd; + bool connected = true; + std::string buffer; +}; + +#endif diff --git a/include/util/x11.hpp b/include/util/x11.hpp new file mode 100644 index 0000000..ee3542b --- /dev/null +++ b/include/util/x11.hpp @@ -0,0 +1,49 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef X11_UTIL_H +#define X11_UTIL_H + +#include <initializer_list> +#include <memory> +#include <unordered_map> +#include <vector> + +#include <xcb/xcb.h> + +class X11Util +{ + public: + X11Util(); + explicit X11Util(xcb_connection_t *connection); + ~X11Util(); + + [[nodiscard]] auto get_server_window_ids() const -> std::vector<xcb_window_t>; + [[nodiscard]] auto get_pid_window_map() const -> std::unordered_map<uint32_t, xcb_window_t>; + [[nodiscard]] auto get_window_dimensions(xcb_window_t window) const -> std::pair<uint16_t, uint16_t>; + [[nodiscard]] auto get_parent_window(int pid) const -> xcb_window_t; + [[nodiscard]] auto window_has_properties(xcb_window_t window, std::initializer_list<xcb_atom_t> properties) const + -> bool; + + bool connected = false; + + private: + xcb_connection_t *connection; + xcb_screen_t *screen = nullptr; + bool owns_connection = true; +}; + +#endif diff --git a/include/version.hpp.in b/include/version.hpp.in new file mode 100644 index 0000000..aa79608 --- /dev/null +++ b/include/version.hpp.in @@ -0,0 +1,19 @@ +// 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 <https://www.gnu.org/licenses/>. + +#define ueberzugpp_VERSION_MAJOR @ueberzugpp_VERSION_MAJOR@ +#define ueberzugpp_VERSION_MINOR @ueberzugpp_VERSION_MINOR@ +#define ueberzugpp_VERSION_PATCH @ueberzugpp_VERSION_PATCH@ diff --git a/include/window.hpp b/include/window.hpp new file mode 100644 index 0000000..44e3eac --- /dev/null +++ b/include/window.hpp @@ -0,0 +1,36 @@ +// 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 <https://www.gnu.org/licenses/>. + +#ifndef WINDOW_H +#define WINDOW_H + +#include <concepts> +#include <memory> + +class Window +{ +public: + virtual ~Window() = default; + virtual void draw() = 0; + virtual void generate_frame() = 0; + virtual void show() {}; + virtual void hide() {}; +}; + +template<class T> +concept WindowType = std::is_base_of<Window, T>::value; + +#endif |
