Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/modules/hyprland/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ void IPC::startIPC() {
std::thread([&]() {
// check for hyprland
const char* his = getenv("HYPRLAND_INSTANCE_SIGNATURE");
const char* xdgRuntimeDir = getenv("XDG_RUNTIME_DIR");

if (xdgRuntimeDir == nullptr) {
spdlog::warn("XDG_RUNTIME_DIR not set, Hyprland IPC will not be available.");
return;
}

if (his == nullptr) {
spdlog::warn("Hyprland is not running, Hyprland IPC will not be available.");
Expand All @@ -41,7 +47,7 @@ void IPC::startIPC() {
addr.sun_family = AF_UNIX;

// socket path, specified by EventManager of Hyprland
std::string socketPath = "/tmp/hypr/" + std::string(his) + "/.socket2.sock";
std::string socketPath = std::string(xdgRuntimeDir) + "/hypr/" + std::string(his) + "/.socket2.sock";

strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);

Expand Down Expand Up @@ -137,6 +143,13 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
// get the instance signature
auto* instanceSig = getenv("HYPRLAND_INSTANCE_SIGNATURE");

auto* xdgRuntimeDir = getenv("XDG_RUNTIME_DIR");

if (xdgRuntimeDir == nullptr) {
spdlog::warn("XDG_RUNTIME_DIR not set, Hyprland IPC will not be available.");
return "";
}

if (instanceSig == nullptr) {
spdlog::error("Hyprland IPC: HYPRLAND_INSTANCE_SIGNATURE was not set! (Is Hyprland running?)");
return "";
Expand All @@ -147,7 +160,7 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
sockaddr_un serverAddress = {0};
serverAddress.sun_family = AF_UNIX;

std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock";
std::string socketPath = std::string(xdgRuntimeDir) + "/hypr/" + instanceSigStr + "/.socket.sock";

// Use snprintf to copy the socketPath string into serverAddress.sun_path
if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) <
Expand Down