Skip to content

Commit d50f0ed

Browse files
authored
core: move socket to runtime dir (#167)
1 parent 4b3843e commit d50f0ed

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/ipc/Socket.cpp

+18-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <sys/types.h>
1212
#include <sys/un.h>
1313
#include <unistd.h>
14+
#include <pwd.h>
1415

1516
void CIPCSocket::initialize() {
1617
std::thread([&]() {
@@ -24,12 +25,14 @@ void CIPCSocket::initialize() {
2425
sockaddr_un SERVERADDRESS = {.sun_family = AF_UNIX};
2526

2627
const auto HISenv = getenv("HYPRLAND_INSTANCE_SIGNATURE");
28+
const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid);
2729

28-
std::string socketPath = HISenv ? "/tmp/hypr/" + std::string(HISenv) + "/.hyprpaper.sock" : "/tmp/hypr/.hyprpaper.sock";
30+
const auto USERDIR = "/run/user/" + USERID + "/hypr/";
2931

30-
if (!HISenv) {
31-
mkdir("/tmp/hypr", S_IRWXU | S_IRWXG);
32-
}
32+
std::string socketPath = HISenv ? USERDIR + std::string(HISenv) + "/.hyprpaper.sock" : USERDIR + ".hyprpaper.sock";
33+
34+
if (!HISenv)
35+
mkdir(USERDIR.c_str(), S_IRWXU);
3336

3437
unlink(socketPath.c_str());
3538

@@ -92,7 +95,7 @@ bool CIPCSocket::mainThreadParseRequest() {
9295

9396
if (copy == "")
9497
return false;
95-
98+
9699
// now we can work on the copy
97100

98101
Debug::log(LOG, "Received a request: %s", copy.c_str());
@@ -102,7 +105,6 @@ bool CIPCSocket::mainThreadParseRequest() {
102105
m_bReplyReady = true;
103106
m_bRequestReady = false;
104107

105-
106108
// config commands
107109
if (copy.find("wallpaper") == 0 || copy.find("preload") == 0 || copy.find("unload") == 0) {
108110

@@ -114,51 +116,50 @@ bool CIPCSocket::mainThreadParseRequest() {
114116
}
115117

116118
return true;
117-
118119
}
119-
120+
120121
if (copy.find("listloaded") == 0) {
121-
122+
122123
const auto numWallpapersLoaded = g_pHyprpaper->m_mWallpaperTargets.size();
123124
Debug::log(LOG, "numWallpapersLoaded: %d", numWallpapersLoaded);
124125

125126
if (numWallpapersLoaded == 0) {
126127
m_szReply = "no wallpapers loaded";
127128
return false;
128129
}
129-
130+
130131
m_szReply = "";
131132
long unsigned int i = 0;
132133
for (auto& [name, target] : g_pHyprpaper->m_mWallpaperTargets) {
133134
m_szReply += name;
134135
i++;
135-
if (i < numWallpapersLoaded) m_szReply += '\n'; // dont add newline on last entry
136+
if (i < numWallpapersLoaded)
137+
m_szReply += '\n'; // dont add newline on last entry
136138
}
137139

138140
return true;
139-
140141
}
141142

142143
if (copy.find("listactive") == 0) {
143-
144+
144145
const auto numWallpapersActive = g_pHyprpaper->m_mMonitorActiveWallpapers.size();
145146
Debug::log(LOG, "numWallpapersActive: %d", numWallpapersActive);
146147

147148
if (numWallpapersActive == 0) {
148149
m_szReply = "no wallpapers active";
149150
return false;
150151
}
151-
152+
152153
m_szReply = "";
153154
long unsigned int i = 0;
154155
for (auto& [mon, path1] : g_pHyprpaper->m_mMonitorActiveWallpapers) {
155156
m_szReply += mon + " = " + path1;
156157
i++;
157-
if (i < numWallpapersActive) m_szReply += '\n'; // dont add newline on last entry
158+
if (i < numWallpapersActive)
159+
m_szReply += '\n'; // dont add newline on last entry
158160
}
159-
160-
return true;
161161

162+
return true;
162163
}
163164

164165
m_szReply = "invalid command";

0 commit comments

Comments
 (0)