]> git.sur5r.net Git - i3/i3/blob - testcases/t/166-assign.t
355058dd01314feecd131b3d13e19a919c286368
[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
21 sub open_special {
22     my %args = @_;
23     $args{name} //= 'special window';
24
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(
28         %args,
29         wm_class => 'special',
30         dont_map => 1,
31     );
32     $window->map;
33     return $window;
34 }
35
36 #####################################################################
37 # start a window and see that it does not get assigned with an empty config
38 #####################################################################
39
40 my $config = <<EOT;
41 # i3 config file (v4)
42 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
43 EOT
44
45 my $pid = launch_with_config($config);
46
47 my $tmp = fresh_workspace;
48
49 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
50
51 my $window = open_special;
52 wait_for_map($window);
53
54 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
55
56 exit_gracefully($pid);
57
58 $window->destroy;
59
60 #####################################################################
61 # start a window and see that it gets assigned to a formerly unused
62 # workspace
63 #####################################################################
64
65 $config = <<EOT;
66 # i3 config file (v4)
67 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
68 assign [class="special"] → targetws
69 EOT
70
71 $pid = launch_with_config($config);
72
73 $tmp = fresh_workspace;
74
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');
78
79 $window = open_special;
80 sync_with_i3;
81
82 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
83 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
84
85 $window->destroy;
86
87 exit_gracefully($pid);
88
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 #####################################################################
93
94 $pid = launch_with_config($config);
95
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');
100 cmd 'open';
101 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
102 $tmp = fresh_workspace;
103
104 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
105 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
106
107
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);
112 $window->map;
113 sync_with_i3;
114
115 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
116 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
117
118 exit_gracefully($pid);
119
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 #####################################################################
124
125 $config = <<EOT;
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
129 EOT
130
131 $pid = launch_with_config($config);
132
133 $tmp = fresh_workspace;
134
135 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
136 $workspaces = get_workspace_names;
137 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
138
139 $window = open_special;
140 sync_with_i3;
141
142 my $content = get_ws($tmp);
143 ok(@{$content->{nodes}} == 0, 'no tiling cons');
144 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
145
146 $window->destroy;
147
148 exit_gracefully($pid);
149
150 #####################################################################
151 # regression test: dock clients with floating assignments should not crash
152 # (instead, nothing should happen - dock clients can’t float)
153 # ticket #501
154 #####################################################################
155
156 # Walks /proc to figure out whether a child process of $i3pid with the name
157 # 'i3-nagbar' exists.
158 sub i3nagbar_running {
159     my ($i3pid) = @_;
160
161     my @procfiles = grep { m,^/proc/[0-9]+$, } </proc/*>;
162     for my $path (@procfiles) {
163         open(my $fh, '<', "$path/stat") or next;
164         my $line = <$fh>;
165         close($fh);
166         my ($comm, $ppid) = ($line =~ /^[0-9]+ \(([^)]+)\) . ([0-9]+)/);
167         return 1 if $ppid == $i3pid && $comm eq 'i3-nagbar';
168     }
169     return 0;
170 }
171
172 $config = <<EOT;
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
176 EOT
177
178 $pid = launch_with_config($config);
179
180 $tmp = fresh_workspace;
181
182 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
183 my @docked = get_dock_clients;
184 is(@docked, 0, 'one dock client yet');
185
186 $window = open_special(
187     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
188 );
189 sync_with_i3;
190
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');
196
197 $window->destroy;
198
199 does_i3_live;
200
201 exit_gracefully($pid);
202
203 done_testing;