]> git.sur5r.net Git - i3/i3/blobdiff - src/commands.c
travis: check spelling of binaries and manpages, use docker
[i3/i3] / src / commands.c
index 579b5e0eb5072c987c79c5e1b6930ad0ae5755fc..1612a5eff608cb8133442fd78cf256060d45684b 100644 (file)
 #include <float.h>
 #include <stdarg.h>
 
+#ifdef I3_ASAN_ENABLED
+#include <sanitizer/lsan_interface.h>
+#endif
+
 #include "all.h"
 #include "shmlog.h"
 
         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);                      \
@@ -133,102 +142,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.
  ******************************************************************************/
@@ -337,7 +250,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;
             }
@@ -1228,7 +1141,7 @@ void cmd_move_workspace_to_output(I3_CMD, const char *name) {
 }
 
 /*
- * Implementation of 'split v|h|vertical|horizontal'.
+ * Implementation of 'split v|h|t|vertical|horizontal|toggle'.
  *
  */
 void cmd_split(I3_CMD, const char *direction) {
@@ -1243,7 +1156,22 @@ void cmd_split(I3_CMD, const char *direction) {
         }
 
         DLOG("matching: %p / %s\n", current->con, current->con->name);
-        tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+        if (direction[0] == 't') {
+            layout_t current_layout;
+            if (current->con->type == CT_WORKSPACE) {
+                current_layout = current->con->layout;
+            } else {
+                current_layout = current->con->parent->layout;
+            }
+            /* toggling split orientation */
+            if (current_layout == L_SPLITH) {
+                tree_split(current->con, VERT);
+            } else {
+                tree_split(current->con, HORIZ);
+            }
+        } else {
+            tree_split(current->con, (direction[0] == 'v' ? VERT : HORIZ));
+        }
     }
 
     cmd_output->needs_tree_render = true;
@@ -1518,6 +1446,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);
 }
@@ -1638,6 +1568,9 @@ void cmd_layout_toggle(I3_CMD, const char *toggle_mode) {
  */
 void cmd_exit(I3_CMD) {
     LOG("Exiting due to user command.\n");
+#ifdef I3_ASAN_ENABLED
+    __lsan_do_leak_check();
+#endif
     ipc_shutdown();
     unlink(config.ipc_socket_path);
     xcb_disconnect(conn);
@@ -1911,27 +1844,33 @@ void cmd_title_format(I3_CMD, const char *format) {
 
     owindow *current;
     TAILQ_FOREACH(current, &owindows, owindows) {
-        if (current->con->window == NULL)
-            continue;
-
         DLOG("setting title_format for %p / %s\n", current->con, current->con->name);
-        FREE(current->con->window->title_format);
+        FREE(current->con->title_format);
 
         /* If we only display the title without anything else, we can skip the parsing step,
          * so we remove the title format altogether. */
         if (strcasecmp(format, "%title") != 0) {
-            current->con->window->title_format = sstrdup(format);
+            current->con->title_format = sstrdup(format);
 
-            i3String *formatted_title = window_parse_title_format(current->con->window);
-            ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
-            I3STRING_FREE(formatted_title);
+            if (current->con->window != NULL) {
+                i3String *formatted_title = con_parse_title_format(current->con);
+                ewmh_update_visible_name(current->con->window->id, i3string_as_utf8(formatted_title));
+                I3STRING_FREE(formatted_title);
+            }
         } else {
-            /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
-            ewmh_update_visible_name(current->con->window->id, NULL);
+            if (current->con->window != NULL) {
+                /* We can remove _NET_WM_VISIBLE_NAME since we don't display a custom title. */
+                ewmh_update_visible_name(current->con->window->id, NULL);
+            }
         }
 
-        /* Make sure the window title is redrawn immediately. */
-        current->con->window->name_x_changed = true;
+        if (current->con->window != NULL) {
+            /* Make sure the window title is redrawn immediately. */
+            current->con->window->name_x_changed = true;
+        } else {
+            /* For windowless containers we also need to force the redrawing. */
+            FREE(current->con->deco_render_params);
+        }
     }
 
     cmd_output->needs_tree_render = true;
@@ -1980,6 +1919,8 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
     }
 
     /* 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);
 
@@ -2020,7 +1961,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);
 }
 
 /*