]> git.sur5r.net Git - i3/i3/blob - testcases/t/504-move-workspace-to-output.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 504-move-workspace-to-output.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 the 'move workspace <ws> to [output] <output>' command works
18 #
19 use List::Util qw(first);
20 use i3test i3_autostart => 0;
21
22 # TODO:
23 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
24
25 # Ensure the pointer is at (0, 0) so that we really start on the first
26 # (the left) workspace.
27 $x->root->warp_pointer(0, 0);
28
29 my $config = <<EOT;
30 # i3 config file (v4)
31 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
32
33 fake-outputs 1024x768+0+0,1024x768+1024+0
34 EOT
35 my $pid = launch_with_config($config);
36
37 ################################################################################
38 # Setup workspaces so that they stay open (with an empty container).
39 ################################################################################
40
41 is(focused_ws, '1', 'starting on workspace 1');
42 # ensure workspace 1 stays open
43 open_window;
44
45 cmd 'focus output right';
46 is(focused_ws, '2', 'workspace 2 on second output');
47 # ensure workspace 2 stays open
48 open_window;
49
50 cmd 'focus output right';
51 is(focused_ws, '1', 'back on workspace 1');
52
53 # We don’t use fresh_workspace with named workspaces here since they come last
54 # when using 'workspace next'.
55 cmd 'workspace 5';
56 # ensure workspace 5 stays open
57 open_window;
58
59 ################################################################################
60 # Move a workspace over and verify that it is on the right output.
61 ################################################################################
62
63 # The current order should be:
64 # output 1: 1, 5
65 # output 2: 2
66 cmd 'workspace 5';
67 is(focused_ws, '5', 'workspace 5 focused');
68
69 my ($x0, $x1) = workspaces_per_screen();
70 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
71
72 cmd 'move workspace to output fake-1';
73
74 sub workspaces_per_screen {
75     my $i3 = i3(get_socket_path());
76     my $tree = $i3->get_tree->recv;
77     my @outputs = @{$tree->{nodes}};
78
79     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
80     my $fake0_content = first { $_->{type} == 2 } @{$fake0->{nodes}};
81
82     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
83     my $fake1_content = first { $_->{type} == 2 } @{$fake1->{nodes}};
84
85     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
86     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
87
88     return \@fake0_workspaces, \@fake1_workspaces;
89 }
90
91 ($x0, $x1) = workspaces_per_screen();
92 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
93
94 ################################################################################
95 # Verify that a new workspace will be created when moving the last workspace.
96 ################################################################################
97
98 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
99
100 cmd 'workspace 1';
101 cmd 'move workspace to output fake-1';
102
103 ($x0, $x1) = workspaces_per_screen();
104 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
105 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
106
107 ################################################################################
108 # Verify that 'move workspace to output <direction>' works
109 ################################################################################
110
111 cmd 'workspace 5';
112 cmd 'move workspace to output left';
113
114 ($x0, $x1) = workspaces_per_screen();
115 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
116
117 ################################################################################
118 # Verify that coordinates of floating windows are fixed correctly when moving a
119 # workspace to a different output.
120 ################################################################################
121
122 cmd 'workspace 5';
123 my $floating_window = open_floating_window;
124
125 my $old_rect = $floating_window->rect;
126
127 cmd 'move workspace to output right';
128
129 my $new_rect = $floating_window->rect;
130
131 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
132 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
133 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
134 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
135
136 ################################################################################
137 # Verify that empty workspaces get cleaned up when moving a different workspace
138 # to that output.
139 ################################################################################
140
141 my $empty_ws = fresh_workspace(output => 0);
142 my $other_output_ws = fresh_workspace(output => 1);
143 cmd 'open';
144
145 ($x0, $x1) = workspaces_per_screen();
146 ok($empty_ws ~~ @$x0, 'empty_ws on fake-0');
147 ok($other_output_ws ~~ @$x1, 'other_output_ws on fake-1');
148
149 cmd 'move workspace to output left';
150
151 ($x0, $x1) = workspaces_per_screen();
152 ok(!($empty_ws ~~ @$x0), 'empty_ws not on fake-0');
153 ok(!($empty_ws ~~ @$x1), 'empty_ws not on fake-1');
154 ok($other_output_ws ~~ @$x0, 'other_output_ws on fake-0');
155
156 exit_gracefully($pid);
157
158 done_testing;