From 4b334594dc0d8989d8bb09c7db76694aacc71951 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 10 Jul 2022 15:41:26 +0200 Subject: [PATCH] Added splashes --- hyprctl/main.cpp | 2 ++ src/Compositor.cpp | 14 +++++++++ src/Compositor.hpp | 2 ++ src/config/ConfigManager.cpp | 4 ++- src/debug/HyprCtl.cpp | 6 ++++ src/helpers/Splashes.hpp | 56 ++++++++++++++++++++++++++++++++++++ src/render/OpenGL.cpp | 24 +++++++++++++++- src/render/OpenGL.hpp | 4 +++ 8 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 src/helpers/Splashes.hpp diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index a1a1122d..b0aa1be8 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -27,6 +27,7 @@ const std::string USAGE = R"#(usage: hyprctl [command] [(opt)args] keyword version kill + splash hyprpaper reload)#"; @@ -201,6 +202,7 @@ int main(int argc, char** argv) { else if (!strcmp(argv[1], "layers")) request("layers"); else if (!strcmp(argv[1], "version")) request("version"); else if (!strcmp(argv[1], "kill")) request("kill"); + else if (!strcmp(argv[1], "splash")) request("splash"); else if (!strcmp(argv[1], "devices")) request("devices"); else if (!strcmp(argv[1], "reload")) request("reload"); else if (!strcmp(argv[1], "dispatch")) dispatchRequest(argc, argv); diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 906946c8..d4899280 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1,4 +1,6 @@ #include "Compositor.hpp" +#include "helpers/Splashes.hpp" +#include CCompositor::CCompositor() { m_szInstanceSignature = GIT_COMMIT_HASH + std::string("_") + std::to_string(time(NULL)); @@ -22,6 +24,10 @@ CCompositor::CCompositor() { Debug::log(INFO, "If you are crashing, or encounter any bugs, please consult https://github.com/hyprwm/Hyprland/wiki/Crashing-and-bugs\n\n"); + setRandomSplash(); + + Debug::log(LOG, "\nCurrent splash: %s\n\n", m_szCurrentSplash.c_str()); + m_sWLDisplay = wl_display_create(); m_sWLRBackend = wlr_backend_autocreate(m_sWLDisplay); @@ -136,6 +142,14 @@ void handleCritSignal(int signo) { exit(signo); } +void CCompositor::setRandomSplash() { + std::random_device dev; + std::mt19937 engine(dev()); + std::uniform_int_distribution<> distribution(0, SPLASHES.size() - 1); + + m_szCurrentSplash = SPLASHES[distribution(engine)]; +} + void CCompositor::initAllSignals() { addWLSignal(&m_sWLRBackend->events.new_output, &Events::listen_newOutput, m_sWLRBackend, "Backend"); addWLSignal(&m_sWLRXDGShell->events.new_surface, &Events::listen_newXDGSurface, m_sWLRXDGShell, "XDG Shell"); diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 5415eff8..caff38de 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -68,6 +68,7 @@ public: const char* m_szWLDisplaySocket; std::string m_szInstanceSignature = ""; + std::string m_szCurrentSplash = "error"; std::vector> m_vMonitors; std::vector> m_vWindows; @@ -144,6 +145,7 @@ public: private: void initAllSignals(); + void setRandomSplash(); }; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 91a73ca1..19db65fd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -36,7 +36,9 @@ void CConfigManager::setDefaultVars() { configValues["general:col.active_border"].intValue = 0xffffffff; configValues["general:col.inactive_border"].intValue = 0xff444444; configValues["general:cursor_inactive_timeout"].intValue = 0; - configValues["general:disable_hyprland_logo"].intValue = 0; + + configValues["misc:disable_hyprland_logo"].intValue = 0; + configValues["misc:disable_splash_rendering"].intValue = 0; configValues["debug:int"].intValue = 0; configValues["debug:log_damage"].intValue = 0; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 84909a8e..7aa0017e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -181,6 +181,10 @@ std::string killRequest() { return "ok"; } +std::string splashRequest() { + return g_pCompositor->m_szCurrentSplash; +} + std::string getReply(std::string); std::string dispatchBatch(std::string request) { @@ -234,6 +238,8 @@ std::string getReply(std::string request) { return reloadRequest(); else if (request == "devices") return devicesRequest(); + else if (request == "splash") + return splashRequest(); else if (request.find("dispatch") == 0) return dispatchRequest(request); else if (request.find("keyword") == 0) diff --git a/src/helpers/Splashes.hpp b/src/helpers/Splashes.hpp new file mode 100644 index 00000000..68681ca2 --- /dev/null +++ b/src/helpers/Splashes.hpp @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +inline const std::vector SPLASHES = { + "Woo, animations!", + "It's like Hypr, but better.", + "Release 1.0 when?", + "It's not awesome, it's Hyprland!", + "\"I commit too often, people can't catch up lmao\" - Vaxry", + "This text is random.", + "\"There are reasons to not use rust.\" - Boga", + "Read the wiki.", + "\"Hello everyone this is YOUR daily dose of ‘read the wiki’\" - Vaxry", + "h", + "\"‘why no work’, bro I haven't hacked your pc to get live feeds yet\" - Vaxry", + "Compile, wait for 20 minutes, notice a new commit, compile again.", + "To rice, or not to rice, that is the question.", + "Now available on Fedora!", + // music reference / quote section + "J'remue le ciel, le jour, la nuit.", + "aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi, aezakmi!", + "Wir sind schon sehr lang zusammen...", + "I see a red door and I want it painted black.", + "Take on me, take me on...", + "You spin me right round baby right round", + "Stayin' alive, stayin' alive", + "Say no way, say no way ya, no way!", + "Ground control to Major Tom...", + "Alors on danse", + "And all that I can see, is just a yellow lemon tree.", + "Got a one-way ticket to the blues", + "Is this the real life, is this just fantasy", + "What's in your head, in your head?", + "We're all living in America, America, America.", + "I'm still standing, better than I ever did", + "Here comes the sun, bringing you love and shining on everyone", + "Two trailer park girls go round the outside", + "With the lights out, it's less dangerous", + "Here we go back, this is the moment, tonight is the night", + "Now you're just somebody that I used to know...", + "Black bird, black moon, black sky", + "Some legends are told, some turn to dust or to gold", + "Your brain gets smart, but your head gets dumb.", + "Save your mercy for someone who needs it more", + "You're gonna hear my voice when I shout it out loud", + "Ding ding pch n daa, bam-ba-ba-re-bam baram bom bom baba-bam-bam-bommm", + "Súbeme la radio que esta es mi canción", + "I'm beggin', beggin' you", + // + "Join the discord server!", + "Thanks ThatOneCalculator!", + "The AUR packages always work, except for the times they don't.", + "Funny animation compositor woo" +}; \ No newline at end of file diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 0fe7a30a..bfe3a9ed 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -915,9 +915,28 @@ void CHyprOpenGLImpl::renderRoundedShadow(wlr_box* box, int round, int range, fl glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); } +void CHyprOpenGLImpl::renderSplash(cairo_t *const CAIRO, cairo_surface_t *const CAIROSURFACE) { + cairo_select_font_face(CAIRO, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + + const auto FONTSIZE = (int)(m_RenderData.pMonitor->vecPixelSize.y / 76); + cairo_set_font_size(CAIRO, FONTSIZE); + + cairo_set_source_rgba(CAIRO, 1.f, 1.f, 1.f, 0.32f); + + cairo_text_extents_t textExtents; + cairo_text_extents(CAIRO, g_pCompositor->m_szCurrentSplash.c_str(), &textExtents); + + cairo_move_to(CAIRO, m_RenderData.pMonitor->vecPixelSize.x / 2.f - textExtents.width / 2.f, m_RenderData.pMonitor->vecPixelSize.y - textExtents.height - 1); + cairo_show_text(CAIRO, g_pCompositor->m_szCurrentSplash.c_str()); + + cairo_surface_flush(CAIROSURFACE); +} + void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) { RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!"); + static auto *const PNOSPLASH = &g_pConfigManager->getConfigValuePtr("misc:disable_splash_rendering")->intValue; + // release the last tex if exists const auto PTEX = &m_mMonitorBGTextures[pMonitor]; PTEX->destroyTexture(); @@ -952,6 +971,9 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) { const auto CAIRO = cairo_create(CAIROSURFACE); + if (!*PNOSPLASH) + renderSplash(CAIRO, CAIROSURFACE); + // copy the data to an OpenGL texture we have const auto DATA = cairo_image_surface_get_data(CAIROSURFACE); glBindTexture(GL_TEXTURE_2D, PTEX->m_iTexID); @@ -972,7 +994,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(SMonitor* pMonitor) { void CHyprOpenGLImpl::clearWithTex() { RASSERT(m_RenderData.pMonitor, "Tried to render BGtex without begin()!"); - static auto *const PRENDERTEX = &g_pConfigManager->getConfigValuePtr("general:disable_hyprland_logo")->intValue; + static auto *const PRENDERTEX = &g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo")->intValue; if (!*PRENDERTEX) { wlr_box box = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 4a6f0598..84cfcd39 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -6,6 +6,8 @@ #include #include +#include + #include "Shaders.hpp" #include "Shader.hpp" #include "Texture.hpp" @@ -121,6 +123,8 @@ private: CFramebuffer* blurMainFramebufferWithDamage(float a, wlr_box* pBox, pixman_region32_t* damage); void renderTextureInternalWithDamage(const CTexture&, wlr_box* pBox, float a, pixman_region32_t* damage, int round = 0, bool discardOpaque = false, bool noAA = false, bool allowCustomUV = false); + + void renderSplash(cairo_t *const, cairo_surface_t *const); }; inline std::unique_ptr g_pHyprOpenGL; \ No newline at end of file