i3 - improved tiling WM


Implement debug command

Patch status: needinfo

Patch by Alexander Berntsen

Long description:

Add debug command that takes toggle|on|off. Add get_debug_logging() to
be able to toggle. Make t/187-commands-parser.t expect 'debug'. Document
the debug command in userguide.

To apply this patch, use:
curl http://cr.i3wm.org/patch/180/raw.patch | git am

b/docs/userguide

22
@@ -1778,6 +1778,18 @@ shmlog on
23
 shmlog off
24
 ---------------
25
 
26
+== Starting/stopping
27
+
28
+You may start, stop or toggle the debug log with the +debug+ command. +debug
29
+toggle+ is useful to bind to a key.
30
+
31
+*Examples*:
32
+------------
33
+debug toggle
34
+debug on
35
+debug off
36
+------------
37
+
38
 === Reloading/Restarting/Exiting
39
 
40
 You can make i3 reload its configuration file with +reload+. You can also

b/include/commands.h

45
@@ -277,4 +277,10 @@ void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id);
46
  */
47
 void cmd_shmlog(I3_CMD, char *argument);
48
 
49
+/*
50
+ * Implementation of 'debug toggle|on|off'
51
+ *
52
+ */
53
+void cmd_debug(I3_CMD, char *argument);
54
+
55
 #endif

b/include/log.h

60
@@ -51,6 +51,12 @@ void open_logbuffer(void);
61
 void close_logbuffer(void);
62
 
63
 /**
64
+ * Checks if debug logging is active.
65
+ *
66
+ */
67
+bool get_debug_logging();
68
+
69
+/**
70
  * Set debug logging.
71
  *
72
  */

b/parser-specs/commands.spec

77
@@ -20,6 +20,7 @@ state INITIAL:
78
   'restart' -> call cmd_restart()
79
   'reload' -> call cmd_reload()
80
   'shmlog' -> SHMLOG
81
+  'debug' -> DEBUG
82
   'border' -> BORDER
83
   'layout' -> LAYOUT
84
   'append_layout' -> APPEND_LAYOUT
85
@@ -69,6 +70,11 @@ state SHMLOG:
86
   argument = string
87
     -> call cmd_shmlog($argument)
88
 
89
+# debug toggle|on|off
90
+state DEBUG:
91
+  argument = 'toggle', 'on', 'off'
92
+    -> call cmd_debug($argument)
93
+
94
 # border normal|none|1pixel|toggle|1pixel
95
 state BORDER:
96
   border_style = 'normal', 'pixel'

b/src/commands.c

101
@@ -2059,3 +2059,19 @@ void cmd_shmlog(I3_CMD, char *argument) {
102
     // XXX: default reply for now, make this a better reply
103
     ysuccess(true);
104
 }
105
+
106
+/*
107
+ * Implementation of 'debug toggle|on|off'
108
+ *
109
+ */
110
+void cmd_debug(I3_CMD, char *argument) {
111
+    LOG("%s debug logging\n", get_debug_logging() ? "Disabling" : "Enabling");
112
+    if (!strcmp(argument,"toggle"))
113
+        set_debug_logging(!get_debug_logging());
114
+    else if (!strcmp(argument, "on"))
115
+        set_debug_logging(true);
116
+    else if (!strcmp(argument, "off"))
117
+        set_debug_logging(false);
118
+    // XXX: default reply for now, make this a better reply
119
+    ysuccess(true);
120
+}

b/src/log.c

125
@@ -180,6 +180,14 @@ void set_verbosity(bool _verbose) {
126
 }
127
 
128
 /*
129
+ * Get debug logging.
130
+ *
131
+ */
132
+bool get_debug_logging() {
133
+    return debug_logging;
134
+}
135
+
136
+/*
137
  * Set debug logging.
138
  *
139
  */

b/testcases/t/187-commands-parser.t

144
@@ -144,7 +144,7 @@ is(parser_calls("\nworkspace test"),
145
 ################################################################################
146
 
147
 is(parser_calls('unknown_literal'),
148
-   "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode', 'bar'\n" .
149
+   "ERROR: Expected one of these tokens: <end>, '[', 'move', 'exec', 'exit', 'restart', 'reload', 'shmlog', 'debug', 'border', 'layout', 'append_layout', 'workspace', 'focus', 'kill', 'open', 'fullscreen', 'split', 'floating', 'mark', 'resize', 'rename', 'nop', 'scratchpad', 'mode', 'bar'\n" .
150
    "ERROR: Your command: unknown_literal\n" .
151
    "ERROR:               ^^^^^^^^^^^^^^^",
152
    'error for unknown literal ok');