aboutsummaryrefslogtreecommitdiff
path: root/sway/debug-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/debug-tree.c')
-rw-r--r--sway/debug-tree.c111
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 @@
#include "sway/server.h"
#include "sway/tree/container.h"
#include "sway/tree/root.h"
+#include "sway/tree/workspace.h"
#include "cairo.h"
#include "config.h"
#include "pango.h"
@@ -32,28 +33,78 @@ static const char *layout_to_str(enum sway_container_layout layout) {
return "L_NONE";
}
-static int draw_container(cairo_t *cairo, struct sway_container *container,
- struct sway_container *focus, int x, int y) {
+static char *get_string(struct sway_node *node) {
+ char *buffer = malloc(512);
+ switch (node->type) {
+ case N_ROOT:
+ snprintf(buffer, 512, "N_ROOT id:%zd %.fx%.f@%.f,%.f", node->id,
+ root->width, root->height, root->x, root->y);
+ break;
+ case N_OUTPUT:
+ snprintf(buffer, 512, "N_OUTPUT id:%zd '%s' %dx%d@%d,%d", node->id,
+ node->sway_output->wlr_output->name,
+ node->sway_output->width,
+ node->sway_output->height,
+ node->sway_output->lx,
+ node->sway_output->ly);
+ break;
+ case N_WORKSPACE:
+ snprintf(buffer, 512, "N_WORKSPACE id:%zd '%s' %s %dx%d@%.f,%.f",
+ node->id, node->sway_workspace->name,
+ layout_to_str(node->sway_workspace->layout),
+ node->sway_workspace->width, node->sway_workspace->height,
+ node->sway_workspace->x, node->sway_workspace->y);
+ break;
+ case N_CONTAINER:
+ snprintf(buffer, 512, "N_CONTAINER id:%zd '%s' %s %.fx%.f@%.f,%.f",
+ node->id, node->sway_container->title,
+ layout_to_str(node->sway_container->layout),
+ node->sway_container->width, node->sway_container->height,
+ node->sway_container->x, node->sway_container->y);
+ break;
+ }
+ return buffer;
+}
+
+static list_t *get_children(struct sway_node *node) {
+ switch (node->type) {
+ case N_ROOT:
+ return root->outputs;
+ case N_OUTPUT:
+ return node->sway_output->workspaces;
+ case N_WORKSPACE:
+ return node->sway_workspace->tiling;
+ case N_CONTAINER:
+ return node->sway_container->children;
+ }
+ return NULL;
+}
+
+static int draw_node(cairo_t *cairo, struct sway_node *node,
+ struct sway_node *focus, int x, int y) {
int text_width, text_height;
+ char *buffer = get_string(node);
get_text_size(cairo, "monospace", &text_width, &text_height,
- 1, false, "%s id:%zd '%s' %s %.fx%.f@%.f,%.f",
- container_type_to_str(container->type), container->id, container->name,
- layout_to_str(container->layout),
- container->width, container->height, container->x, container->y);
+ 1, false, buffer);
cairo_save(cairo);
cairo_rectangle(cairo, x + 2, y, text_width - 2, text_height);
cairo_set_source_u32(cairo, 0xFFFFFFE0);
cairo_fill(cairo);
int height = text_height;
- if (container->children) {
- for (int i = 0; i < container->children->length; ++i) {
- struct sway_container *child = container->children->items[i];
- if (child->parent == container) {
+ list_t *children = get_children(node);
+ if (children) {
+ for (int i = 0; i < children->length; ++i) {
+ // This is really dirty - the list contains specific structs but
+ // we're casting them as nodes. This works because node is the first
+ // item in each specific struct. This is acceptable because this is
+ // debug code.
+ struct sway_node *child = children->items[i];
+ if (node_get_parent(child) == node) {
cairo_set_source_u32(cairo, 0x000000FF);
} else {
cairo_set_source_u32(cairo, 0xFF0000FF);
}
- height += draw_container(cairo, child, focus, x + 10, y + height);
+ height += draw_node(cairo, child, focus, x + 10, y + height);
}
}
cairo_set_source_u32(cairo, 0xFFFFFFE0);
@@ -61,13 +112,11 @@ static int draw_container(cairo_t *cairo, struct sway_container *container,
cairo_fill(cairo);
cairo_restore(cairo);
cairo_move_to(cairo, x, y);
- if (focus == container) {
+ if (focus == node) {
cairo_set_source_u32(cairo, 0x0000FFFF);
}
- pango_printf(cairo, "monospace", 1, false, "%s id:%zd '%s' %s %.fx%.f@%.f,%.f",
- container_type_to_str(container->type), container->id, container->name,
- layout_to_str(container->layout),
- container->width, container->height, container->x, container->y);
+ pango_printf(cairo, "monospace", 1, false, buffer);
+ free(buffer);
return height;
}
@@ -77,13 +126,13 @@ void update_debug_tree() {
}
int width = 640, height = 480;
- for (int i = 0; i < root_container.children->length; ++i) {
- struct sway_container *container = root_container.children->items[i];
- if (container->width > width) {
- width = container->width;
+ for (int i = 0; i < root->outputs->length; ++i) {
+ struct sway_output *output = root->outputs->items[i];
+ if (output->width > width) {
+ width = output->width;
}
- if (container->height > height) {
- height = container->height;
+ if (output->height > height) {
+ height = output->height;
}
}
cairo_surface_t *surface =
@@ -91,28 +140,22 @@ void update_debug_tree() {
cairo_t *cairo = cairo_create(surface);
PangoContext *pango = pango_cairo_create_context(cairo);
- struct sway_seat *seat = NULL;
- wl_list_for_each(seat, &input_manager->seats, link) {
- break;
- }
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_node *focus = seat_get_focus(seat);
- struct sway_container *focus = NULL;
- if (seat != NULL) {
- focus = seat_get_focus(seat);
- }
cairo_set_source_u32(cairo, 0x000000FF);
- draw_container(cairo, &root_container, focus, 0, 0);
+ draw_node(cairo, &root->node, focus, 0, 0);
cairo_surface_flush(surface);
struct wlr_renderer *renderer = wlr_backend_get_renderer(server.backend);
- if (root_container.sway_root->debug_tree) {
- wlr_texture_destroy(root_container.sway_root->debug_tree);
+ if (root->debug_tree) {
+ wlr_texture_destroy(root->debug_tree);
}
unsigned char *data = cairo_image_surface_get_data(surface);
int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
struct wlr_texture *texture = wlr_texture_from_pixels(renderer,
WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
- root_container.sway_root->debug_tree = texture;
+ root->debug_tree = texture;
cairo_surface_destroy(surface);
g_object_unref(pango);
cairo_destroy(cairo);