aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-04-10 07:17:47 -0400
committerLibravatar GitHub <noreply@github.com>2017-04-10 07:17:47 -0400
commit5d3a02a7c624bbef07b1b228eb1bb60fade5248c (patch)
tree35860f43beb1ce46de5a3d780ca33830d4bc9ba4 /sway/ipc-server.c
parentAdd pretty printing to swaymsg (diff)
parentMerge pull request #1150 from JerziKaminsky/cmake_find_libcap (diff)
downloadsway-5d3a02a7c624bbef07b1b228eb1bb60fade5248c.tar.gz
sway-5d3a02a7c624bbef07b1b228eb1bb60fade5248c.tar.zst
sway-5d3a02a7c624bbef07b1b228eb1bb60fade5248c.zip
Merge branch 'master' into pretty-print-swaymsg
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b5f4bb16..67a3cdc8 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -63,6 +63,7 @@ void ipc_client_handle_command(struct ipc_client *client);
63bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); 63bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
64void ipc_get_workspaces_callback(swayc_t *workspace, void *data); 64void ipc_get_workspaces_callback(swayc_t *workspace, void *data);
65void ipc_get_outputs_callback(swayc_t *container, void *data); 65void ipc_get_outputs_callback(swayc_t *container, void *data);
66static void ipc_get_marks_callback(swayc_t *container, void *data);
66 67
67void ipc_init(void) { 68void ipc_init(void) {
68 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); 69 ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
@@ -161,7 +162,8 @@ int ipc_handle_connection(int fd, uint32_t mask, void *data) {
161 } 162 }
162 163
163 int flags; 164 int flags;
164 if ((flags=fcntl(client_fd, F_GETFD)) == -1 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) { 165 if ((flags = fcntl(client_fd, F_GETFD)) == -1
166 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
165 sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket"); 167 sway_log_errno(L_ERROR, "Unable to set CLOEXEC on IPC client socket");
166 close(client_fd); 168 close(client_fd);
167 return 0; 169 return 0;
@@ -193,13 +195,12 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) {
193 195
194 if (mask & WLC_EVENT_ERROR) { 196 if (mask & WLC_EVENT_ERROR) {
195 sway_log(L_ERROR, "IPC Client socket error, removing client"); 197 sway_log(L_ERROR, "IPC Client socket error, removing client");
196 client->fd = -1;
197 ipc_client_disconnect(client); 198 ipc_client_disconnect(client);
198 return 0; 199 return 0;
199 } 200 }
200 201
201 if (mask & WLC_EVENT_HANGUP) { 202 if (mask & WLC_EVENT_HANGUP) {
202 client->fd = -1; 203 sway_log(L_DEBUG, "Client %d hung up", client->fd);
203 ipc_client_disconnect(client); 204 ipc_client_disconnect(client);
204 return 0; 205 return 0;
205 } 206 }
@@ -456,6 +457,19 @@ void ipc_client_handle_command(struct ipc_client *client) {
456 goto exit_cleanup; 457 goto exit_cleanup;
457 } 458 }
458 459
460 case IPC_GET_MARKS:
461 {
462 if (!(client->security_policy & IPC_FEATURE_GET_MARKS)) {
463 goto exit_denied;
464 }
465 json_object *marks = json_object_new_array();
466 container_map(&root_container, ipc_get_marks_callback, marks);
467 const char *json_string = json_object_to_json_string(marks);
468 ipc_send_reply(client, json_string, (uint32_t) strlen(json_string));
469 json_object_put(marks);
470 goto exit_cleanup;
471 }
472
459 case IPC_GET_VERSION: 473 case IPC_GET_VERSION:
460 { 474 {
461 json_object *version = ipc_json_get_version(); 475 json_object *version = ipc_json_get_version();
@@ -609,6 +623,16 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) {
609 } 623 }
610} 624}
611 625
626static void ipc_get_marks_callback(swayc_t *container, void *data) {
627 json_object *object = (json_object *)data;
628 if (container->marks) {
629 for (int i = 0; i < container->marks->length; ++i) {
630 char *mark = (char *)container->marks->items[i];
631 json_object_array_add(object, json_object_new_string(mark));
632 }
633 }
634}
635
612void ipc_send_event(const char *json_string, enum ipc_command_type event) { 636void ipc_send_event(const char *json_string, enum ipc_command_type event) {
613 static struct { 637 static struct {
614 enum ipc_command_type event; 638 enum ipc_command_type event;