aboutsummaryrefslogtreecommitdiff
path: root/common/ipc-client.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-04-12 20:19:54 -0400
committerDrew DeVault <sir@cmpwn.com>2018-04-12 20:19:54 -0400
commitcd1b32453a9296c18b28bff71607aeb22987b5cd (patch)
treec653c6d525b471914c01a9d7ae543f521b6138ed /common/ipc-client.c
parent8e06985cc1b479724446fba752e0fecfb998e87b (diff)
parent5785170421dc38437acde8bb61068cd16fda716c (diff)
Merge branch 'wlroots'
Diffstat (limited to 'common/ipc-client.c')
-rw-r--r--common/ipc-client.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/common/ipc-client.c b/common/ipc-client.c
index 1ab6627b..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) {
@@ -79,7 +97,7 @@ struct ipc_response *ipc_recv_response(int socketfd) {
error_2:
free(response);
error_1:
- sway_log(L_ERROR, "Unable to allocate memory for IPC response");
+ wlr_log(L_ERROR, "Unable to allocate memory for IPC response");
return NULL;
}