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