]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Insert new containers at the right position (and add testcase)
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 3 Jul 2010 15:42:36 +0000 (17:42 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 3 Jul 2010 15:42:36 +0000 (17:42 +0200)
src/con.c
testcases/t/28-open-order.t [new file with mode: 0644]

index c7c1c9036c6501c7f352bd935193597fcb00d9bd..1d8ca82e587b5667154adae8551975c460b6a225 100644 (file)
--- a/src/con.c
+++ b/src/con.c
@@ -58,7 +58,14 @@ Con *con_new(Con *parent) {
 
 void con_attach(Con *con, Con *parent) {
     con->parent = parent;
-    TAILQ_INSERT_TAIL(&(parent->nodes_head), con, nodes);
+    Con *current = TAILQ_FIRST(&(parent->focus_head));
+
+    if (current == TAILQ_END(&(parent->focus_head)))
+        TAILQ_INSERT_TAIL(&(parent->nodes_head), con, nodes);
+    else {
+        DLOG("inserting after\n");
+        TAILQ_INSERT_AFTER(&(parent->nodes_head), current, con, nodes);
+    }
     /* We insert to the TAIL because con_focus() will correct this.
      * This way, we have the option to insert Cons without having
      * to focus them. */
diff --git a/testcases/t/28-open-order.t b/testcases/t/28-open-order.t
new file mode 100644 (file)
index 0000000..b48e5ee
--- /dev/null
@@ -0,0 +1,46 @@
+#!perl
+# vim:ts=4:sw=4:expandtab
+#
+# Check if new containers are opened after the currently focused one instead
+# of always at the end
+use List::Util qw(first);
+use i3test tests => 7;
+
+my $i3 = i3("/tmp/nestedcons");
+
+my $tmp = get_unused_workspace();
+$i3->command("workspace $tmp")->recv;
+
+ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
+
+# Open two new container
+$i3->command("open")->recv;
+
+ok(@{get_ws_content($tmp)} == 1, 'containers opened');
+
+my ($nodes, $focus) = get_ws_content($tmp);
+my $first = $focus->[0];
+
+$i3->command("open")->recv;
+
+($nodes, $focus) = get_ws_content($tmp);
+my $second = $focus->[0];
+
+isnt($first, $second, 'different container focused');
+
+##############################################################
+# see if new containers open after the currently focused
+##############################################################
+
+$i3->command(qq|[con_id="$first"] focus|)->recv;
+$i3->command('open')->recv;
+$content = get_ws_content($tmp);
+ok(@{$content} == 3, 'three containers opened');
+
+is($content->[0]->{id}, $first, 'first container unmodified');
+isnt($content->[1]->{id}, $second, 'second container replaced');
+is($content->[2]->{id}, $second, 'third container unmodified');
+
+diag( "Testing i3, Perl $], $^X" );
+#
+