aboutsummaryrefslogtreecommitdiffstats
path: root/sway/debug-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/debug-tree.c')
-rw-r--r--sway/debug-tree.c161
1 files changed, 0 insertions, 161 deletions
diff --git a/sway/debug-tree.c b/sway/debug-tree.c
deleted file mode 100644
index 0444bb3f..00000000
--- a/sway/debug-tree.c
+++ /dev/null
@@ -1,161 +0,0 @@
1#include <pango/pangocairo.h>
2#include <wlr/backend.h>
3#include <wlr/render/wlr_texture.h>
4#include "config.h"
5#include "sway/debug.h"
6#include "sway/input/input-manager.h"
7#include "sway/input/seat.h"
8#include "sway/output.h"
9#include "sway/server.h"
10#include "sway/tree/container.h"
11#include "sway/tree/root.h"
12#include "sway/tree/workspace.h"
13#include "cairo.h"
14#include "config.h"
15#include "pango.h"
16
17struct sway_debug debug;
18
19static const char *layout_to_str(enum sway_container_layout layout) {
20 switch (layout) {
21 case L_HORIZ:
22 return "L_HORIZ";
23 case L_VERT:
24 return "L_VERT";
25 case L_STACKED:
26 return "L_STACKED";
27 case L_TABBED:
28 return "L_TABBED";
29 case L_NONE:
30 return "L_NONE";
31 }
32 return "L_NONE";
33}
34
35static char *get_string(struct sway_node *node) {
36 char *buffer = malloc(512);
37 switch (node->type) {
38 case N_ROOT:
39 snprintf(buffer, 512, "N_ROOT id:%zd %.fx%.f@%.f,%.f", node->id,
40 root->width, root->height, root->x, root->y);
41 break;
42 case N_OUTPUT:
43 snprintf(buffer, 512, "N_OUTPUT id:%zd '%s' %dx%d@%d,%d", node->id,
44 node->sway_output->wlr_output->name,
45 node->sway_output->width,
46 node->sway_output->height,
47 node->sway_output->lx,
48 node->sway_output->ly);
49 break;
50 case N_WORKSPACE:
51 snprintf(buffer, 512, "N_WORKSPACE id:%zd '%s' %s %dx%d@%.f,%.f",
52 node->id, node->sway_workspace->name,
53 layout_to_str(node->sway_workspace->layout),
54 node->sway_workspace->width, node->sway_workspace->height,
55 node->sway_workspace->x, node->sway_workspace->y);
56 break;
57 case N_CONTAINER:
58 snprintf(buffer, 512, "N_CONTAINER id:%zd '%s' %s %.fx%.f@%.f,%.f",
59 node->id, node->sway_container->title,
60 layout_to_str(node->sway_container->layout),
61 node->sway_container->width, node->sway_container->height,
62 node->sway_container->x, node->sway_container->y);
63 break;
64 }
65 return buffer;
66}
67
68static list_t *get_children(struct sway_node *node) {
69 switch (node->type) {
70 case N_ROOT:
71 return root->outputs;
72 case N_OUTPUT:
73 return node->sway_output->workspaces;
74 case N_WORKSPACE:
75 return node->sway_workspace->tiling;
76 case N_CONTAINER:
77 return node->sway_container->children;
78 }
79 return NULL;
80}
81
82static int draw_node(cairo_t *cairo, struct sway_node *node,
83 struct sway_node *focus, int x, int y) {
84 int text_width, text_height;
85 char *buffer = get_string(node);
86 get_text_size(cairo, "monospace", &text_width, &text_height, NULL,
87 1, false, buffer);
88 cairo_save(cairo);
89 cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height);
90 cairo_set_source_u32(cairo, 0xFFFFFFE0);
91 cairo_fill(cairo);
92 int height = text_height;
93 list_t *children = get_children(node);
94 if (children) {
95 for (int i = 0; i < children->length; ++i) {
96 // This is really dirty - the list contains specific structs but
97 // we're casting them as nodes. This works because node is the first
98 // item in each specific struct. This is acceptable because this is
99 // debug code.
100 struct sway_node *child = children->items[i];
101 if (node_get_parent(child) == node) {
102 cairo_set_source_u32(cairo, 0x000000FF);
103 } else {
104 cairo_set_source_u32(cairo, 0xFF0000FF);
105 }
106 height += draw_node(cairo, child, focus, x + 10, y + height);
107 }
108 }
109 cairo_set_source_u32(cairo, 0xFFFFFFE0);
110 cairo_rectangle(cairo, x, y, 2, height);
111 cairo_fill(cairo);
112 cairo_restore(cairo);
113 cairo_move_to(cairo, x, y);
114 if (focus == node) {
115 cairo_set_source_u32(cairo, 0x0000FFFF);
116 }
117 pango_printf(cairo, "monospace", 1, false, buffer);
118 free(buffer);
119 return height;
120}
121
122void update_debug_tree(void) {
123 if (!debug.render_tree) {
124 return;
125 }
126
127 int width = 640, height = 480;
128 for (int i = 0; i < root->outputs->length; ++i) {
129 struct sway_output *output = root->outputs->items[i];
130 if (output->width > width) {
131 width = output->width;
132 }
133 if (output->height > height) {
134 height = output->height;
135 }
136 }
137 cairo_surface_t *surface =
138 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
139 cairo_t *cairo = cairo_create(surface);
140 PangoContext *pango = pango_cairo_create_context(cairo);
141
142 struct sway_seat *seat = input_manager_current_seat();
143 struct sway_node *focus = seat_get_focus(seat);
144
145 cairo_set_source_u32(cairo, 0x000000FF);
146 draw_node(cairo, &root->node, focus, 0, 0);
147
148 cairo_surface_flush(surface);
149 struct wlr_renderer *renderer = wlr_backend_get_renderer(server.backend);
150 if (root->debug_tree) {
151 wlr_texture_destroy(root->debug_tree);
152 }
153 unsigned char *data = cairo_image_surface_get_data(surface);
154 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
155 struct wlr_texture *texture = wlr_texture_from_pixels(renderer,
156 WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
157 root->debug_tree = texture;
158 cairo_surface_destroy(surface);
159 g_object_unref(pango);
160 cairo_destroy(cairo);
161}