From 2c57525de840e4edada2cfd2924659b80f513ece Mon Sep 17 00:00:00 2001 From: Barguzin <124505224+barrrguzin@users.noreply.github.com> Date: Sun, 26 May 2024 03:40:11 +1000 Subject: [PATCH] internal: Add handler "reload" to do a change of wallpaper by one hyprctl exec (#173) * Add handler "reload" to do a change of wallpaper by one hyprctl execution * fixed contain parameter handling in "handleReload" --- src/config/ConfigManager.cpp | 34 ++++++++++++++++++++++++++++++++++ src/ipc/Socket.cpp | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 2617de5..6990ca6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -124,6 +124,39 @@ static Hyprlang::CParseResult handleUnload(const char* C, const char* V) { return Hyprlang::CParseResult{}; } +static Hyprlang::CParseResult handleReload(const char* C, const char* V) { + const std::string COMMAND = C; + const std::string VALUE = V; + + auto WALLPAPER = g_pConfigManager->trimPath(VALUE.substr(VALUE.find_first_of(',') + 1)); + + if (WALLPAPER.find("contain:") == 0) { + WALLPAPER = WALLPAPER.substr(8); + } + + auto preloadResult = handlePreload(C, WALLPAPER.c_str()); + if (preloadResult.error) + return preloadResult; + + auto MONITOR = VALUE.substr(0, VALUE.find_first_of(',')); + + if (MONITOR.empty()) { + for (auto& m : g_pHyprpaper->m_vMonitors) { + auto OLD_WALLPAPER = g_pHyprpaper->m_mMonitorActiveWallpapers[m->name]; + g_pHyprpaper->unloadWallpaper(OLD_WALLPAPER); + } + } else { + auto OLD_WALLPAPER = g_pHyprpaper->m_mMonitorActiveWallpapers[MONITOR]; + g_pHyprpaper->unloadWallpaper(OLD_WALLPAPER); + } + + auto wallpaperResult = handleWallpaper(C, V); + if (wallpaperResult.error) + return wallpaperResult; + + return Hyprlang::CParseResult{}; +} + CConfigManager::CConfigManager() { // Initialize the configuration // Read file from default location @@ -142,6 +175,7 @@ CConfigManager::CConfigManager() { config->registerHandler(&handleUnload, "unload", {.allowFlags = false}); config->registerHandler(&handlePreload, "preload", {.allowFlags = false}); config->registerHandler(&handleUnloadAll, "unloadAll", {.allowFlags = false}); + config->registerHandler(&handleReload, "reload", {.allowFlags = false}); config->commence(); } diff --git a/src/ipc/Socket.cpp b/src/ipc/Socket.cpp index d868273..c857395 100644 --- a/src/ipc/Socket.cpp +++ b/src/ipc/Socket.cpp @@ -107,7 +107,7 @@ bool CIPCSocket::mainThreadParseRequest() { m_bRequestReady = false; // config commands - if (copy.find("wallpaper") == 0 || copy.find("preload") == 0 || copy.find("unload") == 0) { + if (copy.find("wallpaper") == 0 || copy.find("preload") == 0 || copy.find("unload") == 0 || copy.find("reload") == 0) { const auto RESULT = g_pConfigManager->config->parseDynamic(copy.substr(0, copy.find_first_of(' ')).c_str(), copy.substr(copy.find_first_of(' ') + 1).c_str());