diff options
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r-- | sway/ipc-server.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index aad9a7b5..9692a77f 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -56,7 +56,6 @@ struct ipc_client { | |||
56 | enum ipc_command_type pending_type; | 56 | enum ipc_command_type pending_type; |
57 | }; | 57 | }; |
58 | 58 | ||
59 | struct sockaddr_un *ipc_user_sockaddr(void); | ||
60 | int ipc_handle_connection(int fd, uint32_t mask, void *data); | 59 | 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); | 60 | 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); | 61 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data); |
@@ -150,7 +149,6 @@ struct sockaddr_un *ipc_user_sockaddr(void) { | |||
150 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { | 149 | int ipc_handle_connection(int fd, uint32_t mask, void *data) { |
151 | (void) fd; | 150 | (void) fd; |
152 | struct sway_server *server = data; | 151 | struct sway_server *server = data; |
153 | sway_log(SWAY_DEBUG, "Event on IPC listening socket"); | ||
154 | assert(mask == WL_EVENT_READABLE); | 152 | assert(mask == WL_EVENT_READABLE); |
155 | 153 | ||
156 | int client_fd = accept(ipc_socket, NULL, NULL); | 154 | int client_fd = accept(ipc_socket, NULL, NULL); |
@@ -211,13 +209,10 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { | |||
211 | } | 209 | } |
212 | 210 | ||
213 | if (mask & WL_EVENT_HANGUP) { | 211 | if (mask & WL_EVENT_HANGUP) { |
214 | sway_log(SWAY_DEBUG, "Client %d hung up", client->fd); | ||
215 | ipc_client_disconnect(client); | 212 | ipc_client_disconnect(client); |
216 | return 0; | 213 | return 0; |
217 | } | 214 | } |
218 | 215 | ||
219 | sway_log(SWAY_DEBUG, "Client %d readable", client->fd); | ||
220 | |||
221 | int read_available; | 216 | int read_available; |
222 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { | 217 | if (ioctl(client_fd, FIONREAD, &read_available) == -1) { |
223 | sway_log_errno(SWAY_INFO, "Unable to read IPC socket buffer size"); | 218 | sway_log_errno(SWAY_INFO, "Unable to read IPC socket buffer size"); |
@@ -513,6 +508,20 @@ void ipc_event_input(const char *change, struct sway_input_device *device) { | |||
513 | json_object_put(json); | 508 | json_object_put(json); |
514 | } | 509 | } |
515 | 510 | ||
511 | void ipc_event_output(void) { | ||
512 | if (!ipc_has_event_listeners(IPC_EVENT_OUTPUT)) { | ||
513 | return; | ||
514 | } | ||
515 | sway_log(SWAY_DEBUG, "Sending output event"); | ||
516 | |||
517 | json_object *json = json_object_new_object(); | ||
518 | json_object_object_add(json, "change", json_object_new_string("unspecified")); | ||
519 | |||
520 | const char *json_string = json_object_to_json_string(json); | ||
521 | ipc_send_event(json_string, IPC_EVENT_OUTPUT); | ||
522 | json_object_put(json); | ||
523 | } | ||
524 | |||
516 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | 525 | int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { |
517 | struct ipc_client *client = data; | 526 | struct ipc_client *client = data; |
518 | 527 | ||
@@ -523,7 +532,6 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
523 | } | 532 | } |
524 | 533 | ||
525 | if (mask & WL_EVENT_HANGUP) { | 534 | if (mask & WL_EVENT_HANGUP) { |
526 | sway_log(SWAY_DEBUG, "Client %d hung up", client->fd); | ||
527 | ipc_client_disconnect(client); | 535 | ipc_client_disconnect(client); |
528 | return 0; | 536 | return 0; |
529 | } | 537 | } |
@@ -532,8 +540,6 @@ int ipc_client_handle_writable(int client_fd, uint32_t mask, void *data) { | |||
532 | return 0; | 540 | return 0; |
533 | } | 541 | } |
534 | 542 | ||
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); | 543 | ssize_t written = write(client->fd, client->write_buffer, client->write_buffer_len); |
538 | 544 | ||
539 | if (written == -1 && errno == EAGAIN) { | 545 | if (written == -1 && errno == EAGAIN) { |
@@ -687,11 +693,17 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
687 | } | 693 | } |
688 | struct sway_output *output; | 694 | struct sway_output *output; |
689 | wl_list_for_each(output, &root->all_outputs, link) { | 695 | wl_list_for_each(output, &root->all_outputs, link) { |
690 | if (!output->enabled && output != root->noop_output) { | 696 | if (!output->enabled && output != root->fallback_output) { |
691 | json_object_array_add(outputs, | 697 | json_object_array_add(outputs, |
692 | ipc_json_describe_disabled_output(output)); | 698 | ipc_json_describe_disabled_output(output)); |
693 | } | 699 | } |
694 | } | 700 | } |
701 | |||
702 | for (int i = 0; i < root->non_desktop_outputs->length; i++) { | ||
703 | struct sway_output_non_desktop *non_desktop_output = root->non_desktop_outputs->items[i]; | ||
704 | json_object_array_add(outputs, ipc_json_describe_non_desktop_output(non_desktop_output)); | ||
705 | } | ||
706 | |||
695 | const char *json_string = json_object_to_json_string(outputs); | 707 | const char *json_string = json_object_to_json_string(outputs); |
696 | ipc_send_reply(client, payload_type, json_string, | 708 | ipc_send_reply(client, payload_type, json_string, |
697 | (uint32_t)strlen(json_string)); | 709 | (uint32_t)strlen(json_string)); |
@@ -727,6 +739,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)); | 739 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
728 | if (strcmp(event_type, "workspace") == 0) { | 740 | if (strcmp(event_type, "workspace") == 0) { |
729 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); | 741 | client->subscribed_events |= event_mask(IPC_EVENT_WORKSPACE); |
742 | } else if (strcmp(event_type, "output") == 0) { | ||
743 | client->subscribed_events |= event_mask(IPC_EVENT_OUTPUT); | ||
730 | } else if (strcmp(event_type, "barconfig_update") == 0) { | 744 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
731 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); | 745 | client->subscribed_events |= event_mask(IPC_EVENT_BARCONFIG_UPDATE); |
732 | } else if (strcmp(event_type, "bar_state_update") == 0) { | 746 | } else if (strcmp(event_type, "bar_state_update") == 0) { |
@@ -911,7 +925,6 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt | |||
911 | 925 | ||
912 | exit_cleanup: | 926 | exit_cleanup: |
913 | free(buf); | 927 | free(buf); |
914 | return; | ||
915 | } | 928 | } |
916 | 929 | ||
917 | bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_type, | 930 | bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_type, |
@@ -955,7 +968,5 @@ bool ipc_send_reply(struct ipc_client *client, enum ipc_command_type payload_typ | |||
955 | ipc_client_handle_writable, client); | 968 | ipc_client_handle_writable, client); |
956 | } | 969 | } |
957 | 970 | ||
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; | 971 | return true; |
961 | } | 972 | } |