From: Michael Stapelberg Date: Tue, 26 May 2009 15:09:34 +0000 (+0200) Subject: Don’t process autostart when restarting (new parameter -a) X-Git-Tag: 3.b~98 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=94cead993cea3d33735a0f893f39c03385a7db90;p=i3%2Fi3 Don’t process autostart when restarting (new parameter -a) --- diff --git a/man/asciidoc.conf b/man/asciidoc.conf index 3854debd..cd411ec7 100644 --- a/man/asciidoc.conf +++ b/man/asciidoc.conf @@ -7,7 +7,7 @@ template::[header-declarations] {mantitle} {manvolnum} i3 -alpha +beta i3 Manual diff --git a/man/i3.man b/man/i3.man index 4f0c3fe4..fbe2ac83 100644 --- a/man/i3.man +++ b/man/i3.man @@ -1,7 +1,7 @@ i3(1) ===== Michael Stapelberg -v3.alpha-bf1, May 2009 +v3.beta, May 2009 == NAME @@ -9,7 +9,15 @@ i3 - an improved dynamic, tiling window manager == SYNOPSIS -i3 [-c configfile] +i3 [-c configfile] [-a] + +== OPTIONS + +-c:: +Specifies an alternate configuration file path + +-a:: +Disables autostart. == DESCRIPTION diff --git a/src/commands.c b/src/commands.c index 76953abf..20a8bd05 100644 --- a/src/commands.c +++ b/src/commands.c @@ -731,6 +731,29 @@ static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) { } } +/* + * Goes through the list of arguments (for exec()) and checks if the given argument + * is present. If not, it copies the arguments (because we cannot realloc it) and + * appends the given argument. + * + */ +static char **append_argument(char **original, char *argument) { + int num_args; + for (num_args = 0; original[num_args] != NULL; num_args++) { + LOG("original argument: \"%s\"\n", original[num_args]); + /* If the argument is already present we return the original pointer */ + if (strcmp(original[num_args], argument) == 0) + return original; + } + /* Copy the original array */ + char **result = smalloc((num_args+2) * sizeof(char*)); + memcpy(result, original, num_args * sizeof(char*)); + result[num_args] = argument; + result[num_args+1] = NULL; + + return result; +} + /* * Parses a command, see file CMDMODE for more information * @@ -763,6 +786,9 @@ void parse_command(xcb_connection_t *conn, const char *command) { /* Is it ? Then restart in place. */ if (STARTS_WITH(command, "restart")) { LOG("restarting \"%s\"...\n", start_argv[0]); + /* make sure -a is in the argument list or append it */ + start_argv = append_argument(start_argv, "-a"); + execvp(start_argv[0], start_argv); /* not reached */ } diff --git a/src/mainx.c b/src/mainx.c index 60cd6a0f..50db96d9 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -72,6 +72,7 @@ int num_screens = 0; int main(int argc, char *argv[], char *env[]) { int i, screens, opt; char *override_configpath = NULL; + bool autostart = true; xcb_connection_t *conn; xcb_property_handlers_t prophs; xcb_window_t root; @@ -85,8 +86,12 @@ int main(int argc, char *argv[], char *env[]) { start_argv = argv; - while ((opt = getopt(argc, argv, "c:v")) != -1) { + while ((opt = getopt(argc, argv, "c:va")) != -1) { switch (opt) { + case 'a': + LOG("Autostart disabled using -a\n"); + autostart = false; + break; case 'c': override_configpath = sstrdup(optarg); break; @@ -270,9 +275,11 @@ int main(int argc, char *argv[], char *env[]) { /* Autostarting exec-lines */ struct Autostart *exec; - TAILQ_FOREACH(exec, &autostarts, autostarts) { - LOG("auto-starting %s\n", exec->command); - start_application(exec->command); + if (autostart) { + TAILQ_FOREACH(exec, &autostarts, autostarts) { + LOG("auto-starting %s\n", exec->command); + start_application(exec->command); + } } /* check for Xinerama */