diff --git a/src/ipc.cpp b/src/ipc.cpp index 09c0c7a..03df4ff 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -281,9 +281,31 @@ static std::shared_ptr 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; }