From 1013a80608891f120184aa7c1a7cfde04bfc96fb Mon Sep 17 00:00:00 2001 From: Stephen Toth Date: Sun, 4 Feb 2024 20:07:31 -0500 Subject: [PATCH] ipc: Added listloaded and listactive requests (#132) --- README.md | 7 +++++ src/ipc/Socket.cpp | 71 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d969987..8ee8234 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,13 @@ bind=SUPERSHIFT,1,movetoworkspace,1 #Superkey + Shift + 1 moves windows and swi bind=SUPERSHIFT,1,exec,$w1 #SuperKey + Shift + 1 switches to wallpaper $w1 on DP-1 as defined in the variable ``` +## Getting information from hyprpaper +You can also use `hyprctl hyprpaper` to get information about the state of hyprpaper using the following commands: +``` +listloaded - lists the wallpapers that are currently preloaded (useful for dynamically preloading and unloading) +listactive - prints the active wallpapers hyprpaper is displaying, along with its accociated monitor +``` + # Battery life Since the IPC has to tick every now and then, and poll in the background, battery life might be a tiny bit worse with IPC on. If you want to fully disable it, use ``` diff --git a/src/ipc/Socket.cpp b/src/ipc/Socket.cpp index eeb4238..de2de66 100644 --- a/src/ipc/Socket.cpp +++ b/src/ipc/Socket.cpp @@ -90,34 +90,77 @@ bool CIPCSocket::mainThreadParseRequest() { std::string copy = m_szRequest; - // now we can work on the copy - if (copy == "") return false; + + // now we can work on the copy Debug::log(LOG, "Received a request: %s", copy.c_str()); - // parse + // set default reply + m_szReply = "ok"; + m_bReplyReady = true; + m_bRequestReady = false; + + + // config commands if (copy.find("wallpaper") == 0 || copy.find("preload") == 0 || copy.find("unload") == 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()); if (RESULT.error) { m_szReply = RESULT.getError(); - m_bReplyReady = true; - m_bRequestReady = false; return false; } - } else { - m_szReply = "invalid command"; - m_bReplyReady = true; - m_bRequestReady = false; - return false; + + return true; + + } + + if (copy.find("listloaded") == 0) { + + const auto numWallpapersLoaded = g_pHyprpaper->m_mWallpaperTargets.size(); + Debug::log(LOG, "numWallpapersLoaded: %d", numWallpapersLoaded); + + if (numWallpapersLoaded == 0) { + m_szReply = "no wallpapers loaded"; + return false; + } + + m_szReply = ""; + long unsigned int i = 0; + for (auto& [name, target] : g_pHyprpaper->m_mWallpaperTargets) { + m_szReply += name; + i++; + if (i < numWallpapersLoaded) m_szReply += '\n'; // dont add newline on last entry + } + + return true; + } - m_szReply = "ok"; - m_bReplyReady = true; - m_bRequestReady = false; + if (copy.find("listactive") == 0) { + + const auto numWallpapersActive = g_pHyprpaper->m_mMonitorActiveWallpapers.size(); + Debug::log(LOG, "numWallpapersActive: %d", numWallpapersActive); + + if (numWallpapersActive == 0) { + m_szReply = "no wallpapers active"; + return false; + } + + m_szReply = ""; + long unsigned int i = 0; + for (auto& [mon, path1] : g_pHyprpaper->m_mMonitorActiveWallpapers) { + m_szReply += mon + " = " + path1; + i++; + if (i < numWallpapersActive) m_szReply += '\n'; // dont add newline on last entry + } + + return true; + + } - return true; + m_szReply = "invalid command"; + return false; }