Go to the documentation of this file.
21 #define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
22 #define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
23 #define ysuccess(success) \
25 if (cmd_output->json_gen != NULL) { \
32 #define yerror(format, ...) \
34 if (cmd_output->json_gen != NULL) { \
36 sasprintf(&message, format, ##__VA_ARGS__); \
49 #define HANDLE_INVALID_MATCH \
51 if (current_match->error != NULL) { \
52 yerror("Invalid match: %s", current_match->error); \
62 #define HANDLE_EMPTY_MATCH \
64 HANDLE_INVALID_MATCH; \
66 if (match_is_empty(current_match)) { \
67 while (!TAILQ_EMPTY(&owindows)) { \
68 owindow *ow = TAILQ_FIRST(&owindows); \
69 TAILQ_REMOVE(&owindows, ow, owindows); \
72 owindow *ow = smalloc(sizeof(owindow)); \
74 TAILQ_INIT(&owindows); \
75 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
90 if (strcmp(ws->
name, name) != 0)
93 DLOG(
"This workspace is already focused.\n");
113 if (current == workspace) {
116 DLOG(
"Substituting workspace with back_and_forth, as it is focused.\n");
142 static owindows_head owindows;
178 DLOG(
"match specification finished, matching...\n");
181 struct owindows_head old = owindows;
190 DLOG(
"checking if con %p / %s matches\n", current->
con, current->
con->
name);
194 bool accept_match =
false;
200 DLOG(
"con_id matched.\n");
202 DLOG(
"con_id does not match.\n");
210 bool matched_by_mark =
false;
217 DLOG(
"match by mark\n");
218 matched_by_mark =
true;
222 if (!matched_by_mark) {
223 DLOG(
"mark does not match.\n");
231 DLOG(
"matches window!\n");
234 DLOG(
"doesn't match\n");
270 #define CHECK_MOVE_CON_TO_WORKSPACE \
272 HANDLE_EMPTY_MATCH; \
273 if (TAILQ_EMPTY(&owindows)) { \
274 yerror("Nothing to move: specified criteria don't match any window"); \
277 bool found = false; \
278 owindow *current = TAILQ_FIRST(&owindows); \
280 owindow *next = TAILQ_NEXT(current, owindows); \
282 if (current->con->type == CT_WORKSPACE && !con_has_children(current->con)) { \
283 TAILQ_REMOVE(&owindows, current, owindows); \
291 yerror("Nothing to move: workspace empty"); \
303 DLOG(
"which=%s\n", which);
309 if (strcmp(which,
"next") == 0)
311 else if (strcmp(which,
"prev") == 0)
313 else if (strcmp(which,
"next_on_output") == 0)
315 else if (strcmp(which,
"prev_on_output") == 0)
317 else if (strcmp(which,
"current") == 0)
320 yerror(
"BUG: called with which=%s", which);
326 cmd_output->needs_tree_render =
true;
338 yerror(
"No workspace was previously active.");
346 cmd_output->needs_tree_render =
true;
356 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
357 yerror(
"You cannot move containers to i3-internal workspaces (\"%s\").", name);
363 LOG(
"should move window to workspace %s\n", name);
367 if (no_auto_back_and_forth == NULL) {
373 cmd_output->needs_tree_render =
true;
385 LOG(
"should move window to workspace %s\n", which);
388 if (parsed_num == -1) {
389 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
390 yerror(
"Could not parse number \"%s\"", which);
399 if (no_auto_back_and_forth == NULL) {
405 cmd_output->needs_tree_render =
true;
415 if (strcmp(str,
"left") == 0) {
417 }
else if (strcmp(str,
"right") == 0) {
419 }
else if (strcmp(str,
"up") == 0) {
421 }
else if (strcmp(str,
"down") == 0) {
424 ELOG(
"Invalid direction. This is a parser bug.\n");
434 if (strcmp(direction_str,
"height") == 0) {
436 }
else if (strcmp(direction_str,
"width") == 0) {
447 if (window != NULL) {
448 if (orientation ==
VERT) {
463 if (orientation ==
VERT) {
476 if (direction ==
D_UP) {
478 }
else if (direction ==
D_LEFT) {
490 Con *first = current;
495 yerror(
"No second container found in this direction.");
508 LOG(
"width/height resize\n");
514 if (search_result ==
false) {
515 yerror(
"Failed to find appropriate tiling containers for resize operation");
521 LOG(
"ins. %d children\n", children);
522 double percentage = 1.0 / children;
523 LOG(
"default percentage = %f\n", percentage);
528 LOG(
"child->percent = %f (child %p)\n", child->
percent, child);
533 double new_current_percent;
534 double subtract_percent;
536 new_current_percent = current->
percent + ppt;
540 new_current_percent = current->
percent + ppt;
542 subtract_percent = ppt / (children - 1);
544 yerror(
"Not resizing, container would end with less than 1px");
548 LOG(
"new_current_percent = %f\n", new_current_percent);
549 LOG(
"subtract_percent = %f\n", subtract_percent);
551 if (subtract_percent >= 0.0) {
553 if (child == current) {
557 yerror(
"Not resizing, already at minimum size (child %p would end up with a size of %.f", child, child->
percent - subtract_percent);
563 current->
percent = new_current_percent;
564 LOG(
"current->percent after = %f\n", current->
percent);
567 if (child == current)
569 child->
percent -= subtract_percent;
570 LOG(
"child->percent after (%p) = %f\n", child, child->
percent);
580 void cmd_resize(
I3_CMD,
const char *way,
const char *direction,
long resize_px,
long resize_ppt) {
581 DLOG(
"resizing in way %s, direction %s, px %ld or ppt %ld\n", way, direction, resize_px, resize_ppt);
582 if (strcmp(way,
"shrink") == 0) {
593 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
601 if (strcmp(direction,
"width") == 0 ||
602 strcmp(direction,
"height") == 0) {
603 const double ppt = (double)resize_ppt / 100.0;
605 current->
con, direction,
612 current->
con, direction,
613 resize_px, resize_ppt)) {
621 cmd_output->needs_tree_render =
true;
629 if (resize_orientation ==
HORIZ) {
630 search_direction =
D_LEFT;
633 search_direction =
D_DOWN;
645 ppt = (double)target_size / 100.0 - target->
percent;
652 target, mode, px, ppt);
660 DLOG(
"resizing to %ld %s x %ld %s\n", cwidth, mode_width, cheight, mode_height);
661 if (cwidth < 0 || cheight < 0) {
662 yerror(
"Dimensions cannot be negative.");
676 }
else if (mode_width && strcmp(mode_width,
"ppt") == 0) {
677 cwidth = output->
rect.
width * ((double)cwidth / 100.0);
681 }
else if (mode_height && strcmp(mode_height,
"ppt") == 0) {
682 cheight = output->
rect.
height * ((double)cheight / 100.0);
687 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
692 bool is_ppt = mode_width && strcmp(mode_width,
"ppt") == 0;
694 HORIZ, is_ppt, cwidth);
697 bool is_ppt = mode_height && strcmp(mode_height,
"ppt") == 0;
699 VERT, is_ppt, cheight);
704 cmd_output->needs_tree_render =
true;
712 if (border_width >= 0) {
733 DLOG(
"border style should be changed to %s with border width %ld\n", border_style_str, border_width);
742 if (strcmp(border_style_str,
"toggle") == 0) {
744 }
else if (strcmp(border_style_str,
"normal") == 0) {
746 }
else if (strcmp(border_style_str,
"pixel") == 0) {
748 }
else if (strcmp(border_style_str,
"none") == 0) {
751 yerror(
"BUG: called with border_style=%s", border_style_str);
759 cmd_output->needs_tree_render =
true;
768 LOG(
"-------------------------------------------------\n");
769 LOG(
" NOP: %s\n", comment);
770 LOG(
"-------------------------------------------------\n");
779 LOG(
"Appending layout \"%s\"\n", cpath);
786 if ((len =
slurp(path, &buf)) < 0) {
787 yerror(
"Could not slurp \"%s\".", path);
793 ELOG(
"Could not parse \"%s\" as JSON, not loading.\n", path);
794 yerror(
"Could not parse \"%s\" as JSON.", path);
799 LOG(
"JSON content = %d\n", content);
801 ELOG(
"Could not determine the contents of \"%s\", not loading.\n", path);
802 yerror(
"Could not determine the contents of \"%s\".", path);
817 DLOG(
"Appending to parent=%p instead of focused=%p\n", parent,
focused);
818 char *errormsg = NULL;
820 if (errormsg != NULL) {
844 cmd_output->needs_tree_render =
true;
857 DLOG(
"which=%s\n", which);
860 yerror(
"Cannot switch workspace while in global fullscreen");
864 if (strcmp(which,
"next") == 0)
866 else if (strcmp(which,
"prev") == 0)
868 else if (strcmp(which,
"next_on_output") == 0)
870 else if (strcmp(which,
"prev_on_output") == 0)
873 yerror(
"BUG: called with which=%s", which);
879 cmd_output->needs_tree_render =
true;
889 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
892 yerror(
"Cannot switch workspace while in global fullscreen");
897 if (parsed_num == -1) {
898 yerror(
"Could not parse initial part of \"%s\" as a number.", which);
904 LOG(
"There is no workspace with number %ld, creating a new one.\n", parsed_num);
907 cmd_output->needs_tree_render =
true;
916 cmd_output->needs_tree_render =
true;
927 yerror(
"Cannot switch workspace while in global fullscreen");
933 cmd_output->needs_tree_render =
true;
943 const bool no_auto_back_and_forth = (_no_auto_back_and_forth != NULL);
945 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
946 yerror(
"You cannot switch to the i3-internal workspaces (\"%s\").", name);
951 yerror(
"Cannot switch workspace while in global fullscreen");
955 DLOG(
"should switch to workspace %s\n", name);
962 cmd_output->needs_tree_render =
true;
975 if (current == NULL) {
976 yerror(
"Given criteria don't match a window");
981 if (current !=
TAILQ_LAST(&owindows, owindows_head)) {
982 yerror(
"A mark must not be put onto more than one window");
989 if (toggle != NULL) {
995 cmd_output->needs_tree_render =
true;
1014 cmd_output->needs_tree_render =
true;
1024 DLOG(
"mode=%s\n", mode);
1036 DLOG(
"Should move window to output \"%s\".\n", name);
1040 bool had_error =
false;
1047 cmd_output->needs_tree_render =
true;
1056 DLOG(
"moving window to mark \"%s\"\n", mark);
1063 DLOG(
"moving matched window %p / %s to mark \"%s\"\n", current->
con, current->
con->
name, mark);
1067 cmd_output->needs_tree_render =
true;
1078 DLOG(
"floating_mode=%s\n", floating_mode);
1084 if (strcmp(floating_mode,
"toggle") == 0) {
1085 DLOG(
"should toggle mode\n");
1088 DLOG(
"should switch mode to %s\n", floating_mode);
1089 if (strcmp(floating_mode,
"enable") == 0) {
1097 cmd_output->needs_tree_render =
true;
1107 DLOG(
"should move workspace to output %s\n", name);
1120 if (!target_output) {
1121 yerror(
"Could not get output from string \"%s\"", name);
1128 cmd_output->needs_tree_render =
true;
1140 LOG(
"splitting in direction %c\n", direction[0]);
1143 ELOG(
"Cannot split a docked container, skipping.\n");
1148 if (direction[0] ==
't') {
1150 if (current->
con->
type == CT_WORKSPACE) {
1166 cmd_output->needs_tree_render =
true;
1176 if (kill_mode_str == NULL)
1177 kill_mode_str =
"window";
1179 DLOG(
"kill_mode=%s\n", kill_mode_str);
1182 if (strcmp(kill_mode_str,
"window") == 0)
1184 else if (strcmp(kill_mode_str,
"client") == 0)
1187 yerror(
"BUG: called with kill_mode=%s", kill_mode_str);
1198 cmd_output->needs_tree_render =
true;
1208 bool no_startup_id = (nosn != NULL);
1219 LOG(
"WARNING: Your criteria for the exec command match %d containers, "
1220 "so the command will execute this many times.\n",
1225 DLOG(
"should execute %s, no_startup_id = %d\n", command, no_startup_id);
1232 #define CMD_FOCUS_WARN_CHILDREN \
1236 TAILQ_FOREACH(current, &owindows, owindows) { \
1241 LOG("WARNING: Your criteria for the focus command matches %d containers, " \
1242 "while only exactly one container can be focused at a time.\n", \
1257 bool auto_direction =
true;
1258 if (strcmp(direction_str,
"prev") == 0) {
1260 }
else if (strcmp(direction_str,
"next") == 0) {
1263 auto_direction =
false;
1273 if (auto_direction) {
1280 cmd_output->needs_tree_render =
true;
1302 if (next->
type == CT_WORKSPACE) {
1315 cmd_output->needs_tree_render =
true;
1325 DLOG(
"window_mode = %s\n", window_mode);
1327 bool to_floating =
false;
1328 if (strcmp(window_mode,
"mode_toggle") == 0) {
1330 }
else if (strcmp(window_mode,
"floating") == 0) {
1332 }
else if (strcmp(window_mode,
"tiling") == 0) {
1333 to_floating =
false;
1338 bool success =
false;
1340 if ((to_floating && current->
type != CT_FLOATING_CON) ||
1341 (!to_floating && current->
type == CT_FLOATING_CON))
1350 cmd_output->needs_tree_render =
true;
1353 yerror(
"Failed to find a %s container in workspace.", to_floating ?
"floating" :
"tiling");
1362 DLOG(
"level = %s\n", level);
1363 bool success =
false;
1367 if (strcmp(level,
"parent") == 0) {
1372 ELOG(
"'focus parent': Currently in fullscreen, not going up\n");
1380 cmd_output->needs_tree_render = success;
1393 ELOG(
"You have to specify which window/container should be focused.\n");
1394 ELOG(
"Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1396 yerror(
"You have to specify which window/container should be focused");
1399 yerror(
"No window matches given criteria");
1415 if (ws == __i3_scratch) {
1423 LOG(
"focusing %p / %s\n", current->
con, current->
con->
name);
1427 cmd_output->needs_tree_render =
true;
1438 DLOG(
"%s fullscreen, mode = %s\n", action, fullscreen_mode);
1445 if (strcmp(action,
"toggle") == 0) {
1447 }
else if (strcmp(action,
"enable") == 0) {
1449 }
else if (strcmp(action,
"disable") == 0) {
1454 cmd_output->needs_tree_render =
true;
1464 DLOG(
"%s sticky on window\n", action);
1470 ELOG(
"only containers holding a window can be made sticky, skipping con = %p\n", current->
con);
1473 DLOG(
"setting sticky for container = %p / %s\n", current->
con, current->
con->
name);
1475 bool sticky =
false;
1476 if (strcmp(action,
"enable") == 0)
1478 else if (strcmp(action,
"disable") == 0)
1480 else if (strcmp(action,
"toggle") == 0)
1493 cmd_output->needs_tree_render =
true;
1509 DLOG(
"moving in direction %s, px %ld\n", direction_str, move_px);
1511 DLOG(
"floating move with %ld pixels\n", move_px);
1514 switch (direction) {
1516 newrect.
x -= move_px;
1519 newrect.
x += move_px;
1522 newrect.
y -= move_px;
1525 newrect.
y += move_px;
1532 cmd_output->needs_tree_render =
true;
1555 yerror(
"Unknown layout \"%s\", this is a mismatch between code and parser spec.", layout_str);
1559 DLOG(
"changing layout to %s (%d)\n", layout_str, layout);
1564 ELOG(
"cannot change layout of a docked container, skipping it.\n");
1572 cmd_output->needs_tree_render =
true;
1584 if (toggle_mode == NULL)
1585 toggle_mode =
"default";
1587 DLOG(
"toggling layout (mode = %s)\n", toggle_mode);
1599 cmd_output->needs_tree_render =
true;
1609 LOG(
"Exiting due to user command.\n");
1639 LOG(
"restarting i3\n");
1641 if (cmd_output->client != NULL) {
1642 exempt_fd = cmd_output->client->fd;
1643 LOG(
"Carrying file descriptor %d across restart\n", exempt_fd);
1645 if ((flags = fcntl(exempt_fd, F_GETFD)) < 0 ||
1646 fcntl(exempt_fd, F_SETFD, flags & ~FD_CLOEXEC) < 0) {
1647 ELOG(
"Could not disable FD_CLOEXEC on fd %d\n", exempt_fd);
1651 setenv(
"_I3_RESTART_FD", fdstr, 1);
1668 LOG(
"opening new container\n");
1677 y(integer, (uintptr_t)con);
1680 cmd_output->needs_tree_render =
true;
1699 yerror(
"Output %s not found.", name);
1707 yerror(
"BUG: No workspace found on output.");
1713 cmd_output->needs_tree_render =
true;
1722 bool has_error =
false;
1729 ELOG(
"Cannot change position. The window/container is not floating\n");
1732 yerror(
"Cannot change position of a window/container because it is not floating.");
1741 DLOG(
"moving to position %ld %ld\n", x,
y);
1746 yerror(
"Cannot move window/container out of bounds.");
1760 bool has_error =
false;
1766 if (floating_con == NULL) {
1767 ELOG(
"con %p / %s is not floating, cannot move it to the center.\n",
1771 yerror(
"Cannot change position of a window/container because it is not floating.");
1778 if (strcmp(method,
"absolute") == 0) {
1779 DLOG(
"moving to absolute center\n");
1783 cmd_output->needs_tree_render =
true;
1786 if (strcmp(method,
"position") == 0) {
1787 DLOG(
"moving to center\n");
1790 cmd_output->needs_tree_render =
true;
1809 if (floating_con == NULL) {
1810 DLOG(
"con %p / %s is not floating, cannot move it to the mouse position.\n",
1815 DLOG(
"moving floating container %p / %s to cursor position\n", floating_con, floating_con->
name);
1819 cmd_output->needs_tree_render =
true;
1828 DLOG(
"should move window to scratchpad\n");
1838 cmd_output->needs_tree_render =
true;
1848 DLOG(
"should show scratchpad window\n");
1850 bool result =
false;
1861 cmd_output->needs_tree_render =
true;
1874 if (match == NULL) {
1875 yerror(
"No match found for swapping.");
1878 if (match->
con == NULL) {
1879 yerror(
"Match %p has no container.", match);
1884 if (strcmp(mode,
"id") == 0) {
1887 yerror(
"Failed to parse %s into a window id.", arg);
1892 }
else if (strcmp(mode,
"con_id") == 0) {
1895 yerror(
"Failed to parse %s into a container id.", arg);
1900 }
else if (strcmp(mode,
"mark") == 0) {
1903 yerror(
"Unhandled swap mode \"%s\". This is a bug.", mode);
1908 yerror(
"Could not find container for %s = %s", mode, arg);
1912 if (match !=
TAILQ_LAST(&owindows, owindows_head)) {
1913 LOG(
"More than one container matched the swap command, only using the first one.");
1916 DLOG(
"Swapping %p with %p.\n", match->
con, con);
1919 cmd_output->needs_tree_render =
true;
1929 DLOG(
"setting title_format to \"%s\"\n", format);
1934 DLOG(
"setting title_format for %p / %s\n", current->
con, current->
con->
name);
1939 if (strcasecmp(format,
"%title") != 0) {
1963 cmd_output->needs_tree_render =
true;
1972 if (strncasecmp(new_name,
"__", strlen(
"__")) == 0) {
1973 yerror(
"Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name);
1977 LOG(
"Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1979 LOG(
"Renaming current workspace to \"%s\"\n", new_name);
1987 old_name = workspace->
name;
1991 yerror(
"Old workspace \"%s\" not found", old_name);
1999 if (check_dest != NULL && check_dest != workspace) {
2000 yerror(
"New workspace \"%s\" already exists", new_name);
2006 char *old_name_copy =
sstrdup(old_name);
2011 LOG(
"num = %d\n", workspace->
num);
2024 if (assignment->
output == NULL)
2031 if (!target_output) {
2032 LOG(
"Could not get output named \"%s\"\n", assignment->
output);
2043 bool can_restore_focus = previously_focused != NULL;
2049 if (previously_focused_content) {
2050 Con *workspace = NULL;
2051 GREP_FIRST(workspace, previously_focused_content, child == previously_focused);
2052 can_restore_focus &= (workspace != NULL);
2055 if (can_restore_focus) {
2068 cmd_output->needs_tree_render =
true;
2074 free(old_name_copy);
2083 bool toggle =
false;
2084 if (strcmp(bar_mode,
"dock") == 0)
2086 else if (strcmp(bar_mode,
"hide") == 0)
2088 else if (strcmp(bar_mode,
"invisible") == 0)
2090 else if (strcmp(bar_mode,
"toggle") == 0)
2093 ELOG(
"Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
2097 bool changed_sth =
false;
2100 if (bar_id && strcmp(current->
id, bar_id) != 0)
2104 mode = (current->
mode + 1) % 2;
2106 DLOG(
"Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->
id, bar_mode, mode);
2107 current->
mode = mode;
2114 if (bar_id && !changed_sth) {
2115 DLOG(
"Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
2127 int hidden_state = S_SHOW;
2128 bool toggle =
false;
2129 if (strcmp(bar_hidden_state,
"hide") == 0)
2130 hidden_state = S_HIDE;
2131 else if (strcmp(bar_hidden_state,
"show") == 0)
2132 hidden_state = S_SHOW;
2133 else if (strcmp(bar_hidden_state,
"toggle") == 0)
2136 ELOG(
"Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2140 bool changed_sth =
false;
2143 if (bar_id && strcmp(current->
id, bar_id) != 0)
2149 DLOG(
"Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->
id, bar_hidden_state, hidden_state);
2157 if (bar_id && !changed_sth) {
2158 DLOG(
"Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2169 void cmd_bar(
I3_CMD,
const char *bar_type,
const char *bar_value,
const char *bar_id) {
2171 if (strcmp(bar_type,
"mode") == 0)
2173 else if (strcmp(bar_type,
"hidden_state") == 0)
2176 ELOG(
"Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2192 if (!strcmp(argument,
"toggle"))
2195 else if (!strcmp(argument,
"on"))
2197 else if (!strcmp(argument,
"off"))
2202 yerror(
"Failed to parse %s into a shmlog size.", argument);
2208 LOG(
"Restarting shm logging...\n");
2213 LOG(
"%s shm logging\n",
shmlog_size > 0 ?
"Enabling" :
"Disabling");
2225 if (!strcmp(argument,
"toggle")) {
2226 LOG(
"%s debug logging\n", logging ?
"Disabling" :
"Enabling");
2228 }
else if (!strcmp(argument,
"on") && !logging) {
2229 LOG(
"Enabling debug logging\n");
2231 }
else if (!strcmp(argument,
"off") && logging) {
2232 LOG(
"Disabling debug logging\n");
2243 void cmd_gaps(
I3_CMD,
const char *type,
const char *scope,
const char *mode,
const char *value) {
2247 #define CMD_GAPS(type) \
2249 int current_value = config.gaps.type; \
2250 if (strcmp(scope, "current") == 0) \
2251 current_value += workspace->gaps.type; \
2253 bool reset = false; \
2254 if (!strcmp(mode, "plus")) \
2255 current_value += pixels; \
2256 else if (!strcmp(mode, "minus")) \
2257 current_value -= pixels; \
2258 else if (!strcmp(mode, "set")) { \
2259 current_value = pixels; \
2261 } else if (!strcmp(mode, "toggle")) { \
2262 current_value = !current_value * pixels; \
2265 ELOG("Invalid mode %s when changing gaps", mode); \
2270 if (current_value < 0) \
2271 current_value = 0; \
2273 if (!strcmp(scope, "all")) { \
2274 Con *output, *cur_ws = NULL; \
2275 TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { \
2276 Con *content = output_get_content(output); \
2277 TAILQ_FOREACH(cur_ws, &(content->nodes_head), nodes) { \
2279 cur_ws->gaps.type = 0; \
2280 else if (current_value + cur_ws->gaps.type < 0) \
2281 cur_ws->gaps.type = -current_value; \
2285 config.gaps.type = current_value; \
2287 workspace->gaps.type = current_value - config.gaps.type; \
2291 if (!strcmp(type,
"inner")) {
2293 }
else if (!strcmp(type,
"outer")) {
2298 }
else if (!strcmp(type,
"vertical")) {
2301 }
else if (!strcmp(type,
"horizontal")) {
2304 }
else if (!strcmp(type,
"top")) {
2306 }
else if (!strcmp(type,
"bottom")) {
2308 }
else if (!strcmp(type,
"right")) {
2310 }
else if (!strcmp(type,
"left")) {
2313 ELOG(
"Invalid type %s when changing gaps", type);
2318 cmd_output->needs_tree_render =
true;
void cmd_fullscreen(I3_CMD, const char *action, const char *fullscreen_mode)
Implementation of 'fullscreen [enable|disable|toggle] [global]'.
Con * get_existing_workspace_by_num(int num)
Returns the workspace with the given number or NULL if such a workspace does not exist.
void workspace_show(Con *workspace)
Switches to the given workspace.
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.
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
#define CHECK_MOVE_CON_TO_WORKSPACE
#define I3STRING_FREE(str)
Securely i3string_free by setting the pointer to NULL to prevent accidentally using freed memory.
Stores which workspace (by name or number) goes to which output and its gaps config.
void startup_sequence_rename_workspace(const char *old_name, const char *new_name)
Renames workspaces that are mentioned in the startup sequences.
void update_barconfig(void)
Sends the current bar configuration as an event to all barconfig_update listeners.
pid_t config_error_nagbar_pid
bool get_debug_logging(void)
Checks if debug logging is active.
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>'.
struct _i3String i3String
Opaque data structure for storing strings.
void cmd_exec(I3_CMD, const char *nosn, const char *command)
Implementation of 'exec [–no-startup-id] <command>'.
bool name_x_changed
Flag to force re-rendering the decoration upon changes.
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>]'.
void cmd_layout(I3_CMD, const char *layout_str)
Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.
struct deco_render_params * deco_render_params
Cache for the decoration rendering.
bool json_validate(const char *buf, const size_t len)
Returns true if the provided JSON could be parsed by yajl.
enum Con::@22 scratchpad_state
Holds the status bar configuration (i3bar).
static Con * maybe_auto_back_and_forth_workspace(Con *workspace)
bool scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
void match_init(Match *match)
Initializes the Match data structure.
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
void con_mark_toggle(Con *con, const char *mark, mark_mode_t mode)
Toggles the mark on a container.
double percent_for_1px(Con *con)
Calculate the minimum percent needed for the given container to be at least 1 pixel.
typedef TAILQ_HEAD(owindows_head, owindow)
void floating_resize(Con *floating_con, uint32_t x, uint32_t y)
Sets size of the CT_FLOATING_CON to specified dimensions.
Output * get_output_for_con(Con *con)
Returns the output for the given con.
void cmd_floating(I3_CMD, const char *floating_mode)
Implementation of 'floating enable|disable|toggle'.
void ewmh_update_visible_name(xcb_window_t window, const char *name)
Updates _NET_WM_VISIBLE_NAME.
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...
bool con_is_floating(Con *con)
Returns true if the node is floating.
void set_debug_logging(const bool _debug_logging)
Set debug logging.
void cmd_move_direction(I3_CMD, const char *direction_str, long move_px)
Implementation of 'move <direction> [<pixels> [px]]'.
Con * workspace_prev(void)
Returns the previous workspace.
enum Window::@13 dock
Whether the window says it is a dock window.
char * id
Automatically generated ID for this bar config.
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
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 cmd_gaps(I3_CMD, const char *type, const char *scope, const char *mode, const char *value)
Implementation of 'gaps inner|outer|top|right|bottom|left|horizontal|vertical current|all set|plus|mi...
void cmd_mode(I3_CMD, const char *mode)
Implementation of 'mode <string>'.
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
pid_t command_error_nagbar_pid
void cmd_exit(I3_CMD)
Implementation of 'exit'.
void cmd_layout_toggle(I3_CMD, const char *toggle_mode)
Implementation of 'layout toggle [all|split]'.
border_style_t default_border
The default border style for new windows.
orientation_t orientation_from_direction(direction_t direction)
Convert a direction to its corresponding orientation.
#define TAILQ_EMPTY(head)
static void cmd_resize_floating(I3_CMD, const char *direction_str, Con *floating_con, int px)
struct all_cons_head all_cons
layout_t
Container layouts.
Con * con_by_con_id(long target)
Returns the container with the given container ID or NULL if no such container exists.
struct ws_assignments_head ws_assignments
void con_detach(Con *con)
Detaches the given container from its current parent.
void ewmh_update_desktop_properties(void)
Updates all the EWMH desktop properties.
void floating_disable(Con *con)
Disables floating mode for the given container by re-attaching the container to its old parent.
void cmd_move_con_to_workspace_back_and_forth(I3_CMD)
Implementation of 'move [window|container] [to] workspace back_and_forth'.
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'.
int default_floating_border_width
void cmd_append_layout(I3_CMD, const char *cpath)
Implementation of 'append_layout <path>'.
direction_t direction_from_orientation_position(orientation_t orientation, position_t position)
Convert orientation and position to the corresponding direction.
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
bool match_is_empty(Match *match)
Check if a match is empty.
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
void tree_next(Con *con, direction_t direction)
Changes focus in the given direction.
bool con_swap(Con *first, Con *second)
Swaps the two containers.
void cmd_scratchpad_show(I3_CMD)
Implementation of 'scratchpad show'.
bool output_triggers_assignment(Output *output, struct Workspace_Assignment *assignment)
Returns true if the first output assigned to a workspace with the given workspace assignment is the s...
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, const char *direction, int px, int ppt)
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, const char *name)
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 con_activate(Con *con)
Sets input focus to the given container and raises it to the top.
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
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 not...
void floating_center(Con *con, Rect rect)
Centers a floating con above the specified rect.
void cmd_focus_window_mode(I3_CMD, const char *window_mode)
Implementation of 'focus tiling|floating|mode_toggle'.
void cmd_title_format(I3_CMD, const char *format)
Implementation of 'title_format <format>'.
#define TAILQ_FIRST(head)
void cmd_move_window_to_position(I3_CMD, long x, long y)
Implementation of 'move [window|container] [to] [absolute] position <px> [px] <px> [px].
Con * get_existing_workspace_by_name(const char *name)
Returns the workspace with the given name or NULL if such a workspace does not exist.
#define GREP_FIRST(dest, head, condition)
static bool resize_set_tiling(I3_CMD, Con *target, orientation_t resize_orientation, bool is_ppt, long target_size)
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define HANDLE_EMPTY_MATCH
When the command did not include match criteria (!), we use the currently focused container.
bool level_up(void)
Moves focus one level up.
bool floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction, bool both_sides)
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode)
Enables fullscreen mode for the given container, if necessary.
#define TAILQ_NEXT(elm, field)
void con_close(Con *con, kill_window_t kill_window)
Closes the given container.
uint32_t con_rect_size_in_orientation(Con *con)
Returns given container's rect size depending on its orientation.
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_focus(I3_CMD)
Implementation of 'focus'.
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
void con_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
static Match current_match
void floating_check_size(Con *floating_con, bool prefer_height)
Called when a floating window is created or resized.
An Output is a physical output on your graphics driver.
int con_num_children(Con *con)
Returns the number of children of this container.
void con_mark(Con *con, const char *mark, mark_mode_t mode)
Assigns a mark to the container.
void cmd_split(I3_CMD, const char *direction)
Implementation of 'split v|h|t|vertical|horizontal|toggle'.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on.
void cmd_restart(I3_CMD)
Implementation of 'restart'.
void cmd_workspace(I3_CMD, const char *which)
Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
void cmd_sticky(I3_CMD, const char *action)
Implementation of 'sticky enable|disable|toggle'.
bool con_is_internal(Con *con)
Returns true if the container is internal, such as __i3_scratch.
void cmd_reload(I3_CMD)
Implementation of 'reload'.
void con_unmark(Con *con, const char *name)
Removes marks from containers.
json_content_t json_determine_content(const char *buf, const size_t len)
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
#define TAILQ_LAST(head, headname)
void cmd_kill(I3_CMD, const char *kill_mode_str)
Implementation of 'kill [window|client]'.
void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if *nagbar_pid != -1.
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers.
void cmd_swap(I3_CMD, const char *mode, const char *arg)
Implementation of 'swap [container] [with] id|con_id|mark <arg>'.
void match_free(Match *match)
Frees the given match.
border_style_t default_floating_border
The default border style for new floating windows.
Holds an intermediate represenation of the result of a call to any command.
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
void cmd_shmlog(I3_CMD, const char *argument)
Implementation of 'shmlog <size>|toggle|on|off'.
Con * con_by_mark(const char *mark)
Returns the container with the given mark or NULL if no such container exists.
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
void cmd_open(I3_CMD)
Implementation of 'open'.
const int default_shmlog_size
void cmd_focus_sibling(I3_CMD, const char *direction_str)
Implementation of 'focus next|prev sibling'.
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.
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
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>'.
bool rect_equals(Rect a, Rect b)
bool layout_from_name(const char *layout_str, layout_t *out)
Set 'out' to the layout_t value for the given layout.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name)
Implementation of 'rename workspace <name> to <name>'.
#define yerror(format,...)
void cmd_focus_level(I3_CMD, const char *level)
Implementation of 'focus parent|child'.
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.
#define ysuccess(success)
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, const char *direction, int px, double ppt)
void ewmh_update_sticky(xcb_window_t window, bool sticky)
Set or remove _NET_WM_STATE_STICKY on the window.
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
void cmd_criteria_init(I3_CMD)
Initializes the specified 'Match' data structure and the initial state of commands....
struct pending_marks * marks
void output_push_sticky_windows(Con *old_focus)
Iterates over all outputs and pushes sticky windows to the currently visible workspace on that output...
Con * con
Pointer to the Con which represents this output.
bool level_down(void)
Moves focus one level down.
fullscreen_mode_t
Fullscreen modes.
bool con_move_to_mark(Con *con, const char *mark)
Moves the given container to the given mark.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void cmd_move_workspace_to_output(I3_CMD, const char *name)
Implementation of 'move workspace to [output] <str>'.
Con * workspace_next(void)
Returns the next workspace.
void cmd_debuglog(I3_CMD, const char *argument)
Implementation of 'debuglog toggle|on|off'.
void purge_zerobyte_logfile(void)
Deletes the unused log files.
void tree_move(Con *con, direction_t direction)
Moves the given container in the given direction.
char * previous_workspace_name
Stores a copy of the name of the last used workspace for the workspace back-and-forth switching.
#define TAILQ_FOREACH(var, head, field)
void cmd_mark(I3_CMD, const char *mark, const char *mode, const char *toggle)
Implementation of 'mark [–add|–replace] [–toggle] <mark>'.
void ewmh_update_wm_desktop(void)
Updates _NET_WM_DESKTOP for all windows.
void cmd_criteria_match_windows(I3_CMD)
A match specification just finished (the closing square bracket was found), so we filter the list of ...
void cmd_move_window_to_center(I3_CMD, const char *method)
Implementation of 'move [window|container] [to] [absolute] position center.
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
static bool cmd_bar_hidden_state(const char *bar_hidden_state, const char *bar_id)
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
#define STARTS_WITH(string, needle)
void floating_move_to_pointer(Con *con)
Moves the given floating con to the current pointer position.
static void move_matches_to_workspace(Con *ws)
void cmd_nop(I3_CMD, const char *comment)
Implementation of 'nop <comment>'.
border_style_t border_style
#define TAILQ_ENTRY(type)
#define I3_CMD
The beginning of the prototype for every cmd_ function.
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 tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
enum Barconfig::@10 hidden_state
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.
static int border_width_from_style(border_style_t border_style, long border_width, Con *con)
#define CMD_FOCUS_WARN_CHILDREN
#define TAILQ_REMOVE(head, elm, field)
Con * get_tree_next_sibling(Con *con, position_t direction)
Get the previous / next sibling.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
i3String * con_parse_title_format(Con *con)
Returns the window title considering the current title format.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void cmd_move_window_to_mouse(I3_CMD)
Implementation of 'move [window|container] [to] position mouse'.
struct barconfig_head barconfigs
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_exists(Con *con)
Returns true if the given container (still) exists.
void cmd_move_con_to_output(I3_CMD, const char *name)
Implementation of 'move [window|container] [to] output <str>'.
bool load_configuration(const char *override_configpath, config_load_t load_type)
(Re-)loads the configuration file (sets useful defaults before).
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...
int logical_px(const int logical)
Convert a logical amount of pixels (e.g.
void cmd_move_con_to_mark(I3_CMD, const char *mark)
Implementation of 'move [window|container] [to] mark <str>'.
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
void con_activate_unblock(Con *con)
Activates the container like in con_activate but removes fullscreen restrictions and properly warps t...
void update_shmlog_atom(void)
Set up the SHMLOG_PATH atom.
void render_con(Con *con, bool already_inset)
"Renders" the given container (and its children), meaning that all rects are updated correctly.
void cmd_unmark(I3_CMD, const char *mark)
Implementation of 'unmark [mark]'.
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.
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...
void cmd_workspace_back_and_forth(I3_CMD)
Implementation of 'workspace back_and_forth'.
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...
bool resize_neighboring_cons(Con *first, Con *second, int px, int ppt)
Resize the two given containers using the given amount of pixels or percentage points.
void ipc_shutdown(shutdown_reason_t reason, int exempt_fd)
Calls shutdown() on each socket and closes it.
void tree_append_json(Con *con, const char *buf, const size_t len, char **errormsg)
#define TAILQ_INSERT_TAIL(head, elm, field)
void con_focus(Con *con)
Sets input focus to the given container.
Output * get_output_by_name(const char *name, const bool require_active)
Returns the output with the given name or NULL.
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.
bool workspace_auto_back_and_forth
Automatic workspace back and forth switching.
char * title_format
The format with which the window's name should be displayed.
void cmd_border(I3_CMD, const char *border_style_str, long border_width)
Implementation of 'border normal|pixel [<n>]', 'border none|1pixel|toggle'.
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
@ SHUTDOWN_REASON_RESTART
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void cmd_focus_output(I3_CMD, const char *name)
Implementation of 'focus output <output>'.
void workspace_move_to_output(Con *ws, Output *output)
Move the given workspace to the specified output.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
void cmd_focus_direction(I3_CMD, const char *direction_str)
Implementation of 'focus left|right|up|down'.
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>'.
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
static bool cmd_bar_mode(const char *bar_mode, const char *bar_id)
Con * output_get_content(Con *output)
Returns the output container below the given output container.
enum Barconfig::@9 mode
Bar display mode (hide unless modifier is pressed or show in dock mode or always hide in invisible mo...
bool con_is_docked(Con *con)
Returns true if the container is a docked container.
static direction_t parse_direction(const char *str)
Stores a rectangle, for example the size of a window, the child window etc.
void cmd_move_scratchpad(I3_CMD)
Implementation of 'move scratchpad'.