]> git.sur5r.net Git - i3/i3/blob - src/commands.c
travis: install clang-format-3.5 from llvm repository
[i3/i3] / src / commands.c
1 #undef I3__FILE__
2 #define I3__FILE__ "commands.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
8  *
9  * commands.c: all command functions (see commands_parser.c)
10  *
11  */
12 #include <float.h>
13 #include <stdarg.h>
14
15 #include "all.h"
16 #include "shmlog.h"
17
18 // Macros to make the YAJL API a bit easier to use.
19 #define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
20 #define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
21 #define ysuccess(success)                   \
22     do {                                    \
23         if (cmd_output->json_gen != NULL) { \
24             y(map_open);                    \
25             ystr("success");                \
26             y(bool, success);               \
27             y(map_close);                   \
28         }                                   \
29     } while (0)
30 #define yerror(format, ...)                             \
31     do {                                                \
32         if (cmd_output->json_gen != NULL) {             \
33             char *message;                              \
34             sasprintf(&message, format, ##__VA_ARGS__); \
35             y(map_open);                                \
36             ystr("success");                            \
37             y(bool, false);                             \
38             ystr("error");                              \
39             ystr(message);                              \
40             y(map_close);                               \
41             free(message);                              \
42         }                                               \
43     } while (0)
44
45 /** When the command did not include match criteria (!), we use the currently
46  * focused container. Do not confuse this case with a command which included
47  * criteria but which did not match any windows. This macro has to be called in
48  * every command.
49  */
50 #define HANDLE_EMPTY_MATCH                              \
51     do {                                                \
52         if (match_is_empty(current_match)) {            \
53             owindow *ow = smalloc(sizeof(owindow));     \
54             ow->con = focused;                          \
55             TAILQ_INIT(&owindows);                      \
56             TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
57         }                                               \
58     } while (0)
59
60 /*
61  * Returns true if a is definitely greater than b (using the given epsilon)
62  *
63  */
64 static bool definitelyGreaterThan(float a, float b, float epsilon) {
65     return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
66 }
67
68 /*
69  * Returns the output containing the given container.
70  */
71 static Output *get_output_of_con(Con *con) {
72     Con *output_con = con_get_output(con);
73     Output *output = get_output_by_name(output_con->name);
74     assert(output != NULL);
75
76     return output;
77 }
78
79 /*
80  * Checks whether we switched to a new workspace and returns false in that case,
81  * signaling that further workspace switching should be done by the calling function
82  * If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
83  * and return true, signaling that no further workspace switching should occur in the calling function.
84  *
85  */
86 static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name) {
87     Con *ws = con_get_workspace(focused);
88
89     /* If we switched to a different workspace, do nothing */
90     if (strcmp(ws->name, name) != 0)
91         return false;
92
93     DLOG("This workspace is already focused.\n");
94     if (config.workspace_auto_back_and_forth) {
95         workspace_back_and_forth();
96         cmd_output->needs_tree_render = true;
97     }
98     return true;
99 }
100
101 /*
102  * Return the passed workspace unless it is the current one and auto back and
103  * forth is enabled, in which case the back_and_forth workspace is returned.
104  */
105 static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
106     Con *current, *baf;
107
108     if (!config.workspace_auto_back_and_forth)
109         return workspace;
110
111     current = con_get_workspace(focused);
112
113     if (current == workspace) {
114         baf = workspace_back_and_forth_get();
115         if (baf != NULL) {
116             DLOG("Substituting workspace with back_and_forth, as it is focused.\n");
117             return baf;
118         }
119     }
120
121     return workspace;
122 }
123
124 // This code is commented out because we might recycle it for popping up error
125 // messages on parser errors.
126 #if 0
127 static pid_t migration_pid = -1;
128
129 /*
130  * Handler which will be called when we get a SIGCHLD for the nagbar, meaning
131  * it exited (or could not be started, depending on the exit code).
132  *
133  */
134 static void nagbar_exited(EV_P_ ev_child *watcher, int revents) {
135     ev_child_stop(EV_A_ watcher);
136     if (!WIFEXITED(watcher->rstatus)) {
137         fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n");
138         return;
139     }
140
141     int exitcode = WEXITSTATUS(watcher->rstatus);
142     printf("i3-nagbar process exited with status %d\n", exitcode);
143     if (exitcode == 2) {
144         fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
145     }
146
147     migration_pid = -1;
148 }
149
150 /* We need ev >= 4 for the following code. Since it is not *that* important (it
151  * only makes sure that there are no i3-nagbar instances left behind) we still
152  * support old systems with libev 3. */
153 #if EV_VERSION_MAJOR >= 4
154 /*
155  * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal
156  * SIGKILL (9) to make sure there are no left-over i3-nagbar processes.
157  *
158  */
159 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) {
160     if (migration_pid != -1) {
161         LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
162         kill(migration_pid, SIGKILL);
163     }
164 }
165 #endif
166
167 void cmd_MIGRATION_start_nagbar(void) {
168     if (migration_pid != -1) {
169         fprintf(stderr, "i3-nagbar already running.\n");
170         return;
171     }
172     fprintf(stderr, "Starting i3-nagbar, command parsing differs from expected output.\n");
173     ELOG("Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
174     ELOG("i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
175     ELOG("FYI: Your i3 version is " I3_VERSION "\n");
176     migration_pid = fork();
177     if (migration_pid == -1) {
178         warn("Could not fork()");
179         return;
180     }
181
182     /* child */
183     if (migration_pid == 0) {
184         char *pageraction;
185         sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename);
186         char *argv[] = {
187             NULL, /* will be replaced by the executable path */
188             "-t",
189             "error",
190             "-m",
191             "You found a parsing error. Please, please, please, report it!",
192             "-b",
193             "show errors",
194             pageraction,
195             NULL
196         };
197         exec_i3_utility("i3-nagbar", argv);
198     }
199
200     /* parent */
201     /* install a child watcher */
202     ev_child *child = smalloc(sizeof(ev_child));
203     ev_child_init(child, &nagbar_exited, migration_pid, 0);
204     ev_child_start(main_loop, child);
205
206 /* We need ev >= 4 for the following code. Since it is not *that* important (it
207  * only makes sure that there are no i3-nagbar instances left behind) we still
208  * support old systems with libev 3. */
209 #if EV_VERSION_MAJOR >= 4
210     /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is
211      * still running) */
212     ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup));
213     ev_cleanup_init(cleanup, nagbar_cleanup);
214     ev_cleanup_start(main_loop, cleanup);
215 #endif
216 }
217
218 #endif
219
220 /*******************************************************************************
221  * Criteria functions.
222  ******************************************************************************/
223
224 /*
225  * Helper data structure for an operation window (window on which the operation
226  * will be performed). Used to build the TAILQ owindows.
227  *
228  */
229 typedef struct owindow {
230     Con *con;
231     TAILQ_ENTRY(owindow) owindows;
232 } owindow;
233
234 typedef TAILQ_HEAD(owindows_head, owindow) owindows_head;
235
236 static owindows_head owindows;
237
238 /*
239  * Initializes the specified 'Match' data structure and the initial state of
240  * commands.c for matching target windows of a command.
241  *
242  */
243 void cmd_criteria_init(I3_CMD) {
244     Con *con;
245     owindow *ow;
246
247     DLOG("Initializing criteria, current_match = %p\n", current_match);
248     match_free(current_match);
249     match_init(current_match);
250     while (!TAILQ_EMPTY(&owindows)) {
251         ow = TAILQ_FIRST(&owindows);
252         TAILQ_REMOVE(&owindows, ow, owindows);
253         free(ow);
254     }
255     TAILQ_INIT(&owindows);
256     /* copy all_cons */
257     TAILQ_FOREACH(con, &all_cons, all_cons) {
258         ow = smalloc(sizeof(owindow));
259         ow->con = con;
260         TAILQ_INSERT_TAIL(&owindows, ow, owindows);
261     }
262 }
263
264 /*
265  * A match specification just finished (the closing square bracket was found),
266  * so we filter the list of owindows.
267  *
268  */
269 void cmd_criteria_match_windows(I3_CMD) {
270     owindow *next, *current;
271
272     DLOG("match specification finished, matching...\n");
273     /* copy the old list head to iterate through it and start with a fresh
274      * list which will contain only matching windows */
275     struct owindows_head old = owindows;
276     TAILQ_INIT(&owindows);
277     for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
278         /* make a copy of the next pointer and advance the pointer to the
279          * next element as we are going to invalidate the element’s
280          * next/prev pointers by calling TAILQ_INSERT_TAIL later */
281         current = next;
282         next = TAILQ_NEXT(next, owindows);
283
284         DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
285         if (current_match->con_id != NULL) {
286             if (current_match->con_id == current->con) {
287                 DLOG("matches container!\n");
288                 TAILQ_INSERT_TAIL(&owindows, current, owindows);
289             } else {
290                 DLOG("doesnt match\n");
291                 free(current);
292             }
293         } else if (current_match->mark != NULL && current->con->mark != NULL &&
294                    regex_matches(current_match->mark, current->con->mark)) {
295             DLOG("match by mark\n");
296             TAILQ_INSERT_TAIL(&owindows, current, owindows);
297         } else {
298             if (current->con->window && match_matches_window(current_match, current->con->window)) {
299                 DLOG("matches window!\n");
300                 TAILQ_INSERT_TAIL(&owindows, current, owindows);
301             } else {
302                 DLOG("doesnt match\n");
303                 free(current);
304             }
305         }
306     }
307
308     TAILQ_FOREACH(current, &owindows, owindows) {
309         DLOG("matching: %p / %s\n", current->con, current->con->name);
310     }
311 }
312
313 /*
314  * Interprets a ctype=cvalue pair and adds it to the current match
315  * specification.
316  *
317  */
318 void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue) {
319     match_parse_property(current_match, ctype, cvalue);
320 }
321
322 /*
323  * Implementation of 'move [window|container] [to] workspace
324  * next|prev|next_on_output|prev_on_output|current'.
325  *
326  */
327 void cmd_move_con_to_workspace(I3_CMD, const char *which) {
328     owindow *current;
329
330     DLOG("which=%s\n", which);
331
332     /* We have nothing to move:
333      *  when criteria was specified but didn't match any window or
334      *  when criteria wasn't specified and we don't have any window focused. */
335     if ((!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) ||
336         (match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
337          !con_has_children(focused))) {
338         ysuccess(false);
339         return;
340     }
341
342     HANDLE_EMPTY_MATCH;
343
344     /* get the workspace */
345     Con *ws;
346     if (strcmp(which, "next") == 0)
347         ws = workspace_next();
348     else if (strcmp(which, "prev") == 0)
349         ws = workspace_prev();
350     else if (strcmp(which, "next_on_output") == 0)
351         ws = workspace_next_on_output();
352     else if (strcmp(which, "prev_on_output") == 0)
353         ws = workspace_prev_on_output();
354     else if (strcmp(which, "current") == 0)
355         ws = con_get_workspace(focused);
356     else {
357         ELOG("BUG: called with which=%s\n", which);
358         ysuccess(false);
359         return;
360     }
361
362     TAILQ_FOREACH(current, &owindows, owindows) {
363         DLOG("matching: %p / %s\n", current->con, current->con->name);
364         con_move_to_workspace(current->con, ws, true, false, false);
365     }
366
367     cmd_output->needs_tree_render = true;
368     // XXX: default reply for now, make this a better reply
369     ysuccess(true);
370 }
371
372 /**
373  * Implementation of 'move [window|container] [to] workspace back_and_forth'.
374  *
375  */
376 void cmd_move_con_to_workspace_back_and_forth(I3_CMD) {
377     owindow *current;
378     Con *ws;
379
380     ws = workspace_back_and_forth_get();
381
382     if (ws == NULL) {
383         yerror("No workspace was previously active.");
384         return;
385     }
386
387     HANDLE_EMPTY_MATCH;
388
389     TAILQ_FOREACH(current, &owindows, owindows) {
390         DLOG("matching: %p / %s\n", current->con, current->con->name);
391         con_move_to_workspace(current->con, ws, true, false, false);
392     }
393
394     cmd_output->needs_tree_render = true;
395     // XXX: default reply for now, make this a better reply
396     ysuccess(true);
397 }
398
399 /*
400  * Implementation of 'move [window|container] [to] workspace <name>'.
401  *
402  */
403 void cmd_move_con_to_workspace_name(I3_CMD, const char *name) {
404     if (strncasecmp(name, "__", strlen("__")) == 0) {
405         LOG("You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
406         ysuccess(false);
407         return;
408     }
409
410     owindow *current;
411
412     /* We have nothing to move:
413      *  when criteria was specified but didn't match any window or
414      *  when criteria wasn't specified and we don't have any window focused. */
415     if (!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) {
416         ELOG("No windows match your criteria, cannot move.\n");
417         ysuccess(false);
418         return;
419     } else if (match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
420                !con_has_children(focused)) {
421         ysuccess(false);
422         return;
423     }
424
425     LOG("should move window to workspace %s\n", name);
426     /* get the workspace */
427     Con *ws = workspace_get(name, NULL);
428
429     ws = maybe_auto_back_and_forth_workspace(ws);
430
431     HANDLE_EMPTY_MATCH;
432
433     TAILQ_FOREACH(current, &owindows, owindows) {
434         DLOG("matching: %p / %s\n", current->con, current->con->name);
435         con_move_to_workspace(current->con, ws, true, false, false);
436     }
437
438     cmd_output->needs_tree_render = true;
439     // XXX: default reply for now, make this a better reply
440     ysuccess(true);
441 }
442
443 /*
444  * Implementation of 'move [window|container] [to] workspace number <name>'.
445  *
446  */
447 void cmd_move_con_to_workspace_number(I3_CMD, const char *which) {
448     owindow *current;
449
450     /* We have nothing to move:
451      *  when criteria was specified but didn't match any window or
452      *  when criteria wasn't specified and we don't have any window focused. */
453     if ((!match_is_empty(current_match) && TAILQ_EMPTY(&owindows)) ||
454         (match_is_empty(current_match) && focused->type == CT_WORKSPACE &&
455          !con_has_children(focused))) {
456         ysuccess(false);
457         return;
458     }
459
460     LOG("should move window to workspace %s\n", which);
461     /* get the workspace */
462     Con *output, *workspace = NULL;
463
464     long parsed_num = ws_name_to_number(which);
465
466     if (parsed_num == -1) {
467         LOG("Could not parse initial part of \"%s\" as a number.\n", which);
468         yerror("Could not parse number \"%s\"", which);
469         return;
470     }
471
472     TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
473     GREP_FIRST(workspace, output_get_content(output),
474                child->num == parsed_num);
475
476     if (!workspace) {
477         workspace = workspace_get(which, NULL);
478     }
479
480     workspace = maybe_auto_back_and_forth_workspace(workspace);
481
482     HANDLE_EMPTY_MATCH;
483
484     TAILQ_FOREACH(current, &owindows, owindows) {
485         DLOG("matching: %p / %s\n", current->con, current->con->name);
486         con_move_to_workspace(current->con, workspace, true, false, false);
487     }
488
489     cmd_output->needs_tree_render = true;
490     // XXX: default reply for now, make this a better reply
491     ysuccess(true);
492 }
493
494 static void cmd_resize_floating(I3_CMD, const char *way, const char *direction, Con *floating_con, int px) {
495     LOG("floating resize\n");
496     Rect old_rect = floating_con->rect;
497     Con *focused_con = con_descend_focused(floating_con);
498
499     /* ensure that resize will take place even if pixel increment is smaller than
500      * height increment or width increment.
501      * fixes #1011 */
502     const i3Window *window = focused_con->window;
503     if (window != NULL) {
504         if (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0 ||
505             strcmp(direction, "height") == 0) {
506             if (px < 0)
507                 px = (-px < window->height_increment) ? -window->height_increment : px;
508             else
509                 px = (px < window->height_increment) ? window->height_increment : px;
510         } else if (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0) {
511             if (px < 0)
512                 px = (-px < window->width_increment) ? -window->width_increment : px;
513             else
514                 px = (px < window->width_increment) ? window->width_increment : px;
515         }
516     }
517
518     if (strcmp(direction, "up") == 0) {
519         floating_con->rect.height += px;
520     } else if (strcmp(direction, "down") == 0 || strcmp(direction, "height") == 0) {
521         floating_con->rect.height += px;
522     } else if (strcmp(direction, "left") == 0) {
523         floating_con->rect.width += px;
524     } else {
525         floating_con->rect.width += px;
526     }
527
528     floating_check_size(floating_con);
529
530     /* Did we actually resize anything or did the size constraints prevent us?
531      * If we could not resize, exit now to not move the window. */
532     if (memcmp(&old_rect, &(floating_con->rect), sizeof(Rect)) == 0)
533         return;
534
535     if (strcmp(direction, "up") == 0) {
536         floating_con->rect.y -= (floating_con->rect.height - old_rect.height);
537     } else if (strcmp(direction, "left") == 0) {
538         floating_con->rect.x -= (floating_con->rect.width - old_rect.width);
539     }
540
541     /* If this is a scratchpad window, don't auto center it from now on. */
542     if (floating_con->scratchpad_state == SCRATCHPAD_FRESH)
543         floating_con->scratchpad_state = SCRATCHPAD_CHANGED;
544 }
545
546 static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
547     LOG("tiling resize\n");
548     Con *second = NULL;
549     Con *first = current;
550     direction_t search_direction;
551     if (!strcmp(direction, "left"))
552         search_direction = D_LEFT;
553     else if (!strcmp(direction, "right"))
554         search_direction = D_RIGHT;
555     else if (!strcmp(direction, "up"))
556         search_direction = D_UP;
557     else
558         search_direction = D_DOWN;
559
560     bool res = resize_find_tiling_participants(&first, &second, search_direction);
561     if (!res) {
562         LOG("No second container in this direction found.\n");
563         ysuccess(false);
564         return false;
565     }
566
567     /* get the default percentage */
568     int children = con_num_children(first->parent);
569     LOG("ins. %d children\n", children);
570     double percentage = 1.0 / children;
571     LOG("default percentage = %f\n", percentage);
572
573     /* resize */
574     LOG("second->percent = %f\n", second->percent);
575     LOG("first->percent before = %f\n", first->percent);
576     if (first->percent == 0.0)
577         first->percent = percentage;
578     if (second->percent == 0.0)
579         second->percent = percentage;
580     double new_first_percent = first->percent + ((double)ppt / 100.0);
581     double new_second_percent = second->percent - ((double)ppt / 100.0);
582     LOG("new_first_percent = %f\n", new_first_percent);
583     LOG("new_second_percent = %f\n", new_second_percent);
584     /* Ensure that the new percentages are positive and greater than
585      * 0.05 to have a reasonable minimum size. */
586     if (definitelyGreaterThan(new_first_percent, 0.05, DBL_EPSILON) &&
587         definitelyGreaterThan(new_second_percent, 0.05, DBL_EPSILON)) {
588         first->percent += ((double)ppt / 100.0);
589         second->percent -= ((double)ppt / 100.0);
590         LOG("first->percent after = %f\n", first->percent);
591         LOG("second->percent after = %f\n", second->percent);
592     } else {
593         LOG("Not resizing, already at minimum size\n");
594     }
595
596     return true;
597 }
598
599 static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int ppt) {
600     LOG("width/height resize\n");
601     /* get the appropriate current container (skip stacked/tabbed cons) */
602     while (current->parent->layout == L_STACKED ||
603            current->parent->layout == L_TABBED)
604         current = current->parent;
605
606     /* Then further go up until we find one with the matching orientation. */
607     orientation_t search_orientation =
608         (strcmp(direction, "width") == 0 ? HORIZ : VERT);
609
610     while (current->type != CT_WORKSPACE &&
611            current->type != CT_FLOATING_CON &&
612            con_orientation(current->parent) != search_orientation)
613         current = current->parent;
614
615     /* get the default percentage */
616     int children = con_num_children(current->parent);
617     LOG("ins. %d children\n", children);
618     double percentage = 1.0 / children;
619     LOG("default percentage = %f\n", percentage);
620
621     orientation_t orientation = con_orientation(current->parent);
622
623     if ((orientation == HORIZ &&
624          strcmp(direction, "height") == 0) ||
625         (orientation == VERT &&
626          strcmp(direction, "width") == 0)) {
627         LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
628             (orientation == HORIZ ? "horizontal" : "vertical"));
629         ysuccess(false);
630         return false;
631     }
632
633     if (children == 1) {
634         LOG("This is the only container, cannot resize.\n");
635         ysuccess(false);
636         return false;
637     }
638
639     /* Ensure all the other children have a percentage set. */
640     Con *child;
641     TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
642         LOG("child->percent = %f (child %p)\n", child->percent, child);
643         if (child->percent == 0.0)
644             child->percent = percentage;
645     }
646
647     double new_current_percent = current->percent + ((double)ppt / 100.0);
648     double subtract_percent = ((double)ppt / 100.0) / (children - 1);
649     LOG("new_current_percent = %f\n", new_current_percent);
650     LOG("subtract_percent = %f\n", subtract_percent);
651     /* Ensure that the new percentages are positive and greater than
652      * 0.05 to have a reasonable minimum size. */
653     TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
654         if (child == current)
655             continue;
656         if (!definitelyGreaterThan(child->percent - subtract_percent, 0.05, DBL_EPSILON)) {
657             LOG("Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->percent - subtract_percent);
658             ysuccess(false);
659             return false;
660         }
661     }
662     if (!definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON)) {
663         LOG("Not resizing, already at minimum size\n");
664         ysuccess(false);
665         return false;
666     }
667
668     current->percent += ((double)ppt / 100.0);
669     LOG("current->percent after = %f\n", current->percent);
670
671     TAILQ_FOREACH(child, &(current->parent->nodes_head), nodes) {
672         if (child == current)
673             continue;
674         child->percent -= subtract_percent;
675         LOG("child->percent after (%p) = %f\n", child, child->percent);
676     }
677
678     return true;
679 }
680
681 /*
682  * Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
683  *
684  */
685 void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, long resize_ppt) {
686     DLOG("resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
687     if (strcmp(way, "shrink") == 0) {
688         resize_px *= -1;
689         resize_ppt *= -1;
690     }
691
692     HANDLE_EMPTY_MATCH;
693
694     owindow *current;
695     TAILQ_FOREACH(current, &owindows, owindows) {
696         /* Don't handle dock windows (issue #1201) */
697         if (current->con->window && current->con->window->dock) {
698             DLOG("This is a dock window. Not resizing (con = %p)\n)", current->con);
699             continue;
700         }
701
702         Con *floating_con;
703         if ((floating_con = con_inside_floating(current->con))) {
704             cmd_resize_floating(current_match, cmd_output, way, direction, floating_con, resize_px);
705         } else {
706             if (strcmp(direction, "width") == 0 ||
707                 strcmp(direction, "height") == 0) {
708                 if (!cmd_resize_tiling_width_height(current_match, cmd_output,
709                                                     current->con, way, direction, resize_ppt))
710                     return;
711             } else {
712                 if (!cmd_resize_tiling_direction(current_match, cmd_output,
713                                                  current->con, way, direction, resize_ppt))
714                     return;
715             }
716         }
717     }
718
719     cmd_output->needs_tree_render = true;
720     // XXX: default reply for now, make this a better reply
721     ysuccess(true);
722 }
723
724 /*
725  * Implementation of 'resize set <px> [px] <px> [px]'.
726  *
727  */
728 void cmd_resize_set(I3_CMD, long cwidth, long cheight) {
729     DLOG("resizing to %ldx%ld px\n", cwidth, cheight);
730     if (cwidth <= 0 || cheight <= 0) {
731         ELOG("Resize failed: dimensions cannot be negative (was %ldx%ld)\n", cwidth, cheight);
732         return;
733     }
734
735     HANDLE_EMPTY_MATCH;
736
737     owindow *current;
738     TAILQ_FOREACH(current, &owindows, owindows) {
739         Con *floating_con;
740         if ((floating_con = con_inside_floating(current->con))) {
741             floating_resize(floating_con, cwidth, cheight);
742         } else {
743             ELOG("Resize failed: %p not a floating container\n", current->con);
744         }
745     }
746
747     cmd_output->needs_tree_render = true;
748     // XXX: default reply for now, make this a better reply
749     ysuccess(true);
750 }
751
752 /*
753  * Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
754  *
755  */
756 void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) {
757     DLOG("border style should be changed to %s with border width %s\n", border_style_str, border_width);
758     owindow *current;
759
760     HANDLE_EMPTY_MATCH;
761
762     TAILQ_FOREACH(current, &owindows, owindows) {
763         DLOG("matching: %p / %s\n", current->con, current->con->name);
764         int border_style = current->con->border_style;
765         char *end;
766         int tmp_border_width = -1;
767         tmp_border_width = strtol(border_width, &end, 10);
768         if (end == border_width) {
769             /* no valid digits found */
770             tmp_border_width = -1;
771         }
772         if (strcmp(border_style_str, "toggle") == 0) {
773             border_style++;
774             border_style %= 3;
775             if (border_style == BS_NORMAL)
776                 tmp_border_width = 2;
777             else if (border_style == BS_NONE)
778                 tmp_border_width = 0;
779             else if (border_style == BS_PIXEL)
780                 tmp_border_width = 1;
781         } else {
782             if (strcmp(border_style_str, "normal") == 0)
783                 border_style = BS_NORMAL;
784             else if (strcmp(border_style_str, "pixel") == 0)
785                 border_style = BS_PIXEL;
786             else if (strcmp(border_style_str, "1pixel") == 0) {
787                 border_style = BS_PIXEL;
788                 tmp_border_width = 1;
789             } else if (strcmp(border_style_str, "none") == 0)
790                 border_style = BS_NONE;
791             else {
792                 ELOG("BUG: called with border_style=%s\n", border_style_str);
793                 ysuccess(false);
794                 return;
795             }
796         }
797         con_set_border_style(current->con, border_style, tmp_border_width);
798     }
799
800     cmd_output->needs_tree_render = true;
801     // XXX: default reply for now, make this a better reply
802     ysuccess(true);
803 }
804
805 /*
806  * Implementation of 'nop <comment>'.
807  *
808  */
809 void cmd_nop(I3_CMD, const char *comment) {
810     LOG("-------------------------------------------------\n");
811     LOG("  NOP: %s\n", comment);
812     LOG("-------------------------------------------------\n");
813 }
814
815 /*
816  * Implementation of 'append_layout <path>'.
817  *
818  */
819 void cmd_append_layout(I3_CMD, const char *cpath) {
820     char *path = sstrdup(cpath);
821     LOG("Appending layout \"%s\"\n", path);
822
823     /* Make sure we allow paths like '~/.i3/layout.json' */
824     path = resolve_tilde(path);
825
826     json_content_t content = json_determine_content(path);
827     LOG("JSON content = %d\n", content);
828     if (content == JSON_CONTENT_UNKNOWN) {
829         ELOG("Could not determine the contents of \"%s\", not loading.\n", path);
830         yerror("Could not determine the contents of \"%s\".", path);
831         free(path);
832         return;
833     }
834
835     Con *parent = focused;
836     if (content == JSON_CONTENT_WORKSPACE) {
837         parent = output_get_content(con_get_output(parent));
838     } else {
839         /* We need to append the layout to a split container, since a leaf
840          * container must not have any children (by definition).
841          * Note that we explicitly check for workspaces, since they are okay for
842          * this purpose, but con_accepts_window() returns false for workspaces. */
843         while (parent->type != CT_WORKSPACE && !con_accepts_window(parent))
844             parent = parent->parent;
845     }
846     DLOG("Appending to parent=%p instead of focused=%p\n", parent, focused);
847     char *errormsg = NULL;
848     tree_append_json(parent, path, &errormsg);
849     if (errormsg != NULL) {
850         yerror(errormsg);
851         free(errormsg);
852         /* Note that we continue executing since tree_append_json() has
853          * side-effects — user-provided layouts can be partly valid, partly
854          * invalid, leading to half of the placeholder containers being
855          * created. */
856     } else {
857         ysuccess(true);
858     }
859
860     // XXX: This is a bit of a kludge. Theoretically, render_con(parent,
861     // false); should be enough, but when sending 'workspace 4; append_layout
862     // /tmp/foo.json', the needs_tree_render == true of the workspace command
863     // is not executed yet and will be batched with append_layout’s
864     // needs_tree_render after the parser finished. We should check if that is
865     // necessary at all.
866     render_con(croot, false);
867
868     restore_open_placeholder_windows(parent);
869
870     if (content == JSON_CONTENT_WORKSPACE)
871         ipc_send_workspace_event("restored", parent, NULL);
872
873     free(path);
874     cmd_output->needs_tree_render = true;
875 }
876
877 /*
878  * Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
879  *
880  */
881 void cmd_workspace(I3_CMD, const char *which) {
882     Con *ws;
883
884     DLOG("which=%s\n", which);
885
886     if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
887         LOG("Cannot switch workspace while in global fullscreen\n");
888         ysuccess(false);
889         return;
890     }
891
892     if (strcmp(which, "next") == 0)
893         ws = workspace_next();
894     else if (strcmp(which, "prev") == 0)
895         ws = workspace_prev();
896     else if (strcmp(which, "next_on_output") == 0)
897         ws = workspace_next_on_output();
898     else if (strcmp(which, "prev_on_output") == 0)
899         ws = workspace_prev_on_output();
900     else {
901         ELOG("BUG: called with which=%s\n", which);
902         ysuccess(false);
903         return;
904     }
905
906     workspace_show(ws);
907
908     cmd_output->needs_tree_render = true;
909     // XXX: default reply for now, make this a better reply
910     ysuccess(true);
911 }
912
913 /*
914  * Implementation of 'workspace number <name>'
915  *
916  */
917 void cmd_workspace_number(I3_CMD, const char *which) {
918     Con *output, *workspace = NULL;
919
920     if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
921         LOG("Cannot switch workspace while in global fullscreen\n");
922         ysuccess(false);
923         return;
924     }
925
926     long parsed_num = ws_name_to_number(which);
927
928     if (parsed_num == -1) {
929         LOG("Could not parse initial part of \"%s\" as a number.\n", which);
930         yerror("Could not parse number \"%s\"", which);
931         return;
932     }
933
934     TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
935     GREP_FIRST(workspace, output_get_content(output),
936                child->num == parsed_num);
937
938     if (!workspace) {
939         LOG("There is no workspace with number %ld, creating a new one.\n", parsed_num);
940         ysuccess(true);
941         workspace_show_by_name(which);
942         cmd_output->needs_tree_render = true;
943         return;
944     }
945     if (maybe_back_and_forth(cmd_output, workspace->name))
946         return;
947     workspace_show(workspace);
948
949     cmd_output->needs_tree_render = true;
950     // XXX: default reply for now, make this a better reply
951     ysuccess(true);
952 }
953
954 /*
955  * Implementation of 'workspace back_and_forth'.
956  *
957  */
958 void cmd_workspace_back_and_forth(I3_CMD) {
959     if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
960         LOG("Cannot switch workspace while in global fullscreen\n");
961         ysuccess(false);
962         return;
963     }
964
965     workspace_back_and_forth();
966
967     cmd_output->needs_tree_render = true;
968     // XXX: default reply for now, make this a better reply
969     ysuccess(true);
970 }
971
972 /*
973  * Implementation of 'workspace <name>'
974  *
975  */
976 void cmd_workspace_name(I3_CMD, const char *name) {
977     if (strncasecmp(name, "__", strlen("__")) == 0) {
978         LOG("You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
979         ysuccess(false);
980         return;
981     }
982
983     if (con_get_fullscreen_con(croot, CF_GLOBAL)) {
984         LOG("Cannot switch workspace while in global fullscreen\n");
985         ysuccess(false);
986         return;
987     }
988
989     DLOG("should switch to workspace %s\n", name);
990     if (maybe_back_and_forth(cmd_output, name))
991         return;
992     workspace_show_by_name(name);
993
994     cmd_output->needs_tree_render = true;
995     // XXX: default reply for now, make this a better reply
996     ysuccess(true);
997 }
998
999 /*
1000  * Implementation of 'mark [--toggle] <mark>'
1001  *
1002  */
1003 void cmd_mark(I3_CMD, const char *mark, const char *toggle) {
1004     HANDLE_EMPTY_MATCH;
1005
1006     owindow *current = TAILQ_FIRST(&owindows);
1007     if (current == NULL) {
1008         ysuccess(false);
1009         return;
1010     }
1011
1012     /* Marks must be unique, i.e., no two windows must have the same mark. */
1013     if (current != TAILQ_LAST(&owindows, owindows_head)) {
1014         yerror("A mark must not be put onto more than one window");
1015         return;
1016     }
1017
1018     DLOG("matching: %p / %s\n", current->con, current->con->name);
1019     if (toggle != NULL) {
1020         con_mark_toggle(current->con, mark);
1021     } else {
1022         con_mark(current->con, mark);
1023     }
1024
1025     cmd_output->needs_tree_render = true;
1026     // XXX: default reply for now, make this a better reply
1027     ysuccess(true);
1028 }
1029
1030 /*
1031  * Implementation of 'unmark [mark]'
1032  *
1033  */
1034 void cmd_unmark(I3_CMD, const char *mark) {
1035     con_unmark(mark);
1036
1037     cmd_output->needs_tree_render = true;
1038     // XXX: default reply for now, make this a better reply
1039     ysuccess(true);
1040 }
1041
1042 /*
1043  * Implementation of 'mode <string>'.
1044  *
1045  */
1046 void cmd_mode(I3_CMD, const char *mode) {
1047     DLOG("mode=%s\n", mode);
1048     switch_mode(mode);
1049
1050     // XXX: default reply for now, make this a better reply
1051     ysuccess(true);
1052 }
1053
1054 /*
1055  * Implementation of 'move [window|container] [to] output <str>'.
1056  *
1057  */
1058 void cmd_move_con_to_output(I3_CMD, const char *name) {
1059     DLOG("Should move window to output \"%s\".\n", name);
1060     HANDLE_EMPTY_MATCH;
1061
1062     owindow *current;
1063     bool had_error = false;
1064     TAILQ_FOREACH(current, &owindows, owindows) {
1065         DLOG("matching: %p / %s\n", current->con, current->con->name);
1066
1067         Output *current_output = get_output_of_con(current->con);
1068         assert(current_output != NULL);
1069
1070         Output *output = get_output_from_string(current_output, name);
1071         if (output == NULL) {
1072             ELOG("Could not find output \"%s\", skipping.\n", name);
1073             had_error = true;
1074             continue;
1075         }
1076
1077         Con *ws = NULL;
1078         GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
1079         if (ws == NULL) {
1080             ELOG("Could not find a visible workspace on output %p.\n", output);
1081             had_error = true;
1082             continue;
1083         }
1084
1085         con_move_to_workspace(current->con, ws, true, false, false);
1086     }
1087
1088     cmd_output->needs_tree_render = true;
1089     ysuccess(!had_error);
1090 }
1091
1092 /*
1093  * Implementation of 'move [container|window] [to] mark <str>'.
1094  *
1095  */
1096 void cmd_move_con_to_mark(I3_CMD, const char *mark) {
1097     DLOG("moving window to mark \"%s\"\n", mark);
1098
1099     HANDLE_EMPTY_MATCH;
1100
1101     bool result = true;
1102     owindow *current;
1103     TAILQ_FOREACH(current, &owindows, owindows) {
1104         DLOG("moving matched window %p / %s to mark \"%s\"\n", current->con, current->con->name, mark);
1105         result &= con_move_to_mark(current->con, mark);
1106     }
1107
1108     cmd_output->needs_tree_render = true;
1109     ysuccess(result);
1110 }
1111
1112 /*
1113  * Implementation of 'floating enable|disable|toggle'
1114  *
1115  */
1116 void cmd_floating(I3_CMD, const char *floating_mode) {
1117     owindow *current;
1118
1119     DLOG("floating_mode=%s\n", floating_mode);
1120
1121     HANDLE_EMPTY_MATCH;
1122
1123     TAILQ_FOREACH(current, &owindows, owindows) {
1124         DLOG("matching: %p / %s\n", current->con, current->con->name);
1125         if (strcmp(floating_mode, "toggle") == 0) {
1126             DLOG("should toggle mode\n");
1127             toggle_floating_mode(current->con, false);
1128         } else {
1129             DLOG("should switch mode to %s\n", floating_mode);
1130             if (strcmp(floating_mode, "enable") == 0) {
1131                 floating_enable(current->con, false);
1132             } else {
1133                 floating_disable(current->con, false);
1134             }
1135         }
1136     }
1137
1138     cmd_output->needs_tree_render = true;
1139     // XXX: default reply for now, make this a better reply
1140     ysuccess(true);
1141 }
1142
1143 /*
1144  * Implementation of 'move workspace to [output] <str>'.
1145  *
1146  */
1147 void cmd_move_workspace_to_output(I3_CMD, const char *name) {
1148     DLOG("should move workspace to output %s\n", name);
1149
1150     HANDLE_EMPTY_MATCH;
1151
1152     owindow *current;
1153     TAILQ_FOREACH(current, &owindows, owindows) {
1154         Con *ws = con_get_workspace(current->con);
1155         bool success = workspace_move_to_output(ws, name);
1156         if (!success) {
1157             ELOG("Failed to move workspace to output.\n");
1158             ysuccess(false);
1159             return;
1160         }
1161     }
1162
1163     cmd_output->needs_tree_render = true;
1164     // XXX: default reply for now, make this a better reply
1165     ysuccess(true);
1166 }
1167
1168 /*
1169  * Implementation of 'split v|h|vertical|horizontal'.
1170  *
1171  */
1172 void cmd_split(I3_CMD, const char *direction) {
1173     HANDLE_EMPTY_MATCH;
1174
1175     owindow *current;
1176     LOG("splitting in direction %c\n", direction[0]);
1177     TAILQ_FOREACH(current, &owindows, owindows) {
1178         if (con_is_docked(current->con)) {
1179             ELOG("Cannot split a docked container, skipping.\n");
1180             continue;
1181         }
1182
1183         DLOG("matching: %p / %s\n", current->con, current->con->name);
1184         tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
1185     }
1186
1187     cmd_output->needs_tree_render = true;
1188     // XXX: default reply for now, make this a better reply
1189     ysuccess(true);
1190 }
1191
1192 /*
1193  * Implementation of 'kill [window|client]'.
1194  *
1195  */
1196 void cmd_kill(I3_CMD, const char *kill_mode_str) {
1197     if (kill_mode_str == NULL)
1198         kill_mode_str = "window";
1199     owindow *current;
1200
1201     DLOG("kill_mode=%s\n", kill_mode_str);
1202
1203     int kill_mode;
1204     if (strcmp(kill_mode_str, "window") == 0)
1205         kill_mode = KILL_WINDOW;
1206     else if (strcmp(kill_mode_str, "client") == 0)
1207         kill_mode = KILL_CLIENT;
1208     else {
1209         ELOG("BUG: called with kill_mode=%s\n", kill_mode_str);
1210         ysuccess(false);
1211         return;
1212     }
1213
1214     /* check if the match is empty, not if the result is empty */
1215     if (match_is_empty(current_match))
1216         tree_close_con(kill_mode);
1217     else {
1218         TAILQ_FOREACH(current, &owindows, owindows) {
1219             DLOG("matching: %p / %s\n", current->con, current->con->name);
1220             tree_close(current->con, kill_mode, false, false);
1221         }
1222     }
1223
1224     cmd_output->needs_tree_render = true;
1225     // XXX: default reply for now, make this a better reply
1226     ysuccess(true);
1227 }
1228
1229 /*
1230  * Implementation of 'exec [--no-startup-id] <command>'.
1231  *
1232  */
1233 void cmd_exec(I3_CMD, const char *nosn, const char *command) {
1234     bool no_startup_id = (nosn != NULL);
1235
1236     DLOG("should execute %s, no_startup_id = %d\n", command, no_startup_id);
1237     start_application(command, no_startup_id);
1238
1239     // XXX: default reply for now, make this a better reply
1240     ysuccess(true);
1241 }
1242
1243 /*
1244  * Implementation of 'focus left|right|up|down'.
1245  *
1246  */
1247 void cmd_focus_direction(I3_CMD, const char *direction) {
1248     DLOG("direction = *%s*\n", direction);
1249
1250     if (strcmp(direction, "left") == 0)
1251         tree_next('p', HORIZ);
1252     else if (strcmp(direction, "right") == 0)
1253         tree_next('n', HORIZ);
1254     else if (strcmp(direction, "up") == 0)
1255         tree_next('p', VERT);
1256     else if (strcmp(direction, "down") == 0)
1257         tree_next('n', VERT);
1258     else {
1259         ELOG("Invalid focus direction (%s)\n", direction);
1260         ysuccess(false);
1261         return;
1262     }
1263
1264     cmd_output->needs_tree_render = true;
1265     // XXX: default reply for now, make this a better reply
1266     ysuccess(true);
1267 }
1268
1269 /*
1270  * Implementation of 'focus tiling|floating|mode_toggle'.
1271  *
1272  */
1273 void cmd_focus_window_mode(I3_CMD, const char *window_mode) {
1274     DLOG("window_mode = %s\n", window_mode);
1275
1276     Con *ws = con_get_workspace(focused);
1277     if (ws != NULL) {
1278         if (strcmp(window_mode, "mode_toggle") == 0) {
1279             if (con_inside_floating(focused))
1280                 window_mode = "tiling";
1281             else
1282                 window_mode = "floating";
1283         }
1284         Con *current;
1285         TAILQ_FOREACH(current, &(ws->focus_head), focused) {
1286             if ((strcmp(window_mode, "floating") == 0 && current->type != CT_FLOATING_CON) ||
1287                 (strcmp(window_mode, "tiling") == 0 && current->type == CT_FLOATING_CON))
1288                 continue;
1289
1290             con_focus(con_descend_focused(current));
1291             break;
1292         }
1293     }
1294
1295     cmd_output->needs_tree_render = true;
1296     // XXX: default reply for now, make this a better reply
1297     ysuccess(true);
1298 }
1299
1300 /*
1301  * Implementation of 'focus parent|child'.
1302  *
1303  */
1304 void cmd_focus_level(I3_CMD, const char *level) {
1305     DLOG("level = %s\n", level);
1306     bool success = false;
1307
1308     /* Focusing the parent can only be allowed if the newly
1309      * focused container won't escape the fullscreen container. */
1310     if (strcmp(level, "parent") == 0) {
1311         if (focused && focused->parent) {
1312             if (con_fullscreen_permits_focusing(focused->parent))
1313                 success = level_up();
1314             else
1315                 ELOG("'focus parent': Currently in fullscreen, not going up\n");
1316         }
1317     }
1318
1319     /* Focusing a child should always be allowed. */
1320     else
1321         success = level_down();
1322
1323     cmd_output->needs_tree_render = success;
1324     // XXX: default reply for now, make this a better reply
1325     ysuccess(success);
1326 }
1327
1328 /*
1329  * Implementation of 'focus'.
1330  *
1331  */
1332 void cmd_focus(I3_CMD) {
1333     DLOG("current_match = %p\n", current_match);
1334
1335     if (match_is_empty(current_match)) {
1336         ELOG("You have to specify which window/container should be focused.\n");
1337         ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1338
1339         yerror("You have to specify which window/container should be focused");
1340
1341         return;
1342     }
1343
1344     Con *__i3_scratch = workspace_get("__i3_scratch", NULL);
1345     int count = 0;
1346     owindow *current;
1347     TAILQ_FOREACH(current, &owindows, owindows) {
1348         Con *ws = con_get_workspace(current->con);
1349         /* If no workspace could be found, this was a dock window.
1350          * Just skip it, you cannot focus dock windows. */
1351         if (!ws)
1352             continue;
1353
1354         /* Check the fullscreen focus constraints. */
1355         if (!con_fullscreen_permits_focusing(current->con)) {
1356             LOG("Cannot change focus while in fullscreen mode (fullscreen rules).\n");
1357             ysuccess(false);
1358             return;
1359         }
1360
1361         /* In case this is a scratchpad window, call scratchpad_show(). */
1362         if (ws == __i3_scratch) {
1363             scratchpad_show(current->con);
1364             count++;
1365             /* While for the normal focus case we can change focus multiple
1366              * times and only a single window ends up focused, we could show
1367              * multiple scratchpad windows. So, rather break here. */
1368             break;
1369         }
1370
1371         /* If the container is not on the current workspace,
1372          * workspace_show() will switch to a different workspace and (if
1373          * enabled) trigger a mouse pointer warp to the currently focused
1374          * container (!) on the target workspace.
1375          *
1376          * Therefore, before calling workspace_show(), we make sure that
1377          * 'current' will be focused on the workspace. However, we cannot
1378          * just con_focus(current) because then the pointer will not be
1379          * warped at all (the code thinks we are already there).
1380          *
1381          * So we focus 'current' to make it the currently focused window of
1382          * the target workspace, then revert focus. */
1383         Con *currently_focused = focused;
1384         con_focus(current->con);
1385         con_focus(currently_focused);
1386
1387         /* Now switch to the workspace, then focus */
1388         workspace_show(ws);
1389         LOG("focusing %p / %s\n", current->con, current->con->name);
1390         con_focus(current->con);
1391         count++;
1392     }
1393
1394     if (count > 1)
1395         LOG("WARNING: Your criteria for the focus command matches %d containers, "
1396             "while only exactly one container can be focused at a time.\n",
1397             count);
1398
1399     cmd_output->needs_tree_render = true;
1400     ysuccess(count > 0);
1401 }
1402
1403 /*
1404  * Implementation of 'fullscreen enable|toggle [global]' and
1405  *                   'fullscreen disable'
1406  *
1407  */
1408 void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode) {
1409     fullscreen_mode_t mode = strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT;
1410     DLOG("%s fullscreen, mode = %s\n", action, fullscreen_mode);
1411     owindow *current;
1412
1413     HANDLE_EMPTY_MATCH;
1414
1415     TAILQ_FOREACH(current, &owindows, owindows) {
1416         DLOG("matching: %p / %s\n", current->con, current->con->name);
1417         if (strcmp(action, "toggle") == 0) {
1418             con_toggle_fullscreen(current->con, mode);
1419         } else if (strcmp(action, "enable") == 0) {
1420             con_enable_fullscreen(current->con, mode);
1421         } else if (strcmp(action, "disable") == 0) {
1422             con_disable_fullscreen(current->con);
1423         }
1424     }
1425
1426     cmd_output->needs_tree_render = true;
1427     // XXX: default reply for now, make this a better reply
1428     ysuccess(true);
1429 }
1430
1431 /*
1432  * Implementation of 'sticky enable|disable|toggle'.
1433  *
1434  */
1435 void cmd_sticky(I3_CMD, const char *action) {
1436     DLOG("%s sticky on window\n", action);
1437     HANDLE_EMPTY_MATCH;
1438
1439     owindow *current;
1440     TAILQ_FOREACH(current, &owindows, owindows) {
1441         if (current->con->window == NULL) {
1442             ELOG("only containers holding a window can be made sticky, skipping con = %p\n", current->con);
1443             continue;
1444         }
1445         DLOG("setting sticky for container = %p / %s\n", current->con, current->con->name);
1446
1447         bool sticky = false;
1448         if (strcmp(action, "enable") == 0)
1449             sticky = true;
1450         else if (strcmp(action, "disable") == 0)
1451             sticky = false;
1452         else if (strcmp(action, "toggle") == 0)
1453             sticky = !current->con->sticky;
1454
1455         current->con->sticky = sticky;
1456         ewmh_update_sticky(current->con->window->id, sticky);
1457     }
1458
1459     /* A window we made sticky might not be on a visible workspace right now, so we need to make
1460      * sure it gets pushed to the front now. */
1461     output_push_sticky_windows(focused);
1462
1463     cmd_output->needs_tree_render = true;
1464     ysuccess(true);
1465 }
1466
1467 /*
1468  * Implementation of 'move <direction> [<pixels> [px]]'.
1469  *
1470  */
1471 void cmd_move_direction(I3_CMD, const char *direction, long move_px) {
1472     owindow *current;
1473     HANDLE_EMPTY_MATCH;
1474
1475     Con *initially_focused = focused;
1476
1477     TAILQ_FOREACH(current, &owindows, owindows) {
1478         DLOG("moving in direction %s, px %ld\n", direction, move_px);
1479         if (con_is_floating(current->con)) {
1480             DLOG("floating move with %ld pixels\n", move_px);
1481             Rect newrect = current->con->parent->rect;
1482             if (strcmp(direction, "left") == 0) {
1483                 newrect.x -= move_px;
1484             } else if (strcmp(direction, "right") == 0) {
1485                 newrect.x += move_px;
1486             } else if (strcmp(direction, "up") == 0) {
1487                 newrect.y -= move_px;
1488             } else if (strcmp(direction, "down") == 0) {
1489                 newrect.y += move_px;
1490             }
1491             floating_reposition(current->con->parent, newrect);
1492         } else {
1493             tree_move(current->con, (strcmp(direction, "right") == 0 ? D_RIGHT : (strcmp(direction, "left") == 0 ? D_LEFT : (strcmp(direction, "up") == 0 ? D_UP : D_DOWN))));
1494             cmd_output->needs_tree_render = true;
1495         }
1496     }
1497
1498     /* the move command should not disturb focus */
1499     if (focused != initially_focused)
1500         con_focus(initially_focused);
1501
1502     // XXX: default reply for now, make this a better reply
1503     ysuccess(true);
1504 }
1505
1506 /*
1507  * Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
1508  *
1509  */
1510 void cmd_layout(I3_CMD, const char *layout_str) {
1511     HANDLE_EMPTY_MATCH;
1512
1513     if (strcmp(layout_str, "stacking") == 0)
1514         layout_str = "stacked";
1515     layout_t layout;
1516     /* default is a special case which will be handled in con_set_layout(). */
1517     if (strcmp(layout_str, "default") == 0)
1518         layout = L_DEFAULT;
1519     else if (strcmp(layout_str, "stacked") == 0)
1520         layout = L_STACKED;
1521     else if (strcmp(layout_str, "tabbed") == 0)
1522         layout = L_TABBED;
1523     else if (strcmp(layout_str, "splitv") == 0)
1524         layout = L_SPLITV;
1525     else if (strcmp(layout_str, "splith") == 0)
1526         layout = L_SPLITH;
1527     else {
1528         ELOG("Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
1529         return;
1530     }
1531
1532     DLOG("changing layout to %s (%d)\n", layout_str, layout);
1533
1534     owindow *current;
1535     TAILQ_FOREACH(current, &owindows, owindows) {
1536         if (con_is_docked(current->con)) {
1537             ELOG("cannot change layout of a docked container, skipping it.\n");
1538             continue;
1539         }
1540
1541         DLOG("matching: %p / %s\n", current->con, current->con->name);
1542         con_set_layout(current->con, layout);
1543     }
1544
1545     cmd_output->needs_tree_render = true;
1546     // XXX: default reply for now, make this a better reply
1547     ysuccess(true);
1548 }
1549
1550 /*
1551  * Implementation of 'layout toggle [all|split]'.
1552  *
1553  */
1554 void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
1555     owindow *current;
1556
1557     if (toggle_mode == NULL)
1558         toggle_mode = "default";
1559
1560     DLOG("toggling layout (mode = %s)\n", toggle_mode);
1561
1562     /* check if the match is empty, not if the result is empty */
1563     if (match_is_empty(current_match))
1564         con_toggle_layout(focused, toggle_mode);
1565     else {
1566         TAILQ_FOREACH(current, &owindows, owindows) {
1567             DLOG("matching: %p / %s\n", current->con, current->con->name);
1568             con_toggle_layout(current->con, toggle_mode);
1569         }
1570     }
1571
1572     cmd_output->needs_tree_render = true;
1573     // XXX: default reply for now, make this a better reply
1574     ysuccess(true);
1575 }
1576
1577 /*
1578  * Implementation of 'exit'.
1579  *
1580  */
1581 void cmd_exit(I3_CMD) {
1582     LOG("Exiting due to user command.\n");
1583     ipc_shutdown();
1584     unlink(config.ipc_socket_path);
1585     xcb_disconnect(conn);
1586     exit(0);
1587
1588     /* unreached */
1589 }
1590
1591 /*
1592  * Implementation of 'reload'.
1593  *
1594  */
1595 void cmd_reload(I3_CMD) {
1596     LOG("reloading\n");
1597     kill_nagbar(&config_error_nagbar_pid, false);
1598     kill_nagbar(&command_error_nagbar_pid, false);
1599     load_configuration(conn, NULL, true);
1600     x_set_i3_atoms();
1601     /* Send an IPC event just in case the ws names have changed */
1602     ipc_send_workspace_event("reload", NULL, NULL);
1603     /* Send an update event for the barconfig just in case it has changed */
1604     update_barconfig();
1605
1606     // XXX: default reply for now, make this a better reply
1607     ysuccess(true);
1608 }
1609
1610 /*
1611  * Implementation of 'restart'.
1612  *
1613  */
1614 void cmd_restart(I3_CMD) {
1615     LOG("restarting i3\n");
1616     ipc_shutdown();
1617     unlink(config.ipc_socket_path);
1618     /* We need to call this manually since atexit handlers don’t get called
1619      * when exec()ing */
1620     purge_zerobyte_logfile();
1621     i3_restart(false);
1622
1623     // XXX: default reply for now, make this a better reply
1624     ysuccess(true);
1625 }
1626
1627 /*
1628  * Implementation of 'open'.
1629  *
1630  */
1631 void cmd_open(I3_CMD) {
1632     LOG("opening new container\n");
1633     Con *con = tree_open_con(NULL, NULL);
1634     con->layout = L_SPLITH;
1635     con_focus(con);
1636
1637     y(map_open);
1638     ystr("success");
1639     y(bool, true);
1640     ystr("id");
1641     y(integer, (long int)con);
1642     y(map_close);
1643
1644     cmd_output->needs_tree_render = true;
1645 }
1646
1647 /*
1648  * Implementation of 'focus output <output>'.
1649  *
1650  */
1651 void cmd_focus_output(I3_CMD, const char *name) {
1652     owindow *current;
1653
1654     DLOG("name = %s\n", name);
1655
1656     HANDLE_EMPTY_MATCH;
1657
1658     /* get the output */
1659     Output *current_output = NULL;
1660     Output *output;
1661
1662     TAILQ_FOREACH(current, &owindows, owindows)
1663     current_output = get_output_of_con(current->con);
1664     assert(current_output != NULL);
1665
1666     output = get_output_from_string(current_output, name);
1667
1668     if (!output) {
1669         LOG("No such output found.\n");
1670         ysuccess(false);
1671         return;
1672     }
1673
1674     /* get visible workspace on output */
1675     Con *ws = NULL;
1676     GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
1677     if (!ws) {
1678         ysuccess(false);
1679         return;
1680     }
1681
1682     workspace_show(ws);
1683
1684     cmd_output->needs_tree_render = true;
1685     // XXX: default reply for now, make this a better reply
1686     ysuccess(true);
1687 }
1688
1689 /*
1690  * Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]
1691  *
1692  */
1693 void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y) {
1694     bool has_error = false;
1695
1696     owindow *current;
1697     HANDLE_EMPTY_MATCH;
1698
1699     TAILQ_FOREACH(current, &owindows, owindows) {
1700         if (!con_is_floating(current->con)) {
1701             ELOG("Cannot change position. The window/container is not floating\n");
1702
1703             if (!has_error) {
1704                 yerror("Cannot change position of a window/container because it is not floating.");
1705                 has_error = true;
1706             }
1707
1708             continue;
1709         }
1710
1711         if (strcmp(method, "absolute") == 0) {
1712             current->con->parent->rect.x = x;
1713             current->con->parent->rect.y = y;
1714
1715             DLOG("moving to absolute position %ld %ld\n", x, y);
1716             floating_maybe_reassign_ws(current->con->parent);
1717             cmd_output->needs_tree_render = true;
1718         }
1719
1720         if (strcmp(method, "position") == 0) {
1721             Rect newrect = current->con->parent->rect;
1722
1723             DLOG("moving to position %ld %ld\n", x, y);
1724             newrect.x = x;
1725             newrect.y = y;
1726
1727             floating_reposition(current->con->parent, newrect);
1728         }
1729     }
1730
1731     // XXX: default reply for now, make this a better reply
1732     if (!has_error)
1733         ysuccess(true);
1734 }
1735
1736 /*
1737  * Implementation of 'move [window|container] [to] [absolute] position center
1738  *
1739  */
1740 void cmd_move_window_to_center(I3_CMD, const char *method) {
1741     if (!con_is_floating(focused)) {
1742         ELOG("Cannot change position. The window/container is not floating\n");
1743         yerror("Cannot change position. The window/container is not floating.");
1744         return;
1745     }
1746
1747     if (strcmp(method, "absolute") == 0) {
1748         DLOG("moving to absolute center\n");
1749         floating_center(focused->parent, croot->rect);
1750
1751         floating_maybe_reassign_ws(focused->parent);
1752         cmd_output->needs_tree_render = true;
1753     }
1754
1755     if (strcmp(method, "position") == 0) {
1756         DLOG("moving to center\n");
1757         floating_center(focused->parent, con_get_workspace(focused)->rect);
1758
1759         cmd_output->needs_tree_render = true;
1760     }
1761
1762     // XXX: default reply for now, make this a better reply
1763     ysuccess(true);
1764 }
1765
1766 /*
1767  * Implementation of 'move [window|container] [to] position mouse'
1768  *
1769  */
1770 void cmd_move_window_to_mouse(I3_CMD) {
1771     HANDLE_EMPTY_MATCH;
1772
1773     owindow *current;
1774     TAILQ_FOREACH(current, &owindows, owindows) {
1775         Con *floating_con = con_inside_floating(current->con);
1776         if (floating_con == NULL) {
1777             DLOG("con %p / %s is not floating, cannot move it to the mouse position.\n",
1778                  current->con, current->con->name);
1779             continue;
1780         }
1781
1782         DLOG("moving floating container %p / %s to cursor position\n", floating_con, floating_con->name);
1783         floating_move_to_pointer(floating_con);
1784     }
1785
1786     cmd_output->needs_tree_render = true;
1787     ysuccess(true);
1788 }
1789
1790 /*
1791  * Implementation of 'move scratchpad'.
1792  *
1793  */
1794 void cmd_move_scratchpad(I3_CMD) {
1795     DLOG("should move window to scratchpad\n");
1796     owindow *current;
1797
1798     HANDLE_EMPTY_MATCH;
1799
1800     TAILQ_FOREACH(current, &owindows, owindows) {
1801         DLOG("matching: %p / %s\n", current->con, current->con->name);
1802         scratchpad_move(current->con);
1803     }
1804
1805     cmd_output->needs_tree_render = true;
1806     // XXX: default reply for now, make this a better reply
1807     ysuccess(true);
1808 }
1809
1810 /*
1811  * Implementation of 'scratchpad show'.
1812  *
1813  */
1814 void cmd_scratchpad_show(I3_CMD) {
1815     DLOG("should show scratchpad window\n");
1816     owindow *current;
1817
1818     if (match_is_empty(current_match)) {
1819         scratchpad_show(NULL);
1820     } else {
1821         TAILQ_FOREACH(current, &owindows, owindows) {
1822             DLOG("matching: %p / %s\n", current->con, current->con->name);
1823             scratchpad_show(current->con);
1824         }
1825     }
1826
1827     cmd_output->needs_tree_render = true;
1828     // XXX: default reply for now, make this a better reply
1829     ysuccess(true);
1830 }
1831
1832 /*
1833  * Implementation of 'title_format <format>'
1834  *
1835  */
1836 void cmd_title_format(I3_CMD, const char *format) {
1837     DLOG("setting title_format to \"%s\"\n", format);
1838     HANDLE_EMPTY_MATCH;
1839
1840     owindow *current;
1841     TAILQ_FOREACH(current, &owindows, owindows) {
1842         if (current->con->window == NULL)
1843             continue;
1844
1845         DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
1846         FREE(current->con->window->title_format);
1847
1848         /* If we only display the title without anything else, we can skip the parsing step,
1849          * so we remove the title format altogether. */
1850         if (strcasecmp(format, "%title") != 0) {
1851             current->con->window->title_format = sstrdup(format);
1852
1853             i3String *formatted_title = window_parse_title_format(current->con->window);
1854             ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
1855             I3STRING_FREE(formatted_title);
1856         } else {
1857             /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
1858             ewmh_update_visible_name(current->con->window->id, NULL);
1859         }
1860
1861         /* Make sure the window title is redrawn immediately. */
1862         current->con->window->name_x_changed = true;
1863     }
1864
1865     cmd_output->needs_tree_render = true;
1866     ysuccess(true);
1867 }
1868
1869 /*
1870  * Implementation of 'rename workspace [<name>] to <name>'
1871  *
1872  */
1873 void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
1874     if (strncasecmp(new_name, "__", strlen("__")) == 0) {
1875         LOG("Cannot rename workspace to \"%s\": names starting with __ are i3-internal.\n", new_name);
1876         ysuccess(false);
1877         return;
1878     }
1879     if (old_name) {
1880         LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1881     } else {
1882         LOG("Renaming current workspace to \"%s\"\n", new_name);
1883     }
1884
1885     Con *output, *workspace = NULL;
1886     if (old_name) {
1887         TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
1888         GREP_FIRST(workspace, output_get_content(output),
1889                    !strcasecmp(child->name, old_name));
1890     } else {
1891         workspace = con_get_workspace(focused);
1892         old_name = workspace->name;
1893     }
1894
1895     if (!workspace) {
1896         yerror("Old workspace \"%s\" not found", old_name);
1897         return;
1898     }
1899
1900     Con *check_dest = NULL;
1901     TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
1902     GREP_FIRST(check_dest, output_get_content(output),
1903                !strcasecmp(child->name, new_name));
1904
1905     if (check_dest != NULL) {
1906         yerror("New workspace \"%s\" already exists", new_name);
1907         return;
1908     }
1909
1910     /* Change the name and try to parse it as a number. */
1911     FREE(workspace->name);
1912     workspace->name = sstrdup(new_name);
1913
1914     workspace->num = ws_name_to_number(new_name);
1915     LOG("num = %d\n", workspace->num);
1916
1917     /* By re-attaching, the sort order will be correct afterwards. */
1918     Con *previously_focused = focused;
1919     Con *parent = workspace->parent;
1920     con_detach(workspace);
1921     con_attach(workspace, parent, false);
1922
1923     /* Move the workspace to the correct output if it has an assignment */
1924     struct Workspace_Assignment *assignment = NULL;
1925     TAILQ_FOREACH(assignment, &ws_assignments, ws_assignments) {
1926         if (assignment->output == NULL)
1927             continue;
1928         if (strcmp(assignment->name, workspace->name) != 0 && (!name_is_digits(assignment->name) || ws_name_to_number(assignment->name) != workspace->num)) {
1929             continue;
1930         }
1931
1932         workspace_move_to_output(workspace, assignment->output);
1933
1934         if (previously_focused)
1935             workspace_show(con_get_workspace(previously_focused));
1936
1937         break;
1938     }
1939
1940     /* Restore the previous focus since con_attach messes with the focus. */
1941     con_focus(previously_focused);
1942
1943     cmd_output->needs_tree_render = true;
1944     ysuccess(true);
1945
1946     ipc_send_workspace_event("rename", workspace, NULL);
1947     ewmh_update_desktop_names();
1948     ewmh_update_desktop_viewport();
1949     ewmh_update_current_desktop();
1950
1951     startup_sequence_rename_workspace(old_name, new_name);
1952 }
1953
1954 /*
1955  * Implementation of 'bar mode dock|hide|invisible|toggle [<bar_id>]'
1956  *
1957  */
1958 bool cmd_bar_mode(const char *bar_mode, const char *bar_id) {
1959     int mode = M_DOCK;
1960     bool toggle = false;
1961     if (strcmp(bar_mode, "dock") == 0)
1962         mode = M_DOCK;
1963     else if (strcmp(bar_mode, "hide") == 0)
1964         mode = M_HIDE;
1965     else if (strcmp(bar_mode, "invisible") == 0)
1966         mode = M_INVISIBLE;
1967     else if (strcmp(bar_mode, "toggle") == 0)
1968         toggle = true;
1969     else {
1970         ELOG("Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
1971         return false;
1972     }
1973
1974     bool changed_sth = false;
1975     Barconfig *current = NULL;
1976     TAILQ_FOREACH(current, &barconfigs, configs) {
1977         if (bar_id && strcmp(current->id, bar_id) != 0)
1978             continue;
1979
1980         if (toggle)
1981             mode = (current->mode + 1) % 2;
1982
1983         DLOG("Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->id, bar_mode, mode);
1984         current->mode = mode;
1985         changed_sth = true;
1986
1987         if (bar_id)
1988             break;
1989     }
1990
1991     if (bar_id && !changed_sth) {
1992         DLOG("Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
1993         return false;
1994     }
1995
1996     return true;
1997 }
1998
1999 /*
2000  * Implementation of 'bar hidden_state hide|show|toggle [<bar_id>]'
2001  *
2002  */
2003 bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id) {
2004     int hidden_state = S_SHOW;
2005     bool toggle = false;
2006     if (strcmp(bar_hidden_state, "hide") == 0)
2007         hidden_state = S_HIDE;
2008     else if (strcmp(bar_hidden_state, "show") == 0)
2009         hidden_state = S_SHOW;
2010     else if (strcmp(bar_hidden_state, "toggle") == 0)
2011         toggle = true;
2012     else {
2013         ELOG("Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2014         return false;
2015     }
2016
2017     bool changed_sth = false;
2018     Barconfig *current = NULL;
2019     TAILQ_FOREACH(current, &barconfigs, configs) {
2020         if (bar_id && strcmp(current->id, bar_id) != 0)
2021             continue;
2022
2023         if (toggle)
2024             hidden_state = (current->hidden_state + 1) % 2;
2025
2026         DLOG("Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->id, bar_hidden_state, hidden_state);
2027         current->hidden_state = hidden_state;
2028         changed_sth = true;
2029
2030         if (bar_id)
2031             break;
2032     }
2033
2034     if (bar_id && !changed_sth) {
2035         DLOG("Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2036         return false;
2037     }
2038
2039     return true;
2040 }
2041
2042 /*
2043  * Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'
2044  *
2045  */
2046 void cmd_bar(I3_CMD, const char *bar_type, const char *bar_value, const char *bar_id) {
2047     bool ret;
2048     if (strcmp(bar_type, "mode") == 0)
2049         ret = cmd_bar_mode(bar_value, bar_id);
2050     else if (strcmp(bar_type, "hidden_state") == 0)
2051         ret = cmd_bar_hidden_state(bar_value, bar_id);
2052     else {
2053         ELOG("Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2054         ret = false;
2055     }
2056
2057     ysuccess(ret);
2058     if (!ret)
2059         return;
2060
2061     update_barconfig();
2062 }
2063
2064 /*
2065  * Implementation of 'shmlog <size>|toggle|on|off'
2066  *
2067  */
2068 void cmd_shmlog(I3_CMD, const char *argument) {
2069     if (!strcmp(argument, "toggle"))
2070         /* Toggle shm log, if size is not 0. If it is 0, set it to default. */
2071         shmlog_size = shmlog_size ? -shmlog_size : default_shmlog_size;
2072     else if (!strcmp(argument, "on"))
2073         shmlog_size = default_shmlog_size;
2074     else if (!strcmp(argument, "off"))
2075         shmlog_size = 0;
2076     else {
2077         /* If shm logging now, restart logging with the new size. */
2078         if (shmlog_size > 0) {
2079             shmlog_size = 0;
2080             LOG("Restarting shm logging...\n");
2081             init_logging();
2082         }
2083         shmlog_size = atoi(argument);
2084         /* Make a weakly attempt at ensuring the argument is valid. */
2085         if (shmlog_size <= 0)
2086             shmlog_size = default_shmlog_size;
2087     }
2088     LOG("%s shm logging\n", shmlog_size > 0 ? "Enabling" : "Disabling");
2089     init_logging();
2090     update_shmlog_atom();
2091     // XXX: default reply for now, make this a better reply
2092     ysuccess(true);
2093 }
2094
2095 /*
2096  * Implementation of 'debuglog toggle|on|off'
2097  *
2098  */
2099 void cmd_debuglog(I3_CMD, const char *argument) {
2100     bool logging = get_debug_logging();
2101     if (!strcmp(argument, "toggle")) {
2102         LOG("%s debug logging\n", logging ? "Disabling" : "Enabling");
2103         set_debug_logging(!logging);
2104     } else if (!strcmp(argument, "on") && !logging) {
2105         LOG("Enabling debug logging\n");
2106         set_debug_logging(true);
2107     } else if (!strcmp(argument, "off") && logging) {
2108         LOG("Disabling debug logging\n");
2109         set_debug_logging(false);
2110     }
2111     // XXX: default reply for now, make this a better reply
2112     ysuccess(true);
2113 }