2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://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)
17 # Tests if assignments work
19 use i3test i3_autostart => 0;
23 $args{name} //= 'special window';
25 # We use dont_map because i3 will not map the window on the current
26 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
27 my $window = open_window(
29 wm_class => 'special',
36 #####################################################################
37 # start a window and see that it does not get assigned with an empty config
38 #####################################################################
42 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
45 my $pid = launch_with_config($config);
47 my $tmp = fresh_workspace;
49 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
51 my $window = open_special;
52 wait_for_map($window);
54 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
56 exit_gracefully($pid);
60 #####################################################################
61 # start a window and see that it gets assigned to a formerly unused
63 #####################################################################
67 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
68 assign [class="special"] → targetws
71 $pid = launch_with_config($config);
73 $tmp = fresh_workspace;
75 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
76 my $workspaces = get_workspace_names;
77 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
79 $window = open_special;
82 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
83 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
87 exit_gracefully($pid);
89 #####################################################################
90 # start a window and see that it gets assigned to a workspace which has content
91 # already, next to the existing node.
92 #####################################################################
94 $pid = launch_with_config($config);
96 # initialize the target workspace, then go to a fresh one
97 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
98 cmd 'workspace targetws';
99 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
101 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
102 $tmp = fresh_workspace;
104 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
105 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
108 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
109 # map the window -- it will be assigned to a different workspace and will only
110 # be mapped once you switch to that workspace
111 $window = open_special(dont_map => 1);
115 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
116 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
118 exit_gracefully($pid);
120 #####################################################################
121 # start a window and see that it gets assigned to a workspace which has content
122 # already, next to the existing node.
123 #####################################################################
126 # i3 config file (v4)
127 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
128 for_window [class="special"] floating enable
131 $pid = launch_with_config($config);
133 $tmp = fresh_workspace;
135 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
136 $workspaces = get_workspace_names;
137 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
139 $window = open_special;
142 my $content = get_ws($tmp);
143 ok(@{$content->{nodes}} == 0, 'no tiling cons');
144 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
148 exit_gracefully($pid);
150 #####################################################################
151 # regression test: dock clients with floating assignments should not crash
152 # (instead, nothing should happen - dock clients can’t float)
154 #####################################################################
156 # Walks /proc to figure out whether a child process of $i3pid with the name
157 # 'i3-nagbar' exists.
158 sub i3nagbar_running {
161 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
162 for my $path (@procfiles) {
163 open(my $fh, '<', "$path/stat") or next;
166 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
167 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
173 # i3 config file (v4)
174 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
175 for_window [title="special"] floating enable
178 $pid = launch_with_config($config);
180 $tmp = fresh_workspace;
182 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
183 my @docked = get_dock_clients;
184 is(@docked, 0, 'one dock client yet');
186 $window = open_special(
187 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
191 $content = get_ws($tmp);
192 ok(@{$content->{nodes}} == 0, 'no tiling cons');
193 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
194 @docked = get_dock_clients;
195 is(@docked, 1, 'one dock client now');
201 exit_gracefully($pid);