diff --git a/include/modules/hyprland/backend.hpp b/include/modules/hyprland/backend.hpp index b327482c..11e73d8f 100644 --- a/include/modules/hyprland/backend.hpp +++ b/include/modules/hyprland/backend.hpp @@ -26,6 +26,10 @@ class IPC { static std::string getSocket1Reply(const std::string& rq); Json::Value getSocket1JsonReply(const std::string& rq); + static std::filesystem::path getSocketFolder(const char* instanceSig); + + protected: + static std::filesystem::path socketFolder_; private: void startIPC(); @@ -38,5 +42,4 @@ class IPC { inline std::unique_ptr gIPC; inline bool modulesReady = false; -std::filesystem::path getSocketFolder(const char* instanceSig); }; // namespace waybar::modules::hyprland diff --git a/src/modules/hyprland/backend.cpp b/src/modules/hyprland/backend.cpp index 29c65633..05d16d05 100644 --- a/src/modules/hyprland/backend.cpp +++ b/src/modules/hyprland/backend.cpp @@ -15,22 +15,25 @@ namespace waybar::modules::hyprland { -std::filesystem::path getSocketFolder(const char* instanceSig) { +std::filesystem::path IPC::socketFolder_; + +std::filesystem::path IPC::getSocketFolder(const char* instanceSig) { // socket path, specified by EventManager of Hyprland - static std::filesystem::path socketFolder; - if (!socketFolder.empty()) { - return socketFolder; + if (!socketFolder_.empty()) { + spdlog::warn("socketFolder already set, using {}", socketFolder_.c_str()); + return socketFolder_; + } } std::filesystem::path xdgRuntimeDir = std::filesystem::path(getenv("XDG_RUNTIME_DIR")); if (!xdgRuntimeDir.empty() && std::filesystem::exists(xdgRuntimeDir / "hypr")) { - socketFolder = xdgRuntimeDir / "hypr"; + socketFolder_ = xdgRuntimeDir / "hypr"; } else { spdlog::warn("$XDG_RUNTIME_DIR/hypr does not exist, falling back to /tmp/hypr"); - socketFolder = std::filesystem::path("/tmp") / "hypr"; + socketFolder_ = std::filesystem::path("/tmp") / "hypr"; } - socketFolder = socketFolder / instanceSig; - return socketFolder; + socketFolder_ = socketFolder_ / instanceSig; + return socketFolder_; } void IPC::startIPC() { @@ -59,7 +62,7 @@ void IPC::startIPC() { addr.sun_family = AF_UNIX; - auto socketPath = getSocketFolder(his) / ".socket2.sock"; + auto socketPath = IPC::getSocketFolder(his) / ".socket2.sock"; strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1); addr.sun_path[sizeof(addr.sun_path) - 1] = 0; @@ -169,7 +172,7 @@ std::string IPC::getSocket1Reply(const std::string& rq) { sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; - std::string socketPath = getSocketFolder(instanceSig) / ".socket.sock"; + std::string socketPath = IPC::getSocketFolder(instanceSig) / ".socket.sock"; // Use snprintf to copy the socketPath string into serverAddress.sun_path if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) <