2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests whether moving workspaces between outputs works correctly.
18 use i3test i3_config => <<EOT;
20 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
22 fake-outputs 1024x768+0+0,1024x768+1024+0
24 use List::Util qw(first);
26 sub workspaces_per_screen {
27 my $i3 = i3(get_socket_path());
28 my $tree = $i3->get_tree->recv;
29 my @outputs = @{$tree->{nodes}};
31 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
32 my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
34 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
35 my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
37 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
38 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
40 return \@fake0_workspaces, \@fake1_workspaces;
43 # Switch to temporary workspaces on both outputs so the numbers are free.
44 my $tmp_right = fresh_workspace(output => 1);
45 my $tmp_left = fresh_workspace(output => 0);
48 # Keep that workspace open.
49 my $win1 = open_window;
52 # Keep that workspace open.
55 cmd "workspace $tmp_right";
57 # Keep that workspace open.
60 my ($x0, $x1) = workspaces_per_screen();
61 is_deeply($x0, [ '1', '5' ], 'workspace 1 and 5 on fake-0');
62 is_deeply($x1, [ '2' ], 'workspace 2 on fake-1');
66 my ($nodes, $focus) = get_ws_content('1');
67 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
69 cmd 'move workspace next';
70 cmd '[id="' . $win1->id . '"] focus';
72 ($nodes, $focus) = get_ws_content('2');
73 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 2 after moving');
75 cmd 'move workspace prev';
76 cmd '[id="' . $win1->id . '"] focus';
78 ($nodes, $focus) = get_ws_content('1');
79 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
81 cmd 'move workspace next_on_output';
82 cmd '[id="' . $win1->id . '"] focus';
84 ($nodes, $focus) = get_ws_content('5');
85 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 5 after moving');