X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcommands.c;h=33737f71187647609228d77d9cb24924d8816de0;hb=c474ddd782782190f48c0ea045d485e7974977a0;hp=03ae0ae0685ceb22f43ee977a19a6ba1627f00f1;hpb=3853d1866be47f2fd575e970a12a985c45ac532d;p=i3%2Fi3 diff --git a/src/commands.c b/src/commands.c index 03ae0ae0..33737f71 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1,5 +1,3 @@ -#undef I3__FILE__ -#define I3__FILE__ "commands.c" /* * vim:ts=4:sw=4:expandtab * @@ -9,10 +7,16 @@ * commands.c: all command functions (see commands_parser.c) * */ +#include "all.h" + +#include #include #include -#include "all.h" +#ifdef I3_ASAN_ENABLED +#include +#endif + #include "shmlog.h" // Macros to make the YAJL API a bit easier to use. @@ -42,7 +46,7 @@ } \ } while (0) -/** If an error occured during parsing of the criteria, we want to exit instead +/** If an error occurred during parsing of the criteria, we want to exit instead * of relying on fallback behavior. See #2091. */ #define HANDLE_INVALID_MATCH \ do { \ @@ -62,6 +66,11 @@ HANDLE_INVALID_MATCH; \ \ if (match_is_empty(current_match)) { \ + while (!TAILQ_EMPTY(&owindows)) { \ + owindow *ow = TAILQ_FIRST(&owindows); \ + TAILQ_REMOVE(&owindows, ow, owindows); \ + free(ow); \ + } \ owindow *ow = smalloc(sizeof(owindow)); \ ow->con = focused; \ TAILQ_INIT(&owindows); \ @@ -77,17 +86,6 @@ static bool definitelyGreaterThan(float a, float b, float epsilon) { return (a - b) > ((fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon); } -/* - * Returns the output containing the given container. - */ -static Output *get_output_of_con(Con *con) { - Con *output_con = con_get_output(con); - Output *output = get_output_by_name(output_con->name); - assert(output != NULL); - - return output; -} - /* * Checks whether we switched to a new workspace and returns false in that case, * signaling that further workspace switching should be done by the calling function @@ -133,102 +131,6 @@ static Con *maybe_auto_back_and_forth_workspace(Con *workspace) { return workspace; } -// This code is commented out because we might recycle it for popping up error -// messages on parser errors. -#if 0 -static pid_t migration_pid = -1; - -/* - * Handler which will be called when we get a SIGCHLD for the nagbar, meaning - * it exited (or could not be started, depending on the exit code). - * - */ -static void nagbar_exited(EV_P_ ev_child *watcher, int revents) { - ev_child_stop(EV_A_ watcher); - if (!WIFEXITED(watcher->rstatus)) { - fprintf(stderr, "ERROR: i3-nagbar did not exit normally.\n"); - return; - } - - int exitcode = WEXITSTATUS(watcher->rstatus); - printf("i3-nagbar process exited with status %d\n", exitcode); - if (exitcode == 2) { - fprintf(stderr, "ERROR: i3-nagbar could not be found. Is it correctly installed on your system?\n"); - } - - migration_pid = -1; -} - -/* We need ev >= 4 for the following code. Since it is not *that* important (it - * only makes sure that there are no i3-nagbar instances left behind) we still - * support old systems with libev 3. */ -#if EV_VERSION_MAJOR >= 4 -/* - * Cleanup handler. Will be called when i3 exits. Kills i3-nagbar with signal - * SIGKILL (9) to make sure there are no left-over i3-nagbar processes. - * - */ -static void nagbar_cleanup(EV_P_ ev_cleanup *watcher, int revent) { - if (migration_pid != -1) { - LOG("Sending SIGKILL (9) to i3-nagbar with PID %d\n", migration_pid); - kill(migration_pid, SIGKILL); - } -} -#endif - -void cmd_MIGRATION_start_nagbar(void) { - if (migration_pid != -1) { - fprintf(stderr, "i3-nagbar already running.\n"); - return; - } - fprintf(stderr, "Starting i3-nagbar, command parsing differs from expected output.\n"); - ELOG("Please report this on IRC or in the bugtracker. Make sure to include the full debug level logfile:\n"); - ELOG("i3-dump-log | gzip -9c > /tmp/i3.log.gz\n"); - ELOG("FYI: Your i3 version is " I3_VERSION "\n"); - migration_pid = fork(); - if (migration_pid == -1) { - warn("Could not fork()"); - return; - } - - /* child */ - if (migration_pid == 0) { - char *pageraction; - sasprintf(&pageraction, "i3-sensible-terminal -e i3-sensible-pager \"%s\"", errorfilename); - char *argv[] = { - NULL, /* will be replaced by the executable path */ - "-t", - "error", - "-m", - "You found a parsing error. Please, please, please, report it!", - "-b", - "show errors", - pageraction, - NULL - }; - exec_i3_utility("i3-nagbar", argv); - } - - /* parent */ - /* install a child watcher */ - ev_child *child = smalloc(sizeof(ev_child)); - ev_child_init(child, &nagbar_exited, migration_pid, 0); - ev_child_start(main_loop, child); - -/* We need ev >= 4 for the following code. Since it is not *that* important (it - * only makes sure that there are no i3-nagbar instances left behind) we still - * support old systems with libev 3. */ -#if EV_VERSION_MAJOR >= 4 - /* install a cleanup watcher (will be called when i3 exits and i3-nagbar is - * still running) */ - ev_cleanup *cleanup = smalloc(sizeof(ev_cleanup)); - ev_cleanup_init(cleanup, nagbar_cleanup); - ev_cleanup_start(main_loop, cleanup); -#endif -} - -#endif - /******************************************************************************* * Criteria functions. ******************************************************************************/ @@ -240,7 +142,9 @@ void cmd_MIGRATION_start_nagbar(void) { */ typedef struct owindow { Con *con; - TAILQ_ENTRY(owindow) owindows; + + TAILQ_ENTRY(owindow) + owindows; } owindow; typedef TAILQ_HEAD(owindows_head, owindow) owindows_head; @@ -337,7 +241,7 @@ void cmd_criteria_match_windows(I3_CMD) { DLOG("matches window!\n"); accept_match = true; } else { - DLOG("doesnt match\n"); + DLOG("doesn't match\n"); FREE(current); continue; } @@ -803,8 +707,8 @@ void cmd_resize_set(I3_CMD, long cwidth, long cheight) { * Implementation of 'border normal|pixel []', 'border none|1pixel|toggle'. * */ -void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) { - DLOG("border style should be changed to %s with border width %s\n", border_style_str, border_width); +void cmd_border(I3_CMD, const char *border_style_str, long border_width) { + DLOG("border style should be changed to %s with border width %ld\n", border_style_str, border_width); owindow *current; HANDLE_EMPTY_MATCH; @@ -812,39 +716,35 @@ void cmd_border(I3_CMD, const char *border_style_str, const char *border_width) TAILQ_FOREACH(current, &owindows, owindows) { DLOG("matching: %p / %s\n", current->con, current->con->name); int border_style = current->con->border_style; - char *end; - int tmp_border_width = -1; - tmp_border_width = strtol(border_width, &end, 10); - if (end == border_width) { - /* no valid digits found */ - tmp_border_width = -1; - } + int con_border_width = border_width; + if (strcmp(border_style_str, "toggle") == 0) { border_style++; border_style %= 3; if (border_style == BS_NORMAL) - tmp_border_width = 2; + con_border_width = 2; else if (border_style == BS_NONE) - tmp_border_width = 0; + con_border_width = 0; else if (border_style == BS_PIXEL) - tmp_border_width = 1; + con_border_width = 1; } else { - if (strcmp(border_style_str, "normal") == 0) + if (strcmp(border_style_str, "normal") == 0) { border_style = BS_NORMAL; - else if (strcmp(border_style_str, "pixel") == 0) + } else if (strcmp(border_style_str, "pixel") == 0) { border_style = BS_PIXEL; - else if (strcmp(border_style_str, "1pixel") == 0) { + } else if (strcmp(border_style_str, "1pixel") == 0) { border_style = BS_PIXEL; - tmp_border_width = 1; - } else if (strcmp(border_style_str, "none") == 0) + con_border_width = 1; + } else if (strcmp(border_style_str, "none") == 0) { border_style = BS_NONE; - else { + } else { ELOG("BUG: called with border_style=%s\n", border_style_str); ysuccess(false); return; } } - con_set_border_style(current->con, border_style, tmp_border_width); + + con_set_border_style(current->con, border_style, logical_px(con_border_width)); } cmd_output->needs_tree_render = true; @@ -993,8 +893,10 @@ void cmd_workspace_number(I3_CMD, const char *which, const char *_no_auto_back_a cmd_output->needs_tree_render = true; return; } - if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, workspace->name)) + if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, workspace->name)) { + ysuccess(true); return; + } workspace_show(workspace); cmd_output->needs_tree_render = true; @@ -1040,8 +942,10 @@ void cmd_workspace_name(I3_CMD, const char *name, const char *_no_auto_back_and_ } DLOG("should switch to workspace %s\n", name); - if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, name)) + if (!no_auto_back_and_forth && maybe_back_and_forth(cmd_output, name)) { + ysuccess(true); return; + } workspace_show_by_name(name); cmd_output->needs_tree_render = true; @@ -1126,7 +1030,7 @@ void cmd_move_con_to_output(I3_CMD, const char *name) { TAILQ_FOREACH(current, &owindows, owindows) { DLOG("matching: %p / %s\n", current->con, current->con->name); - Output *current_output = get_output_of_con(current->con); + Output *current_output = get_output_for_con(current->con); assert(current_output != NULL); Output *output = get_output_from_string(current_output, name); @@ -1533,6 +1437,8 @@ void cmd_sticky(I3_CMD, const char *action) { * sure it gets pushed to the front now. */ output_push_sticky_windows(focused); + ewmh_update_wm_desktop(); + cmd_output->needs_tree_render = true; ysuccess(true); } @@ -1583,21 +1489,8 @@ void cmd_move_direction(I3_CMD, const char *direction, long move_px) { void cmd_layout(I3_CMD, const char *layout_str) { HANDLE_EMPTY_MATCH; - if (strcmp(layout_str, "stacking") == 0) - layout_str = "stacked"; layout_t layout; - /* default is a special case which will be handled in con_set_layout(). */ - if (strcmp(layout_str, "default") == 0) - layout = L_DEFAULT; - else if (strcmp(layout_str, "stacked") == 0) - layout = L_STACKED; - else if (strcmp(layout_str, "tabbed") == 0) - layout = L_TABBED; - else if (strcmp(layout_str, "splitv") == 0) - layout = L_SPLITV; - else if (strcmp(layout_str, "splith") == 0) - layout = L_SPLITH; - else { + if (!layout_from_name(layout_str, &layout)) { ELOG("Unknown layout \"%s\", this is a mismatch between code and parser spec.\n", layout_str); return; } @@ -1653,7 +1546,10 @@ void cmd_layout_toggle(I3_CMD, const char *toggle_mode) { */ void cmd_exit(I3_CMD) { LOG("Exiting due to user command.\n"); - ipc_shutdown(); +#ifdef I3_ASAN_ENABLED + __lsan_do_leak_check(); +#endif + ipc_shutdown(SHUTDOWN_REASON_EXIT); unlink(config.ipc_socket_path); xcb_disconnect(conn); exit(0); @@ -1686,7 +1582,7 @@ void cmd_reload(I3_CMD) { */ void cmd_restart(I3_CMD) { LOG("restarting i3\n"); - ipc_shutdown(); + ipc_shutdown(SHUTDOWN_REASON_RESTART); unlink(config.ipc_socket_path); /* We need to call this manually since atexit handlers don’t get called * when exec()ing */ @@ -1711,7 +1607,7 @@ void cmd_open(I3_CMD) { ystr("success"); y(bool, true); ystr("id"); - y(integer, (long int)con); + y(integer, (uintptr_t)con); y(map_close); cmd_output->needs_tree_render = true; @@ -1733,7 +1629,7 @@ void cmd_focus_output(I3_CMD, const char *name) { Output *output; TAILQ_FOREACH(current, &owindows, owindows) - current_output = get_output_of_con(current->con); + current_output = get_output_for_con(current->con); assert(current_output != NULL); output = get_output_from_string(current_output, name); @@ -1995,12 +1891,16 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) { GREP_FIRST(check_dest, output_get_content(output), !strcasecmp(child->name, new_name)); - if (check_dest != NULL) { + /* If check_dest == workspace, the user might be changing the case of the + * workspace, or it might just be a no-op. */ + if (check_dest != NULL && check_dest != workspace) { yerror("New workspace \"%s\" already exists", new_name); return; } /* Change the name and try to parse it as a number. */ + /* old_name might refer to workspace->name, so copy it before free()ing */ + char *old_name_copy = sstrdup(old_name); FREE(workspace->name); workspace->name = sstrdup(new_name); @@ -2041,7 +1941,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) { ewmh_update_desktop_viewport(); ewmh_update_current_desktop(); - startup_sequence_rename_workspace(old_name, new_name); + startup_sequence_rename_workspace(old_name_copy, new_name); + free(old_name_copy); } /*