diff options
| author | Vaxry <vaxry@vaxry.net> | 2024-04-30 14:17:32 +0100 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2024-04-30 14:17:35 +0100 |
| commit | d7a48cf47816041c5cb705c9de218c3395635822 (patch) | |
| tree | d6b40f4fbd051d490d03d273ec34a052bfacaf3e /hyprctl | |
| parent | 07e070012bf02294e66fbb89ac8b37d61b790855 (diff) | |
hyprctl: use XDG_RUNTIME_DIR if available
fixes #5813
Diffstat (limited to 'hyprctl')
| -rw-r--r-- | hyprctl/main.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index dad49fc4..2d1b5a76 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -39,12 +39,21 @@ struct SInstanceData { bool valid = true; }; +std::string getRuntimeDir() { + const auto XDG = getenv("XDG_RUNTIME_DIR"); + + if (!XDG) { + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + return "/run/user/" + USERID + "/hypr"; + } + + return std::string{XDG} + "/hypr"; +} + std::vector<SInstanceData> instances() { std::vector<SInstanceData> result; - const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); - - for (const auto& el : std::filesystem::directory_iterator("/run/user/" + USERID + "/hypr")) { + for (const auto& el : std::filesystem::directory_iterator(getRuntimeDir())) { if (!el.is_directory() || !std::filesystem::exists(el.path().string() + "/hyprland.lock")) continue; @@ -106,7 +115,7 @@ void request(std::string arg, int minArgs = 0) { sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; - std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.socket.sock"; + std::string socketPath = getRuntimeDir() + "/" + instanceSignature + "/.socket.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); @@ -166,7 +175,7 @@ void requestHyprpaper(std::string arg) { const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); - std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.hyprpaper.sock"; + std::string socketPath = getRuntimeDir() + "/" + instanceSignature + "/.hyprpaper.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); |
