aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-04-06 11:49:27 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-04-06 11:49:27 -0400
commit603e0e42c577026f1c688c393989e65dc3482808 (patch)
tree7e2635f8745ed6141f900359eeff9b8d9f418cea
parentFix splitting workspaces (diff)
downloadsway-603e0e42c577026f1c688c393989e65dc3482808.tar.gz
sway-603e0e42c577026f1c688c393989e65dc3482808.tar.zst
sway-603e0e42c577026f1c688c393989e65dc3482808.zip
Add debug tree view
-rw-r--r--include/sway/debug.h7
-rw-r--r--include/sway/tree/layout.h4
-rw-r--r--sway/debug-tree.c110
-rw-r--r--sway/desktop/output.c5
-rw-r--r--sway/input/seat.c3
-rw-r--r--sway/main.c6
-rw-r--r--sway/meson.build4
-rw-r--r--sway/tree/layout.c8
8 files changed, 145 insertions, 2 deletions
diff --git a/include/sway/debug.h b/include/sway/debug.h
new file mode 100644
index 00000000..2430d319
--- /dev/null
+++ b/include/sway/debug.h
@@ -0,0 +1,7 @@
1#ifndef SWAY_DEBUG_H
2#define SWAY_DEBUG_H
3
4extern bool enable_debug_tree;
5void update_debug_tree();
6
7#endif
diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h
index fc5ce21f..49ae00e4 100644
--- a/include/sway/tree/layout.h
+++ b/include/sway/tree/layout.h
@@ -1,7 +1,7 @@
1#ifndef _SWAY_LAYOUT_H 1#ifndef _SWAY_LAYOUT_H
2#define _SWAY_LAYOUT_H 2#define _SWAY_LAYOUT_H
3
4#include <wlr/types/wlr_output_layout.h> 3#include <wlr/types/wlr_output_layout.h>
4#include <wlr/render/wlr_texture.h>
5#include "sway/tree/container.h" 5#include "sway/tree/container.h"
6 6
7enum movement_direction { 7enum movement_direction {
@@ -29,6 +29,8 @@ struct sway_root {
29 29
30 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link 30 struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link
31 31
32 struct wlr_texture *debug_tree;
33
32 struct { 34 struct {
33 struct wl_signal new_container; 35 struct wl_signal new_container;
34 } events; 36 } events;
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 @@
1#include <pango/pangocairo.h>
2#include <wlr/backend.h>
3#include <wlr/render/wlr_texture.h>
4#include <wlr/util/log.h>
5#include "config.h"
6#include "sway/input/input-manager.h"
7#include "sway/input/seat.h"
8#include "sway/server.h"
9#include "sway/tree/container.h"
10#include "sway/tree/layout.h"
11#include "cairo.h"
12#include "config.h"
13#include "pango.h"
14
15static const char *layout_to_str(enum sway_container_layout layout) {
16 switch (layout) {
17 case L_HORIZ:
18 return "L_HORIZ";
19 case L_VERT:
20 return "L_VERT";
21 case L_STACKED:
22 return "L_STACKED";
23 case L_TABBED:
24 return "L_TABBED";
25 case L_FLOATING:
26 return "L_FLOATING";
27 case L_NONE:
28 default:
29 return "L_NONE";
30 }
31}
32
33static int draw_container(cairo_t *cairo, struct sway_container *container,
34 struct sway_container *focus, int x, int y) {
35 int text_width, text_height;
36 get_text_size(cairo, "monospace", &text_width, &text_height,
37 1, false, "%s '%s' %s %dx%d@%d,%d",
38 container_type_to_str(container->type), container->name,
39 layout_to_str(container->layout),
40 container->width, container->height, container->x, container->y);
41 cairo_rectangle(cairo, x, y, text_width, text_height);
42 cairo_set_source_u32(cairo, 0xFFFFFFFF);
43 cairo_fill(cairo);
44 cairo_move_to(cairo, x, y);
45 if (focus == container) {
46 cairo_set_source_u32(cairo, 0xFF0000FF);
47 } else {
48 cairo_set_source_u32(cairo, 0x000000FF);
49 }
50 pango_printf(cairo, "monospace", 1, false, "%s '%s' %s %dx%d@%d,%d",
51 container_type_to_str(container->type), container->name,
52 layout_to_str(container->layout),
53 container->width, container->height, container->x, container->y);
54 int height = text_height;
55 if (container->children) {
56 for (int i = 0; i < container->children->length; ++i) {
57 struct sway_container *child = container->children->items[i];
58 height += draw_container(cairo, child, focus, x + 10, y + height);
59 }
60 }
61 return height;
62}
63
64bool enable_debug_tree = false;
65
66void update_debug_tree() {
67 if (!enable_debug_tree) {
68 return;
69 }
70
71 int width = 640, height = 480;
72 for (int i = 0; i < root_container.children->length; ++i) {
73 struct sway_container *container = root_container.children->items[i];
74 if (container->width > width) {
75 width = container->width;
76 }
77 if (container->height > height) {
78 height = container->height;
79 }
80 }
81 cairo_surface_t *surface =
82 cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
83 cairo_t *cairo = cairo_create(surface);
84 PangoContext *pango = pango_cairo_create_context(cairo);
85
86 struct sway_seat *seat = NULL;
87 wl_list_for_each(seat, &input_manager->seats, link) {
88 break;
89 }
90
91 struct sway_container *focus;
92 if (seat != NULL) {
93 focus = seat_get_focus(seat);
94 }
95 draw_container(cairo, &root_container, focus, 0, 0);
96
97 cairo_surface_flush(surface);
98 struct wlr_renderer *renderer = wlr_backend_get_renderer(server.backend);
99 if (root_container.sway_root->debug_tree) {
100 wlr_texture_destroy(root_container.sway_root->debug_tree);
101 }
102 unsigned char *data = cairo_image_surface_get_data(surface);
103 int stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width);
104 struct wlr_texture *texture = wlr_texture_from_pixels(renderer,
105 WL_SHM_FORMAT_ARGB8888, stride, width, height, data);
106 root_container.sway_root->debug_tree = texture;
107 cairo_surface_destroy(surface);
108 g_object_unref(pango);
109 cairo_destroy(cairo);
110}
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,
294 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); 294 &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]);
295 295
296renderer_end: 296renderer_end:
297 if (root_container.sway_root->debug_tree) {
298 wlr_render_texture(renderer, root_container.sway_root->debug_tree,
299 wlr_output->transform_matrix, 0, 0, 1);
300 }
301
297 wlr_renderer_end(renderer); 302 wlr_renderer_end(renderer);
298 if (!wlr_output_damage_swap_buffers(output->damage, when, damage)) { 303 if (!wlr_output_damage_swap_buffers(output->damage, when, damage)) {
299 return; 304 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 @@
5#include <wlr/types/wlr_cursor.h> 5#include <wlr/types/wlr_cursor.h>
6#include <wlr/types/wlr_output_layout.h> 6#include <wlr/types/wlr_output_layout.h>
7#include <wlr/types/wlr_xcursor_manager.h> 7#include <wlr/types/wlr_xcursor_manager.h>
8#include "sway/debug.h"
8#include "sway/tree/container.h" 9#include "sway/tree/container.h"
9#include "sway/tree/workspace.h" 10#include "sway/tree/workspace.h"
10#include "sway/input/seat.h" 11#include "sway/input/seat.h"
@@ -432,6 +433,8 @@ void seat_set_focus_warp(struct sway_seat *seat,
432 } 433 }
433 434
434 seat->has_focus = (container != NULL); 435 seat->has_focus = (container != NULL);
436
437 update_debug_tree();
435} 438}
436 439
437void seat_set_focus(struct sway_seat *seat, 440void 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 @@
17#endif 17#endif
18#include <wlr/util/log.h> 18#include <wlr/util/log.h>
19#include "sway/config.h" 19#include "sway/config.h"
20#include "sway/debug.h"
20#include "sway/server.h" 21#include "sway/server.h"
21#include "sway/tree/layout.h" 22#include "sway/tree/layout.h"
22#include "sway/ipc-server.h" 23#include "sway/ipc-server.h"
@@ -288,7 +289,7 @@ int main(int argc, char **argv) {
288 int c; 289 int c;
289 while (1) { 290 while (1) {
290 int option_index = 0; 291 int option_index = 0;
291 c = getopt_long(argc, argv, "hCdvVc:", long_options, &option_index); 292 c = getopt_long(argc, argv, "hCdDvVc:", long_options, &option_index);
292 if (c == -1) { 293 if (c == -1) {
293 break; 294 break;
294 } 295 }
@@ -306,6 +307,9 @@ int main(int argc, char **argv) {
306 case 'd': // debug 307 case 'd': // debug
307 debug = 1; 308 debug = 1;
308 break; 309 break;
310 case 'D': // extended debug options
311 enable_debug_tree = true;
312 break;
309 case 'v': // version 313 case 'v': // version
310 fprintf(stdout, "sway version " SWAY_VERSION "\n"); 314 fprintf(stdout, "sway version " SWAY_VERSION "\n");
311 exit(EXIT_SUCCESS); 315 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(
4 'commands.c', 4 'commands.c',
5 'config.c', 5 'config.c',
6 'criteria.c', 6 'criteria.c',
7 'debug-tree.c',
7 'ipc-json.c', 8 'ipc-json.c',
8 'ipc-server.c', 9 'ipc-server.c',
9 'security.c', 10 'security.c',
@@ -102,10 +103,13 @@ sway_sources = files(
102) 103)
103 104
104sway_deps = [ 105sway_deps = [
106 cairo,
107 gdk_pixbuf,
105 jsonc, 108 jsonc,
106 libcap, 109 libcap,
107 libinput, 110 libinput,
108 math, 111 math,
112 pango,
109 pcre, 113 pcre,
110 pixman, 114 pixman,
111 server_protos, 115 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 @@
6#include <string.h> 6#include <string.h>
7#include <wlr/types/wlr_output.h> 7#include <wlr/types/wlr_output.h>
8#include <wlr/types/wlr_output_layout.h> 8#include <wlr/types/wlr_output_layout.h>
9#include "sway/debug.h"
9#include "sway/tree/container.h" 10#include "sway/tree/container.h"
10#include "sway/tree/layout.h" 11#include "sway/tree/layout.h"
11#include "sway/output.h" 12#include "sway/output.h"
@@ -431,6 +432,11 @@ void container_move(struct sway_container *container,
431 return; 432 return;
432 } 433 }
433 434
435 if (old_parent) {
436 seat_set_focus(config->handler_context.seat, old_parent);
437 seat_set_focus(config->handler_context.seat, container);
438 }
439
434 struct sway_container *last_ws = old_parent; 440 struct sway_container *last_ws = old_parent;
435 struct sway_container *next_ws = container->parent; 441 struct sway_container *next_ws = container->parent;
436 if (last_ws && last_ws->type != C_WORKSPACE) { 442 if (last_ws && last_ws->type != C_WORKSPACE) {
@@ -594,6 +600,8 @@ void arrange_windows(struct sway_container *container,
594 break; 600 break;
595 } 601 }
596 container_damage_whole(container); 602 container_damage_whole(container);
603 // TODO: Make this less shitty
604 update_debug_tree();
597} 605}
598 606
599static void apply_horiz_layout(struct sway_container *container, 607static void apply_horiz_layout(struct sway_container *container,