]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Restore focus after changing layout (Thanks fernandotcl)
authorMichael Stapelberg <michael@stapelberg.de>
Sun, 28 Nov 2010 00:39:47 +0000 (01:39 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sun, 28 Nov 2010 00:39:47 +0000 (01:39 +0100)
src/con.c
testcases/t/40-focus-lost.t [new file with mode: 0644]

index 8d24c0df94773a2e0db8cd369bcfe9799f608073..e86f668ceabc5bf40f76f8a55bdd7a921a1474c5 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -567,6 +567,10 @@ void con_set_layout(Con *con, int layout) {
          * container. */
         new->orientation = HORIZ;
 
+        Con *old_focused = TAILQ_FIRST(&(con->focus_head));
+        if (old_focused == TAILQ_END(&(con->focus_head)))
+            old_focused = NULL;
+
         /* 4: move the existing cons of this workspace below the new con */
         DLOG("Moving cons\n");
         Con *child;
@@ -580,6 +584,9 @@ void con_set_layout(Con *con, int layout) {
         DLOG("Attaching new split to ws\n");
         con_attach(new, con);
 
+        if (old_focused)
+            con_focus(old_focused);
+
         return;
     }
 
diff --git a/testcases/t/40-focus-lost.t b/testcases/t/40-focus-lost.t
new file mode 100644 (file)
index 0000000..9b2db07
--- /dev/null
@@ -0,0 +1,46 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+# Regression: Check if the focus stays the same when switching the layout
+# bug introduced by 77d0d42ed2d7ac8cafe267c92b35a81c1b9491eb
+use i3test tests => 4;
+use X11::XCB qw(:all);
+use Time::HiRes qw(sleep);
+
+BEGIN {
+    use_ok('X11::XCB::Window');
+}
+
+my $i3 = i3("/tmp/nestedcons");
+my $x = X11::XCB::Connection->new;
+
+sub check_order {
+    my ($msg) = @_;
+
+    my @ws = @{$i3->get_workspaces->recv};
+    my @nums = map { $_->{num} } grep { defined($_->{num}) } @ws;
+    my @sorted = sort @nums;
+
+    cmp_deeply(\@nums, \@sorted, $msg);
+}
+
+my $tmp = get_unused_workspace();
+$i3->command("workspace $tmp")->recv;
+
+my $left = open_standard_window($x);
+sleep 0.25;
+my $mid = open_standard_window($x);
+sleep 0.25;
+my $right = open_standard_window($x);
+sleep 0.25;
+
+diag("left = " . $left->id . ", mid = " . $mid->id . ", right = " . $right->id);
+
+is($x->input_focus, $right->id, 'Right window focused');
+
+$i3->command('prev h')->recv;
+
+is($x->input_focus, $mid->id, 'Mid window focused');
+
+$i3->command('layout stacked')->recv;
+
+is($x->input_focus, $mid->id, 'Mid window focused');