From b52a317e4efeb9ad92bb0f459df0ce99d5f059fc Mon Sep 17 00:00:00 2001 From: JustKidding Date: Sun, 25 Feb 2024 12:23:37 -0500 Subject: [PATCH] don't use forward declares and naming changes --- .clang-tidy | 2 +- CMakeLists.txt | 2 +- include/application.hpp | 9 ++++---- include/version.hpp.in | 1 + src/application.cpp | 30 +++++++++++++------------- src/canvas/chafa.cpp | 5 ----- src/canvas/chafa.hpp | 3 --- src/canvas/stdout.hpp | 3 ++- src/canvas/wayland/config/hyprland.cpp | 1 - src/canvas/wayland/config/hyprland.hpp | 2 +- src/canvas/wayland/config/sway.cpp | 3 +-- src/canvas/wayland/config/sway.hpp | 2 +- src/canvas/wayland/config/wayfire.cpp | 2 -- src/canvas/wayland/config/wayfire.hpp | 2 +- src/canvas/wayland/wayland.cpp | 6 ++---- src/canvas/wayland/wayland.hpp | 2 +- src/canvas/x11/window/x11.cpp | 1 - src/canvas/x11/window/x11.hpp | 2 +- src/canvas/x11/window/x11egl.cpp | 1 - src/canvas/x11/window/x11egl.hpp | 2 +- src/canvas/x11/x11.cpp | 5 ++--- src/canvas/x11/x11.hpp | 2 +- src/image/libvips.cpp | 1 - src/image/libvips.hpp | 2 +- src/image/opencv.cpp | 1 - src/image/opencv.hpp | 2 +- src/main.cpp | 8 +++---- 27 files changed, 42 insertions(+), 60 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 1f7f46e..600a59f 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -17,7 +17,7 @@ CheckOptions: - key: readability-identifier-naming.ClassMemberCase value: lower_case - key: readability-identifier-naming.ClassMemberSuffix - value: '_' + value: '' - key: readability-identifier-naming.VariableCase value: lower_case - key: readability-identifier-naming.FunctionCase diff --git a/CMakeLists.txt b/CMakeLists.txt index ae7c00f..79ac034 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ endif() cmake_policy(SET CMP0075 NEW) cmake_policy(SET CMP0077 NEW) -set(UEBERZUGPP_VERSION 2.9.3) +set(UEBERZUGPP_VERSION 2.9.3.1) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) diff --git a/include/application.hpp b/include/application.hpp index 721826c..c45a00b 100644 --- a/include/application.hpp +++ b/include/application.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include class Application { @@ -40,13 +40,11 @@ class Application void command_loop(); void handle_tmux_hook(std::string_view hook); - // NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - static std::atomic stop_flag_; + static std::atomic stop_flag; // NOLINT static void print_version(); static void print_header(); - static void daemonize(std::string_view pid_file); - static const pid_t parent_pid_; + static const pid_t parent_pid; private: std::unique_ptr terminal; @@ -61,6 +59,7 @@ class Application void setup_logger(); void set_silent(); void socket_loop(); + void daemonize(); }; #endif diff --git a/include/version.hpp.in b/include/version.hpp.in index aa79608..deef4ff 100644 --- a/include/version.hpp.in +++ b/include/version.hpp.in @@ -17,3 +17,4 @@ #define ueberzugpp_VERSION_MAJOR @ueberzugpp_VERSION_MAJOR@ #define ueberzugpp_VERSION_MINOR @ueberzugpp_VERSION_MINOR@ #define ueberzugpp_VERSION_PATCH @ueberzugpp_VERSION_PATCH@ +#define ueberzugpp_VERSION_TWEAK @ueberzugpp_VERSION_TWEAK@ diff --git a/src/application.cpp b/src/application.cpp index b6affd0..721b7f7 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -30,14 +30,13 @@ #include #include #include -#include #include using njson = nlohmann::json; namespace fs = std::filesystem; -std::atomic Application::stop_flag_{false}; // NOLINT -const pid_t Application::parent_pid_ = os::get_ppid(); +std::atomic Application::stop_flag{false}; // NOLINT +const pid_t Application::parent_pid = os::get_ppid(); Application::Application(const char *executable) { @@ -47,7 +46,7 @@ Application::Application(const char *executable) set_silent(); terminal = std::make_unique(); if (flags->no_stdin) { - daemonize(flags->pid_file); + daemonize(); } canvas = Canvas::create(); const auto cache_path = util::get_cache_path(); @@ -201,7 +200,7 @@ void Application::command_loop() while (true) { try { const auto in_event = os::wait_for_data_on_stdin(100); - if (stop_flag_.load()) { + if (stop_flag.load()) { break; } if (!in_event) { @@ -210,7 +209,7 @@ void Application::command_loop() const auto cmd = os::read_data_from_stdin(); execute(cmd); } catch (const std::system_error &err) { - stop_flag_.store(true); + stop_flag.store(true); break; } } @@ -226,20 +225,20 @@ void Application::socket_loop() int conn = -1; try { conn = socket.wait_for_connections(waitms); - if (stop_flag_.load()) { + if (stop_flag.load()) { break; } if (conn == -1) { continue; } } catch (const std::system_error &err) { - stop_flag_.store(true); + stop_flag.store(true); break; } const auto data = socket.read_data_from_connection(conn); for (const auto &cmd : data) { if (cmd == "EXIT") { - stop_flag_.store(true); + stop_flag.store(true); return; } execute(cmd); @@ -259,8 +258,9 @@ void Application::print_header() | |_| | __/ |_) | __/ | / /| |_| | (_| | |_| |_| \___/ \___|_.__/ \___|_| /___|\__,_|\__, | __/ | - |___/ v{}.{}.{})", - ueberzugpp_VERSION_MAJOR, ueberzugpp_VERSION_MINOR, ueberzugpp_VERSION_PATCH); + |___/ v{}.{}.{}.{})", + ueberzugpp_VERSION_MAJOR, ueberzugpp_VERSION_MINOR, ueberzugpp_VERSION_PATCH, + ueberzugpp_VERSION_TWEAK); std::ofstream ofs(log_path, std::ios::out | std::ios::app); ofs << art << std::endl; } @@ -275,14 +275,14 @@ void Application::set_silent() void Application::print_version() { - const auto ver_str = fmt::format("ueberzugpp {}.{}.{}", ueberzugpp_VERSION_MAJOR, ueberzugpp_VERSION_MINOR, - ueberzugpp_VERSION_PATCH); + const auto ver_str = fmt::format("ueberzugpp {}.{}.{}.{}", ueberzugpp_VERSION_MAJOR, ueberzugpp_VERSION_MINOR, + ueberzugpp_VERSION_PATCH, ueberzugpp_VERSION_TWEAK); std::cout << ver_str << std::endl; } -void Application::daemonize(const std::string_view pid_file) +void Application::daemonize() { os::daemonize(); - std::ofstream ofs(pid_file.data()); + std::ofstream ofs(flags->pid_file); ofs << os::get_pid() << std::flush; } diff --git a/src/canvas/chafa.cpp b/src/canvas/chafa.cpp index f418f71..feb064f 100644 --- a/src/canvas/chafa.cpp +++ b/src/canvas/chafa.cpp @@ -40,11 +40,6 @@ Chafa::Chafa(std::unique_ptr new_image, std::shared_ptr stdou { const auto envp = c_unique_ptr{g_get_environ()}; term_info = chafa_term_db_detect(chafa_term_db_get_default(), envp.get()); - logger = spdlog::get("chafa"); - logger->info("Canvas created"); - logger->warn("This canvas is meant to be used as a last resort. Please" - " use the X11 output or switch to a terminal that has kitty," - " sixel or iterm2 support."); const auto dims = image->dimensions(); x = dims.x + 1; diff --git a/src/canvas/chafa.hpp b/src/canvas/chafa.hpp index e29e30b..8743dd7 100644 --- a/src/canvas/chafa.hpp +++ b/src/canvas/chafa.hpp @@ -21,10 +21,8 @@ #include "window.hpp" #include -#include #include -#include class Chafa : public Window { @@ -43,7 +41,6 @@ class Chafa : public Window std::unique_ptr image; std::shared_ptr stdout_mutex; - std::shared_ptr logger; int x; int y; diff --git a/src/canvas/stdout.hpp b/src/canvas/stdout.hpp index f4387c0..b701a30 100644 --- a/src/canvas/stdout.hpp +++ b/src/canvas/stdout.hpp @@ -36,6 +36,7 @@ class StdoutCanvas : public Canvas { stdout_mutex = std::make_shared(); logger = spdlog::get(output); + logger->info("Canvas created"); } ~StdoutCanvas() override = default; @@ -45,7 +46,7 @@ class StdoutCanvas : public Canvas logger->info("Displaying image with id {}", identifier); images.erase(identifier); const auto [entry, success] = - images.insert({identifier, std::make_unique(std::move(new_image), stdout_mutex)}); + images.emplace(identifier, std::make_unique(std::move(new_image), stdout_mutex)); entry->second->draw(); } diff --git a/src/canvas/wayland/config/hyprland.cpp b/src/canvas/wayland/config/hyprland.cpp index 5dd0e69..24549c9 100644 --- a/src/canvas/wayland/config/hyprland.cpp +++ b/src/canvas/wayland/config/hyprland.cpp @@ -24,7 +24,6 @@ #include #include #include -#include using njson = nlohmann::json; diff --git a/src/canvas/wayland/config/hyprland.hpp b/src/canvas/wayland/config/hyprland.hpp index ca4e730..4353d98 100644 --- a/src/canvas/wayland/config/hyprland.hpp +++ b/src/canvas/wayland/config/hyprland.hpp @@ -20,7 +20,7 @@ #include "../config.hpp" #include -#include +#include class HyprlandSocket : public WaylandConfig { diff --git a/src/canvas/wayland/config/sway.cpp b/src/canvas/wayland/config/sway.cpp index da6f47e..85bff0c 100644 --- a/src/canvas/wayland/config/sway.cpp +++ b/src/canvas/wayland/config/sway.cpp @@ -27,7 +27,6 @@ #include #include -#include using njson = nlohmann::json; @@ -60,7 +59,7 @@ auto SwaySocket::get_window_info() -> struct WaylandWindowGeometry { auto SwaySocket::get_active_window(const std::vector& nodes) -> nlohmann::json { - const auto pids = tmux::get_client_pids().value_or(std::vector{Application::parent_pid_}); + const auto pids = tmux::get_client_pids().value_or(std::vector{Application::parent_pid}); for (const auto pid : pids) { const auto tree = util::get_process_tree(pid); diff --git a/src/canvas/wayland/config/sway.hpp b/src/canvas/wayland/config/sway.hpp index 12ca3cf..9ac4d69 100644 --- a/src/canvas/wayland/config/sway.hpp +++ b/src/canvas/wayland/config/sway.hpp @@ -21,7 +21,7 @@ #include "util/socket.hpp" #include -#include +#include enum ipc_message_type { IPC_COMMAND = 0, IPC_GET_WORKSPACES = 1, IPC_GET_OUTPUTS = 3, IPC_GET_TREE = 4 }; diff --git a/src/canvas/wayland/config/wayfire.cpp b/src/canvas/wayland/config/wayfire.cpp index c6d2dd0..efde546 100644 --- a/src/canvas/wayland/config/wayfire.cpp +++ b/src/canvas/wayland/config/wayfire.cpp @@ -16,8 +16,6 @@ #include "wayfire.hpp" -#include - using njson = nlohmann::json; WayfireSocket::WayfireSocket(const std::string_view endpoint): diff --git a/src/canvas/wayland/config/wayfire.hpp b/src/canvas/wayland/config/wayfire.hpp index c2a418c..e1e83eb 100644 --- a/src/canvas/wayland/config/wayfire.hpp +++ b/src/canvas/wayland/config/wayfire.hpp @@ -21,7 +21,7 @@ #include "util/socket.hpp" #include -#include +#include class WayfireSocket : public WaylandConfig { diff --git a/src/canvas/wayland/wayland.cpp b/src/canvas/wayland/wayland.cpp index 32409fe..4f1457d 100644 --- a/src/canvas/wayland/wayland.cpp +++ b/src/canvas/wayland/wayland.cpp @@ -20,8 +20,6 @@ #include "os.hpp" #include "util.hpp" -#include - #ifdef ENABLE_OPENGL # include "window/waylandegl.hpp" # include @@ -202,7 +200,7 @@ void WaylandCanvas::handle_events() try { const auto in_event = os::wait_for_data_on_fd(wl_fd, waitms); - if (Application::stop_flag_.load()) { + if (Application::stop_flag.load()) { break; } if (in_event) { @@ -212,7 +210,7 @@ void WaylandCanvas::handle_events() wl_display_cancel_read(display); } } catch (const std::system_error &err) { - Application::stop_flag_.store(true); + Application::stop_flag.store(true); break; } } diff --git a/src/canvas/wayland/wayland.hpp b/src/canvas/wayland/wayland.hpp index 3b5bd25..2a6fbd7 100644 --- a/src/canvas/wayland/wayland.hpp +++ b/src/canvas/wayland/wayland.hpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #ifdef ENABLE_OPENGL diff --git a/src/canvas/x11/window/x11.cpp b/src/canvas/x11/window/x11.cpp index bb55808..c32c715 100644 --- a/src/canvas/x11/window/x11.cpp +++ b/src/canvas/x11/window/x11.cpp @@ -19,7 +19,6 @@ #include -#include #include constexpr std::string_view win_name = "ueberzugpp"; diff --git a/src/canvas/x11/window/x11.hpp b/src/canvas/x11/window/x11.hpp index 1e544df..5230b1d 100644 --- a/src/canvas/x11/window/x11.hpp +++ b/src/canvas/x11/window/x11.hpp @@ -22,7 +22,7 @@ #include "window.hpp" #include -#include +#include class Dimensions; diff --git a/src/canvas/x11/window/x11egl.cpp b/src/canvas/x11/window/x11egl.cpp index 268b86c..c494957 100644 --- a/src/canvas/x11/window/x11egl.cpp +++ b/src/canvas/x11/window/x11egl.cpp @@ -20,7 +20,6 @@ #include "util.hpp" #include -#include X11EGLWindow::X11EGLWindow(xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t windowid, xcb_window_t parentid, const EGLUtil *egl, diff --git a/src/canvas/x11/window/x11egl.hpp b/src/canvas/x11/window/x11egl.hpp index a66dd9d..09fdf82 100644 --- a/src/canvas/x11/window/x11egl.hpp +++ b/src/canvas/x11/window/x11egl.hpp @@ -21,7 +21,7 @@ #include "util/egl.hpp" #include -#include +#include #include #include diff --git a/src/canvas/x11/x11.cpp b/src/canvas/x11/x11.cpp index c88f43d..e64862a 100644 --- a/src/canvas/x11/x11.cpp +++ b/src/canvas/x11/x11.cpp @@ -24,7 +24,6 @@ #include #include -#include #ifdef ENABLE_OPENGL # include "window/x11egl.hpp" @@ -128,14 +127,14 @@ void X11Canvas::handle_events() while (true) { try { const bool status = os::wait_for_data_on_fd(connfd, waitms); - if (Application::stop_flag_.load()) { + if (Application::stop_flag.load()) { break; } if (!status) { continue; } } catch (const std::system_error &err) { - Application::stop_flag_.store(true); + Application::stop_flag.store(true); break; } diff --git a/src/canvas/x11/x11.hpp b/src/canvas/x11/x11.hpp index 996dfde..09d99a3 100644 --- a/src/canvas/x11/x11.hpp +++ b/src/canvas/x11/x11.hpp @@ -30,7 +30,7 @@ #include #include -#include +#include #ifdef ENABLE_XCB_ERRORS # include diff --git a/src/image/libvips.cpp b/src/image/libvips.cpp index eb97ea2..08323d3 100644 --- a/src/image/libvips.cpp +++ b/src/image/libvips.cpp @@ -26,7 +26,6 @@ #ifdef ENABLE_OPENCV # include #endif -#include using vips::VError; using vips::VImage; diff --git a/src/image/libvips.hpp b/src/image/libvips.hpp index 0c0e8e0..76cc731 100644 --- a/src/image/libvips.hpp +++ b/src/image/libvips.hpp @@ -21,7 +21,7 @@ #include "util/ptr.hpp" #include -#include +#include #include #include diff --git a/src/image/opencv.cpp b/src/image/opencv.cpp index b577f18..a91c8a6 100644 --- a/src/image/opencv.cpp +++ b/src/image/opencv.cpp @@ -26,7 +26,6 @@ #include #include #include -#include OpencvImage::OpencvImage(std::shared_ptr new_dims, const std::string &filename, bool in_cache) : path(filename), diff --git a/src/image/opencv.hpp b/src/image/opencv.hpp index 2d6d59d..6214abc 100644 --- a/src/image/opencv.hpp +++ b/src/image/opencv.hpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include namespace fs = std::filesystem; diff --git a/src/main.cpp b/src/main.cpp index 8b0f8ed..ba50288 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,7 @@ void signal_handler(const int signal) { - auto &flag = Application::stop_flag_; + auto &flag = Application::stop_flag; flag.store(true); const auto logger = spdlog::get("main"); @@ -38,13 +38,13 @@ void signal_handler(const int signal) } switch (signal) { case SIGINT: - logger->error("SIGINT received, exiting."); + logger->error("SIGINT received, exiting..."); break; case SIGTERM: - logger->error("SIGTERM received, exiting."); + logger->error("SIGTERM received, exiting..."); break; default: - logger->error("UNKNOWN({}) signal received, exiting.", signal); + logger->error("UNKNOWN({}) signal received, exiting...", signal); break; } }