From d7a48cf47816041c5cb705c9de218c3395635822 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 30 Apr 2024 14:17:32 +0100 Subject: [PATCH] hyprctl: use XDG_RUNTIME_DIR if available fixes #5813 --- hyprctl/main.cpp | 19 ++++++++++++++----- 1 file 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 instances() { std::vector 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);