diff options
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 1bf5a05f..7f353c0e 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -1,5 +1,4 @@ | |||
1 | // See https://i3wm.org/docs/ipc.html for protocol information | 1 | // See https://i3wm.org/docs/ipc.html for protocol information |
2 | #define _POSIX_C_SOURCE 200112L | ||
3 | #include <linux/input-event-codes.h> | 2 | #include <linux/input-event-codes.h> |
4 | #include <assert.h> | 3 | #include <assert.h> |
5 | #include <errno.h> | 4 | #include <errno.h> |
@@ -56,7 +55,6 @@ struct ipc_client { | |||
56 | enum ipc_command_type pending_type; | 55 | enum ipc_command_type pending_type; |
57 | }; | 56 | }; |
58 | 57 | ||
59 | struct sockaddr_un *ipc_user_sockaddr(void); | ||
60 | int ipc_handle_connection(int fd, uint32_t mask, void *data); | 58 | int ipc_handle_connection(int fd, uint32_t mask, void *data); |
61 | int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data); | 59 | int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data); |
62 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data); | 60 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data); |
@@ -150,7 +148,6 @@ struct sockaddr_un *ipc_user_sockaddr(void) { | |||
150 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { | 148 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { |
151 | (void) fd; | 149 | (void) fd; |
152 | struct sway_server *server = data; | 150 | struct sway_server *server = data; |
153 | sway_log(SWAY_DEBUG, "Event on IPC listening socket"); | ||
154 | assert(mask == WL_EVENT_READABLE); | 151 | assert(mask == WL_EVENT_READABLE); |
155 | 152 | ||
156 | int client_fd = accept(ipc_socket, NULL, NULL); | 153 | int client_fd = accept(ipc_socket, NULL, NULL); |
@@ -211,13 +208,10 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
211 | } | 208 | } |
212 | 209 | ||
213 | if (mask & WL_EVENT_HANGUP) { | 210 | if (mask & WL_EVENT_HANGUP) { |
214 | sway_log(SWAY_DEBUG, "Client %d hung up", client->fd); | ||
215 | ipc_client_disconnect(client); | 211 | ipc_client_disconnect(client); |
216 | return 0; | 212 | return 0; |
217 | } | 213 | } |
218 | 214 | ||
219 | sway_log(SWAY_DEBUG, "Client %d readable", client->fd); | ||
220 | |||
221 | int read_available; | 215 | int read_available; |
222 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { | 216 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { |
223 | sway_log_errno(SWAY_INFO, "Unable to read IPC socket buffer size"); | 217 | sway_log_errno(SWAY_INFO, "Unable to read IPC socket buffer size"); |
@@ -513,6 +507,20 @@ void ipc_event_input(const char *change, struct sway_input_device *device) { | |||
513 | json_object_put(json); | 507 | json_object_put(json); |
514 | } | 508 | } |
515 | 509 | ||
510 | void ipc_event_output(void) { | ||
511 | if (!ipc_has_event_listeners(IPC_EVENT_OUTPUT)) { | ||
512 | return; | ||
513 | } | ||
514 | sway_log(SWAY_DEBUG, "Sending output event"); | ||
515 | |||
516 | json_object *json = json_object_new_object(); | ||
517 | json_object_object_add(json, "change", json_object_new_string("unspecified")); | ||
518 | |||
519 | const char *json_string = json_object_to_json_string(json); | ||
520 | ipc_send_event(json_string, IPC_EVENT_OUTPUT); | ||
521 | json_object_put(json); | ||
522 | } | ||
523 | |||
516 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | 524 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { |
517 | struct ipc_client *client = data; | 525 | struct ipc_client *client = data; |
518 | 526 | ||
@@ -523,7 +531,6 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
523 | } | 531 | } |
524 | 532 | ||
525 | if (mask & WL_EVENT_HANGUP) { | 533 | if (mask & WL_EVENT_HANGUP) { |
526 | sway_log(SWAY_DEBUG, "Client %d hung up", client->fd); | ||
527 | ipc_client_disconnect(client); | 534 | ipc_client_disconnect(client); |
528 | return 0; | 535 | return 0; |
529 | } | 536 | } |
@@ -532,8 +539,6 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
532 | return 0; | 539 | return 0; |
533 | } | 540 | } |
534 | 541 | ||
535 | sway_log(SWAY_DEBUG, "Client %d writable", client->fd); | ||
536 | |||
537 | ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); | 542 | ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); |
538 | 543 | ||
539 | if (written == -1 && errno == EAGAIN) { | 544 | if (written == -1 && errno == EAGAIN) { |
@@ -692,6 +697,12 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
692 | ipc_json_describe_disabled_output(output)); | 697 | ipc_json_describe_disabled_output(output)); |
693 | } | 698 | } |
694 | } | 699 | } |
700 | |||
701 | for (int i = 0; i < root->non_desktop_outputs->length; i++) { | ||
702 | struct sway_output_non_desktop *non_desktop_output = root->non_desktop_outputs->items[i]; | ||
703 | json_object_array_add(outputs, ipc_json_describe_non_desktop_output(non_desktop_output)); | ||
704 | } | ||
705 | |||
695 | const char *json_string = json_object_to_json_string(outputs); | 706 | const char *json_string = json_object_to_json_string(outputs); |
696 | ipc_send_reply(client, payload_type, json_string, | 707 | ipc_send_reply(client, payload_type, json_string, |
697 | (uint32_t)strlen(json_string)); | 708 | (uint32_t)strlen(json_string)); |
@@ -727,6 +738,8 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
727 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); | 738 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
728 | if (strcmp(event_type, "workspace") == 0) { | 739 | if (strcmp(event_type, "workspace") == 0) { |
729 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); | 740 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); |
741 | } else if (strcmp(event_type, "output") == 0) { | ||
742 | client->subscribed_events |= event_mask(IPC_EVENT_OUTPUT); | ||
730 | } else if (strcmp(event_type, "barconfig_update") == 0) { | 743 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
731 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); | 744 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); |
732 | } else if (strcmp(event_type, "bar_state_update") == 0) { | 745 | } else if (strcmp(event_type, "bar_state_update") == 0) { |
@@ -911,7 +924,6 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
911 | 924 | ||
912 | exit_cleanup: | 925 | exit_cleanup: |
913 | free(buf); | 926 | free(buf); |
914 | return; | ||
915 | } | 927 | } |
916 | 928 | ||
917 | bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_type, | 929 | bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_type, |
@@ -955,7 +967,5 @@ bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_typ | |||
955 | ipc_client_handle_writable, client); | 967 | ipc_client_handle_writable, client); |
956 | } | 968 | } |
957 | 969 | ||
958 | sway_log(SWAY_DEBUG, "Added IPC reply of type 0x%x to client %d queue: %s", | ||
959 | payload_type, client->fd, payload); | ||
960 | return true; | 970 | return true; |
961 | } | 971 | } |