Skip to content

Commit 18ec0de

Browse files
committed
Introduce scene tree dumping mechanic
1 parent a624cce commit 18ec0de

File tree

5 files changed

+155
-0
lines changed

5 files changed

+155
-0
lines changed

include/ipc.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum ipc_command_type {
1818
IPC_SEND_TICK = 10,
1919
IPC_SYNC = 11,
2020
IPC_GET_BINDING_STATE = 12,
21+
IPC_GET_SCENE_TREE = 13,
2122

2223
// sway-specific command types
2324
IPC_GET_INPUTS = 100,

include/sway/ipc-json.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "sway/tree/container.h"
66
#include "sway/input/input-manager.h"
77

8+
#include <wlr/types/wlr_scene.h>
9+
810
json_object *ipc_json_get_version(void);
911

1012
json_object *ipc_json_get_binding_mode(void);
@@ -16,5 +18,6 @@ json_object *ipc_json_describe_node_recursive(struct sway_node *node);
1618
json_object *ipc_json_describe_input(struct sway_input_device *device);
1719
json_object *ipc_json_describe_seat(struct sway_seat *seat);
1820
json_object *ipc_json_describe_bar_config(struct bar_config *bar);
21+
json_object *ipc_json_describe_scene(struct wlr_scene *scene);
1922

2023
#endif

sway/ipc-json.c

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,3 +1446,142 @@ json_object *ipc_json_get_binding_mode(void) {
14461446
json_object_new_string(config->current_mode->name));
14471447
return current_mode;
14481448
}
1449+
1450+
#include "sway/scene_descriptor.h"
1451+
1452+
static enum sway_scene_descriptor_type types[] = {
1453+
SWAY_SCENE_DESC_BUFFER_TIMER,
1454+
SWAY_SCENE_DESC_NON_INTERACTIVE,
1455+
SWAY_SCENE_DESC_CONTAINER,
1456+
SWAY_SCENE_DESC_VIEW,
1457+
SWAY_SCENE_DESC_LAYER_SHELL,
1458+
SWAY_SCENE_DESC_XWAYLAND_UNMANAGED,
1459+
SWAY_SCENE_DESC_POPUP,
1460+
SWAY_SCENE_DESC_DRAG_ICON,
1461+
};
1462+
1463+
static json_object *describe_scene_tree(struct wlr_scene_tree *tree) {
1464+
json_object *object = json_object_new_array();
1465+
1466+
struct wlr_scene_node *node;
1467+
wl_list_for_each(node, &tree->children, link) {
1468+
json_object *json_node = json_object_new_object();
1469+
1470+
json_object_object_add(json_node, "x", json_object_new_int(node->x));
1471+
json_object_object_add(json_node, "y", json_object_new_int(node->y));
1472+
json_object_object_add(json_node, "enabled",
1473+
json_object_new_boolean(node->enabled));
1474+
1475+
const char *type_string = "";
1476+
switch (node->type) {
1477+
case WLR_SCENE_NODE_TREE:;
1478+
type_string = "WLR_SCENE_NODE_TREE";
1479+
struct wlr_scene_tree *tree = (struct wlr_scene_tree *) node;
1480+
json_object_object_add(json_node, "tree",
1481+
describe_scene_tree(tree));
1482+
break;
1483+
case WLR_SCENE_NODE_BUFFER:;
1484+
type_string = "WLR_SCENE_NODE_BUFFER";
1485+
struct wlr_scene_buffer *buffer = (struct wlr_scene_buffer *) node;
1486+
json_object_object_add(json_node, "has_raster",
1487+
json_object_new_boolean(buffer->raster != NULL));
1488+
json_object_object_add(json_node, "is_surface",
1489+
json_object_new_boolean(wlr_scene_surface_try_from_buffer(buffer) != NULL));
1490+
break;
1491+
case WLR_SCENE_NODE_RECT:;
1492+
type_string = "WLR_SCENE_NODE_RECT";
1493+
struct wlr_scene_rect *rect = (struct wlr_scene_rect *) node;
1494+
json_object_object_add(json_node, "width",
1495+
json_object_new_int(rect->width));
1496+
json_object_object_add(json_node, "height",
1497+
json_object_new_int(rect->height));
1498+
json_object_object_add(json_node, "red",
1499+
json_object_new_double(rect->color[0]));
1500+
json_object_object_add(json_node, "green",
1501+
json_object_new_double(rect->color[1]));
1502+
json_object_object_add(json_node, "blue",
1503+
json_object_new_double(rect->color[2]));
1504+
json_object_object_add(json_node, "alpha",
1505+
json_object_new_double(rect->color[3]));
1506+
break;
1507+
}
1508+
json_object_object_add(json_node, "type",
1509+
json_object_new_string(type_string));
1510+
1511+
json_object *descriptors = json_object_new_array();
1512+
1513+
for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); i++) {
1514+
enum sway_scene_descriptor_type type = types[i];
1515+
void *data = scene_descriptor_try_get(node, type);
1516+
if (!data) {
1517+
continue;
1518+
}
1519+
1520+
json_object *json_node_data = json_object_new_object();
1521+
1522+
const char *type_string = "";
1523+
switch (type) {
1524+
case SWAY_SCENE_DESC_BUFFER_TIMER:;
1525+
type_string = "SWAY_SCENE_DESC_BUFFER_TIMER";
1526+
break;
1527+
case SWAY_SCENE_DESC_NON_INTERACTIVE:;
1528+
type_string = "SWAY_SCENE_DESC_NON_INTERACTIVE";
1529+
break;
1530+
case SWAY_SCENE_DESC_CONTAINER:;
1531+
type_string = "SWAY_SCENE_DESC_CONTAINER";
1532+
struct sway_container *con = data;
1533+
1534+
if (con->formatted_title) {
1535+
json_object_object_add(json_node_data, "name",
1536+
json_object_new_string(con->formatted_title));
1537+
}
1538+
break;
1539+
case SWAY_SCENE_DESC_VIEW:;
1540+
type_string = "SWAY_SCENE_DESC_VIEW";
1541+
break;
1542+
case SWAY_SCENE_DESC_LAYER_SHELL:;
1543+
type_string = "SWAY_SCENE_DESC_LAYER_SHELL";
1544+
break;
1545+
case SWAY_SCENE_DESC_XWAYLAND_UNMANAGED:;
1546+
type_string = "SWAY_SCENE_DESC_XWAYLAND_UNMANAGED";
1547+
break;
1548+
case SWAY_SCENE_DESC_POPUP:;
1549+
type_string = "SWAY_SCENE_DESC_POPUP";
1550+
break;
1551+
case SWAY_SCENE_DESC_DRAG_ICON:;
1552+
type_string = "SWAY_SCENE_DESC_DRAG_ICON";
1553+
break;
1554+
}
1555+
json_object_object_add(json_node_data, "type",
1556+
json_object_new_string(type_string));
1557+
1558+
json_object_array_add(descriptors, json_node_data);
1559+
}
1560+
1561+
json_object_object_add(json_node, "descriptors", descriptors);
1562+
json_object_array_add(object, json_node);
1563+
}
1564+
1565+
return object;
1566+
}
1567+
1568+
json_object *ipc_json_describe_scene(struct wlr_scene *scene) {
1569+
json_object *object = json_object_new_object();
1570+
json_object *json_outputs = json_object_new_array();
1571+
1572+
struct wlr_scene_output *output;
1573+
wl_list_for_each(output, &scene->outputs, link) {
1574+
json_object *json_output = json_object_new_object();
1575+
1576+
json_object_object_add(json_output, "x", json_object_new_int(output->x));
1577+
json_object_object_add(json_output, "y", json_object_new_int(output->y));
1578+
json_object_object_add(json_output, "enabled",
1579+
json_object_new_boolean(output->output->enabled));
1580+
1581+
json_object_array_add(json_outputs, json_output);
1582+
}
1583+
1584+
json_object_object_add(object, "outputs", json_outputs);
1585+
json_object_object_add(object, "tree", describe_scene_tree(&scene->tree));
1586+
return object;
1587+
}

sway/ipc-server.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,16 @@ void ipc_client_handle_command(struct ipc_client *client, uint32_t payload_lengt
815815
goto exit_cleanup;
816816
}
817817

818+
case IPC_GET_SCENE_TREE:
819+
{
820+
json_object *tree = ipc_json_describe_scene(root->root_scene);
821+
const char *json_string = json_object_to_json_string(tree);
822+
ipc_send_reply(client, payload_type, json_string,
823+
(uint32_t)strlen(json_string));
824+
json_object_put(tree);
825+
goto exit_cleanup;
826+
}
827+
818828
case IPC_GET_MARKS:
819829
{
820830
json_object *marks = json_object_new_array();

swaymsg/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ int main(int argc, char **argv) {
512512
type = IPC_GET_OUTPUTS;
513513
} else if (strcasecmp(cmdtype, "get_tree") == 0) {
514514
type = IPC_GET_TREE;
515+
} else if (strcasecmp(cmdtype, "get_scene_tree") == 0) {
516+
type = IPC_GET_SCENE_TREE;
515517
} else if (strcasecmp(cmdtype, "get_marks") == 0) {
516518
type = IPC_GET_MARKS;
517519
} else if (strcasecmp(cmdtype, "get_bar_config") == 0) {

0 commit comments

Comments
 (0)