From 82607a7d6f264761b8d514cd5c7354df01b23a21 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Tue, 12 Sep 2023 02:03:24 +1000 Subject: [PATCH] [client] x11: read the i3 IPC response --- client/displayservers/X11/wm/i3.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/client/displayservers/X11/wm/i3.c b/client/displayservers/X11/wm/i3.c index 7443fc946..a2e9d4194 100644 --- a/client/displayservers/X11/wm/i3.c +++ b/client/displayservers/X11/wm/i3.c @@ -26,6 +26,7 @@ #include "atoms.h" #include "common/debug.h" #include "common/option.h" +#include "common/util.h" #include #include @@ -146,7 +147,7 @@ static void wm_i3_setFullscreen(bool enable) while(msgSize) { int wrote = write(i3.sock, buf, msgSize); - if (wrote < 0) + if (wrote <= 0) { DEBUG_WARN("i3 IPC communication failure"); return; @@ -155,6 +156,31 @@ static void wm_i3_setFullscreen(bool enable) buf += wrote; msgSize -= wrote; } + + if ((msgSize = read(i3.sock, msg, sizeof(*msg))) < 0) + { + DEBUG_WARN("i3 IPC read failure"); + return; + } + + if (memcmp(msg->magic, "i3-ipc", 6) != 0 || + msg->type != I3_IPC_TYPE_RUN_COMMAND) + { + DEBUG_WARN("i3 IPC unexpected reply"); + return; + } + + // read and discard the payload + while(msg->length) + { + int len = read(i3.sock, cmd, min(msg->length, sizeof(cmd))); + if (len <= 0) + { + DEBUG_WARN("i3 IPC failed to read payload"); + return; + } + msg->length -= len; + } }; X11WM X11WM_i3 =