]> git.sur5r.net Git - i3/i3/commitdiff
refactor some places to use con_descend_focused instead of duplicating code
authorMichael Stapelberg <michael@stapelberg.de>
Thu, 27 Jan 2011 15:08:25 +0000 (16:08 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Thu, 27 Jan 2011 15:09:14 +0000 (16:09 +0100)
src/con.c
src/handlers.c
src/randr.c
src/tree.c
src/workspace.c

index 2f02bfcd8a4a9a7613c5160c465d96679fb8ae87..50e303ca6a3b5fa19de7fdf2dd7629b638e248b7 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -483,12 +483,8 @@ void con_move_to_workspace(Con *con, Con *workspace) {
      * container is moved away */
     Con *focus_next = con_next_focused(con);
 
-    /* 2: get the focused container of this workspace by going down as far as
-     * possible */
-    Con *next = workspace;
-
-    while (!TAILQ_EMPTY(&(next->focus_head)))
-        next = TAILQ_FIRST(&(next->focus_head));
+    /* 2: get the focused container of this workspace */
+    Con *next = con_descend_focused(workspace);
 
     /* 3: we go up one level, but only when next is a normal container */
     if (next->type != CT_WORKSPACE)
index 3fc18cf515387c826ea25425c6a42bb3fbd7c7a6..4123caee9c176f8a8329e35ef46e316dabc75988 100644 (file)
@@ -210,11 +210,8 @@ int handle_enter_notify(void *ignored, xcb_connection_t *conn,
 
     if (config.disable_focus_follows_mouse)
         return 1;
-    Con *next = con;
-    while (!TAILQ_EMPTY(&(next->focus_head)))
-        next = TAILQ_FIRST(&(next->focus_head));
 
-    con_focus(next);
+    con_focus(con_descend_focused(con));
     x_push_changes(croot);
 
     return 1;
index f6e925a9110138994e6190079020e1f8cae27813..e8b044bb5fa1a6b222cd3c41b6d596c6b8fa48da 100644 (file)
@@ -621,12 +621,7 @@ void randr_query_outputs() {
             continue;
 
         DLOG("Focusing primary output %s\n", output->name);
-        Con *next = output->con;
-        while (!TAILQ_EMPTY(&(next->focus_head)))
-            next = TAILQ_FIRST(&(next->focus_head));
-
-        DLOG("focusing %p\n", next);
-        con_focus(next);
+        con_focus(con_descend_focused(output->con));
     }
 
     /* render_layout flushes */
index 0a18e88d5b49fd1069748b03bf165ac9c3dc80d0..9af64def15336ed13ae20251333dd5a419fd09b6 100644 (file)
@@ -155,11 +155,8 @@ void tree_close(Con *con, bool kill_window, bool dont_kill_parent) {
         DLOG("parent container killed\n");
         if (con == focused) {
             DLOG("This is the focused container, i need to find another one to focus. I start looking at ws = %p\n", ws);
-            next = ws;
-            /* now go down the focus stack as far as
-             * possible, excluding the current container */
-            while (!TAILQ_EMPTY(&(next->focus_head)))
-                next = TAILQ_FIRST(&(next->focus_head));
+            /* go down the focus stack as far as possible */
+            next = con_descend_focused(ws);
 
             dont_kill_parent = true;
             DLOG("Alright, focusing %p\n", next);
@@ -361,11 +358,7 @@ void tree_next(char way, orientation_t orientation) {
     /* 3: focus choice comes in here. at the moment we will go down
      * until we find a window */
     /* TODO: check for window, atm we only go down as far as possible */
-    while (!TAILQ_EMPTY(&(next->focus_head)))
-        next = TAILQ_FIRST(&(next->focus_head));
-
-    DLOG("focusing %p\n", next);
-    con_focus(next);
+    con_focus(con_descend_focused(next));
 }
 
 /*
@@ -450,8 +443,7 @@ void tree_move(char way, orientation_t orientation) {
                 next = current;
             } else {
                 /* if this is a split container, we need to go down */
-                while (!TAILQ_EMPTY(&(next->focus_head)))
-                    next = TAILQ_FIRST(&(next->focus_head));
+                next = con_descend_focused(next);
             }
         }
 
index a1e653ea7c52514679e980a37c5ffb63fa8d993a..55f7dd17246cb2aace774a5bb5154626230b8190 100644 (file)
@@ -226,11 +226,7 @@ void workspace_show(const char *num) {
     workspace_reassign_sticky(workspace);
 
     LOG("switching to %p\n", workspace);
-    Con *next = workspace;
-
-    while (!TAILQ_EMPTY(&(next->focus_head)))
-        next = TAILQ_FIRST(&(next->focus_head));
-
+    Con *next = con_descend_focused(workspace);
 
     if (TAILQ_EMPTY(&(old->nodes_head)) && TAILQ_EMPTY(&(old->floating_head))) {
         /* check if this workspace is currently visible */