aboutsummaryrefslogtreecommitdiffstats
path: root/common/ipc-client.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-28 21:21:36 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit382e8af418a7e1b8cf93d3398509b93c6874cb0d (patch)
tree1b9b619a94322a5b9b6cc206db84153c361a4626 /common/ipc-client.c
parentMerge pull request #1652 from ascent12/glclear (diff)
downloadsway-382e8af418a7e1b8cf93d3398509b93c6874cb0d.tar.gz
sway-382e8af418a7e1b8cf93d3398509b93c6874cb0d.tar.zst
sway-382e8af418a7e1b8cf93d3398509b93c6874cb0d.zip
Allow sway IPC clients to fall back to i3 socket
Diffstat (limited to 'common/ipc-client.c')
-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 @@
1#define _POSIX_C_SOURCE 2 1#define _POSIX_C_SOURCE 200809L
2#include <stdio.h> 2#include <stdio.h>
3#include <stdint.h> 3#include <stdint.h>
4#include <stdlib.h> 4#include <stdlib.h>
@@ -14,13 +14,31 @@ static const char ipc_magic[] = {'i', '3', '-', 'i', 'p', 'c'};
14static const size_t ipc_header_size = sizeof(ipc_magic)+8; 14static const size_t ipc_header_size = sizeof(ipc_magic)+8;
15 15
16char *get_socketpath(void) { 16char *get_socketpath(void) {
17 FILE *fp = popen("sway --get-socketpath", "r"); 17 const char *swaysock = getenv("SWAYSOCK");
18 if (!fp) { 18 if (swaysock) {
19 return NULL; 19 return strdup(swaysock);
20 } 20 }
21 char *line = read_line(fp); 21 FILE *fp = popen("sway --get-socketpath 2>/dev/null", "r");
22 pclose(fp); 22 if (fp) {
23 return line; 23 char *line = read_line(fp);
24 pclose(fp);
25 if (line && *line) {
26 return line;
27 }
28 }
29 const char *i3sock = getenv("I3SOCK");
30 if (i3sock) {
31 return strdup(i3sock);
32 }
33 fp = popen("i3 --get-socketpath 2>/dev/null", "r");
34 if (fp) {
35 char *line = read_line(fp);
36 pclose(fp);
37 if (line && *line) {
38 return line;
39 }
40 }
41 return NULL;
24} 42}
25 43
26int ipc_open_socket(const char *socket_path) { 44int ipc_open_socket(const char *socket_path) {