2 # vim:ts=4:sw=4:expandtab
4 # Tests whether the 'move workspace <ws> to [output] <output>' command works
6 use List::Util qw(first);
7 use i3test i3_autostart => 0;
10 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
14 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
16 fake-outputs 1024x768+0+0,1024x768+1024+0
18 my $pid = launch_with_config($config);
20 ################################################################################
21 # Setup workspaces so that they stay open (with an empty container).
22 ################################################################################
24 is(focused_ws, '1', 'starting on workspace 1');
25 # ensure workspace 1 stays open
28 cmd 'focus output right';
29 is(focused_ws, '2', 'workspace 2 on second output');
30 # ensure workspace 2 stays open
33 cmd 'focus output right';
34 is(focused_ws, '1', 'back on workspace 1');
36 # We don’t use fresh_workspace with named workspaces here since they come last
37 # when using 'workspace next'.
39 # ensure workspace 5 stays open
42 ################################################################################
43 # Move a workspace over and verify that it is on the right output.
44 ################################################################################
46 # The current order should be:
50 is(focused_ws, '5', 'workspace 5 focused');
52 my ($x0, $x1) = workspaces_per_screen();
53 ok('5' ~~ @$x0, 'workspace 5 on fake-0');
55 cmd 'move workspace to output fake-1';
57 sub workspaces_per_screen {
58 my $i3 = i3(get_socket_path());
59 my $tree = $i3->get_tree->recv;
60 my @outputs = @{$tree->{nodes}};
62 my $fake0 = first { $_->{name} eq 'fake-0' } @outputs;
63 my $fake0_content = first { $_->{type} == 2 } @{$fake0->{nodes}};
65 my $fake1 = first { $_->{name} eq 'fake-1' } @outputs;
66 my $fake1_content = first { $_->{type} == 2 } @{$fake1->{nodes}};
68 my @fake0_workspaces = map { $_->{name} } @{$fake0_content->{nodes}};
69 my @fake1_workspaces = map { $_->{name} } @{$fake1_content->{nodes}};
71 return \@fake0_workspaces, \@fake1_workspaces;
74 ($x0, $x1) = workspaces_per_screen();
75 ok('5' ~~ @$x1, 'workspace 5 now on fake-1');
77 ################################################################################
78 # Verify that a new workspace will be created when moving the last workspace.
79 ################################################################################
81 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on fake-0');
84 cmd 'move workspace to output fake-1';
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');
90 ################################################################################
91 # Verify that 'move workspace to output <direction>' works
92 ################################################################################
95 cmd 'move workspace to output left';
97 ($x0, $x1) = workspaces_per_screen();
98 ok('5' ~~ @$x0, 'workspace 5 back on fake-0');
100 ################################################################################
101 # Verify that coordinates of floating windows are fixed correctly when moving a
102 # workspace to a different output.
103 ################################################################################
106 my $floating_window = open_floating_window;
108 my $old_rect = $floating_window->rect;
110 cmd 'move workspace to output right';
112 my $new_rect = $floating_window->rect;
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');
119 exit_gracefully($pid);