@@ -1446,3 +1446,142 @@ json_object *ipc_json_get_binding_mode(void) {
1446
1446
json_object_new_string (config -> current_mode -> name ));
1447
1447
return current_mode ;
1448
1448
}
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
+ }
0 commit comments