diff options
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 0cacc515..6554098b 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -63,6 +63,7 @@ void ipc_client_handle_command(struct ipc_client *client); | |||
63 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); | 63 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); |
64 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); | 64 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); |
65 | void ipc_get_outputs_callback(swayc_t *container, void *data); | 65 | void ipc_get_outputs_callback(swayc_t *container, void *data); |
66 | static void ipc_get_marks_callback(swayc_t *container, void *data); | ||
66 | 67 | ||
67 | void ipc_init(void) { | 68 | void 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 | } |
@@ -464,6 +465,19 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
464 | goto exit_cleanup; | 465 | goto exit_cleanup; |
465 | } | 466 | } |
466 | 467 | ||
468 | case IPC_GET_MARKS: | ||
469 | { | ||
470 | if (!(client->security_policy & IPC_FEATURE_GET_MARKS)) { | ||
471 | goto exit_denied; | ||
472 | } | ||
473 | json_object *marks = json_object_new_array(); | ||
474 | container_map(&root_container, ipc_get_marks_callback, marks); | ||
475 | const char *json_string = json_object_to_json_string(marks); | ||
476 | ipc_send_reply(client, json_string, (uint32_t) strlen(json_string)); | ||
477 | json_object_put(marks); | ||
478 | goto exit_cleanup; | ||
479 | } | ||
480 | |||
467 | case IPC_GET_VERSION: | 481 | case IPC_GET_VERSION: |
468 | { | 482 | { |
469 | json_object *version = ipc_json_get_version(); | 483 | json_object *version = ipc_json_get_version(); |
@@ -617,6 +631,16 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) { | |||
617 | } | 631 | } |
618 | } | 632 | } |
619 | 633 | ||
634 | static void ipc_get_marks_callback(swayc_t *container, void *data) { | ||
635 | json_object *object = (json_object *)data; | ||
636 | if (container->marks) { | ||
637 | for (int i = 0; i < container->marks->length; ++i) { | ||
638 | char *mark = (char *)container->marks->items[i]; | ||
639 | json_object_array_add(object, json_object_new_string(mark)); | ||
640 | } | ||
641 | } | ||
642 | } | ||
643 | |||
620 | void ipc_send_event(const char *json_string, enum ipc_command_type event) { | 644 | void ipc_send_event(const char *json_string, enum ipc_command_type event) { |
621 | static struct { | 645 | static struct { |
622 | enum ipc_command_type event; | 646 | enum ipc_command_type event; |