aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-03-28 21:21:36 -0400
committerDrew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit382e8af418a7e1b8cf93d3398509b93c6874cb0d (patch)
tree1b9b619a94322a5b9b6cc206db84153c361a4626
parent3d29d833b133d48abfa87c1a79d8fbb507fd1426 (diff)
Allow sway IPC clients to fall back to i3 socket
-rw-r--r--common/ipc-client.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c
index 582c5e86..117e9910 100644
--- a/common/ipc-client.c
+++ b/common/ipc-client.c
@@ -1,4 +1,4 @@
-#define _POSIX_C_SOURCE 2
+#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -14,13 +14,31 @@ static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
static const size_t ipc_header_size = sizeof(ipc_magic)+8;
char *get_socketpath(void) {
- FILE *fp = popen("sway --get-socketpath", "r");
- if (!fp) {
- return NULL;
+ const char *swaysock = getenv("SWAYSOCK");
+ if (swaysock) {
+ return strdup(swaysock);
}
- char *line = read_line(fp);
- pclose(fp);
- return line;
+ FILE *fp = popen("sway --get-socketpath 2>/dev/null", "r");
+ if (fp) {
+ char *line = read_line(fp);
+ pclose(fp);
+ if (line && *line) {
+ return line;
+ }
+ }
+ const char *i3sock = getenv("I3SOCK");
+ if (i3sock) {
+ return strdup(i3sock);
+ }
+ fp = popen("i3 --get-socketpath 2>/dev/null", "r");
+ if (fp) {
+ char *line = read_line(fp);
+ pclose(fp);
+ if (line && *line) {
+ return line;
+ }
+ }
+ return NULL;
}
int ipc_open_socket(const char *socket_path) {