From a5a648091760ac002120fab18247e5292b6482de Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:25:24 +0100 Subject: 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`. --- hyprctl/main.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'hyprctl/main.cpp') 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 #include #include +#include #include #include #include @@ -41,21 +42,22 @@ struct SInstanceData { std::vector instances() { std::vector 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); -- cgit v1.2.3