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