]> git.sur5r.net Git - i3/i3/blob - testcases/t/504-move-workspace-to-output.t
tests: make t/504-move-workspace-to-output consistent with the previous commit
[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;
8
9 # TODO:
10 # introduce 'move workspace 3 to output <output>' with synonym 'move workspace 3 to <output>'
11
12 ################################################################################
13 # Setup workspaces so that they stay open (with an empty container).
14 ################################################################################
15
16 is(focused_ws, '1', 'starting on workspace 1');
17 # ensure workspace 1 stays open
18 open_window;
19
20 cmd 'focus output right';
21 is(focused_ws, '2', 'workspace 2 on second output');
22 # ensure workspace 2 stays open
23 open_window;
24
25 cmd 'focus output right';
26 is(focused_ws, '1', 'back on workspace 1');
27
28 # We don’t use fresh_workspace with named workspaces here since they come last
29 # when using 'workspace next'.
30 cmd 'workspace 5';
31 # ensure workspace 5 stays open
32 open_window;
33
34 ################################################################################
35 # Move a workspace over and verify that it is on the right output.
36 ################################################################################
37
38 # The current order should be:
39 # output 1: 1, 5
40 # output 2: 2
41 cmd 'workspace 5';
42 is(focused_ws, '5', 'workspace 5 focused');
43
44 my ($x0, $x1) = workspaces_per_screen();
45 ok('5' ~~ @$x0, 'workspace 5 on xinerama-0');
46
47 cmd 'move workspace to output xinerama-1';
48
49 sub workspaces_per_screen {
50     my $i3 = i3(get_socket_path());
51     my $tree = $i3->get_tree->recv;
52     my @outputs = @{$tree->{nodes}};
53
54     my $xinerama0 = first { $_->{name} eq 'xinerama-0' } @outputs;
55     my $xinerama0_content = first { $_->{type} == 2 } @{$xinerama0->{nodes}};
56
57     my $xinerama1 = first { $_->{name} eq 'xinerama-1' } @outputs;
58     my $xinerama1_content = first { $_->{type} == 2 } @{$xinerama1->{nodes}};
59
60     my @xinerama0_workspaces = map { $_->{name} } @{$xinerama0_content->{nodes}};
61     my @xinerama1_workspaces = map { $_->{name} } @{$xinerama1_content->{nodes}};
62
63     return \@xinerama0_workspaces, \@xinerama1_workspaces;
64 }
65
66 ($x0, $x1) = workspaces_per_screen();
67 ok('5' ~~ @$x1, 'workspace 5 now on xinerama-1');
68
69 ################################################################################
70 # Verify that a new workspace will be created when moving the last workspace.
71 ################################################################################
72
73 is_deeply($x0, [ '1' ], 'only workspace 1 remaining on xinerama-0');
74
75 cmd 'workspace 1';
76 cmd 'move workspace to output xinerama-1';
77
78 ($x0, $x1) = workspaces_per_screen();
79 ok('1' ~~ @$x1, 'workspace 1 now on xinerama-1');
80 is_deeply($x0, [ '3' ], 'workspace 2 created on xinerama-0');
81
82 ################################################################################
83 # Verify that 'move workspace to output <direction>' works
84 ################################################################################
85
86 cmd 'workspace 5';
87 cmd 'move workspace to output left';
88
89 ($x0, $x1) = workspaces_per_screen();
90 ok('5' ~~ @$x0, 'workspace 5 back on xinerama-0');
91
92
93 done_testing;