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(message) \
32 if (cmd_output->json_gen != NULL) { \
47 #define HANDLE_EMPTY_MATCH \
49 if (match_is_empty(current_match)) { \
50 owindow *ow = smalloc(sizeof(owindow)); \
52 TAILQ_INIT(&owindows); \
53 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
62 return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
73 if (strcasecmp(output_str,
"left") == 0)
75 else if (strcasecmp(output_str,
"right") == 0)
77 else if (strcasecmp(output_str,
"up") == 0)
79 else if (strcasecmp(output_str,
"down") == 0)
93 assert(output != NULL);
109 if (strcmp(ws->
name, name) != 0)
112 DLOG(
"This workspace is already focused.\n");
132 if (current == workspace) {
135 DLOG(
"Substituting workspace with back_and_forth, as it is focused.\n");
146 static pid_t migration_pid = -1;
153 static void nagbar_exited(EV_P_ ev_child *watcher,
int revents) {
154 ev_child_stop(EV_A_ watcher);
155 if (!WIFEXITED(watcher->rstatus)) {
156 fprintf(stderr,
"ERROR: i3-nagbar did not exit normally.\n");
160 int exitcode = WEXITSTATUS(watcher->rstatus);
161 printf(
"i3-nagbar process exited with status %d\n", exitcode);
163 fprintf(stderr,
"ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
172 #if EV_VERSION_MAJOR >= 4
178 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher,
int revent) {
179 if (migration_pid != -1) {
180 LOG(
"Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
181 kill(migration_pid, SIGKILL);
186 void cmd_MIGRATION_start_nagbar(
void) {
187 if (migration_pid != -1) {
188 fprintf(stderr,
"i3-nagbar already running.\n");
191 fprintf(stderr,
"Starting i3-nagbar, command parsing differs from expected output.\n");
192 ELOG(
"Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
193 ELOG(
"i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
194 ELOG(
"FYI: Your i3 version is " I3_VERSION
"\n");
195 migration_pid = fork();
196 if (migration_pid == -1) {
197 warn(
"Could not fork()");
202 if (migration_pid == 0) {
210 "You found a parsing error. Please, please, please, report it!",
221 ev_child *child =
smalloc(
sizeof(ev_child));
228 #if EV_VERSION_MAJOR >= 4
231 ev_cleanup *cleanup =
smalloc(
sizeof(ev_cleanup));
255 static owindows_head owindows;
291 DLOG(
"match specification finished, matching...\n");
294 struct owindows_head old = owindows;
303 DLOG(
"checking if con %p / %s matches\n", current->
con, current->
con->
name);
306 DLOG(
"matches container!\n");
309 DLOG(
"doesnt match\n");
314 DLOG(
"match by mark\n");
318 DLOG(
"matches window!\n");
321 DLOG(
"doesnt match\n");
338 DLOG(
"ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
340 if (strcmp(ctype,
"class") == 0) {
345 if (strcmp(ctype,
"instance") == 0) {
350 if (strcmp(ctype,
"window_role") == 0) {
355 if (strcmp(ctype,
"con_id") == 0) {
357 long parsed = strtol(cvalue, &end, 10);
358 if (parsed == LONG_MIN ||
359 parsed == LONG_MAX ||
361 (end && *end !=
'\0')) {
362 ELOG(
"Could not parse con id \"%s\"\n", cvalue);
370 if (strcmp(ctype,
"id") == 0) {
372 long parsed = strtol(cvalue, &end, 10);
373 if (parsed == LONG_MIN ||
374 parsed == LONG_MAX ||
376 (end && *end !=
'\0')) {
377 ELOG(
"Could not parse window id \"%s\"\n", cvalue);
385 if (strcmp(ctype,
"con_mark") == 0) {
390 if (strcmp(ctype,
"title") == 0) {
395 if (strcmp(ctype,
"urgent") == 0) {
396 if (strcasecmp(cvalue,
"latest") == 0 ||
397 strcasecmp(cvalue,
"newest") == 0 ||
398 strcasecmp(cvalue,
"recent") == 0 ||
399 strcasecmp(cvalue,
"last") == 0) {
401 }
else if (strcasecmp(cvalue,
"oldest") == 0 ||
402 strcasecmp(cvalue,
"first") == 0) {
408 ELOG(
"Unknown criterion: %s\n", ctype);
419 DLOG(
"which=%s\n", which);
435 if (strcmp(which,
"next") == 0)
437 else if (strcmp(which,
"prev") == 0)
439 else if (strcmp(which,
"next_on_output") == 0)
441 else if (strcmp(which,
"prev_on_output") == 0)
443 else if (strcmp(which,
"current") == 0)
446 ELOG(
"BUG: called with which=%s\n", which);
456 cmd_output->needs_tree_render =
true;
472 yerror(
"No workspace was previously active.");
483 cmd_output->needs_tree_render =
true;
493 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
494 LOG(
"You cannot move containers to i3-internal workspaces (\"%s\").\n", name);
505 ELOG(
"No windows match your criteria, cannot move.\n");
514 LOG(
"should move window to workspace %s\n", name);
527 cmd_output->needs_tree_render =
true;
549 LOG(
"should move window to workspace %s\n", which);
551 Con *output, *workspace = NULL;
554 long parsed_num = strtol(which, &endptr, 10);
555 if (parsed_num == LONG_MIN ||
556 parsed_num == LONG_MAX ||
559 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
561 yerror(
"Could not parse number");
567 child->
num == parsed_num);
582 cmd_output->needs_tree_render =
true;
588 LOG(
"floating resize\n");
595 if (strcmp(direction,
"up") == 0 || strcmp(direction,
"down") == 0 ||
596 strcmp(direction,
"height") == 0) {
600 px = (px < focused_con->height_increment) ? focused_con->
height_increment : px;
601 }
else if (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0) {
605 px = (px < focused_con->width_increment) ? focused_con->
width_increment : px;
608 if (strcmp(direction,
"up") == 0) {
610 }
else if (strcmp(direction,
"down") == 0 || strcmp(direction,
"height") == 0) {
612 }
else if (strcmp(direction,
"left") == 0) {
622 if (memcmp(&old_rect, &(floating_con->
rect),
sizeof(
Rect)) == 0)
625 if (strcmp(direction,
"up") == 0) {
627 }
else if (strcmp(direction,
"left") == 0) {
637 LOG(
"tiling resize\n");
639 Con *first = current;
641 if (!strcmp(direction,
"left"))
642 search_direction =
D_LEFT;
643 else if (!strcmp(direction,
"right"))
645 else if (!strcmp(direction,
"up"))
646 search_direction =
D_UP;
648 search_direction =
D_DOWN;
652 LOG(
"No second container in this direction found.\n");
659 LOG(
"ins. %d children\n", children);
660 double percentage = 1.0 / children;
661 LOG(
"default percentage = %f\n", percentage);
664 LOG(
"second->percent = %f\n", second->
percent);
665 LOG(
"first->percent before = %f\n", first->
percent);
670 double new_first_percent = first->
percent + ((double)ppt / 100.0);
671 double new_second_percent = second->
percent - ((double)ppt / 100.0);
672 LOG(
"new_first_percent = %f\n", new_first_percent);
673 LOG(
"new_second_percent = %f\n", new_second_percent);
678 first->
percent += ((double)ppt / 100.0);
679 second->
percent -= ((double)ppt / 100.0);
680 LOG(
"first->percent after = %f\n", first->
percent);
681 LOG(
"second->percent after = %f\n", second->
percent);
683 LOG(
"Not resizing, already at minimum size\n");
690 LOG(
"width/height resize\n");
694 current = current->
parent;
698 (strcmp(direction,
"width") == 0 ?
HORIZ :
VERT);
700 while (current->
type != CT_WORKSPACE &&
701 current->
type != CT_FLOATING_CON &&
703 current = current->
parent;
707 LOG(
"ins. %d children\n", children);
708 double percentage = 1.0 / children;
709 LOG(
"default percentage = %f\n", percentage);
713 if ((orientation ==
HORIZ &&
714 strcmp(direction,
"height") == 0) ||
715 (orientation ==
VERT &&
716 strcmp(direction,
"width") == 0)) {
717 LOG(
"You cannot resize in that direction. Your focus is in a %s split container currently.\n",
718 (orientation ==
HORIZ ?
"horizontal" :
"vertical"));
724 LOG(
"This is the only container, cannot resize.\n");
732 LOG(
"child->percent = %f (child %p)\n", child->
percent, child);
737 double new_current_percent = current->
percent + ((double)ppt / 100.0);
738 double subtract_percent = ((double)ppt / 100.0) / (children - 1);
739 LOG(
"new_current_percent = %f\n", new_current_percent);
740 LOG(
"subtract_percent = %f\n", subtract_percent);
744 if (child == current)
747 LOG(
"Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->
percent - subtract_percent);
753 LOG(
"Not resizing, already at minimum size\n");
758 current->
percent += ((double)ppt / 100.0);
759 LOG(
"current->percent after = %f\n", current->
percent);
762 if (child == current)
764 child->
percent -= subtract_percent;
765 LOG(
"child->percent after (%p) = %f\n", child, child->
percent);
777 DLOG(
"resizing in way %s, direction %s, px %s or ppt %s\n", way, direction, resize_px, resize_ppt);
779 int px = atoi(resize_px);
780 int ppt = atoi(resize_ppt);
781 if (strcmp(way,
"shrink") == 0) {
792 DLOG(
"This is a dock window. Not resizing (con = %p)\n)", current->
con);
800 if (strcmp(direction,
"width") == 0 ||
801 strcmp(direction,
"height") == 0) {
811 cmd_output->needs_tree_render =
true;
821 DLOG(
"border style should be changed to %s with border width %s\n", border_style_str, border_width);
830 int tmp_border_width = -1;
831 tmp_border_width = strtol(border_width, &end, 10);
832 if (end == border_width) {
834 tmp_border_width = -1;
836 if (strcmp(border_style_str,
"toggle") == 0) {
840 tmp_border_width = 2;
841 else if (border_style ==
BS_NONE)
842 tmp_border_width = 0;
844 tmp_border_width = 1;
846 if (strcmp(border_style_str,
"normal") == 0)
848 else if (strcmp(border_style_str,
"pixel") == 0)
850 else if (strcmp(border_style_str,
"1pixel") == 0) {
852 tmp_border_width = 1;
853 }
else if (strcmp(border_style_str,
"none") == 0)
856 ELOG(
"BUG: called with border_style=%s\n", border_style_str);
864 cmd_output->needs_tree_render =
true;
874 LOG(
"-------------------------------------------------\n");
875 LOG(
" NOP: %s\n", comment);
876 LOG(
"-------------------------------------------------\n");
884 LOG(
"Appending layout \"%s\"\n", path);
892 DLOG(
"Appending to parent=%p instead of focused=%p\n",
894 char *errormsg = NULL;
896 if (errormsg != NULL) {
917 cmd_output->needs_tree_render =
true;
927 DLOG(
"which=%s\n", which);
929 if (strcmp(which,
"next") == 0)
931 else if (strcmp(which,
"prev") == 0)
933 else if (strcmp(which,
"next_on_output") == 0)
935 else if (strcmp(which,
"prev_on_output") == 0)
938 ELOG(
"BUG: called with which=%s\n", which);
945 cmd_output->needs_tree_render =
true;
955 Con *output, *workspace = NULL;
958 long parsed_num = strtol(which, &endptr, 10);
959 if (parsed_num == LONG_MIN ||
960 parsed_num == LONG_MAX ||
963 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
965 yerror(
"Could not parse number");
972 child->
num == parsed_num);
975 LOG(
"There is no workspace with number %ld, creating a new one.\n", parsed_num);
978 cmd_output->needs_tree_render =
true;
985 cmd_output->needs_tree_render =
true;
997 cmd_output->needs_tree_render =
true;
1007 if (strncasecmp(name,
"__", strlen(
"__")) == 0) {
1008 LOG(
"You cannot switch to the i3-internal workspaces (\"%s\").\n", name);
1013 DLOG(
"should switch to workspace %s\n", name);
1018 cmd_output->needs_tree_render =
true;
1028 DLOG(
"Clearing all windows which have that mark first\n");
1032 if (con->
mark && strcmp(con->
mark, mark) == 0)
1036 DLOG(
"marking window with str %s\n", mark);
1046 cmd_output->needs_tree_render =
true;
1061 DLOG(
"removed all window marks");
1065 if (con->
mark && strcmp(con->
mark, mark) == 0)
1068 DLOG(
"removed window mark %s\n", mark);
1071 cmd_output->needs_tree_render =
true;
1081 DLOG(
"mode=%s\n", mode);
1095 DLOG(
"should move window to output %s\n", name);
1100 Output *current_output = NULL;
1107 assert(current_output != NULL);
1110 if (strcasecmp(name,
"up") == 0)
1112 else if (strcasecmp(name,
"down") == 0)
1114 else if (strcasecmp(name,
"left") == 0)
1116 else if (strcasecmp(name,
"right") == 0)
1122 LOG(
"No such output found.\n");
1140 cmd_output->needs_tree_render =
true;
1152 DLOG(
"floating_mode=%s\n", floating_mode);
1158 if (strcmp(floating_mode,
"toggle") == 0) {
1159 DLOG(
"should toggle mode\n");
1162 DLOG(
"should switch mode to %s\n", floating_mode);
1163 if (strcmp(floating_mode,
"enable") == 0) {
1171 cmd_output->needs_tree_render =
true;
1181 DLOG(
"should move workspace to output %s\n", name);
1188 if (!current_output) {
1189 ELOG(
"Cannot get current output. This is a bug in i3.\n");
1195 ELOG(
"Could not get output from string \"%s\"\n", name);
1201 LOG(
"got output %p with content %p\n", output, content);
1203 Con *previously_visible_ws =
TAILQ_FIRST(&(content->nodes_head));
1204 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
1207 LOG(
"should move workspace %p / %s\n", ws, ws->
name);
1211 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
1214 bool used_assignment =
false;
1217 if (strcmp(assignment->
output, current_output->
name) != 0)
1221 Con *workspace = NULL, *out;
1224 !strcasecmp(child->name, assignment->
name));
1225 if (workspace != NULL)
1229 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
1231 used_assignment =
true;
1237 if (!used_assignment)
1241 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"init\"}");
1243 DLOG(
"Detaching\n");
1248 if (workspace_was_visible) {
1252 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
1259 TAILQ_FOREACH (floating_con, &(ws->floating_head), floating_windows)
1262 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"move\"}");
1263 if (workspace_was_visible) {
1274 if (ws != previously_visible_ws)
1280 CALL(previously_visible_ws, on_remove_child);
1285 cmd_output->needs_tree_render =
true;
1297 LOG(
"splitting in direction %c\n", direction[0]);
1307 cmd_output->needs_tree_render =
true;
1317 if (kill_mode_str == NULL)
1318 kill_mode_str =
"window";
1321 DLOG(
"kill_mode=%s\n", kill_mode_str);
1324 if (strcmp(kill_mode_str,
"window") == 0)
1326 else if (strcmp(kill_mode_str,
"client") == 0)
1329 ELOG(
"BUG: called with kill_mode=%s\n", kill_mode_str);
1344 cmd_output->needs_tree_render =
true;
1354 bool no_startup_id = (nosn != NULL);
1356 DLOG(
"should execute %s, no_startup_id = %d\n", command, no_startup_id);
1368 DLOG(
"direction = *%s*\n", direction);
1370 if (strcmp(direction,
"left") == 0)
1372 else if (strcmp(direction,
"right") == 0)
1374 else if (strcmp(direction,
"up") == 0)
1376 else if (strcmp(direction,
"down") == 0)
1379 ELOG(
"Invalid focus direction (%s)\n", direction);
1384 cmd_output->needs_tree_render =
true;
1394 DLOG(
"window_mode = %s\n", window_mode);
1399 if (strcmp(window_mode,
"mode_toggle") == 0) {
1401 if (current != NULL && current->
type == CT_FLOATING_CON)
1402 window_mode =
"tiling";
1404 window_mode =
"floating";
1407 if ((strcmp(window_mode,
"floating") == 0 && current->
type != CT_FLOATING_CON) ||
1408 (strcmp(window_mode,
"tiling") == 0 && current->
type == CT_FLOATING_CON))
1416 cmd_output->needs_tree_render =
true;
1426 DLOG(
"level = %s\n", level);
1427 bool success =
false;
1431 if (strcmp(level,
"parent") == 0) {
1436 ELOG(
"'focus parent': Currently in fullscreen, not going up\n");
1444 cmd_output->needs_tree_render = success;
1457 ELOG(
"You have to specify which window/container should be focused.\n");
1458 ELOG(
"Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1460 yerror(
"You have to specify which window/container should be focused");
1477 LOG(
"Cannot change focus while in fullscreen mode (fullscreen rules).\n");
1483 if (ws == __i3_scratch) {
1510 LOG(
"focusing %p / %s\n", current->
con, current->
con->
name);
1516 LOG(
"WARNING: Your criteria for the focus command matches %d containers, "
1517 "while only exactly one container can be focused at a time.\n",
1520 cmd_output->needs_tree_render =
true;
1530 if (fullscreen_mode == NULL)
1531 fullscreen_mode =
"output";
1532 DLOG(
"toggling fullscreen, mode = %s\n", fullscreen_mode);
1542 cmd_output->needs_tree_render =
true;
1553 int px = atoi(move_px);
1556 DLOG(
"moving in direction %s, px %s\n", direction, move_px);
1558 DLOG(
"floating move with %d pixels\n", px);
1560 if (strcmp(direction,
"left") == 0) {
1562 }
else if (strcmp(direction,
"right") == 0) {
1564 }
else if (strcmp(direction,
"up") == 0) {
1566 }
else if (strcmp(direction,
"down") == 0) {
1572 cmd_output->needs_tree_render =
true;
1584 if (strcmp(layout_str,
"stacking") == 0)
1585 layout_str =
"stacked";
1589 if (strcmp(layout_str,
"default") == 0)
1591 else if (strcmp(layout_str,
"stacked") == 0)
1593 else if (strcmp(layout_str,
"tabbed") == 0)
1595 else if (strcmp(layout_str,
"splitv") == 0)
1597 else if (strcmp(layout_str,
"splith") == 0)
1600 ELOG(
"Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
1604 DLOG(
"changing layout to %s (%d)\n", layout_str, layout);
1616 cmd_output->needs_tree_render =
true;
1628 if (toggle_mode == NULL)
1629 toggle_mode =
"default";
1631 DLOG(
"toggling layout (mode = %s)\n", toggle_mode);
1643 cmd_output->needs_tree_render =
true;
1653 LOG(
"Exiting due to user command.\n");
1656 xcb_disconnect(
conn);
1673 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"reload\"}");
1686 LOG(
"restarting i3\n");
1706 LOG(
"opening new container\n");
1715 y(integer, (
long int)con);
1718 cmd_output->needs_tree_render =
true;
1728 DLOG(
"name = %s\n", name);
1733 Output *current_output = NULL;
1738 assert(current_output != NULL);
1743 LOG(
"No such output found.\n");
1758 cmd_output->needs_tree_render =
true;
1772 ELOG(
"Cannot change position. The window/container is not floating\n");
1773 yerror(
"Cannot change position. The window/container is not floating.");
1777 if (strcmp(method,
"absolute") == 0) {
1781 DLOG(
"moving to absolute position %d %d\n", x, y);
1783 cmd_output->needs_tree_render =
true;
1786 if (strcmp(method,
"position") == 0) {
1789 DLOG(
"moving to position %d %d\n", x, y);
1806 ELOG(
"Cannot change position. The window/container is not floating\n");
1807 yerror(
"Cannot change position. The window/container is not floating.");
1811 if (strcmp(method,
"absolute") == 0) {
1814 DLOG(
"moving to absolute center\n");
1819 cmd_output->needs_tree_render =
true;
1822 if (strcmp(method,
"position") == 0) {
1826 DLOG(
"moving to center\n");
1827 newrect.
x = wsrect->
width / 2 - newrect.
width / 2;
1842 DLOG(
"should move window to scratchpad\n");
1852 cmd_output->needs_tree_render =
true;
1862 DLOG(
"should show scratchpad window\n");
1874 cmd_output->needs_tree_render =
true;
1884 if (strncasecmp(new_name,
"__", strlen(
"__")) == 0) {
1885 LOG(
"Cannot rename workspace to \"%s\": names starting with __ are i3-internal.", new_name);
1890 LOG(
"Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1892 LOG(
"Renaming current workspace to \"%s\"\n", new_name);
1899 !strcasecmp(child->name, old_name));
1908 yerror(
"Old workspace not found");
1912 Con *check_dest = NULL;
1915 !strcasecmp(child->name, new_name));
1917 if (check_dest != NULL) {
1921 yerror(
"New workspace already exists");
1928 char *endptr = NULL;
1929 long parsed_num = strtol(new_name, &endptr, 10);
1930 if (parsed_num == LONG_MIN ||
1931 parsed_num == LONG_MAX ||
1934 workspace->
num = -1;
1936 workspace->
num = parsed_num;
1937 LOG(
"num = %d\n", workspace->
num);
1947 cmd_output->needs_tree_render =
true;
1950 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"rename\"}");
1959 bool toggle =
false;
1960 if (strcmp(bar_mode,
"dock") == 0)
1962 else if (strcmp(bar_mode,
"hide") == 0)
1964 else if (strcmp(bar_mode,
"invisible") == 0)
1966 else if (strcmp(bar_mode,
"toggle") == 0)
1969 ELOG(
"Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
1973 bool changed_sth =
false;
1976 if (bar_id && strcmp(current->
id, bar_id) != 0)
1980 mode = (current->
mode + 1) % 2;
1982 DLOG(
"Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->
id, bar_mode, mode);
1983 current->
mode = mode;
1990 if (bar_id && !changed_sth) {
1991 DLOG(
"Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
2003 int hidden_state = S_SHOW;
2004 bool toggle =
false;
2005 if (strcmp(bar_hidden_state,
"hide") == 0)
2006 hidden_state = S_HIDE;
2007 else if (strcmp(bar_hidden_state,
"show") == 0)
2008 hidden_state = S_SHOW;
2009 else if (strcmp(bar_hidden_state,
"toggle") == 0)
2012 ELOG(
"Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2016 bool changed_sth =
false;
2019 if (bar_id && strcmp(current->
id, bar_id) != 0)
2025 DLOG(
"Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->
id, bar_hidden_state, hidden_state);
2033 if (bar_id && !changed_sth) {
2034 DLOG(
"Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2047 if (strcmp(bar_type,
"mode") == 0)
2049 else if (strcmp(bar_type,
"hidden_state") == 0)
2052 ELOG(
"Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2068 if (!strcmp(argument,
"toggle"))
2071 else if (!strcmp(argument,
"on"))
2073 else if (!strcmp(argument,
"off"))
2079 LOG(
"Restarting shm logging...\n");
2087 LOG(
"%s shm logging\n",
shmlog_size > 0 ?
"Enabling" :
"Disabling");
2100 if (!strcmp(argument,
"toggle")) {
2101 LOG(
"%s debug logging\n", logging ?
"Disabling" :
"Enabling");
2103 }
else if (!strcmp(argument,
"on") && !logging) {
2104 LOG(
"Enabling debug logging\n");
2106 }
else if (!strcmp(argument,
"off") && logging) {
2107 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)
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 not...
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.
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
#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 <name>'.
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 <direction> [<px> px] [or <ppt> 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 <comment>'.
void floating_disable(Con *con, bool automatic)
Disables floating mode for the given container by re-attaching the container to its old parent...
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 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 <direction> [<pixels> [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] <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_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 ipc_send_event(const char *event, uint32_t message_type, const char *payload)
Sends the specified event to all IPC clients which are currently connected and subscribed to this kin...
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 <number>'.
pid_t config_error_nagbar_pid
void cmd_mark(I3_CMD, char *mark)
Implementation of 'mark <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 <string>'.
void cmd_move_con_to_output(I3_CMD, char *name)
Implementation of 'move [window|container] [to] output <str>'.
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.
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 <name> to <name>'.
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] <str>'.
static bool definitelyGreaterThan(float a, float b, float epsilon)
void restore_open_placeholder_windows(Con *parent)
Open placeholder windows for all children of parent.
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.
void cmd_fullscreen(I3_CMD, char *fullscreen_mode)
Implementation of 'fullscreen [global]'.
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 cmd_append_layout(I3_CMD, char *path)
Implementation of 'append_layout <path>'.
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 <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] <command>'.
void cmd_workspace_number(I3_CMD, char *which)
Implementation of 'workspace number <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) [<bar_id>]'...
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 <name>'.
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_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 TAILQ_HEAD(name, type)
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 tree_move(int direction)
Moves the current container in the given direction (TOK_LEFT, TOK_RIGHT, TOK_UP, TOK_DOWN from cmdpar...
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.