]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
tests: use new assign syntax, drop legacy test
[i3/i3] / testcases / t / 166-assign.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests if assignments work
18 #
19 use i3test i3_autostart => 0;
20 use X11::XCB qw(PROP_MODE_REPLACE);
21
22 # TODO: move to X11::XCB
23 sub set_wm_class {
24     my ($id, $class, $instance) = @_;
25
26     # Add a _NET_WM_STRUT_PARTIAL hint
27     my $atomname = $x->atom(name => 'WM_CLASS');
28     my $atomtype = $x->atom(name => 'STRING');
29
30     $x->change_property(
31         PROP_MODE_REPLACE,
32         $id,
33         $atomname->id,
34         $atomtype->id,
35         8,
36         length($class) + length($instance) + 2,
37         "$instance\x00$class\x00"
38     );
39 }
40
41 sub open_special {
42     my %args = @_;
43     my $wm_class = delete($args{wm_class}) || 'special';
44     $args{name} //= 'special window';
45
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(
49         %args,
50         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
51         dont_map => 1,
52     );
53     $window->map;
54     return $window;
55 }
56
57 #####################################################################
58 # start a window and see that it does not get assigned with an empty config
59 #####################################################################
60
61 my $config = <<EOT;
62 # i3 config file (v4)
63 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
64 EOT
65
66 my $pid = launch_with_config($config);
67
68 my $tmp = fresh_workspace;
69
70 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
71
72 my $window = open_special;
73 wait_for_map($window);
74
75 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
76
77 exit_gracefully($pid);
78
79 $window->destroy;
80
81 #####################################################################
82 # start a window and see that it gets assigned to a formerly unused
83 # workspace
84 #####################################################################
85
86 $config = <<EOT;
87 # i3 config file (v4)
88 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
89 assign [class="special"] → targetws
90 EOT
91
92 $pid = launch_with_config($config);
93
94 $tmp = fresh_workspace;
95
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');
99
100 $window = open_special;
101
102 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
103 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
104
105 $window->destroy;
106
107 exit_gracefully($pid);
108
109 #####################################################################
110 # start a window and see that it gets assigned to a workspace which has content
111 # already, next to the existing node.
112 #####################################################################
113
114 $pid = launch_with_config($config);
115
116 # initialize the target workspace, then go to a fresh one
117 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
118 cmd 'workspace targetws';
119 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
120 cmd 'open';
121 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
122 $tmp = fresh_workspace;
123
124 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
125 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
126
127
128 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
129 # map the window -- it will be assigned to a different workspace and will only
130 # be mapped once you switch to that workspace
131 $window = open_special(dont_map => 1);
132 $window->map;
133 sync_with_i3;
134
135 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
136 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
137
138 exit_gracefully($pid);
139
140 #####################################################################
141 # start a window and see that it gets assigned to a workspace which has content
142 # already, next to the existing node.
143 #####################################################################
144
145 $config = <<EOT;
146 # i3 config file (v4)
147 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
148 for_window [class="special"] floating enable
149 EOT
150
151 $pid = launch_with_config($config);
152
153 $tmp = fresh_workspace;
154
155 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
156 $workspaces = get_workspace_names;
157 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
158
159 $window = open_special;
160
161 my $content = get_ws($tmp);
162 ok(@{$content->{nodes}} == 0, 'no tiling cons');
163 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
164
165 $window->destroy;
166
167 exit_gracefully($pid);
168
169 #####################################################################
170 # regression test: dock clients with floating assignments should not crash
171 # (instead, nothing should happen - dock clients can’t float)
172 # ticket #501
173 #####################################################################
174
175 # Walks /proc to figure out whether a child process of $i3pid with the name
176 # 'i3-nagbar' exists.
177 sub i3nagbar_running {
178     my ($i3pid) = @_;
179
180     my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
181     for my $path (@procfiles) {
182         open(my $fh, '<', "$path/stat") or next;
183         my $line = <$fh>;
184         close($fh);
185         my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
186         return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
187     }
188     return 0;
189 }
190
191 $config = <<EOT;
192 # i3 config file (v4)
193 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
194 for_window [title="special"] floating enable
195 EOT
196
197 $pid = launch_with_config($config);
198
199 $tmp = fresh_workspace;
200
201 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
202 my @docked = get_dock_clients;
203 is(@docked, 0, 'one dock client yet');
204
205 $window = open_special(
206     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
207 );
208
209 $content = get_ws($tmp);
210 ok(@{$content->{nodes}} == 0, 'no tiling cons');
211 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
212 @docked = get_dock_clients;
213 is(@docked, 1, 'one dock client now');
214
215 $window->destroy;
216
217 does_i3_live;
218
219 exit_gracefully($pid);
220
221 done_testing;