mirror of
https://codeberg.org/dnkl/yambar.git
synced 2025-04-25 13:25:39 +02:00
module/i3: break out send_pkg()
This commit is contained in:
parent
76dc4f82cd
commit
92319714c7
3 changed files with 28 additions and 23 deletions
|
@ -1,6 +1,7 @@
|
|||
#include "i3-common.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#if defined(ENABLE_X11)
|
||||
|
@ -8,6 +9,8 @@
|
|||
#include <xcb/xcb_aux.h>
|
||||
#endif
|
||||
|
||||
#include <i3/ipc.h>
|
||||
|
||||
#define LOG_MODULE "i3:common"
|
||||
#include "../log.h"
|
||||
|
||||
|
@ -88,3 +91,24 @@ i3_get_socket_address(struct sockaddr_un *addr)
|
|||
strncpy(addr->sun_path, sway_sock, sizeof(addr->sun_path) - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
i3_send_pkg(int sock, int cmd, char *data)
|
||||
{
|
||||
size_t size = data != NULL ? strlen(data) : 0;
|
||||
i3_ipc_header_t hdr = {
|
||||
.magic = I3_IPC_MAGIC,
|
||||
.size = size,
|
||||
.type = cmd
|
||||
};
|
||||
|
||||
if (write(sock, &hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr))
|
||||
return false;
|
||||
|
||||
if (data != NULL) {
|
||||
if (write(sock, data, size) != (ssize_t)size)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,3 +7,4 @@
|
|||
#include <sys/un.h>
|
||||
|
||||
bool i3_get_socket_address(struct sockaddr_un *addr);
|
||||
bool i3_send_pkg(int sock, int cmd, char *data);
|
||||
|
|
26
modules/i3.c
26
modules/i3.c
|
@ -178,26 +178,6 @@ workspace_lookup(struct private *m, const char *name)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool
|
||||
send_pkg(int sock, int cmd, char *data)
|
||||
{
|
||||
size_t size = data != NULL ? strlen(data) : 0;
|
||||
i3_ipc_header_t hdr = {
|
||||
.magic = I3_IPC_MAGIC,
|
||||
.size = size,
|
||||
.type = cmd
|
||||
};
|
||||
|
||||
if (write(sock, &hdr, sizeof(hdr)) != (ssize_t)sizeof(hdr))
|
||||
return false;
|
||||
|
||||
if (data != NULL) {
|
||||
if (write(sock, data, size) != (ssize_t)size)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
handle_get_version_reply(struct private *m, const struct json_object *json)
|
||||
|
@ -495,9 +475,9 @@ run(struct module *mod)
|
|||
return 1;
|
||||
}
|
||||
|
||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_VERSION, NULL);
|
||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\"]");
|
||||
send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
||||
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_VERSION, NULL);
|
||||
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_SUBSCRIBE, "[\"workspace\", \"window\"]");
|
||||
i3_send_pkg(sock, I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
|
||||
|
||||
/* Initial reply typically requires a couple of KB. But we often
|
||||
* need more later. For example, switching workspaces can result
|
||||
|
|
Loading…
Add table
Reference in a new issue