aboutsummaryrefslogtreecommitdiffstats
path: root/common/ipc-client.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-30 00:11:00 -0400
committerLibravatar GitHub <noreply@github.com>2018-03-30 00:11:00 -0400
commit9d7f47746cdcb0eed3cf41875d06a8ef238eef1c (patch)
tree997658454de40db3f8b76b68d658efaf2b686188 /common/ipc-client.c
parentMerge pull request #1654 from acrisci/refactor-2-electric-boogaloo (diff)
parentMerge remote-tracking branch 'origin/wlroots' into swaybar-layers (diff)
downloadsway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.tar.gz
sway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.tar.zst
sway-9d7f47746cdcb0eed3cf41875d06a8ef238eef1c.zip
Merge pull request #1648 from swaywm/swaybar-layers
Port swaybar to layer shell
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) {