2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
18 # Tests that workspaces are moved to the assigned output if they
19 # are renamed to an assigned name.
22 use i3test i3_config => <<EOT;
24 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25 fake-outputs 1024x768+0+0,1024x768+1024+0
27 workspace 1 output fake-0
28 workspace 2 output fake-1
29 workspace 3:foo output fake-1
30 workspace baz output fake-1
31 workspace 5 output left
34 my $i3 = i3(get_socket_path());
37 # Returns the name of the output on which this workspace resides
38 sub get_output_for_workspace {
39 my $ws_name = shift @_;
41 foreach (grep { not $_->{name} =~ /^__/ } @{$i3->get_tree->recv->{nodes}}) {
42 my $output = $_->{name};
43 foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) {
44 return $output if $_->{nodes}[0]->{name} =~ $ws_name;
49 ##########################################################################
50 # Renaming the workspace to an unassigned name does not move the workspace
52 ##########################################################################
54 cmd 'focus output fake-0';
55 cmd 'rename workspace to unassigned';
56 is(get_output_for_workspace('unassigned'), 'fake-0',
57 'Unassigned workspace should stay on its output when being renamed');
59 ##########################################################################
60 # Renaming a workspace by number only triggers the assignment
61 ##########################################################################
63 cmd 'focus output fake-0';
64 cmd 'rename workspace to 2';
65 is(get_output_for_workspace('2'), 'fake-1',
66 'Renaming the workspace to a number should move it to the assigned output');
68 ##########################################################################
69 # Renaming a workspace by number and name triggers the assignment
70 ##########################################################################
72 cmd 'focus output fake-0';
73 cmd 'rename workspace to "2:foo"';
74 is(get_output_for_workspace('2:foo'), 'fake-1',
75 'Renaming the workspace to a number and name should move it to the assigned output');
77 ##########################################################################
78 # Renaming a workspace by name only triggers the assignment
79 ##########################################################################
81 cmd 'focus output fake-0';
82 cmd 'rename workspace to baz';
83 is(get_output_for_workspace('baz'), 'fake-1',
84 'Renaming the workspace to a number and name should move it to the assigned output');
86 ##########################################################################
87 # Renaming a workspace so that it is assigned a directional output does
88 # not move the workspace or crash
89 ##########################################################################
91 cmd 'focus output fake-0';
93 cmd 'rename workspace to 5';
94 is(get_output_for_workspace('5'), 'fake-0',
95 'Renaming the workspace to a workspace assigned to a directional output should not move the workspace');