From 237208d9728970a4c3a84958319742d8f7a9f32b Mon Sep 17 00:00:00 2001 From: Slendi Date: Fri, 17 Oct 2025 00:20:39 +0300 Subject: [PATCH] Add Waylight namespace Signed-off-by: Slendi --- src/App.cpp | 4 +++ src/App.hpp | 6 +++- src/Cache.cpp | 6 ++-- src/IconRegistry.cpp | 4 +++ src/IconRegistry.hpp | 4 +++ src/ImGui.cpp | 4 +++ src/ImGui.hpp | 4 +++ src/TextRenderer.cpp | 4 +++ src/TextRenderer.hpp | 4 +++ src/Theme.hpp | 4 +++ src/Tick.cpp | 4 +++ src/common.hpp | 4 +++ src/enum_array.hpp | 6 ++++ src/main.cpp | 70 +++++++++++++++++++++++--------------------- 14 files changed, 91 insertions(+), 37 deletions(-) diff --git a/src/App.cpp b/src/App.cpp index b5e0d79..8d7cb78 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -32,6 +32,8 @@ #include "blur-client-protocol.h" #include "ext-background-effect-v1-client-protocol.h" +namespace Waylight { + namespace { constexpr usize MAX_SURROUNDING_BYTES = 4000; @@ -1240,3 +1242,5 @@ auto App::clipboard(std::string_view const &str) -> void m_wayland.ddev, m_wayland.curr_source, m_last_serial); wl_display_flush(m_wayland.display); } + +} // namespace Waylight diff --git a/src/App.hpp b/src/App.hpp index 1868b5d..f256681 100644 --- a/src/App.hpp +++ b/src/App.hpp @@ -30,6 +30,8 @@ extern "C" { #include "Theme.hpp" #include "common.hpp" +namespace Waylight { + struct TypingBuffer : std::pmr::vector { void push_utf8(char const *s); }; @@ -219,7 +221,7 @@ private: enum_array m_themes { make_default_themes() }; Theme m_active_theme { Theme::Light }; IconRegistry m_ir; - std::optional m_cache; + std::optional m_cache; int m_win_w { 800 }; int m_win_h { 600 }; @@ -232,3 +234,5 @@ private: std::shared_ptr m_db {}; int m_sfd { -1 }; }; + +} // namespace Waylight diff --git a/src/Cache.cpp b/src/Cache.cpp index 2eb267d..012e35c 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp @@ -13,6 +13,8 @@ #include "common.hpp" #include +namespace Waylight { + void replace_all( std::string &str, std::string const &from, std::string const &to) { @@ -25,8 +27,6 @@ void replace_all( } } -namespace Waylight { - Cache::Cache(std::shared_ptr db) : m_db(db) { @@ -432,4 +432,4 @@ void Cache::load() } } -} // namespace Cache +} // namespace Waylight diff --git a/src/IconRegistry.cpp b/src/IconRegistry.cpp index 949c78f..8614a19 100644 --- a/src/IconRegistry.cpp +++ b/src/IconRegistry.cpp @@ -13,6 +13,8 @@ #include #include +namespace Waylight { + static inline auto color_to_string(Color const &c) -> std::string { auto const r { c.r / 255.0 }, g { c.g / 255.0 }, b { c.b / 255.0 }; @@ -443,3 +445,5 @@ auto IconRegistry::lookup_cached(std::string_view const name, throw std::runtime_error(std::format("Failed to find icon `{}`!", name)); } + +} // namespace Waylight diff --git a/src/IconRegistry.hpp b/src/IconRegistry.hpp index 36c9d27..2036b07 100644 --- a/src/IconRegistry.hpp +++ b/src/IconRegistry.hpp @@ -8,6 +8,8 @@ #include +namespace Waylight { + struct Icon { Icon(std::filesystem::path path, Texture2D texture, int size) : m_path(path) @@ -87,3 +89,5 @@ private: std::unordered_map m_cached_icons; std::optional m_preferred_theme; }; + +} // namespace Waylight diff --git a/src/ImGui.cpp b/src/ImGui.cpp index 263dea2..ca29c92 100644 --- a/src/ImGui.cpp +++ b/src/ImGui.cpp @@ -11,6 +11,8 @@ #include +namespace Waylight { + namespace { struct CodepointSpan { @@ -786,3 +788,5 @@ auto ImGui::list_view(usize id, Rectangle bounds, usize elements, return submitted; } + +} // namespace Waylight diff --git a/src/ImGui.hpp b/src/ImGui.hpp index cffa192..331d4db 100644 --- a/src/ImGui.hpp +++ b/src/ImGui.hpp @@ -12,6 +12,8 @@ #include "TextRenderer.hpp" +namespace Waylight { + constexpr float DEFAULT_FONT_SIZE { 24 }; struct TextInputOptions { @@ -158,3 +160,5 @@ struct ImGuiGuard { private: std::shared_ptr m_imgui { nullptr }; }; + +} // namespace Waylight diff --git a/src/TextRenderer.cpp b/src/TextRenderer.cpp index fbb1d2b..56f1565 100644 --- a/src/TextRenderer.cpp +++ b/src/TextRenderer.cpp @@ -37,6 +37,8 @@ #include #include +namespace Waylight { + namespace { constexpr int ATLAS_DIMENSION = 1024; @@ -839,3 +841,5 @@ auto find_font_path(std::string_view path) } return final_path; } + +} // namespace Waylight diff --git a/src/TextRenderer.hpp b/src/TextRenderer.hpp index 84bc2ea..adca0a3 100644 --- a/src/TextRenderer.hpp +++ b/src/TextRenderer.hpp @@ -21,6 +21,8 @@ namespace msdfgen { class FontHandle; } +namespace Waylight { + struct FontHandle { // cppcheck-supress noConstructor FontHandle() = default; @@ -145,3 +147,5 @@ private: auto find_font_path(std::string_view path = "sans-serif:style=Regular") -> std::optional; + +} // namespace Waylight diff --git a/src/Theme.hpp b/src/Theme.hpp index 4b87ac3..c6b97c1 100644 --- a/src/Theme.hpp +++ b/src/Theme.hpp @@ -4,6 +4,8 @@ #include "enum_array.hpp" +namespace Waylight { + struct ColorScheme { Color foreground; Color foreground_preedit; @@ -40,3 +42,5 @@ constexpr auto make_default_themes() -> enum_array const }; return array; } + +} // namespace Waylight diff --git a/src/Tick.cpp b/src/Tick.cpp index f01a95a..f92d24b 100644 --- a/src/Tick.cpp +++ b/src/Tick.cpp @@ -10,6 +10,8 @@ #include +namespace Waylight { + auto App::tick() -> void { static std::pmr::string text_input_data {}; @@ -76,3 +78,5 @@ auto App::tick() -> void eglSwapBuffers(m_gl.edpy, m_gl.esurf); } + +} // namespace Waylight diff --git a/src/common.hpp b/src/common.hpp index 9517676..19917d0 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -4,6 +4,8 @@ #include #include +namespace Waylight { + using u8 = std::uint8_t; using i8 = std::int8_t; using u16 = std::uint16_t; @@ -38,3 +40,5 @@ using isize = std::intptr_t; return utf8.data(); } + +} // namespace Waylight diff --git a/src/enum_array.hpp b/src/enum_array.hpp index 1fd53de..e8a40b2 100644 --- a/src/enum_array.hpp +++ b/src/enum_array.hpp @@ -5,6 +5,10 @@ #include #include +#include "common.hpp" + +namespace Waylight { + template struct enum_traits; template @@ -76,3 +80,5 @@ constexpr auto make_enum_array(T &&first_val, U &&...rest) arr._data = { std::forward(first_val), std::forward(rest)... }; return arr; } + +} // namespace Waylight diff --git a/src/main.cpp b/src/main.cpp index 07555f3..f952cae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,43 +17,12 @@ #include "App.hpp" +namespace Waylight { + bool signal_running(); std::optional g_app {}; -auto main() -> int -{ - if (signal_running()) { - return 0; - } - - std::signal(SIGINT, [](int) { - if (g_app) - g_app->stop(); - }); - - CPPTRACE_TRY - { - g_app.emplace(); - g_app->run(); - } - CPPTRACE_CATCH(std::exception const &e) - { - std::string what { e.what() }; - std::ranges::replace(what, '"', '.'); - std::ranges::replace(what, '\'', '.'); - std::ranges::replace(what, '`', '.'); - if (what.empty()) { - std::println(std::cerr, "Unexpected exception!"); - } else { - std::println(std::cerr, "Unexpected exception! Error: {}", what); - } - cpptrace::from_current_exception().print(); - tinyfd_messageBox( - "Unexpected exception", what.c_str(), "ok", "error", 1); - } -} - bool signal_running() { char const *lock_path = "/tmp/waylight.lock"; @@ -82,3 +51,38 @@ bool signal_running() dprintf(fd, "%d\n", getpid()); return false; } + +} // namespace Waylight + +auto main() -> int +{ + if (Waylight::signal_running()) { + return 0; + } + + std::signal(SIGINT, [](int) { + if (Waylight::g_app) + Waylight::g_app->stop(); + }); + + CPPTRACE_TRY + { + Waylight::g_app.emplace(); + Waylight::g_app->run(); + } + CPPTRACE_CATCH(std::exception const &e) + { + std::string what { e.what() }; + std::ranges::replace(what, '"', '.'); + std::ranges::replace(what, '\'', '.'); + std::ranges::replace(what, '`', '.'); + if (what.empty()) { + std::println(std::cerr, "Unexpected exception!"); + } else { + std::println(std::cerr, "Unexpected exception! Error: {}", what); + } + cpptrace::from_current_exception().print(); + tinyfd_messageBox( + "Unexpected exception", what.c_str(), "ok", "error", 1); + } +}