Skip to content

Commit

Permalink
don't use forward declares and naming changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstkdng committed Feb 25, 2024
1 parent 42367f0 commit b52a317
Show file tree
Hide file tree
Showing 27 changed files with 42 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions include/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <string_view>
#include <thread>

#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

class Application
{
Expand All @@ -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<bool> stop_flag_;
static std::atomic<bool> 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> terminal;
Expand All @@ -61,6 +59,7 @@ class Application
void setup_logger();
void set_silent();
void socket_loop();
void daemonize();
};

#endif
1 change: 1 addition & 0 deletions include/version.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
30 changes: 15 additions & 15 deletions src/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>
#include <vips/vips8>

using njson = nlohmann::json;
namespace fs = std::filesystem;

std::atomic<bool> Application::stop_flag_{false}; // NOLINT
const pid_t Application::parent_pid_ = os::get_ppid();
std::atomic<bool> Application::stop_flag{false}; // NOLINT
const pid_t Application::parent_pid = os::get_ppid();

Application::Application(const char *executable)
{
Expand All @@ -47,7 +46,7 @@ Application::Application(const char *executable)
set_silent();
terminal = std::make_unique<Terminal>();
if (flags->no_stdin) {
daemonize(flags->pid_file);
daemonize();
}
canvas = Canvas::create();
const auto cache_path = util::get_cache_path();
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}
5 changes: 0 additions & 5 deletions src/canvas/chafa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ Chafa::Chafa(std::unique_ptr<Image> new_image, std::shared_ptr<std::mutex> stdou
{
const auto envp = c_unique_ptr<gchar *, g_strfreev>{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;
Expand Down
3 changes: 0 additions & 3 deletions src/canvas/chafa.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
#include "window.hpp"

#include <memory>
#include <mutex>

#include <chafa.h>
#include <spdlog/fwd.h>

class Chafa : public Window
{
Expand All @@ -43,7 +41,6 @@ class Chafa : public Window

std::unique_ptr<Image> image;
std::shared_ptr<std::mutex> stdout_mutex;
std::shared_ptr<spdlog::logger> logger;

int x;
int y;
Expand Down
3 changes: 2 additions & 1 deletion src/canvas/stdout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class StdoutCanvas : public Canvas
{
stdout_mutex = std::make_shared<std::mutex>();
logger = spdlog::get(output);
logger->info("Canvas created");
}

~StdoutCanvas() override = default;
Expand All @@ -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<T>(std::move(new_image), stdout_mutex)});
images.emplace(identifier, std::make_unique<T>(std::move(new_image), stdout_mutex));
entry->second->draw();
}

Expand Down
1 change: 0 additions & 1 deletion src/canvas/wayland/config/hyprland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <fmt/format.h>
#include <nlohmann/json.hpp>
#include <range/v3/all.hpp>
#include <spdlog/spdlog.h>

using njson = nlohmann::json;

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/wayland/config/hyprland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "../config.hpp"

#include <nlohmann/json.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

class HyprlandSocket : public WaylandConfig
{
Expand Down
3 changes: 1 addition & 2 deletions src/canvas/wayland/config/sway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

#include <fmt/format.h>
#include <range/v3/all.hpp>
#include <spdlog/spdlog.h>

using njson = nlohmann::json;

Expand Down Expand Up @@ -60,7 +59,7 @@ auto SwaySocket::get_window_info() -> struct WaylandWindowGeometry {

auto SwaySocket::get_active_window(const std::vector<nlohmann::json>& nodes) -> nlohmann::json
{
const auto pids = tmux::get_client_pids().value_or(std::vector<int>{Application::parent_pid_});
const auto pids = tmux::get_client_pids().value_or(std::vector<int>{Application::parent_pid});

for (const auto pid : pids) {
const auto tree = util::get_process_tree(pid);
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/wayland/config/sway.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "util/socket.hpp"

#include <nlohmann/json.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

enum ipc_message_type { IPC_COMMAND = 0, IPC_GET_WORKSPACES = 1, IPC_GET_OUTPUTS = 3, IPC_GET_TREE = 4 };

Expand Down
2 changes: 0 additions & 2 deletions src/canvas/wayland/config/wayfire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

#include "wayfire.hpp"

#include <spdlog/spdlog.h>

using njson = nlohmann::json;

WayfireSocket::WayfireSocket(const std::string_view endpoint):
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/wayland/config/wayfire.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "util/socket.hpp"

#include <nlohmann/json.hpp>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

class WayfireSocket : public WaylandConfig
{
Expand Down
6 changes: 2 additions & 4 deletions src/canvas/wayland/wayland.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include "os.hpp"
#include "util.hpp"

#include <spdlog/spdlog.h>

#ifdef ENABLE_OPENGL
# include "window/waylandegl.hpp"
# include <EGL/eglext.h>
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/wayland/wayland.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <thread>
#include <unordered_map>

#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>
#include <wayland-client.h>

#ifdef ENABLE_OPENGL
Expand Down
1 change: 0 additions & 1 deletion src/canvas/x11/window/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <string_view>

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

constexpr std::string_view win_name = "ueberzugpp";
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/x11/window/x11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "window.hpp"

#include <xcb/xcb_image.h>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>

class Dimensions;

Expand Down
1 change: 0 additions & 1 deletion src/canvas/x11/window/x11egl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "util.hpp"

#include <array>
#include <spdlog/spdlog.h>

X11EGLWindow::X11EGLWindow(xcb_connection_t *connection, xcb_screen_t *screen, xcb_window_t windowid,
xcb_window_t parentid, const EGLUtil<xcb_connection_t, xcb_window_t> *egl,
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/x11/window/x11egl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "util/egl.hpp"

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

#include <memory>
#include <mutex>
Expand Down
5 changes: 2 additions & 3 deletions src/canvas/x11/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <string_view>

#include <range/v3/all.hpp>
#include <spdlog/spdlog.h>

#ifdef ENABLE_OPENGL
# include "window/x11egl.hpp"
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/canvas/x11/x11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <mutex>

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

#ifdef ENABLE_XCB_ERRORS
# include <xcb/xcb_errors.h>
Expand Down
1 change: 0 additions & 1 deletion src/image/libvips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#ifdef ENABLE_OPENCV
# include <opencv2/videoio.hpp>
#endif
#include <spdlog/spdlog.h>

using vips::VError;
using vips::VImage;
Expand Down
2 changes: 1 addition & 1 deletion src/image/libvips.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "util/ptr.hpp"

#include <filesystem>
#include <spdlog/fwd.h>
#include <spdlog/spdlog.h>
#include <string>
#include <vips/vips8>

Expand Down
1 change: 0 additions & 1 deletion src/image/opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <opencv2/core/ocl.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <spdlog/spdlog.h>

OpencvImage::OpencvImage(std::shared_ptr<Dimensions> new_dims, const std::string &filename, bool in_cache)
: path(filename),
Expand Down
Loading

0 comments on commit b52a317

Please sign in to comment.