]> git.sur5r.net Git - i3/i3/blob - testcases/t/504-move-workspace-to-output.t
Merge branch 'fix-coords'
[i3/i3] / testcases / t / 504-move-workspace-to-output.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests whether the 'move workspace <ws> to [output] <output>' command works
5 #
6 use List::Util qw(first);
7 use i3test i3_autostart => 0;
8
9 # TODO:
10 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
11
12 my $config = <<EOT;
13 # i3 config file (v4)
14 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
15
16 fake-outputs 1024x768+0+0,1024x768+1024+0
17 EOT
18 my $pid = launch_with_config($config);
19
20 ################################################################################
21 # Setup workspaces so that they stay open (with an empty container).
22 ################################################################################
23
24 is(focused_ws, '1', 'starting on workspace 1');
25 # ensure workspace 1 stays open
26 open_window;
27
28 cmd 'focus output right';
29 is(focused_ws, '2', 'workspace 2 on second output');
30 # ensure workspace 2 stays open
31 open_window;
32
33 cmd 'focus output right';
34 is(focused_ws, '1', 'back on workspace 1');
35
36 # We don’t use fresh_workspace with named workspaces here since they come last
37 # when using 'workspace next'.
38 cmd 'workspace 5';
39 # ensure workspace 5 stays open
40 open_window;
41
42 ################################################################################
43 # Move a workspace over and verify that it is on the right output.
44 ################################################################################
45
46 # The current order should be:
47 # output 1: 1, 5
48 # output 2: 2
49 cmd 'workspace 5';
50 is(focused_ws, '5', 'workspace 5 focused');
51
52 my ($x0, $x1) = workspaces_per_screen();
53 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
54
55 cmd 'move workspace to output fake-1';
56
57 sub workspaces_per_screen {
58     my $i3 = i3(get_socket_path());
59     my $tree = $i3->get_tree->recv;
60     my @outputs = @{$tree->{nodes}};
61
62     my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
63     my $fake0_content = first { $_->{type} == 2 } @{$fake0->{nodes}};
64
65     my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
66     my $fake1_content = first { $_->{type} == 2 } @{$fake1->{nodes}};
67
68     my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
69     my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
70
71     return \@fake0_workspaces, \@fake1_workspaces;
72 }
73
74 ($x0, $x1) = workspaces_per_screen();
75 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
76
77 ################################################################################
78 # Verify that a new workspace will be created when moving the last workspace.
79 ################################################################################
80
81 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
82
83 cmd 'workspace 1';
84 cmd 'move workspace to output fake-1';
85
86 ($x0, $x1) = workspaces_per_screen();
87 ok('1' ~~ @$x1, 'workspace 1 now on fake-1');
88 is_deeply($x0, [ '3' ], 'workspace 2 created on fake-0');
89
90 ################################################################################
91 # Verify that 'move workspace to output <direction>' works
92 ################################################################################
93
94 cmd 'workspace 5';
95 cmd 'move workspace to output left';
96
97 ($x0, $x1) = workspaces_per_screen();
98 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
99
100 ################################################################################
101 # Verify that coordinates of floating windows are fixed correctly when moving a
102 # workspace to a different output.
103 ################################################################################
104
105 cmd 'workspace 5';
106 my $floating_window = open_floating_window;
107
108 my $old_rect = $floating_window->rect;
109
110 cmd 'move workspace to output right';
111
112 my $new_rect = $floating_window->rect;
113
114 isnt($old_rect->{x}, $new_rect->{x}, 'x coordinate changed');
115 is($old_rect->{y}, $new_rect->{y}, 'y coordinate unchanged');
116 is($old_rect->{width}, $new_rect->{width}, 'width unchanged');
117 is($old_rect->{height}, $new_rect->{height}, 'height unchanged');
118
119 exit_gracefully($pid);
120
121 done_testing;