summaryrefslogtreecommitdiffstats
path: root/sway/debug_log.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-11-12 19:04:01 -0500
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-11-12 19:04:01 -0500
commitbfcabe48ef3fc7a0388de007504fc232f826fb84 (patch)
tree8bef61a10259765dbafed49c9a2a76b4bf9ced2d /sway/debug_log.c
parentMerge branch 'master' of github.com:SirCmpwn/sway (diff)
downloadsway-bfcabe48ef3fc7a0388de007504fc232f826fb84.tar.gz
sway-bfcabe48ef3fc7a0388de007504fc232f826fb84.tar.zst
sway-bfcabe48ef3fc7a0388de007504fc232f826fb84.zip
Start fleshing out wayland client implementation
This introduces a basic shared framework for making wayland clients within sway itself.
Diffstat (limited to 'sway/debug_log.c')
-rw-r--r--sway/debug_log.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/sway/debug_log.c b/sway/debug_log.c
new file mode 100644
index 00000000..4cb97561
--- /dev/null
+++ b/sway/debug_log.c
@@ -0,0 +1,102 @@
1#include "log.h"
2#include "sway.h"
3#include <stdarg.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <libgen.h>
7#include <fcntl.h>
8#include <unistd.h>
9#include <signal.h>
10#include <errno.h>
11#include <string.h>
12#include <stringop.h>
13#include <execinfo.h>
14#include "workspace.h"
15
16extern log_importance_t v;
17
18/* XXX:DEBUG:XXX */
19static void container_log(const swayc_t *c) {
20 fprintf(stderr, "focus:%c|",
21 c == get_focused_view(&root_container) ? 'K':
22 c == get_focused_container(&root_container) ? 'F' : // Focused
23 c == swayc_active_workspace() ? 'W' : // active workspace
24 c == &root_container ? 'R' : // root
25 'X');// not any others
26 fprintf(stderr,"(%p)",c);
27 fprintf(stderr,"(p:%p)",c->parent);
28 fprintf(stderr,"(f:%p)",c->focused);
29 fprintf(stderr,"(h:%ld)",c->handle);
30 fprintf(stderr,"Type:");
31 fprintf(stderr,
32 c->type == C_ROOT ? "Root|" :
33 c->type == C_OUTPUT ? "Output|" :
34 c->type == C_WORKSPACE ? "Workspace|" :
35 c->type == C_CONTAINER ? "Container|" :
36 c->type == C_VIEW ? "View|" : "Unknown|");
37 fprintf(stderr,"layout:");
38 fprintf(stderr,
39 c->layout == L_NONE ? "NONE|" :
40 c->layout == L_HORIZ ? "Horiz|":
41 c->layout == L_VERT ? "Vert|":
42 c->layout == L_STACKED ? "Stacked|":
43 c->layout == L_FLOATING ? "Floating|":
44 "Unknown|");
45 fprintf(stderr, "w:%.f|h:%.f|", c->width, c->height);
46 fprintf(stderr, "x:%.f|y:%.f|", c->x, c->y);
47 fprintf(stderr, "g:%d|",c->gaps);
48 fprintf(stderr, "vis:%c|", c->visible?'t':'f');
49 fprintf(stderr, "name:%.16s|", c->name);
50 fprintf(stderr, "children:%d\n",c->children?c->children->length:0);
51}
52void layout_log(const swayc_t *c, int depth) {
53 if (L_DEBUG > v) return;
54 int i, d;
55 int e = c->children ? c->children->length : 0;
56 container_log(c);
57 if (e) {
58 for (i = 0; i < e; ++i) {
59 fputc('|',stderr);
60 for (d = 0; d < depth; ++d) fputc('-', stderr);
61 layout_log(c->children->items[i], depth + 1);
62 }
63 }
64 if (c->type == C_WORKSPACE) {
65 e = c->floating?c->floating->length:0;
66 if (e) {
67 for (i = 0; i < e; ++i) {
68 fputc('|',stderr);
69 for (d = 0; d < depth; ++d) fputc('=', stderr);
70 layout_log(c->floating->items[i], depth + 1);
71 }
72 }
73 }
74}
75
76const char *swayc_type_string(enum swayc_types type) {
77 return type == C_ROOT ? "ROOT" :
78 type == C_OUTPUT ? "OUTPUT" :
79 type == C_WORKSPACE ? "WORKSPACE" :
80 type == C_CONTAINER ? "CONTAINER" :
81 type == C_VIEW ? "VIEW" :
82 "UNKNOWN";
83}
84
85// Like sway_log, but also appends some info about given container to log output.
86void swayc_log(log_importance_t verbosity, swayc_t *cont, const char* format, ...) {
87 sway_assert(cont, "swayc_log: no container ...");
88 va_list args;
89 va_start(args, format);
90 char *txt = malloc(128);
91 vsprintf(txt, format, args);
92 va_end(args);
93
94 char *debug_txt = malloc(32);
95 snprintf(debug_txt, 32, "%s '%s'", swayc_type_string(cont->type), cont->name);
96
97 sway_log(verbosity, "%s (%s)", txt, debug_txt);
98 free(txt);
99 free(debug_txt);
100}
101
102/* XXX:DEBUG:XXX */