diff options
author | Vaxry <[email protected]> | 2024-04-28 22:25:24 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-04-28 22:25:24 +0100 |
commit | a5a648091760ac002120fab18247e5292b6482de (patch) | |
tree | 0fd68dff8db4277bd2d030867628cbb48f63ce7c /hyprctl | |
parent | d20ee312108d0e7879011cfffa3a83d06e48d29e (diff) | |
download | Hyprland-a5a648091760ac002120fab18247e5292b6482de.tar.gz Hyprland-a5a648091760ac002120fab18247e5292b6482de.zip |
core: Move /tmp/hypr to $XDG_RUNTIME_DIR/hypr (#5788)
Moves the directory containing sockets and logs.
Also restructures lockfiles a bit.
For consumers, check if `$XDG_RUNTIME_DIR/hypr` exists. If so, use it. If not, use the old `/tmp/hypr`.
Diffstat (limited to 'hyprctl')
-rw-r--r-- | hyprctl/main.cpp | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 9b2c2fd2..dad49fc4 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -8,6 +8,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <sys/un.h> +#include <pwd.h> #include <unistd.h> #include <ranges> #include <algorithm> @@ -41,21 +42,22 @@ struct SInstanceData { std::vector<SInstanceData> instances() { std::vector<SInstanceData> result; - for (const auto& el : std::filesystem::directory_iterator("/tmp/hypr")) { - if (el.is_directory() || !el.path().string().ends_with(".lock")) + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + + for (const auto& el : std::filesystem::directory_iterator("/run/user/" + USERID + "/hypr")) { + if (!el.is_directory() || !std::filesystem::exists(el.path().string() + "/hyprland.lock")) continue; // read lock SInstanceData* data = &result.emplace_back(); data->id = el.path().string(); - data->id = data->id.substr(data->id.find_last_of('/') + 1, data->id.find(".lock") - data->id.find_last_of('/') - 1); try { data->time = std::stoull(data->id.substr(data->id.find_first_of('_') + 1, data->id.find_last_of('_') - (data->id.find_first_of('_') + 1))); } catch (std::exception& e) { continue; } // read file - std::ifstream ifs(el.path().string()); + std::ifstream ifs(el.path().string() + "/hyprland.lock"); int i = 0; for (std::string line; std::getline(ifs, line); ++i) { @@ -99,10 +101,12 @@ void request(std::string arg, int minArgs = 0) { return; } - sockaddr_un serverAddress = {0}; - serverAddress.sun_family = AF_UNIX; + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); - std::string socketPath = "/tmp/hypr/" + instanceSignature + "/.socket.sock"; + sockaddr_un serverAddress = {0}; + serverAddress.sun_family = AF_UNIX; + + std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.socket.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); @@ -160,7 +164,9 @@ void requestHyprpaper(std::string arg) { sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; - std::string socketPath = "/tmp/hypr/" + instanceSignature + "/.hyprpaper.sock"; + const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + + std::string socketPath = "/run/user/" + USERID + "/hypr/" + instanceSignature + "/.hyprpaper.sock"; strncpy(serverAddress.sun_path, socketPath.c_str(), sizeof(serverAddress.sun_path) - 1); |