# 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);
+wait_for_unmap($x);
is($x->input_focus, $second->id, 'second con still focused after killing third');
# 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);
+wait_for_unmap($x);
is($x->input_focus, $third->id, 'third con focused');
cmd 'kill';
-# TODO: wait for unmapnotify
-sync_with_i3($x);
+wait_for_unmap($x);
is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
# 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);
+wait_for_unmap($x);
is($x->input_focus, $third->id, 'third con focused');
cmd 'kill';
-# TODO: wait for unmapnotify
-sync_with_i3($x);
+wait_for_unmap($x);
is($x->input_focus, $first->id, 'first con focused after killing all floating cons');
#
use i3test;
use List::Util qw(sum);
+use X11::XCB::Connection;
+
+my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace;
cmd 'exec /usr/bin/urxvt';
-sleep 0.5;
+wait_for_map $x;
cmd 'exec /usr/bin/urxvt';
-sleep 0.5;
+wait_for_map $x;
+
my ($nodes, $focus) = get_ws_content($tmp);
my $old_sum = sum map { $_->{rect}->{width} } @{$nodes};
#cmd 'open';
cmd 'split v';
#cmd 'open';
cmd 'exec /usr/bin/urxvt';
-sleep 0.5;
+wait_for_map $x;
+
cmd 'mode toggle';
-sleep 0.5;
-cmd 'kill';
+sync_with_i3 $x;
-sleep 0.5;
+cmd 'kill';
+wait_for_unmap $x;
($nodes, $focus) = get_ws_content($tmp);
my $new_sum = sum map { $_->{rect}->{width} } @{$nodes};
wait_for_unmap $x;
$window->destroy;
+# give i3 a chance to delete the window from its tree
+sync_with_i3 $x;
+
@content = @{get_ws_content($tmp)};
cmp_ok(@content, '==', 0, 'no nodes on this workspace now');
# Tests if the 'force_focus_wrapping' config directive works correctly.
#
use i3test;
-use X11::XCB qw(:all);
-use X11::XCB::Connection;
-my $x = X11::XCB::Connection->new;
+{
+ package i3test::X11;
+ use parent 'X11::XCB::Connection';
+
+ sub input_focus {
+ my $self = shift;
+ i3test::sync_with_i3($self);
+
+ return $self->SUPER::input_focus(@_);
+ }
+}
+
+my $x = i3test::X11->new;
#####################################################################
# 1: test the wrapping behaviour without force_focus_wrapping