2 #define I3__FILE__ "commands.c"
19 #define y(x, ...) (cmd_output->json_gen != NULL ? yajl_gen_##x(cmd_output->json_gen, ##__VA_ARGS__) : 0)
20 #define ystr(str) (cmd_output->json_gen != NULL ? yajl_gen_string(cmd_output->json_gen, (unsigned char *)str, strlen(str)) : 0)
21 #define ysuccess(success) \
23 if (cmd_output->json_gen != NULL) { \
30 #define yerror(format, ...) \
32 if (cmd_output->json_gen != NULL) { \
34 sasprintf(&message, format, ##__VA_ARGS__); \
50 #define HANDLE_EMPTY_MATCH \
52 if (match_is_empty(current_match)) { \
53 owindow *ow = smalloc(sizeof(owindow)); \
55 TAILQ_INIT(&owindows); \
56 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
65 return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
76 if (strcasecmp(output_str,
"left") == 0)
78 else if (strcasecmp(output_str,
"right") == 0)
80 else if (strcasecmp(output_str,
"up") == 0)
82 else if (strcasecmp(output_str,
"down") == 0)
96 assert(output != NULL);
112 if (strcmp(ws->
name, name) != 0)
115 DLOG(
"This workspace is already focused.\n");
135 if (current == workspace) {
138 DLOG(
"Substituting workspace with back_and_forth, as it is focused.\n");
149 static pid_t migration_pid = -1;
156 static void nagbar_exited(EV_P_ ev_child *watcher,
int revents) {
157 ev_child_stop(EV_A_ watcher);
158 if (!WIFEXITED(watcher->rstatus)) {
159 fprintf(stderr,
"ERROR: i3-nagbar did not exit normally.\n");
163 int exitcode = WEXITSTATUS(watcher->rstatus);
164 printf(
"i3-nagbar process exited with status %d\n", exitcode);
166 fprintf(stderr,
"ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
175 #if EV_VERSION_MAJOR >= 4
181 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher,
int revent) {
182 if (migration_pid != -1) {
183 LOG(
"Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
184 kill(migration_pid, SIGKILL);
189 void cmd_MIGRATION_start_nagbar(
void) {
190 if (migration_pid != -1) {
191 fprintf(stderr,
"i3-nagbar already running.\n");
194 fprintf(stderr,
"Starting i3-nagbar, command parsing differs from expected output.\n");
195 ELOG(
"Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
196 ELOG(
"i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
197 ELOG(
"FYI: Your i3 version is " I3_VERSION
"\n");
198 migration_pid = fork();
199 if (migration_pid == -1) {
200 warn(
"Could not fork()");
205 if (migration_pid == 0) {
213 "You found a parsing error. Please, please, please, report it!",
224 ev_child *child =
smalloc(
sizeof(ev_child));
231 #if EV_VERSION_MAJOR >= 4
234 ev_cleanup *cleanup =
smalloc(
sizeof(ev_cleanup));
258 static owindows_head owindows;
294 DLOG(
"match specification finished, matching...\n");
297 struct owindows_head old = owindows;
306 DLOG(
"checking if con %p / %s matches\n", current->
con, current->
con->
name);
309 DLOG(
"matches container!\n");
312 DLOG(
"doesnt match\n");
317 DLOG(
"match by mark\n");
321 DLOG(
"matches window!\n");
324 DLOG(
"doesnt match\n");
341 DLOG(
"ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
343 if (strcmp(ctype,
"class") == 0) {
348 if (strcmp(ctype,
"instance") == 0) {
353 if (strcmp(ctype,
"window_role") == 0) {
358 if (strcmp(ctype,
"con_id") == 0) {
360 long parsed = strtol(cvalue, &end, 10);
361 if (parsed == LONG_MIN ||
362 parsed == LONG_MAX ||
364 (end && *end !=
'\0')) {
365 ELOG(
"Could not parse con id \"%s\"\n", cvalue);
373 if (strcmp(ctype,
"id") == 0) {
375 long parsed = strtol(cvalue, &end, 10);
376 if (parsed == LONG_MIN ||
377 parsed == LONG_MAX ||
379 (end && *end !=
'\0')) {
380 ELOG(
"Could not parse window id \"%s\"\n", cvalue);
388 if (strcmp(ctype,
"con_mark") == 0) {
393 if (strcmp(ctype,
"title") == 0) {
398 if (strcmp(ctype,
"urgent") == 0) {
399 if (strcasecmp(cvalue,
"latest") == 0 ||
400 strcasecmp(cvalue,
"newest") == 0 ||
401 strcasecmp(cvalue,
"recent") == 0 ||
402 strcasecmp(cvalue,
"last") == 0) {
404 }
else if (strcasecmp(cvalue,
"oldest") == 0 ||
405 strcasecmp(cvalue,
"first") == 0) {
411 ELOG(
"Unknown criterion: %s\n", ctype);
422 DLOG(
"which=%s\n", which);
438 if (strcmp(which,
"next") == 0)
440 else if (strcmp(which,
"prev") == 0)
442 else if (strcmp(which,
"next_on_output") == 0)
444 else if (strcmp(which,
"prev_on_output") == 0)
446 else if (strcmp(which,
"current") == 0)
449 ELOG(
"BUG: called with which=%s\n", which);
459 cmd_output->needs_tree_render =
true;
475 yerror(
"No workspace was previously active.");
486 cmd_output->needs_tree_render =
true;
496 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
497 LOG(
"You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
508 ELOG(
"No windows match your criteria, cannot move.\n");
517 LOG(
"should move window to workspace %s\n", name);
529 if (!ws && name_is_digits(name)) {
533 child->
num == parsed_num);
550 cmd_output->needs_tree_render =
true;
572 LOG(
"should move window to workspace %s\n", which);
574 Con *output, *workspace = NULL;
578 if (parsed_num == -1) {
579 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
580 yerror(
"Could not parse number \"%s\"", which);
586 child->
num == parsed_num);
601 cmd_output->needs_tree_render =
true;
607 LOG(
"floating resize\n");
614 if (strcmp(direction,
"up") == 0 || strcmp(direction,
"down") == 0 ||
615 strcmp(direction,
"height") == 0) {
619 px = (px < focused_con->height_increment) ? focused_con->
height_increment : px;
620 }
else if (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0) {
624 px = (px < focused_con->width_increment) ? focused_con->
width_increment : px;
627 if (strcmp(direction,
"up") == 0) {
629 }
else if (strcmp(direction,
"down") == 0 || strcmp(direction,
"height") == 0) {
631 }
else if (strcmp(direction,
"left") == 0) {
641 if (memcmp(&old_rect, &(floating_con->
rect),
sizeof(
Rect)) == 0)
644 if (strcmp(direction,
"up") == 0) {
646 }
else if (strcmp(direction,
"left") == 0) {
656 LOG(
"tiling resize\n");
658 Con *first = current;
660 if (!strcmp(direction,
"left"))
661 search_direction =
D_LEFT;
662 else if (!strcmp(direction,
"right"))
664 else if (!strcmp(direction,
"up"))
665 search_direction =
D_UP;
667 search_direction =
D_DOWN;
671 LOG(
"No second container in this direction found.\n");
678 LOG(
"ins. %d children\n", children);
679 double percentage = 1.0 / children;
680 LOG(
"default percentage = %f\n", percentage);
683 LOG(
"second->percent = %f\n", second->
percent);
684 LOG(
"first->percent before = %f\n", first->
percent);
689 double new_first_percent = first->
percent + ((double)ppt / 100.0);
690 double new_second_percent = second->
percent - ((double)ppt / 100.0);
691 LOG(
"new_first_percent = %f\n", new_first_percent);
692 LOG(
"new_second_percent = %f\n", new_second_percent);
697 first->
percent += ((double)ppt / 100.0);
698 second->
percent -= ((double)ppt / 100.0);
699 LOG(
"first->percent after = %f\n", first->
percent);
700 LOG(
"second->percent after = %f\n", second->
percent);
702 LOG(
"Not resizing, already at minimum size\n");
709 LOG(
"width/height resize\n");
713 current = current->
parent;
717 (strcmp(direction,
"width") == 0 ?
HORIZ :
VERT);
719 while (current->
type != CT_WORKSPACE &&
720 current->
type != CT_FLOATING_CON &&
722 current = current->
parent;
726 LOG(
"ins. %d children\n", children);
727 double percentage = 1.0 / children;
728 LOG(
"default percentage = %f\n", percentage);
732 if ((orientation ==
HORIZ &&
733 strcmp(direction,
"height") == 0) ||
734 (orientation ==
VERT &&
735 strcmp(direction,
"width") == 0)) {
736 LOG(
"You cannot resize in that direction. Your focus is in a %s split container currently.\n",
737 (orientation ==
HORIZ ?
"horizontal" :
"vertical"));
743 LOG(
"This is the only container, cannot resize.\n");
751 LOG(
"child->percent = %f (child %p)\n", child->
percent, child);
756 double new_current_percent = current->
percent + ((double)ppt / 100.0);
757 double subtract_percent = ((double)ppt / 100.0) / (children - 1);
758 LOG(
"new_current_percent = %f\n", new_current_percent);
759 LOG(
"subtract_percent = %f\n", subtract_percent);
763 if (child == current)
766 LOG(
"Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->
percent - subtract_percent);
772 LOG(
"Not resizing, already at minimum size\n");
777 current->
percent += ((double)ppt / 100.0);
778 LOG(
"current->percent after = %f\n", current->
percent);
781 if (child == current)
783 child->
percent -= subtract_percent;
784 LOG(
"child->percent after (%p) = %f\n", child, child->
percent);
796 DLOG(
"resizing in way %s, direction %s, px %s or ppt %s\n", way, direction, resize_px, resize_ppt);
798 int px = atoi(resize_px);
799 int ppt = atoi(resize_ppt);
800 if (strcmp(way,
"shrink") == 0) {
811 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
819 if (strcmp(direction,
"width") == 0 ||
820 strcmp(direction,
"height") == 0) {
830 cmd_output->needs_tree_render =
true;
840 DLOG(
"border style should be changed to %s with border width %s\n", border_style_str, border_width);
849 int tmp_border_width = -1;
850 tmp_border_width = strtol(border_width, &end, 10);
851 if (end == border_width) {
853 tmp_border_width = -1;
855 if (strcmp(border_style_str,
"toggle") == 0) {
859 tmp_border_width = 2;
860 else if (border_style ==
BS_NONE)
861 tmp_border_width = 0;
863 tmp_border_width = 1;
865 if (strcmp(border_style_str,
"normal") == 0)
867 else if (strcmp(border_style_str,
"pixel") == 0)
869 else if (strcmp(border_style_str,
"1pixel") == 0) {
871 tmp_border_width = 1;
872 }
else if (strcmp(border_style_str,
"none") == 0)
875 ELOG(
"BUG: called with border_style=%s\n", border_style_str);
883 cmd_output->needs_tree_render =
true;
893 LOG(
"-------------------------------------------------\n");
894 LOG(
" NOP: %s\n", comment);
895 LOG(
"-------------------------------------------------\n");
903 LOG(
"Appending layout \"%s\"\n", path);
909 LOG(
"JSON content = %d\n", content);
911 ELOG(
"Could not determine the contents of \"%s\", not loading.\n", path);
912 yerror(
"Could not determine the contents of \"%s\".", path);
928 DLOG(
"Appending to parent=%p instead of focused=%p\n", parent,
focused);
929 char *errormsg = NULL;
931 if (errormsg != NULL) {
956 cmd_output->needs_tree_render =
true;
966 DLOG(
"which=%s\n", which);
969 LOG(
"Cannot switch workspace while in global fullscreen\n");
974 if (strcmp(which,
"next") == 0)
976 else if (strcmp(which,
"prev") == 0)
978 else if (strcmp(which,
"next_on_output") == 0)
980 else if (strcmp(which,
"prev_on_output") == 0)
983 ELOG(
"BUG: called with which=%s\n", which);
990 cmd_output->needs_tree_render =
true;
1000 Con *output, *workspace = NULL;
1003 LOG(
"Cannot switch workspace while in global fullscreen\n");
1010 if (parsed_num == -1) {
1011 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
1012 yerror(
"Could not parse number \"%s\"", which);
1018 child->
num == parsed_num);
1021 LOG(
"There is no workspace with number %ld, creating a new one.\n", parsed_num);
1024 cmd_output->needs_tree_render =
true;
1031 cmd_output->needs_tree_render =
true;
1042 LOG(
"Cannot switch workspace while in global fullscreen\n");
1049 cmd_output->needs_tree_render =
true;
1059 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
1060 LOG(
"You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
1066 LOG(
"Cannot switch workspace while in global fullscreen\n");
1071 DLOG(
"should switch to workspace %s\n", name);
1085 if (!ws && name_is_digits(name)) {
1089 child->
num == parsed_num);
1099 cmd_output->needs_tree_render =
true;
1109 DLOG(
"Clearing all windows which have that mark first\n");
1113 if (con->
mark && strcmp(con->
mark, mark) == 0)
1117 DLOG(
"marking window with str %s\n", mark);
1127 cmd_output->needs_tree_render =
true;
1142 DLOG(
"removed all window marks");
1146 if (con->
mark && strcmp(con->
mark, mark) == 0)
1149 DLOG(
"removed window mark %s\n", mark);
1152 cmd_output->needs_tree_render =
true;
1162 DLOG(
"mode=%s\n", mode);
1176 DLOG(
"should move window to output %s\n", name);
1181 Output *current_output = NULL;
1188 assert(current_output != NULL);
1191 if (strcasecmp(name,
"up") == 0)
1193 else if (strcasecmp(name,
"down") == 0)
1195 else if (strcasecmp(name,
"left") == 0)
1197 else if (strcasecmp(name,
"right") == 0)
1203 LOG(
"No such output found.\n");
1221 cmd_output->needs_tree_render =
true;
1233 DLOG(
"floating_mode=%s\n", floating_mode);
1239 if (strcmp(floating_mode,
"toggle") == 0) {
1240 DLOG(
"should toggle mode\n");
1243 DLOG(
"should switch mode to %s\n", floating_mode);
1244 if (strcmp(floating_mode,
"enable") == 0) {
1252 cmd_output->needs_tree_render =
true;
1262 DLOG(
"should move workspace to output %s\n", name);
1269 if (!current_output) {
1270 ELOG(
"Cannot get current output. This is a bug in i3.\n");
1276 ELOG(
"Could not get output from string \"%s\"\n", name);
1282 LOG(
"got output %p with content %p\n", output, content);
1284 Con *previously_visible_ws =
TAILQ_FIRST(&(content->nodes_head));
1285 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
1288 LOG(
"should move workspace %p / %s\n", ws, ws->
name);
1292 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
1295 bool used_assignment =
false;
1298 if (strcmp(assignment->
output, current_output->
name) != 0)
1302 Con *workspace = NULL, *out;
1305 !strcasecmp(child->name, assignment->
name));
1306 if (workspace != NULL)
1310 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
1312 used_assignment =
true;
1318 if (!used_assignment)
1324 DLOG(
"Detaching\n");
1329 if (workspace_was_visible) {
1333 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
1340 TAILQ_FOREACH(floating_con, &(ws->floating_head), floating_windows)
1344 if (workspace_was_visible) {
1355 if (ws != previously_visible_ws)
1361 CALL(previously_visible_ws, on_remove_child);
1366 cmd_output->needs_tree_render =
true;
1378 LOG(
"splitting in direction %c\n", direction[0]);
1388 cmd_output->needs_tree_render =
true;
1398 if (kill_mode_str == NULL)
1399 kill_mode_str =
"window";
1402 DLOG(
"kill_mode=%s\n", kill_mode_str);
1405 if (strcmp(kill_mode_str,
"window") == 0)
1407 else if (strcmp(kill_mode_str,
"client") == 0)
1410 ELOG(
"BUG: called with kill_mode=%s\n", kill_mode_str);
1425 cmd_output->needs_tree_render =
true;
1435 bool no_startup_id = (nosn != NULL);
1437 DLOG(
"should execute %s, no_startup_id = %d\n", command, no_startup_id);
1449 DLOG(
"direction = *%s*\n", direction);
1451 if (strcmp(direction,
"left") == 0)
1453 else if (strcmp(direction,
"right") == 0)
1455 else if (strcmp(direction,
"up") == 0)
1457 else if (strcmp(direction,
"down") == 0)
1460 ELOG(
"Invalid focus direction (%s)\n", direction);
1465 cmd_output->needs_tree_render =
true;
1475 DLOG(
"window_mode = %s\n", window_mode);
1480 if (strcmp(window_mode,
"mode_toggle") == 0) {
1482 if (current != NULL && current->
type == CT_FLOATING_CON)
1483 window_mode =
"tiling";
1485 window_mode =
"floating";
1488 if ((strcmp(window_mode,
"floating") == 0 && current->
type != CT_FLOATING_CON) ||
1489 (strcmp(window_mode,
"tiling") == 0 && current->
type == CT_FLOATING_CON))
1497 cmd_output->needs_tree_render =
true;
1507 DLOG(
"level = %s\n", level);
1508 bool success =
false;
1512 if (strcmp(level,
"parent") == 0) {
1517 ELOG(
"'focus parent': Currently in fullscreen, not going up\n");
1525 cmd_output->needs_tree_render = success;
1538 ELOG(
"You have to specify which window/container should be focused.\n");
1539 ELOG(
"Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1541 yerror(
"You have to specify which window/container should be focused");
1558 LOG(
"Cannot change focus while in fullscreen mode (fullscreen rules).\n");
1564 if (ws == __i3_scratch) {
1591 LOG(
"focusing %p / %s\n", current->
con, current->
con->
name);
1597 LOG(
"WARNING: Your criteria for the focus command matches %d containers, "
1598 "while only exactly one container can be focused at a time.\n",
1601 cmd_output->needs_tree_render =
true;
1613 DLOG(
"%s fullscreen, mode = %s\n", action, fullscreen_mode);
1620 if (strcmp(action,
"toggle") == 0) {
1622 }
else if (strcmp(action,
"enable") == 0) {
1624 }
else if (strcmp(action,
"disable") == 0) {
1629 cmd_output->needs_tree_render =
true;
1640 int px = atoi(move_px);
1648 DLOG(
"moving in direction %s, px %s\n", direction, move_px);
1650 DLOG(
"floating move with %d pixels\n", px);
1652 if (strcmp(direction,
"left") == 0) {
1654 }
else if (strcmp(direction,
"right") == 0) {
1656 }
else if (strcmp(direction,
"up") == 0) {
1658 }
else if (strcmp(direction,
"down") == 0) {
1664 cmd_output->needs_tree_render =
true;
1669 if (
focused != initially_focused)
1681 if (strcmp(layout_str,
"stacking") == 0)
1682 layout_str =
"stacked";
1686 if (strcmp(layout_str,
"default") == 0)
1688 else if (strcmp(layout_str,
"stacked") == 0)
1690 else if (strcmp(layout_str,
"tabbed") == 0)
1692 else if (strcmp(layout_str,
"splitv") == 0)
1694 else if (strcmp(layout_str,
"splith") == 0)
1697 ELOG(
"Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
1701 DLOG(
"changing layout to %s (%d)\n", layout_str, layout);
1713 cmd_output->needs_tree_render =
true;
1725 if (toggle_mode == NULL)
1726 toggle_mode =
"default";
1728 DLOG(
"toggling layout (mode = %s)\n", toggle_mode);
1740 cmd_output->needs_tree_render =
true;
1750 LOG(
"Exiting due to user command.\n");
1753 xcb_disconnect(
conn);
1783 LOG(
"restarting i3\n");
1800 LOG(
"opening new container\n");
1809 y(integer, (
long int)con);
1812 cmd_output->needs_tree_render =
true;
1822 DLOG(
"name = %s\n", name);
1827 Output *current_output = NULL;
1832 assert(current_output != NULL);
1837 LOG(
"No such output found.\n");
1852 cmd_output->needs_tree_render =
true;
1864 bool has_error =
false;
1871 ELOG(
"Cannot change position. The window/container is not floating\n");
1874 yerror(
"Cannot change position of a window/container because it is not floating.");
1881 if (strcmp(method,
"absolute") == 0) {
1885 DLOG(
"moving to absolute position %d %d\n", x, y);
1887 cmd_output->needs_tree_render =
true;
1890 if (strcmp(method,
"position") == 0) {
1893 DLOG(
"moving to position %d %d\n", x, y);
1912 ELOG(
"Cannot change position. The window/container is not floating\n");
1913 yerror(
"Cannot change position. The window/container is not floating.");
1917 if (strcmp(method,
"absolute") == 0) {
1920 DLOG(
"moving to absolute center\n");
1925 cmd_output->needs_tree_render =
true;
1928 if (strcmp(method,
"position") == 0) {
1932 DLOG(
"moving to center\n");
1933 newrect.
x = wsrect->
width / 2 - newrect.
width / 2;
1948 DLOG(
"should move window to scratchpad\n");
1958 cmd_output->needs_tree_render =
true;
1968 DLOG(
"should show scratchpad window\n");
1980 cmd_output->needs_tree_render =
true;
1990 if (strncasecmp(new_name,
"__", strlen(
"__")) == 0) {
1991 LOG(
"Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name);
1996 LOG(
"Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1998 LOG(
"Renaming current workspace to \"%s\"\n", new_name);
2005 !strcasecmp(child->name, old_name));
2011 yerror(
"Old workspace \"%s\" not found", old_name);
2015 Con *check_dest = NULL;
2018 !strcasecmp(child->name, new_name));
2020 if (check_dest != NULL) {
2021 yerror(
"New workspace \"%s\" already exists", new_name);
2030 LOG(
"num = %d\n", workspace->
num);
2040 cmd_output->needs_tree_render =
true;
2055 bool toggle =
false;
2056 if (strcmp(bar_mode,
"dock") == 0)
2058 else if (strcmp(bar_mode,
"hide") == 0)
2060 else if (strcmp(bar_mode,
"invisible") == 0)
2062 else if (strcmp(bar_mode,
"toggle") == 0)
2065 ELOG(
"Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
2069 bool changed_sth =
false;
2072 if (bar_id && strcmp(current->
id, bar_id) != 0)
2076 mode = (current->
mode + 1) % 2;
2078 DLOG(
"Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->
id, bar_mode, mode);
2079 current->
mode = mode;
2086 if (bar_id && !changed_sth) {
2087 DLOG(
"Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
2099 int hidden_state = S_SHOW;
2100 bool toggle =
false;
2101 if (strcmp(bar_hidden_state,
"hide") == 0)
2102 hidden_state = S_HIDE;
2103 else if (strcmp(bar_hidden_state,
"show") == 0)
2104 hidden_state = S_SHOW;
2105 else if (strcmp(bar_hidden_state,
"toggle") == 0)
2108 ELOG(
"Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2112 bool changed_sth =
false;
2115 if (bar_id && strcmp(current->
id, bar_id) != 0)
2121 DLOG(
"Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->
id, bar_hidden_state, hidden_state);
2129 if (bar_id && !changed_sth) {
2130 DLOG(
"Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2143 if (strcmp(bar_type,
"mode") == 0)
2145 else if (strcmp(bar_type,
"hidden_state") == 0)
2148 ELOG(
"Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2164 if (!strcmp(argument,
"toggle"))
2167 else if (!strcmp(argument,
"on"))
2169 else if (!strcmp(argument,
"off"))
2175 LOG(
"Restarting shm logging...\n");
2183 LOG(
"%s shm logging\n",
shmlog_size > 0 ?
"Enabling" :
"Disabling");
2196 if (!strcmp(argument,
"toggle")) {
2197 LOG(
"%s debug logging\n", logging ?
"Disabling" :
"Enabling");
2199 }
else if (!strcmp(argument,
"on") && !logging) {
2200 LOG(
"Enabling debug logging\n");
2202 }
else if (!strcmp(argument,
"off") && logging) {
2203 LOG(
"Disabling debug logging\n");
enum Con::@20 scratchpad_state
void tree_next(char way, orientation_t orientation)
Changes focus in the given way (next/previous) and given orientation (horizontal/vertical).
static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent)
long ws_name_to_number(const char *name)
Parses the workspace name as a number.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
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 ipc_shutdown(void)
Calls shutdown() on each socket and closes it.
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
char * name
Name of the output.
bool con_is_floating(Con *con)
Returns true if the node is floating.
bool get_debug_logging(void)
Checks if debug logging is active.
json_content_t json_determine_content(const char *filename)
fullscreen_mode_t
Fullscreen modes.
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
void con_enable_fullscreen(Con *con, fullscreen_mode_t fullscreen_mode)
Enables fullscreen mode for the given container, if necessary.
#define TAILQ_REMOVE(head, elm, field)
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
void exec_i3_utility(char *name, char *argv[])
exec()s an i3 utility, for example the config file migration script or i3-nagbar. ...
void cmd_scratchpad_show(I3_CMD)
Implementation of 'scratchpad show'.
void cmd_move_con_to_workspace_name(I3_CMD, char *name)
Implementation of 'move [window|container] [to] workspace '.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, char *way, char *direction, int ppt)
Stores which workspace (by name or number) goes to which output.
Con * workspace_next(void)
Returns the next workspace.
static bool maybe_back_and_forth(struct CommandResultIR *cmd_output, char *name)
Stores a rectangle, for example the size of a window, the child window etc.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
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.
bool cmd_bar_hidden_state(char *bar_hidden_state, char *bar_id)
enum Barconfig::@5 mode
Bar display mode (hide unless modifier is pressed or show in dock mode or always hide in invisible mo...
void con_detach(Con *con)
Detaches the given container from its current parent.
void cmd_shmlog(I3_CMD, char *argument)
void cmd_resize(I3_CMD, char *way, char *direction, char *resize_px, char *resize_ppt)
Implementation of 'resize grow|shrink
[ px] [or ppt]'.
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
void cmd_nop(I3_CMD, char *comment)
Implementation of 'nop '.
void con_disable_fullscreen(Con *con)
Disables fullscreen mode for the given container, if necessary.
void floating_disable(Con *con, bool automatic)
Disables floating mode for the given container by re-attaching the container to its old parent...
void ewmh_update_desktop_names(void)
Updates _NET_DESKTOP_NAMES: "The names of all virtual desktops.
static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floating_con, int px)
void workspace_show(Con *workspace)
Switches to the given workspace.
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
bool con_accepts_window(Con *con)
Returns true if this node accepts a window (if the node swallows windows, it might already have swall...
struct all_cons_head all_cons
void cmd_criteria_match_windows(I3_CMD)
A match specification just finished (the closing square bracket was found), so we filter the list of ...
struct regex * window_role
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
void cmd_floating(I3_CMD, char *floating_mode)
Implementation of 'floating enable|disable|toggle'.
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_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool dont_warp)
Moves the given container to the currently focused container on the given workspace.
void cmd_move_window_to_center(I3_CMD, char *method)
Implementation of 'move [window|container] [to] [absolute] position center.
void cmd_move_direction(I3_CMD, char *direction, char *move_px)
Implementation of 'move
[ [px]]'.
struct ev_loop * main_loop
#define TAILQ_FIRST(head)
void cmd_move_window_to_position(I3_CMD, char *method, char *cx, char *cy)
Implementation of 'move [window|container] [to] [absolute] position
[px] [px]...
bool con_has_children(Con *con)
Returns true if this node has regular or floating children.
static Output * get_output_of_con(Con *con)
void purge_zerobyte_logfile(void)
Deletes the unused log files.
static Con * maybe_auto_back_and_forth_workspace(Con *workspace)
static Output * get_output_from_string(Output *current_output, const char *output_str)
void cmd_focus(I3_CMD)
Implementation of 'focus'.
void cmd_workspace(I3_CMD, char *which)
Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
bool level_up(void)
Moves focus one level up.
Con * create_workspace_on_output(Output *output, Con *content)
bool workspace_auto_back_and_forth
Automatic workspace back and forth switching.
An Output is a physical output on your graphics driver.
layout_t
Container layouts.
void cmd_focus_window_mode(I3_CMD, char *window_mode)
Implementation of 'focus tiling|floating|mode_toggle'.
void floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
#define TAILQ_NEXT(elm, field)
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 tree_append_json(Con *con, const char *filename, char **errormsg)
border_style_t border_style
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
void update_barconfig()
Sends the current bar configuration as an event to all barconfig_update listeners.
void cmd_split(I3_CMD, char *direction)
Implementation of 'split v|h|vertical|horizontal'.
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
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...
pid_t command_error_nagbar_pid
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
static Match current_match
void cmd_move_con_to_workspace_number(I3_CMD, char *which)
Implementation of 'move [window|container] [to] workspace number '.
pid_t config_error_nagbar_pid
void cmd_mark(I3_CMD, char *mark)
Implementation of 'mark '.
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression...
void cmd_border(I3_CMD, char *border_style_str, char *border_width)
Implementation of 'border normal|none|1pixel|toggle'.
void cmd_layout(I3_CMD, char *layout_str)
Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
void cmd_open(I3_CMD)
Implementation of 'open'.
bool cmd_bar_mode(char *bar_mode, char *bar_id)
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 tree_split(Con *con, orientation_t orientation)
Splits (horizontally or vertically) the given container by creating a new container which contains th...
void cmd_criteria_add(I3_CMD, char *ctype, char *cvalue)
Interprets a ctype=cvalue pair and adds it to the current match specification.
void cmd_mode(I3_CMD, char *mode)
Implementation of 'mode '.
void cmd_move_con_to_output(I3_CMD, char *name)
Implementation of 'move [window|container] [to] output '.
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
void floating_check_size(Con *floating_con)
Called when a floating window is created or resized.
Con * con_get_fullscreen_con(Con *con, fullscreen_mode_t fullscreen_mode)
Returns the first fullscreen node below this node.
bool tree_close(Con *con, kill_window_t kill_window, bool dont_kill_parent, bool force_set_focus)
Closes the given container including all children.
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
Con * con
Pointer to the Con which represents this output.
char * id
Automatically generated ID for this bar config.
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, char *way, char *direction, int ppt)
void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if *nagbar_pid != -1.
void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name)
Implementation of 'rename workspace to '.
void ewmh_update_current_desktop(void)
Updates _NET_CURRENT_DESKTOP with the current desktop number.
bool level_down(void)
Moves focus one level down.
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
void con_focus(Con *con)
Sets input focus to the given container.
void cmd_workspace_back_and_forth(I3_CMD)
Implementation of 'workspace back_and_forth'.
#define TAILQ_EMPTY(head)
int con_num_children(Con *con)
Returns the number of children of this container.
void cmd_move_con_to_workspace(I3_CMD, char *which)
Implementation of 'move [window|container] [to] workspace next|prev|next_on_output|prev_on_output'.
const int default_shmlog_size
void cmd_move_workspace_to_output(I3_CMD, char *name)
Implementation of 'move workspace to [output] '.
static bool definitelyGreaterThan(float a, float b, float epsilon)
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
char * resolve_tilde(const char *path)
This function resolves ~ in pathnames.
enum Window::@11 dock
Whether the window says it is a dock window.
#define TAILQ_ENTRY(type)
void scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
#define I3_CMD
The beginning of the prototype for every cmd_ function.
static void nagbar_exited(EV_P_ ev_child *watcher, int revents)
#define GREP_FIRST(dest, head, condition)
orientation_t con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
A 'Con' represents everything from the X11 root window down to a single X11 window.
void cmd_focus_direction(I3_CMD, char *direction)
Implementation of 'focus left|right|up|down'.
enum Barconfig::@6 hidden_state
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 cmd_append_layout(I3_CMD, char *path)
Implementation of 'append_layout
'.
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...
void cmd_focus_output(I3_CMD, char *name)
Implementation of 'focus output
void cmd_layout_toggle(I3_CMD, char *toggle_mode)
Implementation of 'layout toggle [all|split]'.
Con * workspace_prev(void)
Returns the previous workspace.
#define ysuccess(success)
void cmd_reload(I3_CMD)
Implementation of 'reload'.
void con_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
bool resize_find_tiling_participants(Con **current, Con **other, direction_t direction)
#define CALL(obj, member,...)
#define TAILQ_INSERT_TAIL(head, elm, field)
void cmd_exit(I3_CMD)
Implementation of 'exit'.
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
void cmd_exec(I3_CMD, char *nosn, char *command)
Implementation of 'exec [–no-startup-id] '.
void cmd_workspace_number(I3_CMD, char *which)
Implementation of 'workspace number '.
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...
bool match_is_empty(Match *match)
Check if a match is empty.
void cmd_bar(I3_CMD, char *bar_type, char *bar_value, char *bar_id)
Implementation of 'bar (hidden_state hide|show|toggle)|(mode dock|hide|invisible|toggle) []'...
typedef TAILQ_HEAD(owindows_head, owindow)
struct barconfig_head barconfigs
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.
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Con * con_get_output(Con *con)
Gets the output container (first container with CT_OUTPUT in hierarchy) this node is on...
void cmd_workspace_name(I3_CMD, char *name)
Implementation of 'workspace '.
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
void floating_enable(Con *con, bool automatic)
Enables floating mode for the given container by detaching it from its parent, creating a new contain...
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
void cmd_kill(I3_CMD, char *kill_mode_str)
Implementation of 'kill [window|client]'.
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect)
Fixes the coordinates of the floating window whenever the window gets reassigned to a different outpu...
#define HANDLE_EMPTY_MATCH
When the command did not include match criteria (!), we use the currently focused container...
void cmd_focus_level(I3_CMD, char *level)
Implementation of 'focus parent|child'.
#define TAILQ_FOREACH(var, head, field)
void cmd_fullscreen(I3_CMD, char *action, char *fullscreen_mode)
Implementation of 'fullscreen [enable|disable|toggle] [global]'.
void cmd_move_scratchpad(I3_CMD)
Implementation of 'move scratchpad'.
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers...
Holds the status bar configuration (i3bar).
void cmd_move_con_to_workspace_back_and_forth(I3_CMD)
Implementation of 'move [window|container] [to] workspace back_and_forth'.
void cmd_restart(I3_CMD)
Implementation of 'restart'.
void cmd_unmark(I3_CMD, char *mark)
Implementation of 'unmark [mark]'.
void tree_close_con(kill_window_t kill_window)
Closes the current container using tree_close().
struct ws_assignments_head ws_assignments
#define yerror(format,...)
void cmd_debuglog(I3_CMD, char *argument)
void match_init(Match *match)
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
void set_debug_logging(const bool _debug_logging)
Set debug logging.
void render_con(Con *con, bool render_fullscreen)
"Renders" the given container (and its children), meaning that all rects are updated correctly...
void match_free(Match *match)
Frees the given match.