]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Correctly restore focus after close (and add testcase)
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 4 Jul 2010 17:50:44 +0000 (19:50 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 4 Jul 2010 17:50:44 +0000 (19:50 +0200)
src/tree.c
testcases/t/29-focus-after-close.t [new file with mode: 0644]

index ec8b0a83e1b881528f072a8d18908798a944e3a4..5b4e883b6c6930ebd4aef9b67b2586915c09c1f2 100644 (file)
@@ -143,8 +143,11 @@ void tree_close(Con *con, bool kill_window) {
             next = con_get_workspace(con);
     } else {
         next = TAILQ_NEXT(con, focused);
-        if (next == TAILQ_END(&(con->parent->nodes_head)))
+        if (next == TAILQ_END(&(con->parent->nodes_head))) {
             next = con->parent;
+            while (!TAILQ_EMPTY(&(next->focus_head)))
+                next = TAILQ_FIRST(&(next->focus_head));
+        }
     }
 
     DLOG("closing %p, kill_window = %d\n", con, kill_window);
diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t
new file mode 100644 (file)
index 0000000..b28ecf2
--- /dev/null
@@ -0,0 +1,49 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# Check if the focus is correctly restored after closing windows.
+#
+use i3test tests => 6;
+use Time::HiRes qw(sleep);
+
+my $i3 = i3("/tmp/nestedcons");
+
+my $tmp = get_unused_workspace();
+$i3->command("workspace $tmp")->recv;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+$i3->command('open')->recv;
+my ($nodes, $focus) = get_ws_content($tmp);
+my $first = $focus->[0];
+
+$i3->command('split v')->recv;
+
+($nodes, $focus) = get_ws_content($tmp);
+
+is($nodes->[0]->{focused}, 0, 'split container not focused');
+$i3->command('level up')->recv;
+($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{focused}, 1, 'split container focused after level up');
+
+$i3->command('open')->recv;
+
+($nodes, $focus) = get_ws_content($tmp);
+my $second = $focus->[0];
+
+isnt($first, $second, 'different container focused');
+
+##############################################################
+# see if the focus goes down to $first (not to its split parent)
+# when closing $second
+##############################################################
+
+$i3->command('kill')->recv;
+# TODO: this testcase sometimes has different outcomes when the
+# sleep is missing. why?
+sleep 0.25;
+($nodes, $focus) = get_ws_content($tmp);
+is($nodes->[0]->{nodes}->[0]->{id}, $first, 'first container found');
+is($nodes->[0]->{nodes}->[0]->{focused}, 1, 'first container focused');
+
+diag( "Testing i3, Perl $], $^X" );