Skip to content

Commit

Permalink
[client] x11: read the i3 IPC response
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Sep 11, 2023
1 parent 8d90c9c commit 82607a7
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion client/displayservers/X11/wm/i3.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "atoms.h"
#include "common/debug.h"
#include "common/option.h"
#include "common/util.h"

#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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 =
Expand Down

0 comments on commit 82607a7

Please sign in to comment.