Get socket from i3 if I3SOCK not set
This commit is contained in:
26
src/ipc.cpp
26
src/ipc.cpp
@@ -281,9 +281,31 @@ static std::shared_ptr<bar_config_t> parse_bar_config_from_json(const Json::Val
|
||||
#undef i3IPC_TYPE_STR
|
||||
}
|
||||
|
||||
|
||||
std::string get_socketpath() {
|
||||
return std::getenv("I3SOCK");
|
||||
const char* envsock{std::getenv("I3SOCK")};
|
||||
if (envsock) {
|
||||
return envsock;
|
||||
}
|
||||
|
||||
std::string str;
|
||||
{
|
||||
auss_t str_buf;
|
||||
FILE* in;
|
||||
char buf[512] = {0};
|
||||
if (!(in = popen("i3 --get-socketpath", "r"))) {
|
||||
throw errno_error("Failed to get socket path");
|
||||
}
|
||||
|
||||
while (fgets(buf, sizeof(buf), in) != nullptr) {
|
||||
str_buf << buf;
|
||||
}
|
||||
pclose(in);
|
||||
str = str_buf;
|
||||
}
|
||||
if (str.back() == '\n') {
|
||||
str.pop_back();
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user