Fix Hyprland socketpath changed to XDG_RUNTIME_DIR (#3183)
This commit is contained in:
parent
2481f7a292
commit
f41458ea24
|
@ -9,11 +9,30 @@
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
namespace waybar::modules::hyprland {
|
namespace waybar::modules::hyprland {
|
||||||
|
|
||||||
|
std::filesystem::path getSocketFolder(const char* instanceSig) {
|
||||||
|
// socket path, specified by EventManager of Hyprland
|
||||||
|
static std::filesystem::path socketFolder;
|
||||||
|
if (!socketFolder.empty()) {
|
||||||
|
return socketFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::filesystem::path xdgRuntimeDir = std::filesystem::path(getenv("XDG_RUNTIME_DIR"));
|
||||||
|
if (!xdgRuntimeDir.empty() && std::filesystem::exists(xdgRuntimeDir / "hypr")) {
|
||||||
|
socketFolder = xdgRuntimeDir / "hypr";
|
||||||
|
} else {
|
||||||
|
spdlog::warn("$XDG_RUNTIME_DIR/hypr does not exist, falling back to /tmp/hypr");
|
||||||
|
socketFolder = std::filesystem::temp_directory_path() / "hypr";
|
||||||
|
}
|
||||||
|
socketFolder = socketFolder / instanceSig;
|
||||||
|
return socketFolder;
|
||||||
|
}
|
||||||
|
|
||||||
void IPC::startIPC() {
|
void IPC::startIPC() {
|
||||||
// will start IPC and relay events to parseIPC
|
// will start IPC and relay events to parseIPC
|
||||||
|
|
||||||
|
@ -40,9 +59,7 @@ void IPC::startIPC() {
|
||||||
|
|
||||||
addr.sun_family = AF_UNIX;
|
addr.sun_family = AF_UNIX;
|
||||||
|
|
||||||
// socket path, specified by EventManager of Hyprland
|
auto socketPath = getSocketFolder(his) / ".socket2.sock";
|
||||||
std::string socketPath = "/tmp/hypr/" + std::string(his) + "/.socket2.sock";
|
|
||||||
|
|
||||||
strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
strncpy(addr.sun_path, socketPath.c_str(), sizeof(addr.sun_path) - 1);
|
||||||
|
|
||||||
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
|
addr.sun_path[sizeof(addr.sun_path) - 1] = 0;
|
||||||
|
@ -142,12 +159,10 @@ std::string IPC::getSocket1Reply(const std::string& rq) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string instanceSigStr = std::string(instanceSig);
|
|
||||||
|
|
||||||
sockaddr_un serverAddress = {0};
|
sockaddr_un serverAddress = {0};
|
||||||
serverAddress.sun_family = AF_UNIX;
|
serverAddress.sun_family = AF_UNIX;
|
||||||
|
|
||||||
std::string socketPath = "/tmp/hypr/" + instanceSigStr + "/.socket.sock";
|
std::string socketPath = getSocketFolder(instanceSig) / ".socket.sock";
|
||||||
|
|
||||||
// Use snprintf to copy the socketPath string into serverAddress.sun_path
|
// Use snprintf to copy the socketPath string into serverAddress.sun_path
|
||||||
if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) <
|
if (snprintf(serverAddress.sun_path, sizeof(serverAddress.sun_path), "%s", socketPath.c_str()) <
|
||||||
|
|
Loading…
Reference in New Issue