2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009-2012 Michael Stapelberg and contributors (see also: LICENSE)
7 * commands.c: all command functions (see commands_parser.c)
13 #include "cmdparse.tab.h"
15 /** When the command did not include match criteria (!), we use the currently
16 * focused command. Do not confuse this case with a command which included
17 * criteria but which did not match any windows. This macro has to be called in
20 #define HANDLE_EMPTY_MATCH do { \
21 if (match_is_empty(current_match)) { \
22 owindow *ow = smalloc(sizeof(owindow)); \
24 TAILQ_INIT(&owindows); \
25 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
29 static owindows_head owindows;
32 * Returns true if a is definitely greater than b (using the given epsilon)
35 static bool definitelyGreaterThan(float a, float b, float epsilon) {
36 return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
39 static Output *get_output_from_string(Output *current_output, const char *output_str) {
42 if (strcasecmp(output_str, "left") == 0) {
43 output = get_output_next(D_LEFT, current_output);
45 output = get_output_most(D_RIGHT, current_output);
46 } else if (strcasecmp(output_str, "right") == 0) {
47 output = get_output_next(D_RIGHT, current_output);
49 output = get_output_most(D_LEFT, current_output);
50 } else if (strcasecmp(output_str, "up") == 0) {
51 output = get_output_next(D_UP, current_output);
53 output = get_output_most(D_DOWN, current_output);
54 } else if (strcasecmp(output_str, "down") == 0) {
55 output = get_output_next(D_DOWN, current_output);
57 output = get_output_most(D_UP, current_output);
58 } else output = get_output_by_name(output_str);
63 char *cmd_criteria_init(Match *current_match) {
64 DLOG("Initializing criteria, current_match = %p\n", current_match);
65 match_init(current_match);
66 TAILQ_INIT(&owindows);
69 TAILQ_FOREACH(con, &all_cons, all_cons) {
70 owindow *ow = smalloc(sizeof(owindow));
72 TAILQ_INSERT_TAIL(&owindows, ow, owindows);
75 /* This command is internal and does not generate a JSON reply. */
79 char *cmd_criteria_match_windows(Match *current_match) {
80 owindow *next, *current;
82 DLOG("match specification finished, matching...\n");
83 /* copy the old list head to iterate through it and start with a fresh
84 * list which will contain only matching windows */
85 struct owindows_head old = owindows;
86 TAILQ_INIT(&owindows);
87 for (next = TAILQ_FIRST(&old); next != TAILQ_END(&old);) {
88 /* make a copy of the next pointer and advance the pointer to the
89 * next element as we are going to invalidate the element’s
90 * next/prev pointers by calling TAILQ_INSERT_TAIL later */
92 next = TAILQ_NEXT(next, owindows);
94 DLOG("checking if con %p / %s matches\n", current->con, current->con->name);
95 if (current_match->con_id != NULL) {
96 if (current_match->con_id == current->con) {
97 DLOG("matches container!\n");
98 TAILQ_INSERT_TAIL(&owindows, current, owindows);
100 } else if (current_match->mark != NULL && current->con->mark != NULL &&
101 regex_matches(current_match->mark, current->con->mark)) {
102 DLOG("match by mark\n");
103 TAILQ_INSERT_TAIL(&owindows, current, owindows);
105 if (current->con->window == NULL)
107 if (match_matches_window(current_match, current->con->window)) {
108 DLOG("matches window!\n");
109 TAILQ_INSERT_TAIL(&owindows, current, owindows);
111 DLOG("doesnt match\n");
117 TAILQ_FOREACH(current, &owindows, owindows) {
118 DLOG("matching: %p / %s\n", current->con, current->con->name);
121 /* This command is internal and does not generate a JSON reply. */
125 char *cmd_criteria_add(Match *current_match, char *ctype, char *cvalue) {
126 DLOG("ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
128 if (strcmp(ctype, "class") == 0) {
129 current_match->class = regex_new(cvalue);
133 if (strcmp(ctype, "instance") == 0) {
134 current_match->instance = regex_new(cvalue);
138 if (strcmp(ctype, "window_role") == 0) {
139 current_match->role = regex_new(cvalue);
143 if (strcmp(ctype, "con_id") == 0) {
145 long parsed = strtol(cvalue, &end, 10);
146 if (parsed == LONG_MIN ||
147 parsed == LONG_MAX ||
149 (end && *end != '\0')) {
150 ELOG("Could not parse con id \"%s\"\n", cvalue);
152 current_match->con_id = (Con*)parsed;
153 printf("id as int = %p\n", current_match->con_id);
158 if (strcmp(ctype, "id") == 0) {
160 long parsed = strtol(cvalue, &end, 10);
161 if (parsed == LONG_MIN ||
162 parsed == LONG_MAX ||
164 (end && *end != '\0')) {
165 ELOG("Could not parse window id \"%s\"\n", cvalue);
167 current_match->id = parsed;
168 printf("window id as int = %d\n", current_match->id);
173 if (strcmp(ctype, "con_mark") == 0) {
174 current_match->mark = regex_new(cvalue);
178 if (strcmp(ctype, "title") == 0) {
179 current_match->title = regex_new(cvalue);
183 ELOG("Unknown criterion: %s\n", ctype);
185 /* This command is internal and does not generate a JSON reply. */
189 char *cmd_move_con_to_workspace(Match *current_match, char *which) {
192 DLOG("which=%s\n", which);
196 /* get the workspace */
198 if (strcmp(which, "next") == 0)
199 ws = workspace_next();
200 else if (strcmp(which, "prev") == 0)
201 ws = workspace_prev();
202 else if (strcmp(which, "next_on_output") == 0)
203 ws = workspace_next_on_output();
204 else if (strcmp(which, "prev_on_output") == 0)
205 ws = workspace_prev_on_output();
207 ELOG("BUG: called with which=%s\n", which);
208 return sstrdup("{\"sucess\": false}");
211 TAILQ_FOREACH(current, &owindows, owindows) {
212 DLOG("matching: %p / %s\n", current->con, current->con->name);
213 con_move_to_workspace(current->con, ws, true, false);
218 // XXX: default reply for now, make this a better reply
219 return sstrdup("{\"success\": true}");
222 char *cmd_move_con_to_workspace_name(Match *current_match, char *name) {
223 if (strncasecmp(name, "__i3_", strlen("__i3_")) == 0) {
224 LOG("You cannot switch to the i3 internal workspaces.\n");
225 return sstrdup("{\"sucess\": false}");
230 /* Error out early to not create a non-existing workspace (in
231 * workspace_get()) if we are not actually able to move anything. */
232 if (match_is_empty(current_match) && focused->type == CT_WORKSPACE)
233 return sstrdup("{\"sucess\": false}");
235 LOG("should move window to workspace %s\n", name);
236 /* get the workspace */
237 Con *ws = workspace_get(name, NULL);
241 TAILQ_FOREACH(current, &owindows, owindows) {
242 DLOG("matching: %p / %s\n", current->con, current->con->name);
243 con_move_to_workspace(current->con, ws, true, false);
248 // XXX: default reply for now, make this a better reply
249 return sstrdup("{\"success\": true}");
252 char *cmd_resize(Match *current_match, char *way, char *direction, char *resize_px, char *resize_ppt) {
253 /* resize <grow|shrink> <direction> [<px> px] [or <ppt> ppt] */
254 DLOG("resizing in way %s, direction %s, px %s or ppt %s\n", way, direction, resize_px, resize_ppt);
255 // TODO: We could either handle this in the parser itself as a separate token (and make the stack typed) or we need a better way to convert a string to a number with error checking
256 int px = atoi(resize_px);
257 int ppt = atoi(resize_ppt);
258 if (strcmp(way, "shrink") == 0) {
264 if ((floating_con = con_inside_floating(focused))) {
265 printf("floating resize\n");
266 if (strcmp(direction, "up") == 0) {
267 floating_con->rect.y -= px;
268 floating_con->rect.height += px;
269 } else if (strcmp(direction, "down") == 0) {
270 floating_con->rect.height += px;
271 } else if (strcmp(direction, "left") == 0) {
272 floating_con->rect.x -= px;
273 floating_con->rect.width += px;
275 floating_con->rect.width += px;
278 LOG("tiling resize\n");
279 /* get the appropriate current container (skip stacked/tabbed cons) */
280 Con *current = focused;
281 while (current->parent->layout == L_STACKED ||
282 current->parent->layout == L_TABBED)
283 current = current->parent;
285 /* Then further go up until we find one with the matching orientation. */
286 orientation_t search_orientation =
287 (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0 ? HORIZ : VERT);
289 while (current->type != CT_WORKSPACE &&
290 current->type != CT_FLOATING_CON &&
291 current->parent->orientation != search_orientation)
292 current = current->parent;
294 /* get the default percentage */
295 int children = con_num_children(current->parent);
297 LOG("ins. %d children\n", children);
298 double percentage = 1.0 / children;
299 LOG("default percentage = %f\n", percentage);
301 orientation_t orientation = current->parent->orientation;
303 if ((orientation == HORIZ &&
304 (strcmp(direction, "up") == 0 || strcmp(direction, "down") == 0)) ||
305 (orientation == VERT &&
306 (strcmp(direction, "left") == 0 || strcmp(direction, "right") == 0))) {
307 LOG("You cannot resize in that direction. Your focus is in a %s split container currently.\n",
308 (orientation == HORIZ ? "horizontal" : "vertical"));
309 return sstrdup("{\"sucess\": false}");
312 if (strcmp(direction, "up") == 0 || strcmp(direction, "left") == 0) {
313 other = TAILQ_PREV(current, nodes_head, nodes);
315 other = TAILQ_NEXT(current, nodes);
317 if (other == TAILQ_END(workspaces)) {
318 LOG("No other container in this direction found, cannot resize.\n");
319 return sstrdup("{\"sucess\": false}");
321 LOG("other->percent = %f\n", other->percent);
322 LOG("current->percent before = %f\n", current->percent);
323 if (current->percent == 0.0)
324 current->percent = percentage;
325 if (other->percent == 0.0)
326 other->percent = percentage;
327 double new_current_percent = current->percent + ((double)ppt / 100.0);
328 double new_other_percent = other->percent - ((double)ppt / 100.0);
329 LOG("new_current_percent = %f\n", new_current_percent);
330 LOG("new_other_percent = %f\n", new_other_percent);
331 /* Ensure that the new percentages are positive and greater than
332 * 0.05 to have a reasonable minimum size. */
333 if (definitelyGreaterThan(new_current_percent, 0.05, DBL_EPSILON) &&
334 definitelyGreaterThan(new_other_percent, 0.05, DBL_EPSILON)) {
335 current->percent += ((double)ppt / 100.0);
336 other->percent -= ((double)ppt / 100.0);
337 LOG("current->percent after = %f\n", current->percent);
338 LOG("other->percent after = %f\n", other->percent);
340 LOG("Not resizing, already at minimum size\n");
346 // XXX: default reply for now, make this a better reply
347 return sstrdup("{\"success\": true}");
350 char *cmd_border(Match *current_match, char *border_style_str) {
351 DLOG("border style should be changed to %s\n", border_style_str);
356 TAILQ_FOREACH(current, &owindows, owindows) {
357 DLOG("matching: %p / %s\n", current->con, current->con->name);
358 int border_style = current->con->border_style;
359 if (strcmp(border_style_str, "toggle") == 0) {
363 if (strcmp(border_style_str, "normal") == 0)
364 border_style = BS_NORMAL;
365 else if (strcmp(border_style_str, "none") == 0)
366 border_style = BS_NONE;
367 else if (strcmp(border_style_str, "1pixel") == 0)
368 border_style = BS_1PIXEL;
370 ELOG("BUG: called with border_style=%s\n", border_style_str);
371 return sstrdup("{\"sucess\": false}");
374 con_set_border_style(current->con, border_style);
379 // XXX: default reply for now, make this a better reply
380 return sstrdup("{\"success\": true}");
383 char *cmd_nop(Match *current_match, char *comment) {
384 LOG("-------------------------------------------------\n");
385 LOG(" NOP: %s\n", comment);
386 LOG("-------------------------------------------------\n");
391 char *cmd_append_layout(Match *current_match, char *path) {
392 LOG("Appending layout \"%s\"\n", path);
393 tree_append_json(path);
396 // XXX: default reply for now, make this a better reply
397 return sstrdup("{\"success\": true}");
400 char *cmd_workspace(Match *current_match, char *which) {
403 DLOG("which=%s\n", which);
405 if (strcmp(which, "next") == 0)
406 ws = workspace_next();
407 else if (strcmp(which, "prev") == 0)
408 ws = workspace_prev();
409 else if (strcmp(which, "next_on_output") == 0)
410 ws = workspace_next_on_output();
411 else if (strcmp(which, "prev_on_output") == 0)
412 ws = workspace_prev_on_output();
414 ELOG("BUG: called with which=%s\n", which);
415 return sstrdup("{\"sucess\": false}");
421 // XXX: default reply for now, make this a better reply
422 return sstrdup("{\"success\": true}");
425 char *cmd_workspace_back_and_forth(Match *current_match) {
426 workspace_back_and_forth();
429 // XXX: default reply for now, make this a better reply
430 return sstrdup("{\"success\": true}");
433 char *cmd_workspace_name(Match *current_match, char *name) {
434 if (strncasecmp(name, "__i3_", strlen("__i3_")) == 0) {
435 LOG("You cannot switch to the i3 internal workspaces.\n");
436 return sstrdup("{\"sucess\": false}");
439 DLOG("should switch to workspace %s\n", name);
441 Con *ws = con_get_workspace(focused);
443 /* Check if the command wants to switch to the current workspace */
444 if (strcmp(ws->name, name) == 0) {
445 DLOG("This workspace is already focused.\n");
446 if (config.workspace_auto_back_and_forth) {
447 workspace_back_and_forth();
450 return sstrdup("{\"sucess\": false}");
453 workspace_show_by_name(name);
457 // XXX: default reply for now, make this a better reply
458 return sstrdup("{\"success\": true}");
461 char *cmd_mark(Match *current_match, char *mark) {
462 DLOG("Clearing all windows which have that mark first\n");
465 TAILQ_FOREACH(con, &all_cons, all_cons) {
466 if (con->mark && strcmp(con->mark, mark) == 0)
470 DLOG("marking window with str %s\n", mark);
475 TAILQ_FOREACH(current, &owindows, owindows) {
476 DLOG("matching: %p / %s\n", current->con, current->con->name);
477 current->con->mark = sstrdup(mark);
482 // XXX: default reply for now, make this a better reply
483 return sstrdup("{\"success\": true}");
486 char *cmd_mode(Match *current_match, char *mode) {
487 DLOG("mode=%s\n", mode);
490 // XXX: default reply for now, make this a better reply
491 return sstrdup("{\"success\": true}");
494 char *cmd_move_con_to_output(Match *current_match, char *name) {
497 DLOG("should move window to output %s\n", name);
502 Output *current_output = NULL;
505 // TODO: fix the handling of criteria
506 TAILQ_FOREACH(current, &owindows, owindows)
507 current_output = get_output_containing(current->con->rect.x, current->con->rect.y);
509 assert(current_output != NULL);
511 // TODO: clean this up with commands.spec as soon as we switched away from the lex/yacc command parser
512 if (strcasecmp(name, "up") == 0)
513 output = get_output_next(D_UP, current_output);
514 else if (strcasecmp(name, "down") == 0)
515 output = get_output_next(D_DOWN, current_output);
516 else if (strcasecmp(name, "left") == 0)
517 output = get_output_next(D_LEFT, current_output);
518 else if (strcasecmp(name, "right") == 0)
519 output = get_output_next(D_RIGHT, current_output);
521 output = get_output_by_name(name);
524 LOG("No such output found.\n");
525 return sstrdup("{\"sucess\": false}");
528 /* get visible workspace on output */
530 GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
532 return sstrdup("{\"sucess\": false}");
534 TAILQ_FOREACH(current, &owindows, owindows) {
535 DLOG("matching: %p / %s\n", current->con, current->con->name);
536 con_move_to_workspace(current->con, ws, true, false);
541 // XXX: default reply for now, make this a better reply
542 return sstrdup("{\"success\": true}");
545 char *cmd_floating(Match *current_match, char *floating_mode) {
548 DLOG("floating_mode=%s\n", floating_mode);
552 TAILQ_FOREACH(current, &owindows, owindows) {
553 DLOG("matching: %p / %s\n", current->con, current->con->name);
554 if (strcmp(floating_mode, "toggle") == 0) {
555 DLOG("should toggle mode\n");
556 toggle_floating_mode(current->con, false);
558 DLOG("should switch mode to %s\n", floating_mode);
559 if (strcmp(floating_mode, "enable") == 0) {
560 floating_enable(current->con, false);
562 floating_disable(current->con, false);
569 // XXX: default reply for now, make this a better reply
570 return sstrdup("{\"success\": true}");
573 char *cmd_move_workspace_to_output(Match *current_match, char *name) {
574 DLOG("should move workspace to output %s\n", name);
579 TAILQ_FOREACH(current, &owindows, owindows) {
580 Output *current_output = get_output_containing(current->con->rect.x,
581 current->con->rect.y);
582 Output *output = get_output_from_string(current_output, name);
584 LOG("No such output\n");
585 return sstrdup("{\"sucess\": false}");
588 Con *content = output_get_content(output->con);
589 LOG("got output %p with content %p\n", output, content);
591 Con *ws = con_get_workspace(current->con);
592 LOG("should move workspace %p / %s\n", ws, ws->name);
593 if (con_num_children(ws->parent) == 1) {
594 LOG("Not moving workspace \"%s\", it is the only workspace on its output.\n", ws->name);
597 bool workspace_was_visible = workspace_is_visible(ws);
598 Con *old_content = ws->parent;
600 if (workspace_was_visible) {
601 /* The workspace which we just detached was visible, so focus
602 * the next one in the focus-stack. */
603 Con *focus_ws = TAILQ_FIRST(&(old_content->focus_head));
604 LOG("workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->name);
605 workspace_show(focus_ws);
607 con_attach(ws, content, false);
608 ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"move\"}");
609 if (workspace_was_visible) {
610 /* Focus the moved workspace on the destination output. */
617 // XXX: default reply for now, make this a better reply
618 return sstrdup("{\"success\": true}");
621 char *cmd_split(Match *current_match, char *direction) {
622 /* TODO: use matches */
623 LOG("splitting in direction %c\n", direction[0]);
624 tree_split(focused, (direction[0] == 'v' ? VERT : HORIZ));
628 // XXX: default reply for now, make this a better reply
629 return sstrdup("{\"success\": true}");
632 char *cmd_kill(Match *current_match, char *kill_mode_str) {
635 DLOG("kill_mode=%s\n", kill_mode_str);
638 if (kill_mode_str == NULL || strcmp(kill_mode_str, "window") == 0)
639 kill_mode = KILL_WINDOW;
640 else if (strcmp(kill_mode_str, "client") == 0)
641 kill_mode = KILL_CLIENT;
643 ELOG("BUG: called with kill_mode=%s\n", kill_mode_str);
644 return sstrdup("{\"sucess\": false}");
647 /* check if the match is empty, not if the result is empty */
648 if (match_is_empty(current_match))
649 tree_close_con(kill_mode);
651 TAILQ_FOREACH(current, &owindows, owindows) {
652 DLOG("matching: %p / %s\n", current->con, current->con->name);
653 tree_close(current->con, kill_mode, false, false);
659 // XXX: default reply for now, make this a better reply
660 return sstrdup("{\"success\": true}");
663 char *cmd_exec(Match *current_match, char *nosn, char *command) {
664 bool no_startup_id = (nosn != NULL);
666 DLOG("should execute %s, no_startup_id = %d\n", command, no_startup_id);
667 start_application(command, no_startup_id);
669 // XXX: default reply for now, make this a better reply
670 return sstrdup("{\"success\": true}");
673 char *cmd_focus_direction(Match *current_match, char *direction) {
675 focused->type != CT_WORKSPACE &&
676 focused->fullscreen_mode != CF_NONE) {
677 LOG("Cannot change focus while in fullscreen mode.\n");
678 return sstrdup("{\"sucess\": false}");
681 DLOG("direction = *%s*\n", direction);
683 if (strcmp(direction, "left") == 0)
684 tree_next('p', HORIZ);
685 else if (strcmp(direction, "right") == 0)
686 tree_next('n', HORIZ);
687 else if (strcmp(direction, "up") == 0)
688 tree_next('p', VERT);
689 else if (strcmp(direction, "down") == 0)
690 tree_next('n', VERT);
692 ELOG("Invalid focus direction (%s)\n", direction);
693 return sstrdup("{\"sucess\": false}");
698 // XXX: default reply for now, make this a better reply
699 return sstrdup("{\"success\": true}");
702 char *cmd_focus_window_mode(Match *current_match, char *window_mode) {
704 focused->type != CT_WORKSPACE &&
705 focused->fullscreen_mode != CF_NONE) {
706 LOG("Cannot change focus while in fullscreen mode.\n");
707 return sstrdup("{\"sucess\": false}");
710 DLOG("window_mode = %s\n", window_mode);
712 Con *ws = con_get_workspace(focused);
715 if (strcmp(window_mode, "mode_toggle") == 0) {
716 current = TAILQ_FIRST(&(ws->focus_head));
717 if (current != NULL && current->type == CT_FLOATING_CON)
718 window_mode = "tiling";
719 else window_mode = "floating";
721 TAILQ_FOREACH(current, &(ws->focus_head), focused) {
722 if ((strcmp(window_mode, "floating") == 0 && current->type != CT_FLOATING_CON) ||
723 (strcmp(window_mode, "tiling") == 0 && current->type == CT_FLOATING_CON))
726 con_focus(con_descend_focused(current));
733 // XXX: default reply for now, make this a better reply
734 return sstrdup("{\"success\": true}");
737 char *cmd_focus_level(Match *current_match, char *level) {
739 focused->type != CT_WORKSPACE &&
740 focused->fullscreen_mode != CF_NONE) {
741 LOG("Cannot change focus while in fullscreen mode.\n");
742 return sstrdup("{\"sucess\": false}");
745 DLOG("level = %s\n", level);
747 if (strcmp(level, "parent") == 0)
753 // XXX: default reply for now, make this a better reply
754 return sstrdup("{\"success\": true}");
757 char *cmd_focus(Match *current_match) {
758 DLOG("current_match = %p\n", current_match);
760 focused->type != CT_WORKSPACE &&
761 focused->fullscreen_mode != CF_NONE) {
762 LOG("Cannot change focus while in fullscreen mode.\n");
763 return sstrdup("{\"sucess\": false}");
768 if (match_is_empty(current_match)) {
769 ELOG("You have to specify which window/container should be focused.\n");
770 ELOG("Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
774 sasprintf(&json_output, "{\"success\":false, \"error\":\"You have to "
775 "specify which window/container should be focused\"}");
781 TAILQ_FOREACH(current, &owindows, owindows) {
782 Con *ws = con_get_workspace(current->con);
783 /* If no workspace could be found, this was a dock window.
784 * Just skip it, you cannot focus dock windows. */
789 /* If the container is not on the current workspace,
790 * workspace_show() will switch to a different workspace and (if
791 * enabled) trigger a mouse pointer warp to the currently focused
792 * container (!) on the target workspace.
794 * Therefore, before calling workspace_show(), we make sure that
795 * 'current' will be focused on the workspace. However, we cannot
796 * just con_focus(current) because then the pointer will not be
797 * warped at all (the code thinks we are already there).
799 * So we focus 'current' to make it the currently focused window of
800 * the target workspace, then revert focus. */
801 Con *currently_focused = focused;
802 con_focus(current->con);
803 con_focus(currently_focused);
805 /* Now switch to the workspace, then focus */
807 LOG("focusing %p / %s\n", current->con, current->con->name);
808 con_focus(current->con);
813 LOG("WARNING: Your criteria for the focus command matches %d containers, "
814 "while only exactly one container can be focused at a time.\n", count);
818 // XXX: default reply for now, make this a better reply
819 return sstrdup("{\"success\": true}");
822 char *cmd_fullscreen(Match *current_match, char *fullscreen_mode) {
823 DLOG("toggling fullscreen, mode = %s\n", fullscreen_mode);
828 TAILQ_FOREACH(current, &owindows, owindows) {
829 printf("matching: %p / %s\n", current->con, current->con->name);
830 con_toggle_fullscreen(current->con, (fullscreen_mode && strcmp(fullscreen_mode, "global") == 0 ? CF_GLOBAL : CF_OUTPUT));
835 // XXX: default reply for now, make this a better reply
836 return sstrdup("{\"success\": true}");
839 char *cmd_move_direction(Match *current_match, char *direction, char *move_px) {
840 // TODO: We could either handle this in the parser itself as a separate token (and make the stack typed) or we need a better way to convert a string to a number with error checking
841 int px = atoi(move_px);
843 /* TODO: make 'move' work with criteria. */
844 DLOG("moving in direction %s, px %s\n", direction, move_px);
845 if (con_is_floating(focused)) {
846 DLOG("floating move with %d pixels\n", px);
847 Rect newrect = focused->parent->rect;
848 if (strcmp(direction, "left") == 0) {
850 } else if (strcmp(direction, "right") == 0) {
852 } else if (strcmp(direction, "up") == 0) {
854 } else if (strcmp(direction, "down") == 0) {
857 floating_reposition(focused->parent, newrect);
859 tree_move((strcmp(direction, "right") == 0 ? TOK_RIGHT :
860 (strcmp(direction, "left") == 0 ? TOK_LEFT :
861 (strcmp(direction, "up") == 0 ? TOK_UP :
867 // XXX: default reply for now, make this a better reply
868 return sstrdup("{\"success\": true}");
871 char *cmd_layout(Match *current_match, char *layout_str) {
872 DLOG("changing layout to %s\n", layout_str);
874 int layout = (strcmp(layout_str, "default") == 0 ? L_DEFAULT :
875 (strcmp(layout_str, "stacked") == 0 || strcmp(layout_str, "stacking") == 0 ? L_STACKED :
878 /* check if the match is empty, not if the result is empty */
879 if (match_is_empty(current_match))
880 con_set_layout(focused->parent, layout);
882 TAILQ_FOREACH(current, &owindows, owindows) {
883 DLOG("matching: %p / %s\n", current->con, current->con->name);
884 con_set_layout(current->con, layout);
890 // XXX: default reply for now, make this a better reply
891 return sstrdup("{\"success\": true}");
894 char *cmd_exit(Match *current_match) {
895 LOG("Exiting due to user command.\n");
901 char *cmd_reload(Match *current_match) {
903 kill_configerror_nagbar(false);
904 load_configuration(conn, NULL, true);
906 /* Send an IPC event just in case the ws names have changed */
907 ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"reload\"}");
909 // XXX: default reply for now, make this a better reply
910 return sstrdup("{\"success\": true}");
913 char *cmd_restart(Match *current_match) {
914 LOG("restarting i3\n");
917 // XXX: default reply for now, make this a better reply
918 return sstrdup("{\"success\": true}");
921 char *cmd_open(Match *current_match) {
922 LOG("opening new container\n");
923 Con *con = tree_open_con(NULL, NULL);
926 sasprintf(&json_output, "{\"success\":true, \"id\":%ld}", (long int)con);
933 char *cmd_focus_output(Match *current_match, char *name) {
936 DLOG("name = %s\n", name);
941 Output *current_output = NULL;
944 TAILQ_FOREACH(current, &owindows, owindows)
945 current_output = get_output_containing(current->con->rect.x, current->con->rect.y);
946 assert(current_output != NULL);
948 output = get_output_from_string(current_output, name);
951 LOG("No such output found.\n");
952 return sstrdup("{\"sucess\": false}");
955 /* get visible workspace on output */
957 GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child));
959 return sstrdup("{\"sucess\": false}");
964 // XXX: default reply for now, make this a better reply
965 return sstrdup("{\"success\": true}");
968 char *cmd_move_scratchpad(Match *current_match) {
969 DLOG("should move window to scratchpad\n");
974 TAILQ_FOREACH(current, &owindows, owindows) {
975 DLOG("matching: %p / %s\n", current->con, current->con->name);
976 scratchpad_move(current->con);
981 // XXX: default reply for now, make this a better reply
982 return sstrdup("{\"success\": true}");
985 char *cmd_scratchpad_show(Match *current_match) {
986 DLOG("should show scratchpad window\n");
989 if (match_is_empty(current_match)) {
990 scratchpad_show(NULL);
992 TAILQ_FOREACH(current, &owindows, owindows) {
993 DLOG("matching: %p / %s\n", current->con, current->con->name);
994 scratchpad_show(current->con);
1000 // XXX: default reply for now, make this a better reply
1001 return sstrdup("{\"success\": true}");