diff options
-rw-r--r-- | include/ipc-server.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 5 | ||||
-rw-r--r-- | sway/ipc-server.c | 147 |
3 files changed, 92 insertions, 62 deletions
diff --git a/include/ipc-server.h b/include/ipc-server.h index 5ac255cf..9858d6f0 100644 --- a/include/ipc-server.h +++ b/include/ipc-server.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _SWAY_IPC_SERVER_H | 2 | #define _SWAY_IPC_SERVER_H |
3 | 3 | ||
4 | #include "container.h" | 4 | #include "container.h" |
5 | #include "config.h" | ||
5 | #include "ipc.h" | 6 | #include "ipc.h" |
6 | 7 | ||
7 | void ipc_init(void); | 8 | void ipc_init(void); |
@@ -9,6 +10,7 @@ void ipc_terminate(void); | |||
9 | struct sockaddr_un *ipc_user_sockaddr(void); | 10 | struct sockaddr_un *ipc_user_sockaddr(void); |
10 | 11 | ||
11 | void ipc_event_workspace(swayc_t *old, swayc_t *new); | 12 | void ipc_event_workspace(swayc_t *old, swayc_t *new); |
13 | void ipc_event_barconfig_update(struct bar_config *bar); | ||
12 | const char *swayc_type_string(enum swayc_types type); | 14 | const char *swayc_type_string(enum swayc_types type); |
13 | 15 | ||
14 | #endif | 16 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index de5b9705..93c74915 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "resize.h" | 25 | #include "resize.h" |
26 | #include "input_state.h" | 26 | #include "input_state.h" |
27 | #include "criteria.h" | 27 | #include "criteria.h" |
28 | #include "ipc-server.h" | ||
28 | 29 | ||
29 | typedef struct cmd_results *sway_cmd(int argc, char **argv); | 30 | typedef struct cmd_results *sway_cmd(int argc, char **argv); |
30 | 31 | ||
@@ -1707,7 +1708,7 @@ static struct cmd_results *bar_set_hidden_state(struct bar_config *bar, const ch | |||
1707 | 1708 | ||
1708 | if (strcmp(old_state, bar->hidden_state) != 0) { | 1709 | if (strcmp(old_state, bar->hidden_state) != 0) { |
1709 | if (!config->reading) { | 1710 | if (!config->reading) { |
1710 | // TODO: IPC event | 1711 | ipc_event_barconfig_update(bar); |
1711 | } | 1712 | } |
1712 | sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id); | 1713 | sway_log(L_DEBUG, "Setting hidden_state: '%s' for bar: %s", bar->hidden_state, bar->id); |
1713 | } | 1714 | } |
@@ -1779,7 +1780,7 @@ static struct cmd_results *bar_set_mode(struct bar_config *bar, const char *mode | |||
1779 | 1780 | ||
1780 | if (strcmp(old_mode, bar->mode) != 0) { | 1781 | if (strcmp(old_mode, bar->mode) != 0) { |
1781 | if (!config->reading) { | 1782 | if (!config->reading) { |
1782 | // TODO: IPC event | 1783 | ipc_event_barconfig_update(bar); |
1783 | } | 1784 | } |
1784 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); | 1785 | sway_log(L_DEBUG, "Setting mode: '%s' for bar: %s", bar->mode, bar->id); |
1785 | } | 1786 | } |
diff --git a/sway/ipc-server.c b/sway/ipc-server.c index 9dd3e1a5..96d4f945 100644 --- a/sway/ipc-server.c +++ b/sway/ipc-server.c | |||
@@ -43,6 +43,7 @@ void ipc_client_handle_command(struct ipc_client *client); | |||
43 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); | 43 | bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); |
44 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); | 44 | void ipc_get_workspaces_callback(swayc_t *workspace, void *data); |
45 | void ipc_get_outputs_callback(swayc_t *container, void *data); | 45 | void ipc_get_outputs_callback(swayc_t *container, void *data); |
46 | json_object *ipc_json_describe_bar_config(struct bar_config *bar); | ||
46 | 47 | ||
47 | void ipc_init(void) { | 48 | void ipc_init(void) { |
48 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); | 49 | ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); |
@@ -290,8 +291,9 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
290 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); | 291 | const char *event_type = json_object_get_string(json_object_array_get_idx(request, i)); |
291 | if (strcmp(event_type, "workspace") == 0) { | 292 | if (strcmp(event_type, "workspace") == 0) { |
292 | client->subscribed_events |= IPC_GET_WORKSPACES; | 293 | client->subscribed_events |= IPC_GET_WORKSPACES; |
293 | } | 294 | } else if (strcmp(event_type, "barconfig_update") == 0) { |
294 | else { | 295 | client->subscribed_events |= IPC_GET_BAR_CONFIG; |
296 | } else { | ||
295 | ipc_send_reply(client, "{\"success\": false}", 18); | 297 | ipc_send_reply(client, "{\"success\": false}", 18); |
296 | ipc_client_disconnect(client); | 298 | ipc_client_disconnect(client); |
297 | json_object_put(request); | 299 | json_object_put(request); |
@@ -397,64 +399,7 @@ void ipc_client_handle_command(struct ipc_client *client) { | |||
397 | ipc_send_reply(client, error, (uint32_t)strlen(error)); | 399 | ipc_send_reply(client, error, (uint32_t)strlen(error)); |
398 | break; | 400 | break; |
399 | } | 401 | } |
400 | json_object *json = json_object_new_object(); | 402 | json_object *json = ipc_json_describe_bar_config(bar); |
401 | json_object_object_add(json, "id", json_object_new_string(bar->id)); | ||
402 | json_object_object_add(json, "tray_output", NULL); | ||
403 | json_object_object_add(json, "mode", json_object_new_string(bar->mode)); | ||
404 | json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); | ||
405 | //json_object_object_add(json, "modifier", json_object_new_string(bar->modifier)); // TODO: Fix modifier | ||
406 | switch (bar->position) { | ||
407 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | ||
408 | json_object_object_add(json, "position", json_object_new_string("top")); | ||
409 | break; | ||
410 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: | ||
411 | json_object_object_add(json, "position", json_object_new_string("bottom")); | ||
412 | break; | ||
413 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: | ||
414 | json_object_object_add(json, "position", json_object_new_string("left")); | ||
415 | break; | ||
416 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: | ||
417 | json_object_object_add(json, "position", json_object_new_string("right")); | ||
418 | break; | ||
419 | } | ||
420 | json_object_object_add(json, "status_command", json_object_new_string(bar->status_command)); | ||
421 | json_object_object_add(json, "font", json_object_new_string(bar->font)); | ||
422 | if (bar->separator_symbol) { | ||
423 | json_object_object_add(json, "separator_symbol", json_object_new_string(bar->separator_symbol)); | ||
424 | } | ||
425 | json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); | ||
426 | json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); | ||
427 | json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); | ||
428 | json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); | ||
429 | json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose)); | ||
430 | |||
431 | json_object *colors = json_object_new_object(); | ||
432 | json_object_object_add(colors, "background", json_object_new_string(bar->colors.background)); | ||
433 | json_object_object_add(colors, "statusline", json_object_new_string(bar->colors.statusline)); | ||
434 | json_object_object_add(colors, "separator", json_object_new_string(bar->colors.separator)); | ||
435 | |||
436 | json_object_object_add(colors, "focused_workspace_border", json_object_new_string(bar->colors.focused_workspace_border)); | ||
437 | json_object_object_add(colors, "focused_workspace_bg", json_object_new_string(bar->colors.focused_workspace_bg)); | ||
438 | json_object_object_add(colors, "focused_workspace_text", json_object_new_string(bar->colors.focused_workspace_text)); | ||
439 | |||
440 | json_object_object_add(colors, "inactive_workspace_border", json_object_new_string(bar->colors.inactive_workspace_border)); | ||
441 | json_object_object_add(colors, "inactive_workspace_bg", json_object_new_string(bar->colors.inactive_workspace_bg)); | ||
442 | json_object_object_add(colors, "inactive_workspace_text", json_object_new_string(bar->colors.inactive_workspace_text)); | ||
443 | |||
444 | json_object_object_add(colors, "active_workspace_border", json_object_new_string(bar->colors.active_workspace_border)); | ||
445 | json_object_object_add(colors, "active_workspace_bg", json_object_new_string(bar->colors.active_workspace_bg)); | ||
446 | json_object_object_add(colors, "active_workspace_text", json_object_new_string(bar->colors.active_workspace_text)); | ||
447 | |||
448 | json_object_object_add(colors, "urgent_workspace_border", json_object_new_string(bar->colors.urgent_workspace_border)); | ||
449 | json_object_object_add(colors, "urgent_workspace_bg", json_object_new_string(bar->colors.urgent_workspace_bg)); | ||
450 | json_object_object_add(colors, "urgent_workspace_text", json_object_new_string(bar->colors.urgent_workspace_text)); | ||
451 | |||
452 | json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.binding_mode_border)); | ||
453 | json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.binding_mode_bg)); | ||
454 | json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.binding_mode_text)); | ||
455 | |||
456 | json_object_object_add(json, "colors", colors); | ||
457 | |||
458 | const char *json_string = json_object_to_json_string(json); | 403 | const char *json_string = json_object_to_json_string(json); |
459 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | 404 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); |
460 | json_object_put(json); // free | 405 | json_object_put(json); // free |
@@ -551,6 +496,72 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) { | |||
551 | } | 496 | } |
552 | } | 497 | } |
553 | 498 | ||
499 | json_object *ipc_json_describe_bar_config(struct bar_config *bar) { | ||
500 | if (!sway_assert(bar, "Bar must not be NULL")) { | ||
501 | return NULL; | ||
502 | } | ||
503 | |||
504 | json_object *json = json_object_new_object(); | ||
505 | json_object_object_add(json, "id", json_object_new_string(bar->id)); | ||
506 | json_object_object_add(json, "tray_output", NULL); | ||
507 | json_object_object_add(json, "mode", json_object_new_string(bar->mode)); | ||
508 | json_object_object_add(json, "hidden_state", json_object_new_string(bar->hidden_state)); | ||
509 | //json_object_object_add(json, "modifier", json_object_new_string(bar->modifier)); // TODO: Fix modifier | ||
510 | switch (bar->position) { | ||
511 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | ||
512 | json_object_object_add(json, "position", json_object_new_string("top")); | ||
513 | break; | ||
514 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: | ||
515 | json_object_object_add(json, "position", json_object_new_string("bottom")); | ||
516 | break; | ||
517 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: | ||
518 | json_object_object_add(json, "position", json_object_new_string("left")); | ||
519 | break; | ||
520 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: | ||
521 | json_object_object_add(json, "position", json_object_new_string("right")); | ||
522 | break; | ||
523 | } | ||
524 | json_object_object_add(json, "status_command", json_object_new_string(bar->status_command)); | ||
525 | json_object_object_add(json, "font", json_object_new_string(bar->font)); | ||
526 | if (bar->separator_symbol) { | ||
527 | json_object_object_add(json, "separator_symbol", json_object_new_string(bar->separator_symbol)); | ||
528 | } | ||
529 | json_object_object_add(json, "bar_height", json_object_new_int(bar->height)); | ||
530 | json_object_object_add(json, "workspace_buttons", json_object_new_boolean(bar->workspace_buttons)); | ||
531 | json_object_object_add(json, "strip_workspace_numbers", json_object_new_boolean(bar->strip_workspace_numbers)); | ||
532 | json_object_object_add(json, "binding_mode_indicator", json_object_new_boolean(bar->binding_mode_indicator)); | ||
533 | json_object_object_add(json, "verbose", json_object_new_boolean(bar->verbose)); | ||
534 | |||
535 | json_object *colors = json_object_new_object(); | ||
536 | json_object_object_add(colors, "background", json_object_new_string(bar->colors.background)); | ||
537 | json_object_object_add(colors, "statusline", json_object_new_string(bar->colors.statusline)); | ||
538 | json_object_object_add(colors, "separator", json_object_new_string(bar->colors.separator)); | ||
539 | |||
540 | json_object_object_add(colors, "focused_workspace_border", json_object_new_string(bar->colors.focused_workspace_border)); | ||
541 | json_object_object_add(colors, "focused_workspace_bg", json_object_new_string(bar->colors.focused_workspace_bg)); | ||
542 | json_object_object_add(colors, "focused_workspace_text", json_object_new_string(bar->colors.focused_workspace_text)); | ||
543 | |||
544 | json_object_object_add(colors, "inactive_workspace_border", json_object_new_string(bar->colors.inactive_workspace_border)); | ||
545 | json_object_object_add(colors, "inactive_workspace_bg", json_object_new_string(bar->colors.inactive_workspace_bg)); | ||
546 | json_object_object_add(colors, "inactive_workspace_text", json_object_new_string(bar->colors.inactive_workspace_text)); | ||
547 | |||
548 | json_object_object_add(colors, "active_workspace_border", json_object_new_string(bar->colors.active_workspace_border)); | ||
549 | json_object_object_add(colors, "active_workspace_bg", json_object_new_string(bar->colors.active_workspace_bg)); | ||
550 | json_object_object_add(colors, "active_workspace_text", json_object_new_string(bar->colors.active_workspace_text)); | ||
551 | |||
552 | json_object_object_add(colors, "urgent_workspace_border", json_object_new_string(bar->colors.urgent_workspace_border)); | ||
553 | json_object_object_add(colors, "urgent_workspace_bg", json_object_new_string(bar->colors.urgent_workspace_bg)); | ||
554 | json_object_object_add(colors, "urgent_workspace_text", json_object_new_string(bar->colors.urgent_workspace_text)); | ||
555 | |||
556 | json_object_object_add(colors, "binding_mode_border", json_object_new_string(bar->colors.binding_mode_border)); | ||
557 | json_object_object_add(colors, "binding_mode_bg", json_object_new_string(bar->colors.binding_mode_bg)); | ||
558 | json_object_object_add(colors, "binding_mode_text", json_object_new_string(bar->colors.binding_mode_text)); | ||
559 | |||
560 | json_object_object_add(json, "colors", colors); | ||
561 | |||
562 | return json; | ||
563 | } | ||
564 | |||
554 | void ipc_event_workspace(swayc_t *old, swayc_t *new) { | 565 | void ipc_event_workspace(swayc_t *old, swayc_t *new) { |
555 | json_object *obj = json_object_new_object(); | 566 | json_object *obj = json_object_new_object(); |
556 | json_object_object_add(obj, "change", json_object_new_string("focus")); | 567 | json_object_object_add(obj, "change", json_object_new_string("focus")); |
@@ -570,3 +581,19 @@ void ipc_event_workspace(swayc_t *old, swayc_t *new) { | |||
570 | 581 | ||
571 | json_object_put(obj); // free | 582 | json_object_put(obj); // free |
572 | } | 583 | } |
584 | |||
585 | void ipc_event_barconfig_update(struct bar_config *bar) { | ||
586 | json_object *json = ipc_json_describe_bar_config(bar); | ||
587 | const char *json_string = json_object_to_json_string(json); | ||
588 | int i; | ||
589 | struct ipc_client *client; | ||
590 | for (i = 0; i < ipc_client_list->length; ++i) { | ||
591 | client = ipc_client_list->items[i]; | ||
592 | if ((client->subscribed_events & IPC_GET_BAR_CONFIG) == 0) { | ||
593 | continue; | ||
594 | } | ||
595 | ipc_send_reply(client, json_string, (uint32_t)strlen(json_string)); | ||
596 | } | ||
597 | |||
598 | json_object_put(json); // free | ||
599 | } | ||