]> git.sur5r.net Git - i3/i3/commitdiff
refactor some places to use output_get_content()
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 21 Feb 2011 00:55:36 +0000 (01:55 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 21 Feb 2011 00:55:36 +0000 (01:55 +0100)
src/ipc.c
src/workspace.c

index b80eae1262c614f2b92140ef3ddb34ea7df32148..c375ac0ab643f1813ee8358bf8b6d2166dfcd8a3 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -288,50 +288,44 @@ IPC_HANDLER(get_workspaces) {
 
     Con *output;
     TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
-        Con *child;
-        TAILQ_FOREACH(child, &(output->nodes_head), nodes) {
-            if (child->type != CT_CON)
-                continue;
+        Con *ws;
+        TAILQ_FOREACH(ws, &(output_get_content(output)->nodes_head), nodes) {
+            assert(ws->type == CT_WORKSPACE);
+            y(map_open);
+
+            ystr("num");
+            if (ws->num == -1)
+                y(null);
+            else y(integer, ws->num);
+
+            ystr("name");
+            ystr(ws->name);
+
+            ystr("visible");
+            y(bool, workspace_is_visible(ws));
+
+            ystr("focused");
+            y(bool, ws == focused_ws);
 
-            Con *ws;
-            TAILQ_FOREACH(ws, &(child->nodes_head), nodes) {
-                assert(ws->type == CT_WORKSPACE);
-                y(map_open);
-
-                ystr("num");
-                if (ws->num == -1)
-                    y(null);
-                else y(integer, ws->num);
-
-                ystr("name");
-                ystr(ws->name);
-
-                ystr("visible");
-                y(bool, workspace_is_visible(ws));
-
-                ystr("focused");
-                y(bool, ws == focused_ws);
-
-                ystr("rect");
-                y(map_open);
-                ystr("x");
-                y(integer, ws->rect.x);
-                ystr("y");
-                y(integer, ws->rect.y);
-                ystr("width");
-                y(integer, ws->rect.width);
-                ystr("height");
-                y(integer, ws->rect.height);
-                y(map_close);
-
-                ystr("output");
-                ystr(output->name);
-
-                ystr("urgent");
-                y(bool, ws->urgent);
-
-                y(map_close);
-            }
+            ystr("rect");
+            y(map_open);
+            ystr("x");
+            y(integer, ws->rect.x);
+            ystr("y");
+            y(integer, ws->rect.y);
+            ystr("width");
+            y(integer, ws->rect.width);
+            ystr("height");
+            y(integer, ws->rect.height);
+            y(map_close);
+
+            ystr("output");
+            ystr(output->name);
+
+            ystr("urgent");
+            y(bool, ws->urgent);
+
+            y(map_close);
         }
     }
 
index d5875f99cf61a7bcdb9a48af2e67206cc3b71747..2912278d3089e0c55ee25f3efa8aac677ff5c758 100644 (file)
  *
  */
 Con *workspace_get(const char *num) {
-    Con *output, *workspace = NULL, *current, *child;
+    Con *output, *workspace = NULL, *child;
 
     /* TODO: could that look like this in the future?
     GET_MATCHING_NODE(workspace, croot, strcasecmp(current->name, num) != 0);
     */
-    TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
-        TAILQ_FOREACH(current, &(output->nodes_head), nodes) {
-            if (current->type != CT_CON)
+    TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
+        TAILQ_FOREACH(child, &(output_get_content(output)->nodes_head), nodes) {
+            if (strcasecmp(child->name, num) != 0)
                 continue;
 
-            TAILQ_FOREACH(child, &(current->nodes_head), nodes) {
-                if (strcasecmp(child->name, num) != 0)
-                    continue;
-
-                workspace = child;
-                break;
-            }
+            workspace = child;
+            break;
         }
-    }
 
     LOG("getting ws %s\n", num);
     if (workspace == NULL) {
         LOG("need to create this one\n");
         output = con_get_output(focused);
-        Con *child, *content = NULL;
-        TAILQ_FOREACH(child, &(output->nodes_head), nodes) {
-            if (child->type == CT_CON) {
-                content = child;
-                break;
-            }
-        }
-        assert(content != NULL);
-        LOG("got output %p with child %p\n", output, content);
+        Con *content = output_get_content(output);
+        LOG("got output %p with content %p\n", output, content);
         /* We need to attach this container after setting its type. con_attach
          * will handle CT_WORKSPACEs differently */
         workspace = con_new(NULL);