diff --git a/include/all.h b/include/all.h index ba582a80..b87be518 100644 --- a/include/all.h +++ b/include/all.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #include diff --git a/src/cfgparse.y b/src/cfgparse.y index 06d9c664..38f306e9 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -8,7 +8,6 @@ #include #include #include -#include #include "all.h" diff --git a/src/cmdparse.y b/src/cmdparse.y index df7b6efe..e115f3e5 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -13,7 +13,6 @@ #include #include #include -#include #include #include "all.h" diff --git a/src/handlers.c b/src/handlers.c index 0fd7dbbd..89a6bd0a 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -6,7 +6,6 @@ * */ #include -#include #include diff --git a/src/main.c b/src/main.c index 53067744..69598b35 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,6 @@ */ #include #include -#include #include "all.h" static int xkb_event_base; diff --git a/src/randr.c b/src/randr.c index 505eb49b..e48e2065 100644 --- a/src/randr.c +++ b/src/randr.c @@ -392,27 +392,40 @@ void init_ws_for_output(Output *output, Con *content) { GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); exists = (current != NULL); - if (!exists) + if (!exists) { + /* Set ->num to the number of the workspace, if the name actually + * is a number or starts with a number */ + long parsed_num = strtol(ws->name, NULL, 10); + if (parsed_num == LONG_MIN || + parsed_num == LONG_MAX || + parsed_num <= 0) + ws->num = -1; + else ws->num = parsed_num; + LOG("Used number %d for workspace with name %s\n", ws->num, ws->name); + break; + } } - /* get the next unused workspace number */ - DLOG("Getting next unused workspace\n"); - int c = 0; - while (exists) { - c++; + if (exists) { + /* get the next unused workspace number */ + DLOG("Getting next unused workspace by number\n"); + int c = 0; + while (exists) { + c++; - FREE(ws->name); - asprintf(&(ws->name), "%d", c); + FREE(ws->name); + asprintf(&(ws->name), "%d", c); - current = NULL; - TAILQ_FOREACH(out, &(croot->nodes_head), nodes) - GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); - exists = (current != NULL); + current = NULL; + TAILQ_FOREACH(out, &(croot->nodes_head), nodes) + GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); + exists = (current != NULL); - DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists); + DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists); + } + ws->num = c; } - ws->num = c; con_attach(ws, content, false); asprintf(&name, "[i3 con] workspace %s", ws->name); diff --git a/src/workspace.c b/src/workspace.c index 4021dd14..8354906a 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -7,8 +7,6 @@ * workspace.c: Functions for modifying workspaces * */ -#include - #include "all.h" /*