2010-07-04 19:50:44 +02:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
2012-09-10 14:09:01 +02:00
|
|
|
# Please read the following documents before working on tests:
|
|
|
|
# • http://build.i3wm.org/docs/testsuite.html
|
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
|
|
|
# • http://build.i3wm.org/docs/lib-i3test.html
|
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
|
|
|
# • http://build.i3wm.org/docs/ipc.html
|
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
#
|
2010-07-04 19:50:44 +02:00
|
|
|
# Check if the focus is correctly restored after closing windows.
|
|
|
|
#
|
2011-03-09 20:25:17 +01:00
|
|
|
use i3test;
|
2010-07-17 15:17:33 +02:00
|
|
|
use List::Util qw(first);
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2011-07-25 13:35:56 +02:00
|
|
|
my $i3 = i3(get_socket_path());
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
my $tmp = fresh_workspace;
|
2010-07-04 19:50:44 +02:00
|
|
|
|
|
|
|
ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
|
|
|
|
|
2010-07-17 15:17:33 +02:00
|
|
|
my $first = open_empty_con($i3);
|
2010-11-28 21:16:58 +01:00
|
|
|
my $second = open_empty_con($i3);
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
cmd 'split v';
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2010-07-17 15:17:33 +02:00
|
|
|
my ($nodes, $focus) = get_ws_content($tmp);
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2011-07-24 15:00:09 +02:00
|
|
|
ok(!$nodes->[1]->{focused}, 'split container not focused');
|
2011-06-10 01:36:33 +02:00
|
|
|
cmd 'focus parent';
|
2010-07-04 19:50:44 +02:00
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
2011-07-24 15:00:09 +02:00
|
|
|
ok($nodes->[1]->{focused}, 'split container focused after focus parent');
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2010-11-28 21:16:58 +01:00
|
|
|
my $third = open_empty_con($i3);
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2010-11-28 21:16:58 +01:00
|
|
|
isnt(get_focused($tmp), $second, 'different container focused');
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2010-07-17 13:37:21 +02:00
|
|
|
# We have the following layout now (con is focused):
|
|
|
|
# .----------------.
|
|
|
|
# | split | |
|
|
|
|
# | .----. | con |
|
|
|
|
# | | cn | | |
|
|
|
|
# | `----' | |
|
|
|
|
# `----------------'
|
|
|
|
|
2010-07-04 19:50:44 +02:00
|
|
|
##############################################################
|
|
|
|
# see if the focus goes down to $first (not to its split parent)
|
|
|
|
# when closing $second
|
|
|
|
##############################################################
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
cmd 'kill';
|
2011-11-23 12:57:13 +01:00
|
|
|
sync_with_i3;
|
|
|
|
|
2010-07-04 19:50:44 +02:00
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
2010-11-28 21:16:58 +01:00
|
|
|
is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found');
|
2011-07-24 15:00:09 +02:00
|
|
|
ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused');
|
2010-07-04 19:50:44 +02:00
|
|
|
|
2010-07-17 15:17:33 +02:00
|
|
|
##############################################################
|
|
|
|
# another case, using a slightly different layout (regression)
|
|
|
|
##############################################################
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
$tmp = fresh_workspace;
|
2010-07-17 15:17:33 +02:00
|
|
|
|
|
|
|
ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
|
|
|
|
|
2011-03-09 20:25:17 +01:00
|
|
|
cmd 'split v';
|
2010-07-17 15:17:33 +02:00
|
|
|
$first = open_empty_con($i3);
|
|
|
|
my $bottom = open_empty_con($i3);
|
|
|
|
|
2011-06-08 20:49:49 +02:00
|
|
|
cmd 'focus up';
|
2011-03-09 20:25:17 +01:00
|
|
|
cmd 'split h';
|
2010-07-17 15:17:33 +02:00
|
|
|
my $middle = open_empty_con($i3);
|
|
|
|
my $right = open_empty_con($i3);
|
2011-06-08 20:49:49 +02:00
|
|
|
cmd 'focus down';
|
2010-07-17 15:17:33 +02: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 20:25:17 +01:00
|
|
|
cmd 'kill';
|
2010-07-17 15:17:33 +02: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 16:34:35 +01: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);
|
2011-11-22 00:47:32 +01:00
|
|
|
my $win = open_window({ background_color => '#00ff00' });
|
2011-03-14 16:34:35 +01:00
|
|
|
|
|
|
|
cmd qq|[con_id="$middle"] focus|;
|
|
|
|
$win->destroy;
|
2011-11-23 12:57:13 +01:00
|
|
|
sync_with_i3;
|
2011-03-14 16:34:35 +01:00
|
|
|
|
|
|
|
is(get_focused($tmp), $middle, 'middle container focused');
|
|
|
|
|
2013-09-19 14:34:02 +02:00
|
|
|
##############################################################
|
|
|
|
# check if the workspace container can be closed
|
|
|
|
##############################################################
|
|
|
|
|
|
|
|
$tmp = fresh_workspace;
|
|
|
|
|
|
|
|
my $window = open_window();
|
|
|
|
|
|
|
|
# one window opened on the current workspace
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
|
|
|
is(scalar @$nodes, 1, 'workspace contains one node');
|
|
|
|
|
|
|
|
# focus the workspace
|
|
|
|
cmd "focus parent";
|
|
|
|
cmd "focus parent";
|
|
|
|
|
|
|
|
# try to kill the workspace
|
|
|
|
cmd "kill";
|
|
|
|
sync_with_i3;
|
|
|
|
|
|
|
|
# the workspace should now be empty
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
|
|
|
is(scalar @$nodes, 0, 'workspace is empty');
|
|
|
|
|
2013-10-13 17:57:50 +02:00
|
|
|
################################################################################
|
|
|
|
# check if killing a workspace also closes floating windows.
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
$tmp = fresh_workspace;
|
|
|
|
|
|
|
|
$window = open_window;
|
|
|
|
my $floating_window = open_floating_window;
|
|
|
|
|
|
|
|
# one window opened on the current workspace
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
|
|
|
is(scalar @$focus, 2, 'workspace contains two nodes');
|
|
|
|
|
|
|
|
# focus the workspace
|
|
|
|
cmd "focus parent";
|
|
|
|
cmd "focus parent";
|
|
|
|
|
|
|
|
# try to kill the workspace
|
|
|
|
cmd "kill";
|
|
|
|
sync_with_i3;
|
|
|
|
|
|
|
|
# the workspace should now be empty
|
|
|
|
($nodes, $focus) = get_ws_content($tmp);
|
|
|
|
is(scalar @$focus, 0, 'workspace is empty');
|
|
|
|
|
2010-07-17 15:17:33 +02: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 20:25:17 +01:00
|
|
|
done_testing;
|