]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/35-floating-focus.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 35-floating-focus.t
index e07b91bd13b54e7d7ba2dfd8b9fd4ef162287d73..4c5b562ff12ef21a40ca6df520baaf25bcdffaf6 100644 (file)
@@ -2,6 +2,10 @@
 # vim:ts=4:sw=4:expandtab
 
 use i3test;
+use X11::XCB qw(:all);
+use X11::XCB::Connection;
+
+my $x = X11::XCB::Connection->new;
 
 my $tmp = fresh_workspace;
 
@@ -9,61 +13,216 @@ my $tmp = fresh_workspace;
 # 1: see if focus stays the same when toggling tiling/floating mode
 #############################################################################
 
-cmd "open";
-cmd "open";
+my $first = open_window($x);
+my $second = open_window($x);
 
-my @content = @{get_ws_content($tmp)};
-cmp_ok(@content, '==', 2, 'two containers opened');
-cmp_ok($content[1]->{focused}, '==', 1, 'Second container focused');
+is($x->input_focus, $second->id, 'second window focused');
 
-cmd "mode floating";
-cmd "mode tiling";
+cmd 'floating enable';
+cmd 'floating disable';
 
-@content = @{get_ws_content($tmp)};
-cmp_ok($content[1]->{focused}, '==', 1, 'Second container still focused after mode toggle');
+is($x->input_focus, $second->id, 'second window still focused after mode toggle');
 
 #############################################################################
-# 2: see if the focus gets reverted correctly when closing floating clients
+# 2: see if focus stays on the current floating window if killing another
+# floating window
+#############################################################################
+
+$tmp = fresh_workspace;
+
+$first = open_window($x);    # window 2
+$second = open_window($x);   # window 3
+my $third = open_window($x); # window 4
+
+is($x->input_focus, $third->id, 'last container focused');
+
+cmd 'floating enable';
+
+cmd '[id="' . $second->id . '"] focus';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second con focused');
+
+cmd 'floating enable';
+
+# now kill the third one (it's floating). focus should stay unchanged
+cmd '[id="' . $third->id . '"] kill';
+
+# TODO: wait for unmapnotify
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second con still focused after killing third');
+
+
+#############################################################################
+# 3: see if the focus gets reverted correctly when closing floating clients
 # (first to the next floating client, then to the last focused tiling client)
 #############################################################################
 
 $tmp = fresh_workspace;
 
-cmd "open";
-cmd "open";
-cmd "open";
+$first = open_window($x, '#ff0000');    # window 5
+$second = open_window($x, '#00ff00');   # window 6
+my $third = open_window($x, '#0000ff'); # window 7
+
+is($x->input_focus, $third->id, 'last container focused');
+
+cmd 'floating enable';
+
+cmd '[id="' . $second->id . '"] focus';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second con focused');
+
+cmd 'floating enable';
+
+# now kill the second one. focus should fall back to the third one, which is
+# also floating
+cmd 'kill';
+
+# TODO: wait for unmapnotify
+sync_with_i3($x);
+
+is($x->input_focus, $third->id, 'third con focused');
+
+cmd 'kill';
+# TODO: wait for unmapnotify
+sync_with_i3($x);
+
+is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
+
+#############################################################################
+# 4: same test as 3, but with another split con
+#############################################################################
+
+$tmp = fresh_workspace;
+
+$first = open_window($x, { background_color => '#ff0000' });    # window 5
+cmd 'split v';
+cmd 'layout stacked';
+$second = open_window($x, { background_color => '#00ff00' });   # window 6
+$third = open_window($x, { background_color => '#0000ff' }); # window 7
+
+is($x->input_focus, $third->id, 'last container focused');
+
+cmd 'floating enable';
+
+cmd '[id="' . $second->id . '"] focus';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second con focused');
+
+cmd 'floating enable';
+
+sync_with_i3($x);
+
+# now kill the second one. focus should fall back to the third one, which is
+# also floating
+cmd 'kill';
+
+# TODO: wait for unmapnotify
+sync_with_i3($x);
+
+is($x->input_focus, $third->id, 'third con focused');
+
+cmd 'kill';
+# TODO: wait for unmapnotify
+sync_with_i3($x);
+
+is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
+
+#############################################################################
+# 5: see if the 'focus tiling' and 'focus floating' commands work
+#############################################################################
+
+$tmp = fresh_workspace;
+
+$first = open_window($x, { background_color => '#ff0000' });    # window 8
+$second = open_window($x, { background_color => '#00ff00' });   # window 9
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second container focused');
+
+cmd 'floating enable';
+
+is($x->input_focus, $second->id, 'second container focused');
+
+cmd 'focus tiling';
+
+sync_with_i3($x);
+
+is($x->input_focus, $first->id, 'first (tiling) container focused');
+
+cmd 'focus floating';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second (floating) container focused');
+
+cmd 'focus floating';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second (floating) container still focused');
+
+cmd 'focus mode_toggle';
+
+sync_with_i3($x);
+
+is($x->input_focus, $first->id, 'first (tiling) container focused');
+
+cmd 'focus mode_toggle';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second (floating) container focused');
+
+#############################################################################
+# 6: see if switching floating focus using the focus left/right command works
+#############################################################################
+
+$tmp = fresh_workspace;
+
+$first = open_floating_window($x, { background_color => '#ff0000' });# window 10
+$second = open_floating_window($x, { background_color => '#00ff00' }); # window 11
+$third = open_floating_window($x, { background_color => '#0000ff' }); # window 12
+
+sync_with_i3($x);
+
+is($x->input_focus, $third->id, 'third container focused');
+
+cmd 'focus left';
+
+sync_with_i3($x);
+
+is($x->input_focus, $second->id, 'second container focused');
+
+cmd 'focus left';
+
+sync_with_i3($x);
 
-@content = @{get_ws_content($tmp)};
-cmp_ok(@content, '==', 3, 'two containers opened');
-cmp_ok($content[2]->{focused}, '==', 1, 'Last container focused');
+is($x->input_focus, $first->id, 'first container focused');
 
-my $last_id = $content[2]->{id};
-my $second_id = $content[1]->{id};
-my $first_id = $content[0]->{id};
-diag("last_id = $last_id, second_id = $second_id, first_id = $first_id");
+cmd 'focus left';
 
-cmd qq|[con_id="$second_id"] focus|;
-@content = @{get_ws_content($tmp)};
-cmp_ok($content[1]->{focused}, '==', 1, 'Second container focused');
+sync_with_i3($x);
 
-cmd "mode floating";
+is($x->input_focus, $third->id, 'focus wrapped to third container');
 
-cmd qq|[con_id="$last_id"] focus|;
-@content = @{get_ws_content($tmp)};
-cmp_ok($content[1]->{focused}, '==', 1, 'Last container focused');
+cmd 'focus right';
 
-cmd "mode floating";
+sync_with_i3($x);
 
-diag("focused = " . get_focused($tmp));
+is($x->input_focus, $first->id, 'focus wrapped to first container');
 
-cmd "kill";
+cmd 'focus right';
 
-diag("focused = " . get_focused($tmp));
-# TODO: this test result is actually not right. the focus reverts to where the mouse pointer is.
-cmp_ok(get_focused($tmp), '==', $second_id, 'Focus reverted to second floating container');
+sync_with_i3($x);
 
-cmd "kill";
-@content = @{get_ws_content($tmp)};
-cmp_ok($content[0]->{focused}, '==', 1, 'Focus reverted to tiling container');
+is($x->input_focus, $second->id, 'focus on second container');
 
 done_testing;