diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/debug-tree.c | 110 | ||||
-rw-r--r-- | sway/desktop/output.c | 5 | ||||
-rw-r--r-- | sway/input/seat.c | 3 | ||||
-rw-r--r-- | sway/main.c | 6 | ||||
-rw-r--r-- | sway/meson.build | 4 | ||||
-rw-r--r-- | sway/tree/layout.c | 8 |
6 files changed, 135 insertions, 1 deletions
diff --git a/sway/debug-tree.c b/sway/debug-tree.c new file mode 100644 index 00000000..08ee3585 --- /dev/null +++ b/sway/debug-tree.c @@ -0,0 +1,110 @@ +#include <pango/pangocairo.h> +#include <wlr/backend.h> +#include <wlr/render/wlr_texture.h> +#include <wlr/util/log.h> +#include "config.h" +#include "sway/input/input-manager.h" +#include "sway/input/seat.h" +#include "sway/server.h" +#include "sway/tree/container.h" +#include "sway/tree/layout.h" +#include "cairo.h" +#include "config.h" +#include "pango.h" + +static const char *layout_to_str(enum sway_container_layout layout) { + switch (layout) { + case L_HORIZ: + return "L_HORIZ"; + case L_VERT: + return "L_VERT"; + case L_STACKED: + return "L_STACKED"; + case L_TABBED: + return "L_TABBED"; + case L_FLOATING: + return "L_FLOATING"; + case L_NONE: + default: + return "L_NONE"; + } +} + +static int draw_container(cairo_t *cairo, struct sway_container *container, + struct sway_container *focus, int x, int y) { + int text_width, text_height; + get_text_size(cairo, "monospace", &text_width, &text_height, + 1, false, "%s '%s' %s %dx%d@%d,%d", + container_type_to_str(container->type), container->name, + layout_to_str(container->layout), + container->width, container->height, container->x, container->y); + cairo_rectangle(cairo, x, y, text_width, text_height); + cairo_set_source_u32(cairo, 0xFFFFFFFF); + cairo_fill(cairo); + cairo_move_to(cairo, x, y); + if (focus == container) { + cairo_set_source_u32(cairo, 0xFF0000FF); + } else { + cairo_set_source_u32(cairo, 0x000000FF); + } + pango_printf(cairo, "monospace", 1, false, "%s '%s' %s %dx%d@%d,%d", + container_type_to_str(container->type), container->name, + layout_to_str(container->layout), + container->width, container->height, container->x, container->y); + int height = text_height; + if (container->children) { + for (int i = 0; i < container->children->length; ++i) { + struct sway_container *child = container->children->items[i]; + height += draw_container(cairo, child, focus, x + 10, y + height); + } + } + return height; +} + +bool enable_debug_tree = false; + +void update_debug_tree() { + if (!enable_debug_tree) { + return; + } + + 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; + } + if (container->height > height) { + height = container->height; + } + } + cairo_surface_t *surface = + cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); + 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_container *focus; + if (seat != NULL) { + focus = seat_get_focus(seat); + } + draw_container(cairo, &root_container, 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); + } + 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; + cairo_surface_destroy(surface); + g_object_unref(pango); + cairo_destroy(cairo); +} diff --git a/sway/desktop/output.c b/sway/desktop/output.c index aa18f1b8..ad777796 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -294,6 +294,11 @@ static void render_output(struct sway_output *output, struct timespec *when, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); renderer_end: + if (root_container.sway_root->debug_tree) { + wlr_render_texture(renderer, root_container.sway_root->debug_tree, + wlr_output->transform_matrix, 0, 0, 1); + } + wlr_renderer_end(renderer); if (!wlr_output_damage_swap_buffers(output->damage, when, damage)) { return; diff --git a/sway/input/seat.c b/sway/input/seat.c index ad3584a0..e8cf9824 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -5,6 +5,7 @@ #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_xcursor_manager.h> +#include "sway/debug.h" #include "sway/tree/container.h" #include "sway/tree/workspace.h" #include "sway/input/seat.h" @@ -432,6 +433,8 @@ void seat_set_focus_warp(struct sway_seat *seat, } seat->has_focus = (container != NULL); + + update_debug_tree(); } void seat_set_focus(struct sway_seat *seat, diff --git a/sway/main.c b/sway/main.c index e7f8ddd3..efb674b6 100644 --- a/sway/main.c +++ b/sway/main.c @@ -17,6 +17,7 @@ #endif #include <wlr/util/log.h> #include "sway/config.h" +#include "sway/debug.h" #include "sway/server.h" #include "sway/tree/layout.h" #include "sway/ipc-server.h" @@ -288,7 +289,7 @@ int main(int argc, char **argv) { int c; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "hCdvVc:", long_options, &option_index); + c = getopt_long(argc, argv, "hCdDvVc:", long_options, &option_index); if (c == -1) { break; } @@ -306,6 +307,9 @@ int main(int argc, char **argv) { case 'd': // debug debug = 1; break; + case 'D': // extended debug options + enable_debug_tree = true; + break; case 'v': // version fprintf(stdout, "sway version " SWAY_VERSION "\n"); exit(EXIT_SUCCESS); diff --git a/sway/meson.build b/sway/meson.build index 29aaa7b7..1fe0f29a 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -4,6 +4,7 @@ sway_sources = files( 'commands.c', 'config.c', 'criteria.c', + 'debug-tree.c', 'ipc-json.c', 'ipc-server.c', 'security.c', @@ -102,10 +103,13 @@ sway_sources = files( ) sway_deps = [ + cairo, + gdk_pixbuf, jsonc, libcap, libinput, math, + pango, pcre, pixman, server_protos, diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 0011a9e3..e633acc6 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -6,6 +6,7 @@ #include <string.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output_layout.h> +#include "sway/debug.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" #include "sway/output.h" @@ -431,6 +432,11 @@ void container_move(struct sway_container *container, return; } + if (old_parent) { + seat_set_focus(config->handler_context.seat, old_parent); + seat_set_focus(config->handler_context.seat, container); + } + struct sway_container *last_ws = old_parent; struct sway_container *next_ws = container->parent; if (last_ws && last_ws->type != C_WORKSPACE) { @@ -594,6 +600,8 @@ void arrange_windows(struct sway_container *container, break; } container_damage_whole(container); + // TODO: Make this less shitty + update_debug_tree(); } static void apply_horiz_layout(struct sway_container *container, |