diff options
Diffstat (limited to 'hyprctl/main.cpp')
| -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); |
