summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hyprctl/main.cpp19
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);