16 #ifdef I3_ASAN_ENABLED 17 #include <sanitizer/lsan_interface.h> 23 #define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0) 24 #define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0) 25 #define ysuccess(success) \ 27 if (cmd_output->json_gen != NULL) { \ 34 #define yerror(format, ...) \ 36 if (cmd_output->json_gen != NULL) { \ 38 sasprintf(&message, format, ##__VA_ARGS__); \ 51 #define HANDLE_INVALID_MATCH \ 53 if (current_match->error != NULL) { \ 54 yerror("Invalid match: %s", current_match->error); \ 64 #define HANDLE_EMPTY_MATCH \ 66 HANDLE_INVALID_MATCH; \ 68 if (match_is_empty(current_match)) { \ 69 while (!TAILQ_EMPTY(&owindows)) { \ 70 owindow *ow = TAILQ_FIRST(&owindows); \ 71 TAILQ_REMOVE(&owindows, ow, owindows); \ 74 owindow *ow = smalloc(sizeof(owindow)); \ 76 TAILQ_INIT(&owindows); \ 77 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \ 92 if (strcmp(ws->
name, name) != 0)
95 DLOG(
"This workspace is already focused.\n");
115 if (current == workspace) {
118 DLOG(
"Substituting workspace with back_and_forth, as it is focused.\n");
180 DLOG(
"match specification finished, matching...\n");
183 struct owindows_head old =
owindows;
192 DLOG(
"checking if con %p / %s matches\n", current->
con, current->
con->
name);
196 bool accept_match =
false;
202 DLOG(
"con_id matched.\n");
204 DLOG(
"con_id does not match.\n");
212 bool matched_by_mark =
false;
219 DLOG(
"match by mark\n");
220 matched_by_mark =
true;
224 if (!matched_by_mark) {
225 DLOG(
"mark does not match.\n");
233 DLOG(
"matches window!\n");
236 DLOG(
"doesn't match\n");
278 DLOG(
"which=%s\n", which);
294 if (strcmp(which,
"next") == 0)
296 else if (strcmp(which,
"prev") == 0)
298 else if (strcmp(which,
"next_on_output") == 0)
300 else if (strcmp(which,
"prev_on_output") == 0)
302 else if (strcmp(which,
"current") == 0)
305 ELOG(
"BUG: called with which=%s\n", which);
312 cmd_output->needs_tree_render =
true;
324 yerror(
"No workspace was previously active.");
332 cmd_output->needs_tree_render =
true;
342 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
343 LOG(
"You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
348 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
354 ELOG(
"No windows match your criteria, cannot move.\n");
363 LOG(
"should move window to workspace %s\n", name);
367 if (!no_auto_back_and_forth)
374 cmd_output->needs_tree_render =
true;
384 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
396 LOG(
"should move window to workspace %s\n", which);
398 Con *output, *ws = NULL;
402 if (parsed_num == -1) {
403 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
404 yerror(
"Could not parse number \"%s\"", which);
410 child->
num == parsed_num);
416 if (!no_auto_back_and_forth)
423 cmd_output->needs_tree_render =
true;
429 LOG(
"floating resize\n");
437 if (window != NULL) {
438 if (strcmp(direction,
"up") == 0 || strcmp(direction,
"down") == 0 ||
439 strcmp(direction,
"height") == 0) {
444 }
else if (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0) {
452 if (strcmp(direction,
"up") == 0) {
454 }
else if (strcmp(direction,
"down") == 0 || strcmp(direction,
"height") == 0) {
456 }
else if (strcmp(direction,
"left") == 0) {
466 if (memcmp(&old_rect, &(floating_con->
rect),
sizeof(
Rect)) == 0)
469 if (strcmp(direction,
"up") == 0) {
471 }
else if (strcmp(direction,
"left") == 0) {
481 LOG(
"tiling resize\n");
483 Con *first = current;
485 if (!strcmp(direction,
"left"))
486 search_direction =
D_LEFT;
487 else if (!strcmp(direction,
"right"))
489 else if (!strcmp(direction,
"up"))
490 search_direction =
D_UP;
492 search_direction =
D_DOWN;
496 LOG(
"No second container in this direction found.\n");
503 LOG(
"ins. %d children\n", children);
504 double percentage = 1.0 / children;
505 LOG(
"default percentage = %f\n", percentage);
508 LOG(
"first->percent before = %f\n", first->
percent);
509 LOG(
"second->percent before = %f\n", second->
percent);
514 double new_first_percent = first->
percent + ((double)ppt / 100.0);
515 double new_second_percent = second->
percent - ((double)ppt / 100.0);
516 LOG(
"new_first_percent = %f\n", new_first_percent);
517 LOG(
"new_second_percent = %f\n", new_second_percent);
519 if (new_first_percent > 0.0 && new_second_percent > 0.0) {
520 first->
percent = new_first_percent;
521 second->
percent = new_second_percent;
522 LOG(
"first->percent after = %f\n", first->
percent);
523 LOG(
"second->percent after = %f\n", second->
percent);
525 LOG(
"Not resizing, already at minimum size\n");
532 LOG(
"width/height resize\n");
538 if (search_result ==
false) {
545 LOG(
"ins. %d children\n", children);
546 double percentage = 1.0 / children;
547 LOG(
"default percentage = %f\n", percentage);
552 LOG(
"child->percent = %f (child %p)\n", child->
percent, child);
557 double new_current_percent = current->
percent + ((double)ppt / 100.0);
558 double subtract_percent = ((double)ppt / 100.0) / (children - 1);
559 LOG(
"new_current_percent = %f\n", new_current_percent);
560 LOG(
"subtract_percent = %f\n", subtract_percent);
563 if (child == current)
565 if (child->
percent - subtract_percent <= 0.0) {
566 LOG(
"Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->
percent - subtract_percent);
571 if (new_current_percent <= 0.0) {
572 LOG(
"Not resizing, already at minimum size\n");
577 current->
percent = new_current_percent;
578 LOG(
"current->percent after = %f\n", current->
percent);
581 if (child == current)
583 child->
percent -= subtract_percent;
584 LOG(
"child->percent after (%p) = %f\n", child, child->
percent);
594 void cmd_resize(
I3_CMD,
const char *way,
const char *direction,
long resize_px,
long resize_ppt) {
595 DLOG(
"resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
596 if (strcmp(way,
"shrink") == 0) {
607 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
615 if (strcmp(direction,
"width") == 0 ||
616 strcmp(direction,
"height") == 0) {
618 current->
con, way, direction, resize_ppt))
622 current->
con, way, direction, resize_ppt))
628 cmd_output->needs_tree_render =
true;
638 DLOG(
"resizing to %ld %s x %ld %s\n", cwidth, mode_width, cheight, mode_height);
639 if (cwidth < 0 || cheight < 0) {
640 ELOG(
"Resize failed: dimensions cannot be negative (was %ld %s x %ld %s)\n", cwidth, mode_width, cheight, mode_height);
654 }
else if (mode_width && strcmp(mode_width,
"ppt") == 0) {
655 cwidth = output->
rect.
width * ((double)cwidth / 100.0);
659 }
else if (mode_height && strcmp(mode_height,
"ppt") == 0) {
660 cheight = output->
rect.
height * ((double)cheight / 100.0);
665 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
669 if (cwidth > 0 && mode_width && strcmp(mode_width,
"ppt") == 0) {
671 Con *target = current->
con;
676 double current_percent = target->
percent;
680 if (current_percent > cwidth) {
681 action_string =
"shrink";
682 adjustment = (int)(current_percent * 100) - cwidth;
684 action_string =
"grow";
685 adjustment = cwidth - (int)(current_percent * 100);
690 target, action_string,
"width", adjustment)) {
695 if (cheight > 0 && mode_width && strcmp(mode_width,
"ppt") == 0) {
697 Con *target = current->
con;
702 double current_percent = target->
percent;
706 if (current_percent > cheight) {
707 action_string =
"shrink";
708 adjustment = (int)(current_percent * 100) - cheight;
710 action_string =
"grow";
711 adjustment = cheight - (int)(current_percent * 100);
716 target, action_string,
"height", adjustment)) {
723 cmd_output->needs_tree_render =
true;
732 DLOG(
"border style should be changed to %s with border width %ld\n", border_style_str, border_width);
740 int con_border_width = border_width;
742 if (strcmp(border_style_str,
"toggle") == 0) {
746 con_border_width = 2;
747 else if (border_style ==
BS_NONE)
748 con_border_width = 0;
750 con_border_width = 1;
752 if (strcmp(border_style_str,
"normal") == 0) {
754 }
else if (strcmp(border_style_str,
"pixel") == 0) {
756 }
else if (strcmp(border_style_str,
"1pixel") == 0) {
758 con_border_width = 1;
759 }
else if (strcmp(border_style_str,
"none") == 0) {
762 ELOG(
"BUG: called with border_style=%s\n", border_style_str);
771 cmd_output->needs_tree_render =
true;
781 LOG(
"-------------------------------------------------\n");
782 LOG(
" NOP: %s\n", comment);
783 LOG(
"-------------------------------------------------\n");
793 LOG(
"Appending layout \"%s\"\n", path);
800 if ((len =
slurp(path, &buf)) < 0) {
806 ELOG(
"Could not parse \"%s\" as JSON, not loading.\n", path);
807 yerror(
"Could not parse \"%s\" as JSON.", path);
812 LOG(
"JSON content = %d\n", content);
814 ELOG(
"Could not determine the contents of \"%s\", not loading.\n", path);
815 yerror(
"Could not determine the contents of \"%s\".", path);
830 DLOG(
"Appending to parent=%p instead of focused=%p\n", parent,
focused);
831 char *errormsg = NULL;
833 if (errormsg != NULL) {
857 cmd_output->needs_tree_render =
true;
870 DLOG(
"which=%s\n", which);
873 LOG(
"Cannot switch workspace while in global fullscreen\n");
878 if (strcmp(which,
"next") == 0)
880 else if (strcmp(which,
"prev") == 0)
882 else if (strcmp(which,
"next_on_output") == 0)
884 else if (strcmp(which,
"prev_on_output") == 0)
887 ELOG(
"BUG: called with which=%s\n", which);
894 cmd_output->needs_tree_render =
true;
904 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
905 Con *output, *workspace = NULL;
908 LOG(
"Cannot switch workspace while in global fullscreen\n");
915 if (parsed_num == -1) {
916 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
917 yerror(
"Could not parse number \"%s\"", which);
923 child->
num == parsed_num);
926 LOG(
"There is no workspace with number %ld, creating a new one.\n", parsed_num);
929 cmd_output->needs_tree_render =
true;
938 cmd_output->needs_tree_render =
true;
949 LOG(
"Cannot switch workspace while in global fullscreen\n");
956 cmd_output->needs_tree_render =
true;
966 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
968 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
969 LOG(
"You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
975 LOG(
"Cannot switch workspace while in global fullscreen\n");
980 DLOG(
"should switch to workspace %s\n", name);
987 cmd_output->needs_tree_render =
true;
1000 if (current == NULL) {
1007 yerror(
"A mark must not be put onto more than one window");
1014 if (toggle != NULL) {
1020 cmd_output->needs_tree_render =
true;
1039 cmd_output->needs_tree_render =
true;
1049 DLOG(
"mode=%s\n", mode);
1061 DLOG(
"Should move window to output \"%s\".\n", name);
1065 bool had_error =
false;
1072 cmd_output->needs_tree_render =
true;
1081 DLOG(
"moving window to mark \"%s\"\n", mark);
1088 DLOG(
"moving matched window %p / %s to mark \"%s\"\n", current->
con, current->
con->
name, mark);
1092 cmd_output->needs_tree_render =
true;
1103 DLOG(
"floating_mode=%s\n", floating_mode);
1109 if (strcmp(floating_mode,
"toggle") == 0) {
1110 DLOG(
"should toggle mode\n");
1113 DLOG(
"should switch mode to %s\n", floating_mode);
1114 if (strcmp(floating_mode,
"enable") == 0) {
1122 cmd_output->needs_tree_render =
true;
1132 DLOG(
"should move workspace to output %s\n", name);
1145 ELOG(
"Failed to move workspace to output.\n");
1151 cmd_output->needs_tree_render =
true;
1164 LOG(
"splitting in direction %c\n", direction[0]);
1167 ELOG(
"Cannot split a docked container, skipping.\n");
1172 if (direction[0] ==
't') {
1174 if (current->
con->
type == CT_WORKSPACE) {
1190 cmd_output->needs_tree_render =
true;
1200 if (kill_mode_str == NULL)
1201 kill_mode_str =
"window";
1203 DLOG(
"kill_mode=%s\n", kill_mode_str);
1206 if (strcmp(kill_mode_str,
"window") == 0)
1208 else if (strcmp(kill_mode_str,
"client") == 0)
1211 ELOG(
"BUG: called with kill_mode=%s\n", kill_mode_str);
1223 cmd_output->needs_tree_render =
true;
1233 bool no_startup_id = (nosn != NULL);
1235 DLOG(
"should execute %s, no_startup_id = %d\n", command, no_startup_id);
1247 DLOG(
"direction = *%s*\n", direction);
1249 if (strcmp(direction,
"left") == 0)
1251 else if (strcmp(direction,
"right") == 0)
1253 else if (strcmp(direction,
"up") == 0)
1255 else if (strcmp(direction,
"down") == 0)
1258 ELOG(
"Invalid focus direction (%s)\n", direction);
1263 cmd_output->needs_tree_render =
true;
1276 if (fullscreen_on_ws && fullscreen_on_ws != con && !
con_has_parent(con, fullscreen_on_ws)) {
1287 DLOG(
"window_mode = %s\n", window_mode);
1289 bool to_floating =
false;
1290 if (strcmp(window_mode,
"mode_toggle") == 0) {
1292 }
else if (strcmp(window_mode,
"floating") == 0) {
1294 }
else if (strcmp(window_mode,
"tiling") == 0) {
1295 to_floating =
false;
1300 bool success =
false;
1302 if ((to_floating && current->
type != CT_FLOATING_CON) ||
1303 (!to_floating && current->
type == CT_FLOATING_CON))
1312 cmd_output->needs_tree_render =
true;
1315 yerror(
"Failed to find a %s container in workspace.", to_floating ?
"floating" :
"tiling");
1324 DLOG(
"level = %s\n", level);
1325 bool success =
false;
1329 if (strcmp(level,
"parent") == 0) {
1334 ELOG(
"'focus parent': Currently in fullscreen, not going up\n");
1342 cmd_output->needs_tree_render = success;
1355 ELOG(
"You have to specify which window/container should be focused.\n");
1356 ELOG(
"Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1358 yerror(
"You have to specify which window/container should be focused");
1374 if (ws == __i3_scratch) {
1401 LOG(
"focusing %p / %s\n", current->
con, current->
con->
name);
1407 LOG(
"WARNING: Your criteria for the focus command matches %d containers, " 1408 "while only exactly one container can be focused at a time.\n",
1411 cmd_output->needs_tree_render =
true;
1422 DLOG(
"%s fullscreen, mode = %s\n", action, fullscreen_mode);
1429 if (strcmp(action,
"toggle") == 0) {
1431 }
else if (strcmp(action,
"enable") == 0) {
1433 }
else if (strcmp(action,
"disable") == 0) {
1438 cmd_output->needs_tree_render =
true;
1448 DLOG(
"%s sticky on window\n", action);
1454 ELOG(
"only containers holding a window can be made sticky, skipping con = %p\n", current->
con);
1457 DLOG(
"setting sticky for container = %p / %s\n", current->
con, current->
con->
name);
1459 bool sticky =
false;
1460 if (strcmp(action,
"enable") == 0)
1462 else if (strcmp(action,
"disable") == 0)
1464 else if (strcmp(action,
"toggle") == 0)
1477 cmd_output->needs_tree_render =
true;
1492 DLOG(
"moving in direction %s, px %ld\n", direction, move_px);
1494 DLOG(
"floating move with %ld pixels\n", move_px);
1496 if (strcmp(direction,
"left") == 0) {
1497 newrect.
x -= move_px;
1498 }
else if (strcmp(direction,
"right") == 0) {
1499 newrect.
x += move_px;
1500 }
else if (strcmp(direction,
"up") == 0) {
1501 newrect.
y -= move_px;
1502 }
else if (strcmp(direction,
"down") == 0) {
1503 newrect.
y += move_px;
1508 cmd_output->needs_tree_render =
true;
1513 if (
focused != initially_focused)
1529 ELOG(
"Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
1533 DLOG(
"changing layout to %s (%d)\n", layout_str, layout);
1538 ELOG(
"cannot change layout of a docked container, skipping it.\n");
1546 cmd_output->needs_tree_render =
true;
1558 if (toggle_mode == NULL)
1559 toggle_mode =
"default";
1561 DLOG(
"toggling layout (mode = %s)\n", toggle_mode);
1573 cmd_output->needs_tree_render =
true;
1583 LOG(
"Exiting due to user command.\n");
1584 #ifdef I3_ASAN_ENABLED 1585 __lsan_do_leak_check();
1589 xcb_disconnect(
conn);
1619 LOG(
"restarting i3\n");
1636 LOG(
"opening new container\n");
1645 y(integer, (uintptr_t)con);
1648 cmd_output->needs_tree_render =
true;
1658 DLOG(
"name = %s\n", name);
1663 Output *current_output = NULL;
1668 assert(current_output != NULL);
1673 LOG(
"No such output found.\n");
1688 cmd_output->needs_tree_render =
true;
1698 bool has_error =
false;
1705 ELOG(
"Cannot change position. The window/container is not floating\n");
1708 yerror(
"Cannot change position of a window/container because it is not floating.");
1715 if (strcmp(method,
"absolute") == 0) {
1719 DLOG(
"moving to absolute position %ld %ld\n", x, y);
1721 cmd_output->needs_tree_render =
true;
1724 if (strcmp(method,
"position") == 0) {
1727 DLOG(
"moving to position %ld %ld\n", x, y);
1745 bool has_error =
false;
1751 if (floating_con == NULL) {
1752 ELOG(
"con %p / %s is not floating, cannot move it to the center.\n",
1756 yerror(
"Cannot change position of a window/container because it is not floating.");
1763 if (strcmp(method,
"absolute") == 0) {
1764 DLOG(
"moving to absolute center\n");
1768 cmd_output->needs_tree_render =
true;
1771 if (strcmp(method,
"position") == 0) {
1772 DLOG(
"moving to center\n");
1775 cmd_output->needs_tree_render =
true;
1794 if (floating_con == NULL) {
1795 DLOG(
"con %p / %s is not floating, cannot move it to the mouse position.\n",
1800 DLOG(
"moving floating container %p / %s to cursor position\n", floating_con, floating_con->
name);
1804 cmd_output->needs_tree_render =
true;
1813 DLOG(
"should move window to scratchpad\n");
1823 cmd_output->needs_tree_render =
true;
1833 DLOG(
"should show scratchpad window\n");
1845 cmd_output->needs_tree_render =
true;
1858 if (match == NULL) {
1859 DLOG(
"No match found for swapping.\n");
1864 if (strcmp(mode,
"id") == 0) {
1867 yerror(
"Failed to parse %s into a window id.\n", arg);
1872 }
else if (strcmp(mode,
"con_id") == 0) {
1875 yerror(
"Failed to parse %s into a container id.\n", arg);
1880 }
else if (strcmp(mode,
"mark") == 0) {
1883 yerror(
"Unhandled swap mode \"%s\". This is a bug.\n", mode);
1888 yerror(
"Could not find container for %s = %s\n", mode, arg);
1893 DLOG(
"More than one container matched the swap command, only using the first one.");
1896 if (match->
con == NULL) {
1897 DLOG(
"Match %p has no container.\n", match);
1902 DLOG(
"Swapping %p with %p.\n", match->
con, con);
1905 cmd_output->needs_tree_render =
true;
1914 DLOG(
"setting title_format to \"%s\"\n", format);
1919 DLOG(
"setting title_format for %p / %s\n", current->
con, current->
con->
name);
1924 if (strcasecmp(format,
"%title") != 0) {
1948 cmd_output->needs_tree_render =
true;
1957 if (strncasecmp(new_name,
"__", strlen(
"__")) == 0) {
1958 LOG(
"Cannot rename workspace to \"%s\": names starting with __ are i3-internal.\n", new_name);
1963 LOG(
"Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1965 LOG(
"Renaming current workspace to \"%s\"\n", new_name);
1968 Con *output, *workspace = NULL;
1972 !strcasecmp(child->name, old_name));
1975 old_name = workspace->
name;
1979 yerror(
"Old workspace \"%s\" not found", old_name);
1983 Con *check_dest = NULL;
1986 !strcasecmp(child->name, new_name));
1990 if (check_dest != NULL && check_dest != workspace) {
1991 yerror(
"New workspace \"%s\" already exists", new_name);
1997 char *old_name_copy =
sstrdup(old_name);
2002 LOG(
"num = %d\n", workspace->
num);
2013 if (assignment->
output == NULL)
2021 if (previously_focused)
2030 cmd_output->needs_tree_render =
true;
2039 free(old_name_copy);
2048 bool toggle =
false;
2049 if (strcmp(bar_mode,
"dock") == 0)
2051 else if (strcmp(bar_mode,
"hide") == 0)
2053 else if (strcmp(bar_mode,
"invisible") == 0)
2055 else if (strcmp(bar_mode,
"toggle") == 0)
2058 ELOG(
"Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
2062 bool changed_sth =
false;
2065 if (bar_id && strcmp(current->
id, bar_id) != 0)
2069 mode = (current->
mode + 1) % 2;
2071 DLOG(
"Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->
id, bar_mode, mode);
2072 current->
mode = mode;
2079 if (bar_id && !changed_sth) {
2080 DLOG(
"Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
2092 int hidden_state = S_SHOW;
2093 bool toggle =
false;
2094 if (strcmp(bar_hidden_state,
"hide") == 0)
2095 hidden_state = S_HIDE;
2096 else if (strcmp(bar_hidden_state,
"show") == 0)
2097 hidden_state = S_SHOW;
2098 else if (strcmp(bar_hidden_state,
"toggle") == 0)
2101 ELOG(
"Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2105 bool changed_sth =
false;
2108 if (bar_id && strcmp(current->
id, bar_id) != 0)
2114 DLOG(
"Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->
id, bar_hidden_state, hidden_state);
2122 if (bar_id && !changed_sth) {
2123 DLOG(
"Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2134 void cmd_bar(
I3_CMD,
const char *bar_type,
const char *bar_value,
const char *bar_id) {
2136 if (strcmp(bar_type,
"mode") == 0)
2138 else if (strcmp(bar_type,
"hidden_state") == 0)
2141 ELOG(
"Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2157 if (!strcmp(argument,
"toggle"))
2160 else if (!strcmp(argument,
"on"))
2162 else if (!strcmp(argument,
"off"))
2168 LOG(
"Restarting shm logging...\n");
2176 LOG(
"%s shm logging\n",
shmlog_size > 0 ?
"Enabling" :
"Disabling");
2189 if (!strcmp(argument,
"toggle")) {
2190 LOG(
"%s debug logging\n", logging ?
"Disabling" :
"Enabling");
2192 }
else if (!strcmp(argument,
"on") && !logging) {
2193 LOG(
"Enabling debug logging\n");
2195 }
else if (!strcmp(argument,
"off") && logging) {
2196 LOG(
"Disabling debug logging\n");
void cmd_reload(I3_CMD)
Implementation of 'reload'.
bool con_move_to_mark(Con *con, const char *mark)
Moves the given container to the given mark.
struct _i3String i3String
Opaque data structure for storing strings.
void con_detach(Con *con)
Detaches the given container from its current parent.
void cmd_kill(I3_CMD, const char *kill_mode_str)
Implementation of 'kill [window|client]'.
void cmd_resize_set(I3_CMD, long cwidth, const char *mode_width, long cheight, const char *mode_height)
Implementation of 'resize set <width> [px | ppt] <height> [px | ppt]'.
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle)
Implementation of 'mark [–add|–replace] [–toggle] <mark>'.
bool con_swap(Con *first, Con *second)
Swaps the two containers.
void tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
void cmd_title_format(I3_CMD, const char *format)
Implementation of 'title_format <format>'.
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers...
void cmd_move_con_to_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth)
Implementation of 'move [–no-auto-back-and-forth] [window|container] [to] workspace <name>'...
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
char * title_format
The format with which the window's name should be displayed.
void cmd_open(I3_CMD)
Implementation of 'open'.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_forth)
Implementation of 'workspace [–no-auto-back-and-forth] <name>'.
static void cmd_resize_floating(I3_CMD, const char *way, const char *direction, Con *floating_con, int px)
bool layout_from_name(const char *layout_str, layout_t *out)
Set 'out' to the layout_t value for the given layout.
void cmd_focus_direction(I3_CMD, const char *direction)
Implementation of 'focus left|right|up|down'.
void floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *way, const char *direction, int ppt)
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name)
Implementation of 'rename workspace <name> to <name>'.
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
static void cmd_focus_force_focus(Con *con)
struct barconfig_head barconfigs
#define yerror(format,...)
Output * get_output_for_con(Con *con)
Returns the output for the given con.
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
void cmd_criteria_add(I3_CMD, const char *ctype, const char *cvalue)
Interprets a ctype=cvalue pair and adds it to the current match specification.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
#define TAILQ_EMPTY(head)
void cmd_move_con_to_output(I3_CMD, const char *name)
Implementation of 'move [window|container] [to] output <str>'.
Holds the status bar configuration (i3bar).
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides)
A 'Con' represents everything from the X11 root window down to a single X11 window.
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
bool workspace_move_to_output(Con *ws, const char *name)
Move the given workspace to the specified output.
#define TAILQ_LAST(head, headname)
Con * con_by_con_id(long target)
Returns the container with the given container ID or NULL if no such container exists.
bool get_debug_logging(void)
Checks if debug logging is active.
xcb_connection_t * conn
XCB connection and root screen.
void match_free(Match *match)
Frees the given match.
Output * get_output_from_string(Output *current_output, const char *output_str)
Returns an 'output' corresponding to one of left/right/down/up or a specific output name...
void workspace_show(Con *workspace)
Switches to the given workspace.
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
#define TAILQ_INSERT_TAIL(head, elm, field)
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
void cmd_criteria_match_windows(I3_CMD)
A match specification just finished (the closing square bracket was found), so we filter the list of ...
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
void cmd_move_window_to_position(I3_CMD, const char *method, long x, long y)
Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px]...
void ewmh_update_sticky(xcb_window_t window, bool sticky)
Set or remove _NET_WM_STATE_STICKY on the window.
bool con_has_parent(Con *con, Con *parent)
Checks if the container has the given parent as an actual parent.
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
void tree_move(Con *con, int direction)
Moves the given container in the given direction (TOK_LEFT, TOK_RIGHT, TOK_UP, TOK_DOWN from cmdparse...
void cmd_resize(I3_CMD, const char *way, const char *direction, long resize_px, long resize_ppt)
Implementation of 'resize grow|shrink <direction> [<px> px] [or <ppt> ppt]'.
void con_unmark(Con *con, const char *name)
const int default_shmlog_size
void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode)
Implementation of 'fullscreen [enable|disable|toggle] [global]'.
#define ysuccess(success)
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
void cmd_move_window_to_mouse(I3_CMD)
Implementation of 'move [window|container] [to] position mouse'.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists...
void match_parse_property(Match *match, const char *ctype, const char *cvalue)
Interprets a ctype=cvalue pair and adds it to the given match specification.
pid_t command_error_nagbar_pid
void cmd_layout_toggle(I3_CMD, const char *toggle_mode)
Implementation of 'layout toggle [all|split]'.
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
void ewmh_update_current_desktop(void)
Updates _NET_CURRENT_DESKTOP with the current desktop number.
enum Barconfig::@9 hidden_state
void floating_center(Con *con, Rect rect)
Centers a floating con above the specified rect.
void cmd_unmark(I3_CMD, const char *mark)
Implementation of 'unmark [mark]'.
void cmd_bar(I3_CMD, const char *bar_type, const char *bar_value, const char *bar_id)
Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) [<bar_id>]'...
bool cmd_bar_mode(const char *bar_mode, const char *bar_id)
void cmd_restart(I3_CMD)
Implementation of 'restart'.
void cmd_workspace_back_and_forth(I3_CMD)
Implementation of 'workspace back_and_forth'.
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
void cmd_layout(I3_CMD, const char *layout_str)
Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
layout_t
Container layouts.
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory...
void cmd_move_workspace_to_output(I3_CMD, const char *name)
Implementation of 'move workspace to [output] <str>'.
void cmd_sticky(I3_CMD, const char *action)
Implementation of 'sticky enable|disable|toggle'.
typedef TAILQ_HEAD(owindows_head, owindow)
void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode)
Toggles the mark on a container.
bool level_up(void)
Moves focus one level up.
void ewmh_update_desktop_viewport(void)
Updates _NET_DESKTOP_VIEWPORT, which is an array of pairs of cardinals that define the top left corne...
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
void cmd_swap(I3_CMD, const char *mode, const char *arg)
Implementation of 'swap [container] [with] id|con_id|mark <arg>'.
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
bool floating_maybe_reassign_ws(Con *con)
Checks if con’s coordinates are within its workspace and re-assigns it to the actual workspace if no...
void cmd_scratchpad_show(I3_CMD)
Implementation of 'scratchpad show'.
void cmd_border(I3_CMD, const char *border_style_str, long border_width)
Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
void cmd_nop(I3_CMD, const char *comment)
Implementation of 'nop <comment>'.
int con_num_children(Con *con)
Returns the number of children of this container.
#define TAILQ_FOREACH(var, head, field)
bool con_is_floating(Con *con)
Returns true if the node is floating.
void cmd_focus_output(I3_CMD, const char *name)
Implementation of 'focus output <output>'.
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name)
#define TAILQ_FIRST(head)
bool match_is_empty(Match *match)
Check if a match is empty.
void cmd_move_direction(I3_CMD, const char *direction, long move_px)
Implementation of 'move <direction> [<pixels> [px]]'.
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *way, const char *direction, int ppt)
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
bool level_down(void)
Moves focus one level down.
void cmd_move_scratchpad(I3_CMD)
Implementation of 'move scratchpad'.
fullscreen_mode_t fullscreen_mode
void floating_disable(Con *con, bool automatic)
Disables floating mode for the given container by re-attaching the container to its old parent...
bool workspace_auto_back_and_forth
Automatic workspace back and forth switching.
void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp, bool ignore_focus)
Moves the given container to the currently focused container on the given workspace.
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
#define TAILQ_REMOVE(head, elm, field)
void ewmh_update_desktop_names(void)
Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops.
json_content_t json_determine_content(const char *buf, const size_t len)
void output_push_sticky_windows(Con *to_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
struct all_cons_head all_cons
void load_configuration(xcb_connection_t *conn, const char *override_configpath, bool reload)
Reads the configuration from ~/.i3/config or /etc/i3/config if not found.
void cmd_move_con_to_workspace(I3_CMD, const char *which)
Implementation of 'move [window|container] [to] workspace next|prev|next_on_output|prev_on_output'.
void update_barconfig()
Sends the current bar configuration as an event to all barconfig_update listeners.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
Stores which workspace (by name or number) goes to which output.
Con * output_get_content(Con *output)
Returns the output container below the given output container.
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
void cmd_move_window_to_center(I3_CMD, const char *method)
Implementation of 'move [window|container] [to] [absolute] position center.
void floating_check_size(Con *floating_con)
Called when a floating window is created or resized.
void ipc_shutdown(shutdown_reason_t reason)
Calls shutdown() on each socket and closes it.
char * id
Automatically generated ID for this bar config.
void tree_next(char way, orientation_t orientation)
Changes focus in the given way (next/previous) and given orientation (horizontal/vertical).
void cmd_workspace(I3_CMD, const char *which)
Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
An Output is a physical output on your graphics driver.
void scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
void startup_sequence_rename_workspace(const char *old_name, const char *new_name)
Renames workspaces that are mentioned in the startup sequences.
bool con_has_children(Con *con)
Returns true if this node has regular or floating children.
void set_debug_logging(const bool _debug_logging)
Set debug logging.
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
Con * con_by_mark(const char *mark)
Returns the container with the given mark or NULL if no such container exists.
void con_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth)
Implementation of 'workspace [–no-auto-back-and-forth] number <number>'.
fullscreen_mode_t
Fullscreen modes.
void ewmh_update_visible_name(xcb_window_t window, const char *name)
Updates _NET_WM_VISIBLE_NAME.
void cmd_exec(I3_CMD, const char *nosn, const char *command)
Implementation of 'exec [–no-startup-id] <command>'.
Con * workspace_next(void)
Returns the next workspace.
void purge_zerobyte_logfile(void)
Deletes the unused log files.
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
enum Barconfig::@8 mode
Bar display mode (hide unless modifier is pressed or show in dock mode or always hide in invisible mo...
#define HANDLE_EMPTY_MATCH
When the command did not include match criteria (!), we use the currently focused container...
void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if *nagbar_pid != -1.
void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode)
Enables fullscreen mode for the given container, if necessary.
#define I3_CMD
The beginning of the prototype for every cmd_ function.
void cmd_move_con_to_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_and_forth)
Implementation of 'move [–no-auto-back-and-forth] [window|container] [to] workspace number <number>'...
void con_set_border_style(Con *con, int border_style, int border_width)
Sets the given border style on con, correctly keeping the position/size of a floating window...
void cmd_move_con_to_workspace_back_and_forth(I3_CMD)
Implementation of 'move [window|container] [to] workspace back_and_forth'.
void con_close(Con *con, kill_window_t kill_window)
Closes the given container.
void cmd_focus(I3_CMD)
Implementation of 'focus'.
#define TAILQ_NEXT(elm, field)
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
static Match current_match
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
enum Window::@13 dock
Whether the window says it is a dock window.
Con * con
Pointer to the Con which represents this output.
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
void cmd_floating(I3_CMD, const char *floating_mode)
Implementation of 'floating enable|disable|toggle'.
struct ws_assignments_head ws_assignments
void cmd_criteria_init(I3_CMD)
Initializes the specified 'Match' data structure and the initial state of commands.c for matching target windows of a command.
bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates)
Moves the given container to the currently focused container on the visible workspace on the output s...
border_style_t border_style
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void cmd_split(I3_CMD, const char *direction)
Implementation of 'split v|h|t|vertical|horizontal|toggle'.
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void cmd_debuglog(I3_CMD, const char *argument)
#define TAILQ_ENTRY(type)
void con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
enum Con::@22 scratchpad_state
bool regex_matches(struct regex *regex, const char *input)
Checks if the given regular expression matches the given input and returns true if it does...
void cmd_shmlog(I3_CMD, const char *argument)
void cmd_mode(I3_CMD, const char *mode)
Implementation of 'mode <string>'.
void match_init(Match *match)
void cmd_exit(I3_CMD)
Implementation of 'exit'.
void ipc_send_workspace_event(const char *change, Con *current, Con *old)
For the workspace events we send, along with the usual "change" field, also the workspace container i...
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
void cmd_focus_window_mode(I3_CMD, const char *window_mode)
Implementation of 'focus tiling|floating|mode_toggle'.
static void move_matches_to_workspace(Con *ws)
void floating_resize(Con *floating_con, int x, int y)
Sets size of the CT_FLOATING_CON to specified dimensions.
#define GREP_FIRST(dest, head, condition)
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
void floating_move_to_pointer(Con *con)
Moves the given floating con to the current pointer position.
Stores a rectangle, for example the size of a window, the child window etc.
Con * workspace_prev(void)
Returns the previous workspace.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
pid_t config_error_nagbar_pid
Con * workspace_get(const char *num, bool *created)
Returns a pointer to the workspace with the given number (starting at 0), creating the workspace if n...
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
ssize_t slurp(const char *path, char **buf)
Slurp reads path in its entirety into buf, returning the length of the file or -1 if the file could n...
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
void cmd_append_layout(I3_CMD, const char *cpath)
Implementation of 'append_layout <path>'.
void cmd_focus_level(I3_CMD, const char *level)
Implementation of 'focus parent|child'.
static Con * maybe_auto_back_and_forth_workspace(Con *workspace)
bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id)
void cmd_move_con_to_mark(I3_CMD, const char *mark)
Implementation of 'move [window|container] [to] mark <str>'.