Skip to content

Commit

Permalink
internal: Add handler "reload" to do a change of wallpaper by one hyp…
Browse files Browse the repository at this point in the history
…rctl exec (#173)

* Add handler "reload" to do a change of wallpaper by one hyprctl execution

* fixed contain parameter handling in "handleReload"
  • Loading branch information
barrrguzin authored May 25, 2024
1 parent 678d0e8 commit 2c57525
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ipc/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit 2c57525

Please sign in to comment.