]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
Merge branch 'master' into next
[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 sync_with_i3;
102
103 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
104 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
105
106 $window->destroy;
107
108 exit_gracefully($pid);
109
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 #####################################################################
114
115 $pid = launch_with_config($config);
116
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');
121 cmd 'open';
122 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
123 $tmp = fresh_workspace;
124
125 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
126 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
127
128
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);
133 $window->map;
134 sync_with_i3;
135
136 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
137 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
138
139 exit_gracefully($pid);
140
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 #####################################################################
145
146 $config = <<EOT;
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
150 EOT
151
152 $pid = launch_with_config($config);
153
154 $tmp = fresh_workspace;
155
156 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
157 $workspaces = get_workspace_names;
158 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
159
160 $window = open_special;
161 sync_with_i3;
162
163 my $content = get_ws($tmp);
164 ok(@{$content->{nodes}} == 0, 'no tiling cons');
165 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
166
167 $window->destroy;
168
169 exit_gracefully($pid);
170
171 #####################################################################
172 # regression test: dock clients with floating assignments should not crash
173 # (instead, nothing should happen - dock clients can’t float)
174 # ticket #501
175 #####################################################################
176
177 # Walks /proc to figure out whether a child process of $i3pid with the name
178 # 'i3-nagbar' exists.
179 sub i3nagbar_running {
180     my ($i3pid) = @_;
181
182     my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
183     for my $path (@procfiles) {
184         open(my $fh, '<', "$path/stat") or next;
185         my $line = <$fh>;
186         close($fh);
187         my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
188         return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
189     }
190     return 0;
191 }
192
193 $config = <<EOT;
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
197 EOT
198
199 $pid = launch_with_config($config);
200
201 $tmp = fresh_workspace;
202
203 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
204 my @docked = get_dock_clients;
205 is(@docked, 0, 'one dock client yet');
206
207 $window = open_special(
208     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
209 );
210 sync_with_i3;
211
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');
217
218 $window->destroy;
219
220 does_i3_live;
221
222 exit_gracefully($pid);
223
224 done_testing;