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"
This commit is contained in:
Barguzin 2024-05-26 03:40:11 +10:00 committed by GitHub
parent 678d0e8959
commit 2c57525de8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 35 additions and 1 deletions

View File

@ -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();
}

View File

@ -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());