]> git.sur5r.net Git - i3/i3/blob - testcases/t/513-move-workspace.t
tests: use i3_config arg instead of precisely one launch_with_config
[i3/i3] / testcases / t / 513-move-workspace.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests whether moving workspaces between outputs works correctly.
18 use i3test i3_config => <<EOT;
19 # i3 config file (v4)
20 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
21
22 fake-outputs 1024x768+0+0,1024x768+1024+0
23 EOT
24 use List::Util qw(first);
25
26 sub workspaces_per_screen {
27     my $i3 = i3(get_socket_path());
28     my $tree = $i3->get_tree->recv;
29     my @outputs = @{$tree->{nodes}};
30
31     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
32     my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
33
34     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
35     my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
36
37     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
38     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
39
40     return \@fake0_workspaces, \@fake1_workspaces;
41 }
42
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);
46
47 cmd 'workspace 1';
48 # Keep that workspace open.
49 my $win1 = open_window;
50
51 cmd 'workspace 5';
52 # Keep that workspace open.
53 open_window;
54
55 cmd "workspace $tmp_right";
56 cmd 'workspace 2';
57 # Keep that workspace open.
58 open_window;
59
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');
63
64 cmd 'workspace 1';
65
66 my ($nodes, $focus) = get_ws_content('1');
67 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
68
69 cmd 'move workspace next';
70 cmd '[id="' . $win1->id . '"] focus';
71
72 ($nodes, $focus) = get_ws_content('2');
73 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 2 after moving');
74
75 cmd 'move workspace prev';
76 cmd '[id="' . $win1->id . '"] focus';
77
78 ($nodes, $focus) = get_ws_content('1');
79 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
80
81 cmd 'move workspace next_on_output';
82 cmd '[id="' . $win1->id . '"] focus';
83
84 ($nodes, $focus) = get_ws_content('5');
85 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 5 after moving');
86
87 done_testing;