summaryrefslogtreecommitdiffstats
path: root/sway/ipc-server.c
diff options
context:
space:
mode:
authorLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-21 15:28:34 +0100
committerLibravatar Mikkel Oscar Lyderik <mikkeloscar@gmail.com>2015-12-21 15:28:34 +0100
commit66c66c730436f325c6917b787b742af5e89102ab (patch)
tree652ecc369b72dcfa1265c7f0a9a7664470ba9ab2 /sway/ipc-server.c
parentHandle bar commands outside config file (diff)
downloadsway-66c66c730436f325c6917b787b742af5e89102ab.tar.gz
sway-66c66c730436f325c6917b787b742af5e89102ab.tar.zst
sway-66c66c730436f325c6917b787b742af5e89102ab.zip
Implement `barconfig_update` IPC event
Diffstat (limited to 'sway/ipc-server.c')
-rw-r--r--sway/ipc-server.c147
1 files changed, 87 insertions, 60 deletions
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);
43bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); 43bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length);
44void ipc_get_workspaces_callback(swayc_t *workspace, void *data); 44void ipc_get_workspaces_callback(swayc_t *workspace, void *data);
45void ipc_get_outputs_callback(swayc_t *container, void *data); 45void ipc_get_outputs_callback(swayc_t *container, void *data);
46json_object *ipc_json_describe_bar_config(struct bar_config *bar);
46 47
47void ipc_init(void) { 48void 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
499json_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
554void ipc_event_workspace(swayc_t *old, swayc_t *new) { 565void 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
585void 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}