From 2b14cbe87a72b2dbeee52a77da6ef0d5c1735549 Mon Sep 17 00:00:00 2001 From: Mike Wallio Date: Fri, 23 Oct 2020 09:51:02 -0400 Subject: [PATCH 1/2] Get socket path from env I3SOCK - Adds support for sway --- src/ipc.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/ipc.cpp b/src/ipc.cpp index e4f06bd..09c0c7a 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -283,25 +283,7 @@ static std::shared_ptr parse_bar_config_from_json(const Json::Val std::string get_socketpath() { - 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; + return std::getenv("I3SOCK"); } From 83d263d4f1f26f9e4c0a009554cabb21201c8a78 Mon Sep 17 00:00:00 2001 From: Mike Wallio Date: Sun, 25 Oct 2020 23:10:40 -0400 Subject: [PATCH 2/2] Get socket from i3 if I3SOCK not set --- src/ipc.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) 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; }