]> git.sur5r.net Git - i3/i3/blob - testcases/t/513-move-workspace.t
3e27a6c09f070560a26a9902de592ee559f53cb7
[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_autostart => 0;
19 use List::Util qw(first);
20
21 # Ensure the pointer is at (0, 0) so that we really start on the first
22 # (the left) workspace.
23 $x->root->warp_pointer(0, 0);
24
25 my $config = <<EOT;
26 # i3 config file (v4)
27 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
28
29 fake-outputs 1024x768+0+0,1024x768+1024+0
30 EOT
31
32 my $pid = launch_with_config($config);
33
34 sub workspaces_per_screen {
35     my $i3 = i3(get_socket_path());
36     my $tree = $i3->get_tree->recv;
37     my @outputs = @{$tree->{nodes}};
38
39     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
40     my $fake0_content = first { $_->{type} eq 'con' } @{$fake0->{nodes}};
41
42     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
43     my $fake1_content = first { $_->{type} eq 'con' } @{$fake1->{nodes}};
44
45     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
46     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
47
48     return \@fake0_workspaces, \@fake1_workspaces;
49 }
50
51 # Switch to temporary workspaces on both outputs so the numbers are free.
52 my $tmp_right = fresh_workspace(output => 1);
53 my $tmp_left = fresh_workspace(output => 0);
54
55 cmd 'workspace 1';
56 # Keep that workspace open.
57 my $win1 = open_window;
58
59 cmd 'workspace 5';
60 # Keep that workspace open.
61 open_window;
62
63 cmd "workspace $tmp_right";
64 cmd 'workspace 2';
65 # Keep that workspace open.
66 open_window;
67
68 my ($x0, $x1) = workspaces_per_screen();
69 is_deeply($x0, [ '1', '5' ], 'workspace 1 and 5 on fake-0');
70 is_deeply($x1, [ '2' ], 'workspace 2 on fake-1');
71
72 cmd 'workspace 1';
73
74 my ($nodes, $focus) = get_ws_content('1');
75 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
76
77 cmd 'move workspace next';
78 cmd '[id="' . $win1->id . '"] focus';
79
80 ($nodes, $focus) = get_ws_content('2');
81 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 2 after moving');
82
83 cmd 'move workspace prev';
84 cmd '[id="' . $win1->id . '"] focus';
85
86 ($nodes, $focus) = get_ws_content('1');
87 is($nodes->[0]->{window}, $win1->id, 'window 1 on workspace 1');
88
89 cmd 'move workspace next_on_output';
90 cmd '[id="' . $win1->id . '"] focus';
91
92 ($nodes, $focus) = get_ws_content('5');
93 is($nodes->[1]->{window}, $win1->id, 'window 1 on workspace 5 after moving');
94
95 exit_gracefully($pid);
96
97 done_testing;