aboutsummaryrefslogtreecommitdiffstats
path: root/sway/ipc-json.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/ipc-json.c')
-rw-r--r--sway/ipc-json.c132
1 files changed, 76 insertions, 56 deletions
diff --git a/sway/ipc-json.c b/sway/ipc-json.c
index fceee84d..6c438424 100644
--- a/sway/ipc-json.c
+++ b/sway/ipc-json.c
@@ -1,3 +1,4 @@
1#include <float.h>
1#include <json.h> 2#include <json.h>
2#include <libevdev/libevdev.h> 3#include <libevdev/libevdev.h>
3#include <stdio.h> 4#include <stdio.h>
@@ -23,6 +24,20 @@
23static const int i3_output_id = INT32_MAX; 24static const int i3_output_id = INT32_MAX;
24static const int i3_scratch_id = INT32_MAX - 1; 25static const int i3_scratch_id = INT32_MAX - 1;
25 26
27static const char *ipc_json_node_type_description(enum sway_node_type node_type) {
28 switch (node_type) {
29 case N_ROOT:
30 return "root";
31 case N_OUTPUT:
32 return "output";
33 case N_WORKSPACE:
34 return "workspace";
35 case N_CONTAINER:
36 return "con";
37 }
38 return "none";
39}
40
26static const char *ipc_json_layout_description(enum sway_container_layout l) { 41static const char *ipc_json_layout_description(enum sway_container_layout l) {
27 switch (l) { 42 switch (l) {
28 case L_VERT: 43 case L_VERT:
@@ -189,16 +204,22 @@ static json_object *ipc_json_create_empty_rect(void) {
189 return ipc_json_create_rect(&empty); 204 return ipc_json_create_rect(&empty);
190} 205}
191 206
192static json_object *ipc_json_create_node(int id, char *name, 207static json_object *ipc_json_create_node(int id, const char* type, char *name,
193 bool focused, json_object *focus, struct wlr_box *box) { 208 bool focused, json_object *focus, struct wlr_box *box) {
194 json_object *object = json_object_new_object(); 209 json_object *object = json_object_new_object();
195 210
196 json_object_object_add(object, "id", json_object_new_int(id)); 211 json_object_object_add(object, "id", json_object_new_int(id));
197 json_object_object_add(object, "name", 212 json_object_object_add(object, "type", json_object_new_string(type));
198 name ? json_object_new_string(name) : NULL); 213 json_object_object_add(object, "orientation",
199 json_object_object_add(object, "rect", ipc_json_create_rect(box)); 214 json_object_new_string(
215 ipc_json_orientation_description(L_HORIZ)));
216 json_object_object_add(object, "percent", NULL);
217 json_object_object_add(object, "urgent", json_object_new_boolean(false));
218 json_object_object_add(object, "marks", json_object_new_array());
200 json_object_object_add(object, "focused", json_object_new_boolean(focused)); 219 json_object_object_add(object, "focused", json_object_new_boolean(focused));
201 json_object_object_add(object, "focus", focus); 220 json_object_object_add(object, "layout",
221 json_object_new_string(
222 ipc_json_layout_description(L_HORIZ)));
202 223
203 // set default values to be compatible with i3 224 // set default values to be compatible with i3
204 json_object_object_add(object, "border", 225 json_object_object_add(object, "border",
@@ -206,35 +227,25 @@ static json_object *ipc_json_create_node(int id, char *name,
206 ipc_json_border_description(B_NONE))); 227 ipc_json_border_description(B_NONE)));
207 json_object_object_add(object, "current_border_width", 228 json_object_object_add(object, "current_border_width",
208 json_object_new_int(0)); 229 json_object_new_int(0));
209 json_object_object_add(object, "layout", 230 json_object_object_add(object, "rect", ipc_json_create_rect(box));
210 json_object_new_string(
211 ipc_json_layout_description(L_HORIZ)));
212 json_object_object_add(object, "orientation",
213 json_object_new_string(
214 ipc_json_orientation_description(L_HORIZ)));
215 json_object_object_add(object, "percent", NULL);
216 json_object_object_add(object, "window_rect", ipc_json_create_empty_rect());
217 json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect()); 231 json_object_object_add(object, "deco_rect", ipc_json_create_empty_rect());
232 json_object_object_add(object, "window_rect", ipc_json_create_empty_rect());
218 json_object_object_add(object, "geometry", ipc_json_create_empty_rect()); 233 json_object_object_add(object, "geometry", ipc_json_create_empty_rect());
234 json_object_object_add(object, "name",
235 name ? json_object_new_string(name) : NULL);
219 json_object_object_add(object, "window", NULL); 236 json_object_object_add(object, "window", NULL);
220 json_object_object_add(object, "urgent", json_object_new_boolean(false));
221 json_object_object_add(object, "marks", json_object_new_array());
222 json_object_object_add(object, "fullscreen_mode", json_object_new_int(0));
223 json_object_object_add(object, "nodes", json_object_new_array()); 237 json_object_object_add(object, "nodes", json_object_new_array());
224 json_object_object_add(object, "floating_nodes", json_object_new_array()); 238 json_object_object_add(object, "floating_nodes", json_object_new_array());
239 json_object_object_add(object, "focus", focus);
240 json_object_object_add(object, "fullscreen_mode", json_object_new_int(0));
225 json_object_object_add(object, "sticky", json_object_new_boolean(false)); 241 json_object_object_add(object, "sticky", json_object_new_boolean(false));
226 242
227 return object; 243 return object;
228} 244}
229 245
230static void ipc_json_describe_root(struct sway_root *root, json_object *object) {
231 json_object_object_add(object, "type", json_object_new_string("root"));
232}
233
234static void ipc_json_describe_output(struct sway_output *output, 246static void ipc_json_describe_output(struct sway_output *output,
235 json_object *object) { 247 json_object *object) {
236 struct wlr_output *wlr_output = output->wlr_output; 248 struct wlr_output *wlr_output = output->wlr_output;
237 json_object_object_add(object, "type", json_object_new_string("output"));
238 json_object_object_add(object, "active", json_object_new_boolean(true)); 249 json_object_object_add(object, "active", json_object_new_boolean(true));
239 json_object_object_add(object, "dpms", 250 json_object_object_add(object, "dpms",
240 json_object_new_boolean(wlr_output->enabled)); 251 json_object_new_boolean(wlr_output->enabled));
@@ -369,11 +380,9 @@ static json_object *ipc_json_describe_scratchpad_output(void) {
369 json_object_new_int(container->node.id)); 380 json_object_new_int(container->node.id));
370 } 381 }
371 382
372 json_object *workspace = ipc_json_create_node(i3_scratch_id, 383 json_object *workspace = ipc_json_create_node(i3_scratch_id, "workspace",
373 "__i3_scratch", false, workspace_focus, &box); 384 "__i3_scratch", false, workspace_focus, &box);
374 json_object_object_add(workspace, "fullscreen_mode", json_object_new_int(1)); 385 json_object_object_add(workspace, "fullscreen_mode", json_object_new_int(1));
375 json_object_object_add(workspace, "type",
376 json_object_new_string("workspace"));
377 386
378 // List all hidden scratchpad containers as floating nodes 387 // List all hidden scratchpad containers as floating nodes
379 json_object *floating_array = json_object_new_array(); 388 json_object *floating_array = json_object_new_array();
@@ -390,10 +399,8 @@ static json_object *ipc_json_describe_scratchpad_output(void) {
390 json_object *output_focus = json_object_new_array(); 399 json_object *output_focus = json_object_new_array();
391 json_object_array_add(output_focus, json_object_new_int(i3_scratch_id)); 400 json_object_array_add(output_focus, json_object_new_int(i3_scratch_id));
392 401
393 json_object *output = ipc_json_create_node(i3_output_id, 402 json_object *output = ipc_json_create_node(i3_output_id, "output",
394 "__i3", false, output_focus, &box); 403 "__i3", false, output_focus, &box);
395 json_object_object_add(output, "type",
396 json_object_new_string("output"));
397 json_object_object_add(output, "layout", 404 json_object_object_add(output, "layout",
398 json_object_new_string("output")); 405 json_object_new_string("output"));
399 406
@@ -423,7 +430,6 @@ static void ipc_json_describe_workspace(struct sway_workspace *workspace,
423 json_object_object_add(object, "fullscreen_mode", json_object_new_int(1)); 430 json_object_object_add(object, "fullscreen_mode", json_object_new_int(1));
424 json_object_object_add(object, "output", workspace->output ? 431 json_object_object_add(object, "output", workspace->output ?
425 json_object_new_string(workspace->output->wlr_output->name) : NULL); 432 json_object_new_string(workspace->output->wlr_output->name) : NULL);
426 json_object_object_add(object, "type", json_object_new_string("workspace"));
427 json_object_object_add(object, "urgent", 433 json_object_object_add(object, "urgent",
428 json_object_new_boolean(workspace->urgent)); 434 json_object_new_boolean(workspace->urgent));
429 json_object_object_add(object, "representation", workspace->representation ? 435 json_object_object_add(object, "representation", workspace->representation ?
@@ -451,27 +457,27 @@ static void get_deco_rect(struct sway_container *c, struct wlr_box *deco_rect) {
451 bool tab_or_stack = parent_layout == L_TABBED || parent_layout == L_STACKED; 457 bool tab_or_stack = parent_layout == L_TABBED || parent_layout == L_STACKED;
452 if (((!tab_or_stack || container_is_floating(c)) && 458 if (((!tab_or_stack || container_is_floating(c)) &&
453 c->current.border != B_NORMAL) || 459 c->current.border != B_NORMAL) ||
454 c->fullscreen_mode != FULLSCREEN_NONE || 460 c->pending.fullscreen_mode != FULLSCREEN_NONE ||
455 c->workspace == NULL) { 461 c->pending.workspace == NULL) {
456 deco_rect->x = deco_rect->y = deco_rect->width = deco_rect->height = 0; 462 deco_rect->x = deco_rect->y = deco_rect->width = deco_rect->height = 0;
457 return; 463 return;
458 } 464 }
459 465
460 if (c->parent) { 466 if (c->pending.parent) {
461 deco_rect->x = c->x - c->parent->x; 467 deco_rect->x = c->pending.x - c->pending.parent->pending.x;
462 deco_rect->y = c->y - c->parent->y; 468 deco_rect->y = c->pending.y - c->pending.parent->pending.y;
463 } else { 469 } else {
464 deco_rect->x = c->x - c->workspace->x; 470 deco_rect->x = c->pending.x - c->pending.workspace->x;
465 deco_rect->y = c->y - c->workspace->y; 471 deco_rect->y = c->pending.y - c->pending.workspace->y;
466 } 472 }
467 deco_rect->width = c->width; 473 deco_rect->width = c->pending.width;
468 deco_rect->height = container_titlebar_height(); 474 deco_rect->height = container_titlebar_height();
469 475
470 if (!container_is_floating(c)) { 476 if (!container_is_floating(c)) {
471 if (parent_layout == L_TABBED) { 477 if (parent_layout == L_TABBED) {
472 deco_rect->width = c->parent 478 deco_rect->width = c->pending.parent
473 ? c->parent->width / c->parent->children->length 479 ? c->pending.parent->pending.width / c->pending.parent->pending.children->length
474 : c->workspace->width / c->workspace->tiling->length; 480 : c->pending.workspace->width / c->pending.workspace->tiling->length;
475 deco_rect->x += deco_rect->width * container_sibling_index(c); 481 deco_rect->x += deco_rect->width * container_sibling_index(c);
476 } else if (parent_layout == L_STACKED) { 482 } else if (parent_layout == L_STACKED) {
477 if (!c->view) { 483 if (!c->view) {
@@ -494,10 +500,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
494 json_object_object_add(object, "visible", json_object_new_boolean(visible)); 500 json_object_object_add(object, "visible", json_object_new_boolean(visible));
495 501
496 struct wlr_box window_box = { 502 struct wlr_box window_box = {
497 c->content_x - c->x, 503 c->pending.content_x - c->pending.x,
498 (c->current.border == B_PIXEL) ? c->current.border_thickness : 0, 504 (c->current.border == B_PIXEL) ? c->current.border_thickness : 0,
499 c->content_width, 505 c->pending.content_width,
500 c->content_height 506 c->pending.content_height
501 }; 507 };
502 508
503 json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box)); 509 json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box));
@@ -583,16 +589,18 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
583static void ipc_json_describe_container(struct sway_container *c, json_object *object) { 589static void ipc_json_describe_container(struct sway_container *c, json_object *object) {
584 json_object_object_add(object, "name", 590 json_object_object_add(object, "name",
585 c->title ? json_object_new_string(c->title) : NULL); 591 c->title ? json_object_new_string(c->title) : NULL);
586 json_object_object_add(object, "type", 592 if (container_is_floating(c)) {
587 json_object_new_string(container_is_floating(c) ? "floating_con" : "con")); 593 json_object_object_add(object, "type",
594 json_object_new_string("floating_con"));
595 }
588 596
589 json_object_object_add(object, "layout", 597 json_object_object_add(object, "layout",
590 json_object_new_string( 598 json_object_new_string(
591 ipc_json_layout_description(c->layout))); 599 ipc_json_layout_description(c->pending.layout)));
592 600
593 json_object_object_add(object, "orientation", 601 json_object_object_add(object, "orientation",
594 json_object_new_string( 602 json_object_new_string(
595 ipc_json_orientation_description(c->layout))); 603 ipc_json_orientation_description(c->pending.layout)));
596 604
597 bool urgent = c->view ? 605 bool urgent = c->view ?
598 view_is_urgent(c->view) : container_has_urgent_child(c); 606 view_is_urgent(c->view) : container_has_urgent_child(c);
@@ -600,7 +608,7 @@ static void ipc_json_describe_container(struct sway_container *c, json_object *o
600 json_object_object_add(object, "sticky", json_object_new_boolean(c->is_sticky)); 608 json_object_object_add(object, "sticky", json_object_new_boolean(c->is_sticky));
601 609
602 json_object_object_add(object, "fullscreen_mode", 610 json_object_object_add(object, "fullscreen_mode",
603 json_object_new_int(c->fullscreen_mode)); 611 json_object_new_int(c->pending.fullscreen_mode));
604 612
605 struct sway_node *parent = node_get_parent(&c->node); 613 struct sway_node *parent = node_get_parent(&c->node);
606 struct wlr_box parent_box = {0, 0, 0, 0}; 614 struct wlr_box parent_box = {0, 0, 0, 0};
@@ -610,8 +618,8 @@ static void ipc_json_describe_container(struct sway_container *c, json_object *o
610 } 618 }
611 619
612 if (parent_box.width != 0 && parent_box.height != 0) { 620 if (parent_box.width != 0 && parent_box.height != 0) {
613 double percent = ((double)c->width / parent_box.width) 621 double percent = ((double)c->pending.width / parent_box.width)
614 * ((double)c->height / parent_box.height); 622 * ((double)c->pending.height / parent_box.height);
615 json_object_object_add(object, "percent", json_object_new_double(percent)); 623 json_object_object_add(object, "percent", json_object_new_double(percent));
616 } 624 }
617 625
@@ -692,12 +700,11 @@ json_object *ipc_json_describe_node(struct sway_node *node) {
692 }; 700 };
693 seat_for_each_node(seat, focus_inactive_children_iterator, &data); 701 seat_for_each_node(seat, focus_inactive_children_iterator, &data);
694 702
695 json_object *object = ipc_json_create_node( 703 json_object *object = ipc_json_create_node((int)node->id,
696 (int)node->id, name, focused, focus, &box); 704 ipc_json_node_type_description(node->type), name, focused, focus, &box);
697 705
698 switch (node->type) { 706 switch (node->type) {
699 case N_ROOT: 707 case N_ROOT:
700 ipc_json_describe_root(root, object);
701 break; 708 break;
702 case N_OUTPUT: 709 case N_OUTPUT:
703 ipc_json_describe_output(node->sway_output, object); 710 ipc_json_describe_output(node->sway_output, object);
@@ -743,10 +750,10 @@ json_object *ipc_json_describe_node_recursive(struct sway_node *node) {
743 } 750 }
744 break; 751 break;
745 case N_CONTAINER: 752 case N_CONTAINER:
746 if (node->sway_container->children) { 753 if (node->sway_container->pending.children) {
747 for (i = 0; i < node->sway_container->children->length; ++i) { 754 for (i = 0; i < node->sway_container->pending.children->length; ++i) {
748 struct sway_container *child = 755 struct sway_container *child =
749 node->sway_container->children->items[i]; 756 node->sway_container->pending.children->items[i];
750 json_object_array_add(children, 757 json_object_array_add(children,
751 ipc_json_describe_node_recursive(&child->node)); 758 ipc_json_describe_node_recursive(&child->node));
752 } 759 }
@@ -996,6 +1003,17 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) {
996 } 1003 }
997 } 1004 }
998 1005
1006 if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER) {
1007 struct input_config *ic = input_device_get_config(device);
1008 float scroll_factor = 1.0f;
1009 if (ic != NULL && !isnan(ic->scroll_factor) &&
1010 ic->scroll_factor != FLT_MIN) {
1011 scroll_factor = ic->scroll_factor;
1012 }
1013 json_object_object_add(object, "scroll_factor",
1014 json_object_new_double(scroll_factor));
1015 }
1016
999 if (wlr_input_device_is_libinput(device->wlr_device)) { 1017 if (wlr_input_device_is_libinput(device->wlr_device)) {
1000 struct libinput_device *libinput_dev; 1018 struct libinput_device *libinput_dev;
1001 libinput_dev = wlr_libinput_get_device_handle(device->wlr_device); 1019 libinput_dev = wlr_libinput_get_device_handle(device->wlr_device);
@@ -1109,7 +1127,9 @@ json_object *ipc_json_describe_bar_config(struct bar_config *bar) {
1109 json_object_object_add(json, "verbose", 1127 json_object_object_add(json, "verbose",
1110 json_object_new_boolean(bar->verbose)); 1128 json_object_new_boolean(bar->verbose));
1111 json_object_object_add(json, "pango_markup", 1129 json_object_object_add(json, "pango_markup",
1112 json_object_new_boolean(bar->pango_markup)); 1130 json_object_new_boolean(bar->pango_markup == PANGO_MARKUP_DEFAULT
1131 ? config->pango_markup
1132 : bar->pango_markup));
1113 1133
1114 json_object *colors = json_object_new_object(); 1134 json_object *colors = json_object_new_object();
1115 json_object_object_add(colors, "background", 1135 json_object_object_add(colors, "background",