Bugfix: Use the appropriate number when assigning numbered workspaces in randr.c

This commit is contained in:
Michael Stapelberg 2011-08-04 00:10:23 +02:00
parent c883e7050a
commit d0741975f1
1 changed files with 27 additions and 14 deletions

View File

@ -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)); GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name));
exists = (current != NULL); 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; break;
}
} }
/* get the next unused workspace number */ if (exists) {
DLOG("Getting next unused workspace\n"); /* get the next unused workspace number */
int c = 0; DLOG("Getting next unused workspace by number\n");
while (exists) { int c = 0;
c++; while (exists) {
c++;
FREE(ws->name); FREE(ws->name);
asprintf(&(ws->name), "%d", c); asprintf(&(ws->name), "%d", c);
current = NULL; current = NULL;
TAILQ_FOREACH(out, &(croot->nodes_head), nodes) TAILQ_FOREACH(out, &(croot->nodes_head), nodes)
GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name)); GREP_FIRST(current, output_get_content(out), !strcasecmp(child->name, ws->name));
exists = (current != NULL); 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); con_attach(ws, content, false);
asprintf(&name, "[i3 con] workspace %s", ws->name); asprintf(&name, "[i3 con] workspace %s", ws->name);