2010-07-04 13:50:44 -04:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
|
|
|
# Check if the focus is correctly restored after closing windows.
|
|
|
|
#
|
2011-03-09 14:25:17 -05:00
|
|
|
use i3test;
|
2011-03-14 11:34:35 -04:00
|
|
|
use X11::XCB qw(:all);
|
2010-07-17 09:17:33 -04:00
|
|
|
use List::Util qw(first);
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2011-03-14 11:34:35 -04:00
|
|
|
my $x = X11::XCB::Connection->new;
|
|
|
|
|
2010-07-04 13:50:44 -04:00
|
|
|
my $i3 = i3("/tmp/nestedcons");
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
my $tmp = fresh_workspace;
|
2010-07-04 13:50:44 -04:00
|
|
|
|
|
|
|
ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
|
|
|
|
|
2010-07-17 09:17:33 -04:00
|
|
|
my $first = open_empty_con($i3);
|
2010-11-28 15:16:58 -05:00
|
|
|
my $second = open_empty_con($i3);
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'split v';
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-07-17 09:17:33 -04:00
|
|
|
my ($nodes, $focus) = get_ws_content($tmp);
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-11-28 15:16:58 -05:00
|
|
|
is($nodes->[1]->{focused}, 0, 'split container not focused');
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'level up';
|
2010-07-04 13:50:44 -04:00
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
2010-11-28 15:16:58 -05:00
|
|
|
is($nodes->[1]->{focused}, 1, 'split container focused after level up');
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-11-28 15:16:58 -05:00
|
|
|
my $third = open_empty_con($i3);
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-11-28 15:16:58 -05:00
|
|
|
isnt(get_focused($tmp), $second, 'different container focused');
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-07-17 07:37:21 -04:00
|
|
|
# We have the following layout now (con is focused):
|
|
|
|
# .----------------.
|
|
|
|
# | split | |
|
|
|
|
# | .----. | con |
|
|
|
|
# | | cn | | |
|
|
|
|
# | `----' | |
|
|
|
|
# `----------------'
|
|
|
|
|
2010-07-04 13:50:44 -04:00
|
|
|
##############################################################
|
|
|
|
# see if the focus goes down to $first (not to its split parent)
|
|
|
|
# when closing $second
|
|
|
|
##############################################################
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'kill';
|
2010-07-04 13:50:44 -04:00
|
|
|
# TODO: this testcase sometimes has different outcomes when the
|
|
|
|
# sleep is missing. why?
|
|
|
|
sleep 0.25;
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
2010-11-28 15:16:58 -05:00
|
|
|
is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
|
|
|
|
is($nodes->[1]->{nodes}->[0]->{focused}, 1, 'second container focused');
|
2010-07-04 13:50:44 -04:00
|
|
|
|
2010-07-17 09:17:33 -04:00
|
|
|
##############################################################
|
|
|
|
# another case, using a slightly different layout (regression)
|
|
|
|
##############################################################
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
$tmp = fresh_workspace;
|
2010-07-17 09:17:33 -04:00
|
|
|
|
|
|
|
ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'split v';
|
2010-07-17 09:17:33 -04:00
|
|
|
$first = open_empty_con($i3);
|
|
|
|
my $bottom = open_empty_con($i3);
|
|
|
|
|
2011-06-08 14:49:49 -04:00
|
|
|
cmd 'focus up';
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'split h';
|
2010-07-17 09:17:33 -04:00
|
|
|
my $middle = open_empty_con($i3);
|
|
|
|
my $right = open_empty_con($i3);
|
2011-06-08 14:49:49 -04:00
|
|
|
cmd 'focus down';
|
2010-07-17 09:17:33 -04:00
|
|
|
|
|
|
|
# We have the following layout now (second is focused):
|
|
|
|
# .----------------------------.
|
|
|
|
# | .------------------------. |
|
|
|
|
# | | first | middle | right | |
|
|
|
|
# | `------------------------' |
|
|
|
|
# |----------------------------|
|
|
|
|
# | |
|
|
|
|
# | second |
|
|
|
|
# | |
|
|
|
|
# `----------------------------'
|
|
|
|
|
|
|
|
# Check if the focus is restored to $right when we close $second
|
2011-03-09 14:25:17 -05:00
|
|
|
cmd 'kill';
|
2010-07-17 09:17:33 -04:00
|
|
|
|
|
|
|
is(get_focused($tmp), $right, 'top right container focused (in focus stack)');
|
|
|
|
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
|
|
|
my $tr = first { $_->{id} eq $right } @{$nodes->[0]->{nodes}};
|
|
|
|
is($tr->{focused}, 1, 'top right container really has focus');
|
|
|
|
|
2011-03-14 11:34:35 -04:00
|
|
|
##############################################################
|
|
|
|
# check if focus is correct after closing an unfocused window
|
|
|
|
##############################################################
|
|
|
|
|
|
|
|
$tmp = fresh_workspace;
|
|
|
|
|
|
|
|
ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
|
|
|
|
|
|
|
|
$first = open_empty_con($i3);
|
|
|
|
$middle = open_empty_con($i3);
|
|
|
|
# XXX: the $right empty con will be filled with the x11 window we are creating afterwards
|
|
|
|
$right = open_empty_con($i3);
|
|
|
|
my $win = open_standard_window($x, '#00ff00');
|
|
|
|
|
|
|
|
cmd qq|[con_id="$middle"] focus|;
|
|
|
|
$win->destroy;
|
|
|
|
|
|
|
|
sleep 0.25;
|
|
|
|
|
|
|
|
is(get_focused($tmp), $middle, 'middle container focused');
|
|
|
|
|
2010-07-17 09:17:33 -04:00
|
|
|
##############################################################
|
|
|
|
# and now for something completely different:
|
|
|
|
# check if the pointer position is relevant when restoring focus
|
|
|
|
# (it should not be relevant, of course)
|
|
|
|
##############################################################
|
|
|
|
|
|
|
|
# TODO: add test code as soon as I can reproduce it
|
|
|
|
|
2011-03-09 14:25:17 -05:00
|
|
|
done_testing;
|