diff --git a/src/Hyprpaper.cpp b/src/Hyprpaper.cpp index 33f36fe..840d307 100644 --- a/src/Hyprpaper.cpp +++ b/src/Hyprpaper.cpp @@ -473,6 +473,32 @@ void CHyprpaper::renderWallpaperForMonitor(SMonitor* pMonitor) { cairo_set_source_surface(PCAIRO, PWALLPAPERTARGET->m_pCairoSurface, origin.x, origin.y); cairo_paint(PCAIRO); + + if (g_pHyprpaper->m_bRenderSplash && getenv("HYPRLAND_INSTANCE_SIGNATURE")) { + auto SPLASH = execAndGet("hyprctl splash"); + SPLASH.pop_back(); + + Debug::log(LOG, "Rendering splash: %s", SPLASH.c_str()); + + cairo_select_font_face(PCAIRO, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + + const auto FONTSIZE = (int)(DIMENSIONS.y / 76.0 / scale); + cairo_set_font_size(PCAIRO, FONTSIZE); + + cairo_set_source_rgba(PCAIRO, 1.0, 1.0, 1.0, 0.32); + + cairo_text_extents_t textExtents; + cairo_text_extents(PCAIRO, SPLASH.c_str(), &textExtents); + + cairo_move_to(PCAIRO, ((DIMENSIONS.x - textExtents.width * scale) / 2.0) / scale, (DIMENSIONS.y * 0.99 - textExtents.height * scale) / scale); + + Debug::log(LOG, "Splash font size: %d, pos: %.2f, %.2f", FONTSIZE, (DIMENSIONS.x - textExtents.width) / 2.0 / scale, DIMENSIONS.y * 0.95 - textExtents.height / scale); + + cairo_show_text(PCAIRO, SPLASH.c_str()); + + cairo_surface_flush(PWALLPAPERTARGET->m_pCairoSurface); + } + cairo_restore(PCAIRO); if (pMonitor->pCurrentLayerSurface) { diff --git a/src/Hyprpaper.hpp b/src/Hyprpaper.hpp index cdc94bf..9d6287c 100644 --- a/src/Hyprpaper.hpp +++ b/src/Hyprpaper.hpp @@ -37,6 +37,7 @@ public: std::vector> m_vMonitors; bool m_bIPCEnabled = true; + bool m_bRenderSplash = false; std::string m_szExplicitConfigPath; bool m_bNoFractionalScale = false; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6279c32..c7faadb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -107,6 +107,8 @@ void CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& handleUnload(COMMAND, VALUE); else if (COMMAND == "ipc") g_pHyprpaper->m_bIPCEnabled = VALUE == "1" || VALUE == "yes" || VALUE == "on" || VALUE == "true"; + else if (COMMAND == "splash") + g_pHyprpaper->m_bRenderSplash = VALUE == "1" || VALUE == "yes" || VALUE == "on" || VALUE == "true"; else parseError = "unknown keyword " + COMMAND; } diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 40a9668..e35afcb 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -1,4 +1,7 @@ #include "MiscFunctions.hpp" +#include +#include "../debug/Log.hpp" +#include bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta) { return std::abs(a.x - b.x) < delta && std::abs(a.y - b.y) < delta; @@ -7,3 +10,17 @@ bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delt bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta) { return std::abs(a.x - b.x) < delta.x && std::abs(a.y - b.y) < delta.y; } + +std::string execAndGet(const char* cmd) { + std::array buffer; + std::string result; + const std::unique_ptr pipe(popen(cmd, "r"), pclose); + if (!pipe) { + Debug::log(ERR, "execAndGet: failed in pipe"); + return ""; + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { + result += buffer.data(); + } + return result; +} diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index 69d8695..9b76297 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -1,5 +1,7 @@ #pragma once +#include #include "Vector2D.hpp" bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const float& delta); -bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta); \ No newline at end of file +bool vectorDeltaLessThan(const Vector2D& a, const Vector2D& b, const Vector2D& delta); +std::string execAndGet(const char*); \ No newline at end of file