]> git.sur5r.net Git - i3/i3/commitdiff
RandR: use the next unused workspace instead of fixed counting
authorMichael Stapelberg <michael@stapelberg.de>
Tue, 4 Jan 2011 23:26:23 +0000 (00:26 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Tue, 4 Jan 2011 23:26:23 +0000 (00:26 +0100)
src/randr.c
src/workspace.c

index 5da9ab2cba73c07eec97b09885d127d105f75033..26f9102b4a83d2cb0f28015712ade5ca4ed40c31 100644 (file)
@@ -227,7 +227,6 @@ void disable_randr(xcb_connection_t *conn) {
 void output_init_con(Output *output) {
     Con *con = NULL, *current;
     bool reused = false;
-    static int c = 1;
 
     DLOG("init_con for output %s\n", output->name);
 
@@ -266,11 +265,33 @@ void output_init_con(Output *output) {
     /* add a workspace to this output */
     Con *ws = con_new(NULL);
     ws->type = CT_WORKSPACE;
-    /* TODO: don't just number workspaces, but get the next assigned one / unused one */
+
+    /* get the next unused workspace number */
+    DLOG("Getting next unused workspace\n");
+    int c = 0;
+    bool exists = true;
+    while (exists) {
+        Con *out, *current;
+
+        c++;
+
+        FREE(ws->name);
+        asprintf(&(ws->name), "%d", c);
+
+        exists = false;
+        TAILQ_FOREACH(out, &(croot->nodes_head), nodes) {
+            TAILQ_FOREACH(current, &(out->nodes_head), nodes) {
+                if (strcasecmp(current->name, ws->name) != 0)
+                    continue;
+
+                exists = true;
+                break;
+            }
+        }
+
+        DLOG("result for ws %s / %d: exists = %d\n", ws->name, c, exists);
+    }
     ws->num = c;
-    FREE(ws->name);
-    asprintf(&(ws->name), "%d", c);
-    c++;
     con_attach(ws, con, false);
 
     asprintf(&name, "[i3 con] workspace %s", ws->name);
index eeb756b170da9e4f6a4001fe973cd17acd5d5890..b5095d118341080a1a646873fd62663d847bdb7c 100644 (file)
@@ -26,7 +26,7 @@ Con *workspace_get(const char *num) {
     TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
         TAILQ_FOREACH(current, &(output->nodes_head), nodes) {
             if (strcasecmp(current->name, num) != 0)
-                    continue;
+                continue;
 
             workspace = current;
             break;