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;
20 use X11::XCB qw(PROP_MODE_REPLACE);
22 # TODO: move to X11::XCB
24 my ($id, $class, $instance) = @_;
26 # Add a _NET_WM_STRUT_PARTIAL hint
27 my $atomname = $x->atom(name => 'WM_CLASS');
28 my $atomtype = $x->atom(name => 'STRING');
36 length($class) + length($instance) + 2,
37 "$instance\x00$class\x00"
43 my $wm_class = delete($args{wm_class}) || 'special';
44 $args{name} //= 'special window';
46 # We use dont_map because i3 will not map the window on the current
47 # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
48 my $window = open_window(
50 before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
57 #####################################################################
58 # start a window and see that it does not get assigned with an empty config
59 #####################################################################
63 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
66 my $pid = launch_with_config($config);
68 my $tmp = fresh_workspace;
70 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
72 my $window = open_special;
73 wait_for_map($window);
75 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
77 exit_gracefully($pid);
81 #####################################################################
82 # start a window and see that it gets assigned to a formerly unused
84 #####################################################################
88 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
89 assign [class="special"] → targetws
92 $pid = launch_with_config($config);
94 $tmp = fresh_workspace;
96 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
97 my $workspaces = get_workspace_names;
98 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
100 $window = open_special;
103 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
104 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
108 exit_gracefully($pid);
110 #####################################################################
111 # start a window and see that it gets assigned to a workspace which has content
112 # already, next to the existing node.
113 #####################################################################
115 $pid = launch_with_config($config);
117 # initialize the target workspace, then go to a fresh one
118 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
119 cmd 'workspace targetws';
120 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
122 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
123 $tmp = fresh_workspace;
125 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
126 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
129 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
130 # map the window -- it will be assigned to a different workspace and will only
131 # be mapped once you switch to that workspace
132 $window = open_special(dont_map => 1);
136 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
137 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
139 exit_gracefully($pid);
141 #####################################################################
142 # start a window and see that it gets assigned to a workspace which has content
143 # already, next to the existing node.
144 #####################################################################
147 # i3 config file (v4)
148 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
149 for_window [class="special"] floating enable
152 $pid = launch_with_config($config);
154 $tmp = fresh_workspace;
156 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
157 $workspaces = get_workspace_names;
158 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
160 $window = open_special;
163 my $content = get_ws($tmp);
164 ok(@{$content->{nodes}} == 0, 'no tiling cons');
165 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
169 exit_gracefully($pid);
171 #####################################################################
172 # regression test: dock clients with floating assignments should not crash
173 # (instead, nothing should happen - dock clients can’t float)
175 #####################################################################
177 # Walks /proc to figure out whether a child process of $i3pid with the name
178 # 'i3-nagbar' exists.
179 sub i3nagbar_running {
182 my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
183 for my $path (@procfiles) {
184 open(my $fh, '<', "$path/stat") or next;
187 my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
188 return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
194 # i3 config file (v4)
195 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
196 for_window [title="special"] floating enable
199 $pid = launch_with_config($config);
201 $tmp = fresh_workspace;
203 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
204 my @docked = get_dock_clients;
205 is(@docked, 0, 'one dock client yet');
207 $window = open_special(
208 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
212 $content = get_ws($tmp);
213 ok(@{$content->{nodes}} == 0, 'no tiling cons');
214 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
215 @docked = get_dock_clients;
216 is(@docked, 1, 'one dock client now');
222 exit_gracefully($pid);