2 #define I3__FILE__ "commands.c"
19 #define y(x, ...) yajl_gen_ ## x (cmd_output->json_gen, ##__VA_ARGS__)
20 #define ystr(str) yajl_gen_string(cmd_output->json_gen, (unsigned char*)str, strlen(str))
21 #define ysuccess(success) do { \
33 #define HANDLE_EMPTY_MATCH do { \
34 if (match_is_empty(current_match)) { \
35 owindow *ow = smalloc(sizeof(owindow)); \
37 TAILQ_INIT(&owindows); \
38 TAILQ_INSERT_TAIL(&owindows, ow, owindows); \
48 return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
59 if (strcasecmp(output_str,
"left") == 0)
61 else if (strcasecmp(output_str,
"right") == 0)
63 else if (strcasecmp(output_str,
"up") == 0)
65 else if (strcasecmp(output_str,
"down") == 0)
83 if (strcmp(ws->
name, name) != 0)
86 DLOG(
"This workspace is already focused.\n");
106 if (current == workspace) {
109 DLOG(
"Substituting workspace with back_and_forth, as it is focused.\n");
120 static pid_t migration_pid = -1;
127 static void nagbar_exited(EV_P_ ev_child *watcher,
int revents) {
128 ev_child_stop(EV_A_ watcher);
129 if (!WIFEXITED(watcher->rstatus)) {
130 fprintf(stderr,
"ERROR: i3-nagbar did not exit normally.\n");
134 int exitcode = WEXITSTATUS(watcher->rstatus);
135 printf(
"i3-nagbar process exited with status %d\n", exitcode);
137 fprintf(stderr,
"ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n");
146 #if EV_VERSION_MAJOR >= 4
152 static void nagbar_cleanup(EV_P_ ev_cleanup *watcher,
int revent) {
153 if (migration_pid != -1) {
154 LOG(
"Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid);
155 kill(migration_pid, SIGKILL);
160 void cmd_MIGRATION_start_nagbar(
void) {
161 if (migration_pid != -1) {
162 fprintf(stderr,
"i3-nagbar already running.\n");
165 fprintf(stderr,
"Starting i3-nagbar, command parsing differs from expected output.\n");
166 ELOG(
"Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n");
167 ELOG(
"i3-dump-log | gzip -9c > /tmp/i3.log.gz\n");
168 ELOG(
"FYI: Your i3 version is " I3_VERSION
"\n");
169 migration_pid = fork();
170 if (migration_pid == -1) {
171 warn(
"Could not fork()");
176 if (migration_pid == 0) {
184 "You found a parsing error. Please, please, please, report it!",
195 ev_child *child =
smalloc(
sizeof(ev_child));
202 #if EV_VERSION_MAJOR >= 4
205 ev_cleanup *cleanup =
smalloc(
sizeof(ev_cleanup));
229 static owindows_head owindows;
264 DLOG(
"match specification finished, matching...\n");
267 struct owindows_head old = owindows;
276 DLOG(
"checking if con %p / %s matches\n", current->
con, current->
con->
name);
279 DLOG(
"matches container!\n");
284 DLOG(
"match by mark\n");
290 DLOG(
"matches window!\n");
293 DLOG(
"doesnt match\n");
310 DLOG(
"ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
312 if (strcmp(ctype,
"class") == 0) {
317 if (strcmp(ctype,
"instance") == 0) {
322 if (strcmp(ctype,
"window_role") == 0) {
327 if (strcmp(ctype,
"con_id") == 0) {
329 long parsed = strtol(cvalue, &end, 10);
330 if (parsed == LONG_MIN ||
331 parsed == LONG_MAX ||
333 (end && *end !=
'\0')) {
334 ELOG(
"Could not parse con id \"%s\"\n", cvalue);
342 if (strcmp(ctype,
"id") == 0) {
344 long parsed = strtol(cvalue, &end, 10);
345 if (parsed == LONG_MIN ||
346 parsed == LONG_MAX ||
348 (end && *end !=
'\0')) {
349 ELOG(
"Could not parse window id \"%s\"\n", cvalue);
357 if (strcmp(ctype,
"con_mark") == 0) {
362 if (strcmp(ctype,
"title") == 0) {
367 if (strcmp(ctype,
"urgent") == 0) {
368 if (strcasecmp(cvalue,
"latest") == 0 ||
369 strcasecmp(cvalue,
"newest") == 0 ||
370 strcasecmp(cvalue,
"recent") == 0 ||
371 strcasecmp(cvalue,
"last") == 0) {
373 }
else if (strcasecmp(cvalue,
"oldest") == 0 ||
374 strcasecmp(cvalue,
"first") == 0) {
380 ELOG(
"Unknown criterion: %s\n", ctype);
391 DLOG(
"which=%s\n", which);
407 if (strcmp(which,
"next") == 0)
409 else if (strcmp(which,
"prev") == 0)
411 else if (strcmp(which,
"next_on_output") == 0)
413 else if (strcmp(which,
"prev_on_output") == 0)
415 else if (strcmp(which,
"current") == 0)
418 ELOG(
"BUG: called with which=%s\n", which);
428 cmd_output->needs_tree_render =
true;
448 ystr(
"No workspace was previously active.");
460 cmd_output->needs_tree_render =
true;
470 if (strncasecmp(name,
"__i3_", strlen(
"__i3_")) == 0) {
471 LOG(
"You cannot switch to the i3 internal workspaces.\n");
482 ELOG(
"No windows match your criteria, cannot move.\n");
492 LOG(
"should move window to workspace %s\n", name);
505 cmd_output->needs_tree_render =
true;
527 LOG(
"should move window to workspace %s\n", which);
529 Con *output, *workspace = NULL;
532 long parsed_num = strtol(which, &endptr, 10);
533 if (parsed_num == LONG_MIN ||
534 parsed_num == LONG_MAX ||
537 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
543 ystr(
"Could not parse number");
550 child->
num == parsed_num);
565 cmd_output->needs_tree_render =
true;
571 LOG(
"floating resize\n");
578 if (strcmp(direction,
"up") == 0 || strcmp(direction,
"down") == 0 ||
579 strcmp(direction,
"height") == 0) {
583 px = (px < focused_con->height_increment) ? focused_con->
height_increment : px;
584 }
else if (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0) {
588 px = (px < focused_con->width_increment) ? focused_con->
width_increment : px;
591 if (strcmp(direction,
"up") == 0) {
593 }
else if (strcmp(direction,
"down") == 0 || strcmp(direction,
"height") == 0) {
595 }
else if (strcmp(direction,
"left") == 0) {
605 if (memcmp(&old_rect, &(floating_con->
rect),
sizeof(
Rect)) == 0)
608 if (strcmp(direction,
"up") == 0) {
610 }
else if (strcmp(direction,
"left") == 0) {
620 LOG(
"tiling resize\n");
623 double percentage = 0;
626 current = current->
parent;
630 (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0 ?
HORIZ :
VERT);
634 current = current->
parent;
640 LOG(
"ins. %d children\n", children);
641 percentage = 1.0 / children;
642 LOG(
"default percentage = %f\n", percentage);
646 if ((orientation ==
HORIZ &&
647 (strcmp(direction,
"up") == 0 || strcmp(direction,
"down") == 0)) ||
648 (orientation ==
VERT &&
649 (strcmp(direction,
"left") == 0 || strcmp(direction,
"right") == 0))) {
650 LOG(
"You cannot resize in that direction. Your focus is in a %s split container currently.\n",
651 (orientation ==
HORIZ ?
"horizontal" :
"vertical"));
656 if (strcmp(direction,
"up") == 0 || strcmp(direction,
"left") == 0) {
657 other =
TAILQ_PREV(current, nodes_head, nodes);
662 LOG(
"No other container in this direction found, trying to look further up in the tree...\n");
663 current = current->
parent;
667 }
while (current->
type != CT_WORKSPACE &&
668 current->
type != CT_FLOATING_CON);
671 LOG(
"No other container in this direction found, trying to look further up in the tree...\n");
677 LOG(
"current->percent before = %f\n", current->
percent);
682 double new_current_percent = current->
percent + ((double)ppt / 100.0);
683 double new_other_percent = other->
percent - ((double)ppt / 100.0);
684 LOG(
"new_current_percent = %f\n", new_current_percent);
685 LOG(
"new_other_percent = %f\n", new_other_percent);
690 current->
percent += ((double)ppt / 100.0);
691 other->
percent -= ((double)ppt / 100.0);
692 LOG(
"current->percent after = %f\n", current->
percent);
693 LOG(
"other->percent after = %f\n", other->
percent);
695 LOG(
"Not resizing, already at minimum size\n");
702 LOG(
"width/height resize\n");
706 current = current->
parent;
710 (strcmp(direction,
"width") == 0 ?
HORIZ :
VERT);
712 while (current->
type != CT_WORKSPACE &&
713 current->
type != CT_FLOATING_CON &&
715 current = current->
parent;
719 LOG(
"ins. %d children\n", children);
720 double percentage = 1.0 / children;
721 LOG(
"default percentage = %f\n", percentage);
725 if ((orientation ==
HORIZ &&
726 strcmp(direction,
"height") == 0) ||
727 (orientation ==
VERT &&
728 strcmp(direction,
"width") == 0)) {
729 LOG(
"You cannot resize in that direction. Your focus is in a %s split container currently.\n",
730 (orientation ==
HORIZ ?
"horizontal" :
"vertical"));
736 LOG(
"This is the only container, cannot resize.\n");
744 LOG(
"child->percent = %f (child %p)\n", child->
percent, child);
749 double new_current_percent = current->
percent + ((double)ppt / 100.0);
750 double subtract_percent = ((double)ppt / 100.0) / (children - 1);
751 LOG(
"new_current_percent = %f\n", new_current_percent);
752 LOG(
"subtract_percent = %f\n", subtract_percent);
756 if (child == current)
759 LOG(
"Not resizing, already at minimum size (child %p would end up with a size of %.f\n", child, child->
percent - subtract_percent);
765 LOG(
"Not resizing, already at minimum size\n");
770 current->
percent += ((double)ppt / 100.0);
771 LOG(
"current->percent after = %f\n", current->
percent);
774 if (child == current)
776 child->
percent -= subtract_percent;
777 LOG(
"child->percent after (%p) = %f\n", child, child->
percent);
789 DLOG(
"resizing in way %s, direction %s, px %s or ppt %s\n", way, direction, resize_px, resize_ppt);
791 int px = atoi(resize_px);
792 int ppt = atoi(resize_ppt);
793 if (strcmp(way,
"shrink") == 0) {
806 if (strcmp(direction,
"width") == 0 ||
807 strcmp(direction,
"height") == 0) {
817 cmd_output->needs_tree_render =
true;
827 DLOG(
"border style should be changed to %s with border width %s\n", border_style_str, border_width);
836 int tmp_border_width = -1;
837 tmp_border_width = strtol(border_width, &end, 10);
838 if (end == border_width) {
840 tmp_border_width = -1;
842 if (strcmp(border_style_str,
"toggle") == 0) {
846 tmp_border_width = 2;
847 else if (border_style ==
BS_NONE)
848 tmp_border_width = 0;
850 tmp_border_width = 1;
852 if (strcmp(border_style_str,
"normal") == 0)
854 else if (strcmp(border_style_str,
"pixel") == 0)
856 else if (strcmp(border_style_str,
"1pixel") == 0){
858 tmp_border_width = 1;
859 }
else if (strcmp(border_style_str,
"none") == 0)
862 ELOG(
"BUG: called with border_style=%s\n", border_style_str);
870 cmd_output->needs_tree_render =
true;
880 LOG(
"-------------------------------------------------\n");
881 LOG(
" NOP: %s\n", comment);
882 LOG(
"-------------------------------------------------\n");
890 LOG(
"Appending layout \"%s\"\n", path);
893 cmd_output->needs_tree_render =
true;
905 DLOG(
"which=%s\n", which);
907 if (strcmp(which,
"next") == 0)
909 else if (strcmp(which,
"prev") == 0)
911 else if (strcmp(which,
"next_on_output") == 0)
913 else if (strcmp(which,
"prev_on_output") == 0)
916 ELOG(
"BUG: called with which=%s\n", which);
923 cmd_output->needs_tree_render =
true;
933 Con *output, *workspace = NULL;
936 long parsed_num = strtol(which, &endptr, 10);
937 if (parsed_num == LONG_MIN ||
938 parsed_num == LONG_MAX ||
941 LOG(
"Could not parse initial part of \"%s\" as a number.\n", which);
947 ystr(
"Could not parse number");
955 child->
num == parsed_num);
958 LOG(
"There is no workspace with number %ld, creating a new one.\n", parsed_num);
961 cmd_output->needs_tree_render =
true;
968 cmd_output->needs_tree_render =
true;
980 cmd_output->needs_tree_render =
true;
990 if (strncasecmp(name,
"__i3_", strlen(
"__i3_")) == 0) {
991 LOG(
"You cannot switch to the i3 internal workspaces.\n");
996 DLOG(
"should switch to workspace %s\n", name);
1001 cmd_output->needs_tree_render =
true;
1011 DLOG(
"Clearing all windows which have that mark first\n");
1015 if (con->
mark && strcmp(con->
mark, mark) == 0)
1019 DLOG(
"marking window with str %s\n", mark);
1029 cmd_output->needs_tree_render =
true;
1044 DLOG(
"removed all window marks");
1048 if (con->
mark && strcmp(con->
mark, mark) == 0)
1051 DLOG(
"removed window mark %s\n", mark);
1054 cmd_output->needs_tree_render =
true;
1064 DLOG(
"mode=%s\n", mode);
1078 DLOG(
"should move window to output %s\n", name);
1083 Output *current_output = NULL;
1090 assert(current_output != NULL);
1093 if (strcasecmp(name,
"up") == 0)
1095 else if (strcasecmp(name,
"down") == 0)
1097 else if (strcasecmp(name,
"left") == 0)
1099 else if (strcasecmp(name,
"right") == 0)
1105 LOG(
"No such output found.\n");
1123 cmd_output->needs_tree_render =
true;
1135 DLOG(
"floating_mode=%s\n", floating_mode);
1141 if (strcmp(floating_mode,
"toggle") == 0) {
1142 DLOG(
"should toggle mode\n");
1145 DLOG(
"should switch mode to %s\n", floating_mode);
1146 if (strcmp(floating_mode,
"enable") == 0) {
1154 cmd_output->needs_tree_render =
true;
1164 DLOG(
"should move workspace to output %s\n", name);
1172 if (!current_output) {
1173 ELOG(
"Cannot get current output. This is a bug in i3.\n");
1179 ELOG(
"Could not get output from string \"%s\"\n", name);
1185 LOG(
"got output %p with content %p\n", output, content);
1187 Con *previously_visible_ws =
TAILQ_FIRST(&(content->nodes_head));
1188 LOG(
"Previously visible workspace = %p / %s\n", previously_visible_ws, previously_visible_ws->
name);
1191 LOG(
"should move workspace %p / %s\n", ws, ws->
name);
1195 LOG(
"Creating a new workspace to replace \"%s\" (last on its output).\n", ws->
name);
1198 bool used_assignment =
false;
1201 if (strcmp(assignment->
output, current_output->
name) != 0)
1205 Con *workspace = NULL, *out;
1208 !strcasecmp(child->name, assignment->
name));
1209 if (workspace != NULL)
1213 LOG(
"Creating workspace from assignment %s.\n", assignment->
name);
1215 used_assignment =
true;
1221 if (!used_assignment)
1225 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"init\"}");
1227 DLOG(
"Detaching\n");
1232 if (workspace_was_visible) {
1236 LOG(
"workspace was visible, focusing %p / %s now\n", focus_ws, focus_ws->
name);
1243 TAILQ_FOREACH(floating_con, &(ws->floating_head), floating_windows)
1246 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"move\"}");
1247 if (workspace_was_visible) {
1258 if (ws != previously_visible_ws)
1264 CALL(previously_visible_ws, on_remove_child);
1269 cmd_output->needs_tree_render =
true;
1281 LOG(
"splitting in direction %c\n", direction[0]);
1291 cmd_output->needs_tree_render =
true;
1301 if (kill_mode_str == NULL)
1302 kill_mode_str =
"window";
1305 DLOG(
"kill_mode=%s\n", kill_mode_str);
1308 if (strcmp(kill_mode_str,
"window") == 0)
1310 else if (strcmp(kill_mode_str,
"client") == 0)
1313 ELOG(
"BUG: called with kill_mode=%s\n", kill_mode_str);
1328 cmd_output->needs_tree_render =
true;
1338 bool no_startup_id = (nosn != NULL);
1340 DLOG(
"should execute %s, no_startup_id = %d\n", command, no_startup_id);
1352 DLOG(
"direction = *%s*\n", direction);
1354 if (strcmp(direction,
"left") == 0)
1356 else if (strcmp(direction,
"right") == 0)
1358 else if (strcmp(direction,
"up") == 0)
1360 else if (strcmp(direction,
"down") == 0)
1363 ELOG(
"Invalid focus direction (%s)\n", direction);
1368 cmd_output->needs_tree_render =
true;
1378 DLOG(
"window_mode = %s\n", window_mode);
1383 if (strcmp(window_mode,
"mode_toggle") == 0) {
1385 if (current != NULL && current->
type == CT_FLOATING_CON)
1386 window_mode =
"tiling";
1387 else window_mode =
"floating";
1390 if ((strcmp(window_mode,
"floating") == 0 && current->
type != CT_FLOATING_CON) ||
1391 (strcmp(window_mode,
"tiling") == 0 && current->
type == CT_FLOATING_CON))
1399 cmd_output->needs_tree_render =
true;
1409 DLOG(
"level = %s\n", level);
1410 bool success =
false;
1414 if (strcmp(level,
"parent") == 0) {
1419 ELOG(
"'focus parent': Currently in fullscreen, not going up\n");
1426 cmd_output->needs_tree_render = success;
1439 ELOG(
"You have to specify which window/container should be focused.\n");
1440 ELOG(
"Example: [class=\"urxvt\" title=\"irssi\"] focus\n");
1446 ystr(
"You have to specify which window/container should be focused");
1464 LOG(
"Cannot change focus while in fullscreen mode (fullscreen rules).\n");
1470 if (ws == __i3_scratch) {
1497 LOG(
"focusing %p / %s\n", current->
con, current->
con->
name);
1503 LOG(
"WARNING: Your criteria for the focus command matches %d containers, "
1504 "while only exactly one container can be focused at a time.\n", count);
1506 cmd_output->needs_tree_render =
true;
1516 if (fullscreen_mode == NULL)
1517 fullscreen_mode =
"output";
1518 DLOG(
"toggling fullscreen, mode = %s\n", fullscreen_mode);
1524 printf(
"matching: %p / %s\n", current->
con, current->
con->
name);
1528 cmd_output->needs_tree_render =
true;
1539 int px = atoi(move_px);
1542 DLOG(
"moving in direction %s, px %s\n", direction, move_px);
1544 DLOG(
"floating move with %d pixels\n", px);
1546 if (strcmp(direction,
"left") == 0) {
1548 }
else if (strcmp(direction,
"right") == 0) {
1550 }
else if (strcmp(direction,
"up") == 0) {
1552 }
else if (strcmp(direction,
"down") == 0) {
1558 (strcmp(direction,
"left") == 0 ?
D_LEFT :
1559 (strcmp(direction,
"up") == 0 ?
D_UP :
1561 cmd_output->needs_tree_render =
true;
1573 if (strcmp(layout_str,
"stacking") == 0)
1574 layout_str =
"stacked";
1578 if (strcmp(layout_str,
"default") == 0)
1580 else if (strcmp(layout_str,
"stacked") == 0)
1582 else if (strcmp(layout_str,
"tabbed") == 0)
1584 else if (strcmp(layout_str,
"splitv") == 0)
1586 else if (strcmp(layout_str,
"splith") == 0)
1589 ELOG(
"Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str);
1593 DLOG(
"changing layout to %s (%d)\n", layout_str, layout);
1605 cmd_output->needs_tree_render =
true;
1617 if (toggle_mode == NULL)
1618 toggle_mode =
"default";
1620 DLOG(
"toggling layout (mode = %s)\n", toggle_mode);
1632 cmd_output->needs_tree_render =
true;
1642 LOG(
"Exiting due to user command.\n");
1643 xcb_disconnect(
conn);
1660 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"reload\"}");
1673 LOG(
"restarting i3\n");
1685 LOG(
"opening new container\n");
1694 y(integer, (
long int)con);
1697 cmd_output->needs_tree_render =
true;
1707 DLOG(
"name = %s\n", name);
1712 Output *current_output = NULL;
1717 assert(current_output != NULL);
1722 LOG(
"No such output found.\n");
1737 cmd_output->needs_tree_render =
true;
1752 ELOG(
"Cannot change position. The window/container is not floating\n");
1757 ystr(
"Cannot change position. The window/container is not floating.");
1762 if (strcmp(method,
"absolute") == 0) {
1766 DLOG(
"moving to absolute position %d %d\n", x, y);
1768 cmd_output->needs_tree_render =
true;
1771 if (strcmp(method,
"position") == 0) {
1774 DLOG(
"moving to position %d %d\n", x, y);
1792 ELOG(
"Cannot change position. The window/container is not floating\n");
1797 ystr(
"Cannot change position. The window/container is not floating.");
1801 if (strcmp(method,
"absolute") == 0) {
1804 DLOG(
"moving to absolute center\n");
1809 cmd_output->needs_tree_render =
true;
1812 if (strcmp(method,
"position") == 0) {
1816 DLOG(
"moving to center\n");
1832 DLOG(
"should move window to scratchpad\n");
1842 cmd_output->needs_tree_render =
true;
1852 DLOG(
"should show scratchpad window\n");
1864 cmd_output->needs_tree_render =
true;
1875 LOG(
"Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
1877 LOG(
"Renaming current workspace to \"%s\"\n", new_name);
1884 !strcasecmp(child->name, old_name));
1897 ystr(
"Old workspace not found");
1902 Con *check_dest = NULL;
1905 !strcasecmp(child->name, new_name));
1907 if (check_dest != NULL) {
1915 ystr(
"New workspace already exists");
1923 char *endptr = NULL;
1924 long parsed_num = strtol(new_name, &endptr, 10);
1925 if (parsed_num == LONG_MIN ||
1926 parsed_num == LONG_MAX ||
1929 workspace->
num = -1;
1930 else workspace->
num = parsed_num;
1931 LOG(
"num = %d\n", workspace->
num);
1941 cmd_output->needs_tree_render =
true;
1944 ipc_send_event(
"workspace", I3_IPC_EVENT_WORKSPACE,
"{\"change\":\"rename\"}");
1953 bool toggle =
false;
1954 if (strcmp(bar_mode,
"dock") == 0)
1956 else if (strcmp(bar_mode,
"hide") == 0)
1958 else if (strcmp(bar_mode,
"invisible") == 0)
1960 else if (strcmp(bar_mode,
"toggle") == 0)
1963 ELOG(
"Unknown bar mode \"%s\", this is a mismatch between code and parser spec.\n", bar_mode);
1967 bool changed_sth =
false;
1970 if (bar_id && strcmp(current->
id, bar_id) != 0)
1974 mode = (current->
mode + 1) % 2;
1976 DLOG(
"Changing bar mode of bar_id '%s' to '%s (%d)'\n", current->
id, bar_mode, mode);
1977 current->
mode = mode;
1984 if (bar_id && !changed_sth) {
1985 DLOG(
"Changing bar mode of bar_id %s failed, bar_id not found.\n", bar_id);
1998 bool toggle =
false;
1999 if (strcmp(bar_hidden_state,
"hide") == 0)
2000 hidden_state = S_HIDE;
2001 else if (strcmp(bar_hidden_state,
"show") == 0)
2002 hidden_state = S_SHOW;
2003 else if (strcmp(bar_hidden_state,
"toggle") == 0)
2006 ELOG(
"Unknown bar state \"%s\", this is a mismatch between code and parser spec.\n", bar_hidden_state);
2010 bool changed_sth =
false;
2013 if (bar_id && strcmp(current->
id, bar_id) != 0)
2019 DLOG(
"Changing bar hidden_state of bar_id '%s' to '%s (%d)'\n", current->
id, bar_hidden_state, hidden_state);
2027 if (bar_id && !changed_sth) {
2028 DLOG(
"Changing bar hidden_state of bar_id %s failed, bar_id not found.\n", bar_id);
2041 if (strcmp(bar_type,
"mode") == 0)
2043 else if (strcmp(bar_type,
"hidden_state") == 0)
2046 ELOG(
"Unknown bar option type \"%s\", this is a mismatch between code and parser spec.\n", bar_type);
2062 if (!strcmp(argument,
"toggle"))
2065 else if (!strcmp(argument,
"on"))
2067 else if (!strcmp(argument,
"off"))
2073 LOG(
"Restarting shm logging...\n");
2081 LOG(
"%s shm logging\n",
shmlog_size > 0 ?
"Enabling" :
"Disabling");
2094 if (!strcmp(argument,
"toggle")) {
2095 LOG(
"%s debug logging\n", logging ?
"Disabling" :
"Enabling");
2097 }
else if (!strcmp(argument,
"on") && !logging) {
2098 LOG(
"Enabling debug logging\n");
2100 }
else if (!strcmp(argument,
"off") && logging) {
2101 LOG(
"Disabling debug logging\n");
char * name
Name of the output.
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 get_debug_logging(void)
Checks if debug logging is active.
static void cmd_resize_floating(I3_CMD, char *way, char *direction, Con *floating_con, int px)
void cmd_workspace_name(I3_CMD, char *name)
Implementation of 'workspace <name>'.
#define GREP_FIRST(dest, head, condition)
#define I3_CMD
The beginning of the prototype for every cmd_ function.
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...
static bool cmd_resize_tiling_width_height(I3_CMD, Con *current, char *way, char *direction, int ppt)
void con_set_layout(Con *con, layout_t layout)
This function changes the layout of a given container.
A 'Con' represents everything from the X11 root window down to a single X11 window.
void cmd_floating(I3_CMD, char *floating_mode)
Implementation of 'floating enable|disable|toggle'.
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
void con_toggle_fullscreen(Con *con, int fullscreen_mode)
Toggles fullscreen mode for the given container.
void workspace_show(Con *workspace)
Switches to the given workspace.
void cmd_fullscreen(I3_CMD, char *fullscreen_mode)
Implementation of 'fullscreen [global]'.
struct all_cons_head all_cons
Stores which workspace (by name) goes to which output.
#define TAILQ_INSERT_TAIL(head, elm, field)
Stores a rectangle, for example the size of a window, the child window etc.
void cmd_unmark(I3_CMD, char *mark)
Implementation of 'unmark [mark]'.
bool workspace_is_visible(Con *ws)
Returns true if the workspace is currently visible.
void cmd_focus_window_mode(I3_CMD, char *window_mode)
Implementation of 'focus tiling|floating|mode_toggle'.
border_style_t border_style
void cmd_workspace_number(I3_CMD, char *which)
Implementation of 'workspace number <number>'.
void cmd_move_con_to_workspace_back_and_forth(I3_CMD)
Implementation of 'move [window|container] [to] workspace back_and_forth'.
struct barconfig_head barconfigs
static bool definitelyGreaterThan(float a, float b, float epsilon)
void init_logging(void)
Initializes logging by creating an error logfile in /tmp (or XDG_RUNTIME_DIR, see get_process_filenam...
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_toggle_layout(Con *con, const char *toggle_mode)
This function toggles the layout of a given container.
void cmd_border(I3_CMD, char *border_style_str, char *border_width)
Implementation of 'border normal|none|1pixel|toggle'.
void con_attach(Con *con, Con *parent, bool ignore_focus)
Attaches the given container to the given parent.
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.
#define TAILQ_EMPTY(head)
int con_num_children(Con *con)
Returns the number of children of this container.
void cmd_focus_output(I3_CMD, char *name)
Implementation of 'focus output <output>'.
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
bool match_is_empty(Match *match)
Check if a match is empty.
Con * workspace_next_on_output(void)
Returns the next workspace on the same output.
#define TAILQ_PREV(elm, headname, field)
layout_t
Container layouts.
static void nagbar_exited(EV_P_ ev_child *watcher, int revents)
void tree_next(char way, orientation_t orientation)
Changes focus in the given way (next/previous) and given orientation (horizontal/vertical).
void toggle_floating_mode(Con *con, bool automatic)
Calls floating_enable() for tiling containers and floating_disable() for floating containers...
void cmd_scratchpad_show(I3_CMD)
Implementation of 'scratchpad show'.
void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name)
Implementation of 'rename workspace <name> to <name>'.
void floating_disable(Con *con, bool automatic)
Disables floating mode for the given container by re-attaching the container to its old parent...
void cmd_open(I3_CMD)
Implementation of 'open'.
Output * get_output_by_name(const char *name)
Returns the output with the given name if it is active (!) or NULL.
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
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]...
void cmd_criteria_add(I3_CMD, char *ctype, char *cvalue)
Interprets a ctype=cvalue pair and adds it to the current match specification.
Con * workspace_prev(void)
Returns the previous workspace.
void cmd_mark(I3_CMD, char *mark)
Implementation of 'mark <mark>'.
void cmd_shmlog(I3_CMD, char *argument)
#define TAILQ_REMOVE(head, elm, field)
void workspace_back_and_forth(void)
Focuses the previously focused workspace.
void update_shmlog_atom()
Set up the SHMLOG_PATH atom.
void scratchpad_move(Con *con)
Moves the specified window to the __i3_scratch workspace, making it floating and setting the appropri...
void cmd_exec(I3_CMD, char *nosn, char *command)
Implementation of 'exec [–no-startup-id] <command>'.
void match_init(Match *match)
void floating_reposition(Con *con, Rect newrect)
Repositions the CT_FLOATING_CON to have the coordinates specified by newrect, but only if the coordin...
void kill_nagbar(pid_t *nagbar_pid, bool wait_for_it)
Kills the i3-nagbar process, if *nagbar_pid != -1.
void cmd_debuglog(I3_CMD, char *argument)
void scratchpad_show(Con *con)
Either shows the top-most scratchpad window (con == NULL) or shows the specified con (if it is scratc...
Con * tree_open_con(Con *con, i3Window *window)
Opens an empty container in the current container.
void cmd_exit(I3_CMD)
Implementation of 'exit'.
void update_barconfig()
Sends the current bar configuration as an event to all barconfig_update listeners.
struct ws_assignments_head ws_assignments
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...
#define TAILQ_HEAD(name, type)
void cmd_move_con_to_workspace_name(I3_CMD, char *name)
Implementation of 'move [window|container] [to] workspace <name>'.
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_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 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]'.
void cmd_workspace_back_and_forth(I3_CMD)
Implementation of 'workspace back_and_forth'.
static Con * maybe_auto_back_and_forth_workspace(Con *workspace)
bool cmd_bar_hidden_state(char *bar_hidden_state, char *bar_id)
void workspace_show_by_name(const char *num)
Looks up the workspace by name and switches to it.
void cmd_layout_toggle(I3_CMD, char *toggle_mode)
Implementation of 'layout toggle [all|split]'.
#define CALL(obj, member,...)
static bool maybe_back_and_forth(struct CommandResult *cmd_output, char *name)
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...
#define ysuccess(success)
Con * con_descend_focused(Con *con)
Returns the focused con inside this client, descending the tree as far as possible.
char * id
Automatically generated ID for this bar config.
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...
Output * get_output_next_wrap(direction_t direction, Output *current)
Like get_output_next with close_far == CLOSEST_OUTPUT, but wraps.
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 * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression...
static Match current_match
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.
static bool cmd_resize_tiling_direction(I3_CMD, Con *current, char *way, char *direction, int ppt)
void cmd_kill(I3_CMD, char *kill_mode_str)
Implementation of 'kill [window|client]'.
static Output * get_output_from_string(Output *current_output, const char *output_str)
Con * workspace_back_and_forth_get(void)
Returns the previously focused workspace con, or NULL if unavailable.
void cmd_move_direction(I3_CMD, char *direction, char *move_px)
Implementation of 'move <direction> [<pixels> [px]]'.
void cmd_nop(I3_CMD, char *comment)
Implementation of 'nop <comment>'.
void * smalloc(size_t size)
Safe-wrapper around malloc which exits if malloc returns NULL (meaning that there is no more memory a...
Con * workspace_next(void)
Returns the next workspace.
void cmd_move_workspace_to_output(I3_CMD, char *name)
Implementation of 'move workspace to [output] <str>'.
void cmd_split(I3_CMD, char *direction)
Implementation of 'split v|h|vertical|horizontal'.
#define TAILQ_NEXT(elm, field)
bool level_up(void)
Moves focus one level up.
void con_focus(Con *con)
Sets input focus to 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...
Con * workspace_prev_on_output(void)
Returns the previous workspace on the same output.
void switch_mode(const char *new_mode)
Switches the key bindings to the given mode, if the mode exists.
#define TAILQ_FIRST(head)
pid_t command_error_nagbar_pid
void cmd_layout(I3_CMD, char *layout_str)
Implementation of 'layout default|stacked|stacking|tabbed|splitv|splith'.
void start_application(const char *command, bool no_startup_id)
Starts the given application by passing it through a shell.
void cmd_reload(I3_CMD)
Implementation of 'reload'.
An Output is a physical output on your graphics driver.
enum Barconfig::@6 hidden_state
void x_set_i3_atoms(void)
Sets up i3 specific atoms (I3_SOCKET_PATH and I3_CONFIG_PATH)
bool con_has_children(Con *con)
Returns true if this node has regular or floating children.
Output * get_output_containing(int x, int y)
Returns the active (!) output which contains the coordinates x, y or NULL if there is no output which...
void cmd_focus_direction(I3_CMD, char *direction)
Implementation of 'focus left|right|up|down'.
void cmd_move_con_to_output(I3_CMD, char *name)
Implementation of 'move [window|container] [to] output <str>'.
bool cmd_bar_mode(char *bar_mode, char *bar_id)
#define TAILQ_FOREACH(var, head, field)
void cmd_move_window_to_center(I3_CMD, char *method)
Implementation of 'move [window|container] [to] [absolute] position center.
void tree_append_json(const char *filename)
void cmd_mode(I3_CMD, char *mode)
Implementation of 'mode <string>'.
void cmd_focus_level(I3_CMD, char *level)
Implementation of 'focus parent|child'.
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...
struct ev_loop * main_loop
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...
#define TAILQ_ENTRY(type)
int num
the workspace number, if this Con is of type CT_WORKSPACE and the workspace is not a named workspace ...
void con_detach(Con *con)
Detaches the given container from its current parent.
#define HANDLE_EMPTY_MATCH
When the command did not include match criteria (!), we use the currently focused container...
Con * output_get_content(Con *output)
Returns the output container below the given output container.
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 floating_check_size(Con *floating_con)
Called when a floating window is created or resized.
bool workspace_auto_back_and_forth
Automatic workspace back and forth switching.
Con * con
Pointer to the Con which represents this output.
static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent)
enum Con::@21 scratchpad_state
bool con_is_floating(Con *con)
Returns true if the node is floating.
void cmd_move_scratchpad(I3_CMD)
Implementation of 'move scratchpad'.
void cmd_focus(I3_CMD)
Implementation of 'focus'.
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...
Con * create_workspace_on_output(Output *output, Con *content)
bool level_down(void)
Moves focus one level down.
void cmd_append_layout(I3_CMD, char *path)
Implementation of 'append_layout <path>'.
pid_t config_error_nagbar_pid
void cmd_move_con_to_workspace_number(I3_CMD, char *which)
Implementation of 'move [window|container] [to] workspace number <number>'.
Holds the status bar configuration (i3bar).
void cmd_restart(I3_CMD)
Implementation of 'restart'.
void i3_restart(bool forget_layout)
Restart i3 in-place appends -a to argument list to disable autostart.
void set_debug_logging(const bool _debug_logging)
Set debug logging.
const int default_shmlog_size
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
bool con_fullscreen_permits_focusing(Con *con)
Returns true if changing the focus to con would be allowed considering the fullscreen focus constrain...
int con_orientation(Con *con)
Returns the orientation of the given container (for stacked containers, vertical orientation is used ...
void cmd_workspace(I3_CMD, char *which)
Implementation of 'workspace next|prev|next_on_output|prev_on_output'.
void tree_close_con(kill_window_t kill_window)
Closes the current container using tree_close().
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_move_con_to_workspace(I3_CMD, char *which)
Implementation of 'move [window|container] [to] workspace next|prev|next_on_output|prev_on_output'.
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>]'...