]> git.sur5r.net Git - i3/i3/blob - testcases/t/66-assign.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 66-assign.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
4 #
5 # Tests if assignments work
6 #
7 use i3test;
8 use Cwd qw(abs_path);
9 use Proc::Background;
10 use File::Temp qw(tempfile tempdir);
11 use X11::XCB qw(:all);
12 use X11::XCB::Connection;
13 use v5.10;
14
15 my $x = X11::XCB::Connection->new;
16
17 # assuming we are run by complete-run.pl
18 my $i3_path = abs_path("../i3");
19
20 # TODO: move to X11::XCB
21 sub set_wm_class {
22     my ($id, $class, $instance) = @_;
23
24     # Add a _NET_WM_STRUT_PARTIAL hint
25     my $atomname = $x->atom(name => 'WM_CLASS');
26     my $atomtype = $x->atom(name => 'STRING');
27
28     $x->change_property(
29         PROP_MODE_REPLACE,
30         $id,
31         $atomname->id,
32         $atomtype->id,
33         8,
34         length($class) + length($instance) + 2,
35         "$instance\x00$class\x00"
36     );
37 }
38
39
40 #####################################################################
41 # start a window and see that it does not get assigned with an empty config
42 #####################################################################
43
44 my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
45
46 my ($fh, $tmpfile) = tempfile();
47 say $fh "# i3 config file (v4)";
48 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
49 say $fh "ipc-socket $socketpath";
50 close($fh);
51
52 diag("Starting i3");
53 my $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
54 my $process = Proc::Background->new($i3cmd);
55 sleep 1;
56
57 # force update of the cached socket path in lib/i3test
58 get_socket_path(0);
59
60 diag("pid = " . $process->pid);
61
62 my $tmp = fresh_workspace;
63
64 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
65
66 my $window = $x->root->create_child(
67     class => WINDOW_CLASS_INPUT_OUTPUT,
68     rect => [ 0, 0, 30, 30 ],
69     background_color => '#0000ff',
70 );
71
72 $window->_create;
73 set_wm_class($window->id, 'special', 'special');
74 $window->name('special window');
75 $window->map;
76 sleep 0.25;
77
78 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
79
80 exit_gracefully($process->pid);
81
82 $window->destroy;
83
84 sleep 0.25;
85
86 #####################################################################
87 # start a window and see that it gets assigned to a formerly unused
88 # workspace
89 #####################################################################
90
91 ($fh, $tmpfile) = tempfile();
92 say $fh "# i3 config file (v4)";
93 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
94 say $fh "ipc-socket $socketpath";
95 say $fh q|assign "special" → targetws|;
96 close($fh);
97
98 diag("Starting i3");
99 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
100 $process = Proc::Background->new($i3cmd);
101 sleep 1;
102
103 # force update of the cached socket path in lib/i3test
104 get_socket_path(0);
105
106 diag("pid = " . $process->pid);
107
108 $tmp = fresh_workspace;
109
110 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
111 my $workspaces = get_workspace_names;
112 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
113
114 my $window = $x->root->create_child(
115     class => WINDOW_CLASS_INPUT_OUTPUT,
116     rect => [ 0, 0, 30, 30 ],
117     background_color => '#0000ff',
118 );
119
120 $window->_create;
121 set_wm_class($window->id, 'special', 'special');
122 $window->name('special window');
123 $window->map;
124 sleep 0.25;
125
126 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
127 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
128
129 $window->destroy;
130
131 exit_gracefully($process->pid);
132
133 sleep 0.25;
134
135 #####################################################################
136 # start a window and see that it gets assigned to a workspace which has content
137 # already, next to the existing node.
138 #####################################################################
139
140 diag("Starting i3");
141 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
142 $process = Proc::Background->new($i3cmd);
143 sleep 1;
144
145 # force update of the cached socket path in lib/i3test
146 get_socket_path(0);
147
148 diag("pid = " . $process->pid);
149
150 # initialize the target workspace, then go to a fresh one
151 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
152 cmd 'workspace targetws';
153 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
154 cmd 'open';
155 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
156 $tmp = fresh_workspace;
157
158 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
159 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
160
161 my $window = $x->root->create_child(
162     class => WINDOW_CLASS_INPUT_OUTPUT,
163     rect => [ 0, 0, 30, 30 ],
164     background_color => '#0000ff',
165 );
166
167 $window->_create;
168 set_wm_class($window->id, 'special', 'special');
169 $window->name('special window');
170 $window->map;
171 sleep 0.25;
172
173 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
174 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
175
176 exit_gracefully($process->pid);
177
178 #####################################################################
179 # start a window and see that it gets assigned to a workspace which has content
180 # already, next to the existing node.
181 #####################################################################
182
183 ($fh, $tmpfile) = tempfile();
184 say $fh "# i3 config file (v4)";
185 say $fh "font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1";
186 say $fh "ipc-socket $socketpath";
187 say $fh q|assign "special" → ~|;
188 close($fh);
189
190 diag("Starting i3");
191 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
192 $process = Proc::Background->new($i3cmd);
193 sleep 1;
194
195 # force update of the cached socket path in lib/i3test
196 get_socket_path(0);
197
198 diag("pid = " . $process->pid);
199
200 $tmp = fresh_workspace;
201
202 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
203 my $workspaces = get_workspace_names;
204 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
205
206 my $window = $x->root->create_child(
207     class => WINDOW_CLASS_INPUT_OUTPUT,
208     rect => [ 0, 0, 30, 30 ],
209     background_color => '#0000ff',
210 );
211
212 $window->_create;
213 set_wm_class($window->id, 'special', 'special');
214 $window->name('special window');
215 $window->map;
216 sleep 0.25;
217
218 my $content = get_ws($tmp);
219 ok(@{$content->{nodes}} == 0, 'no tiling cons');
220 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
221
222 $window->destroy;
223
224 exit_gracefully($process->pid);
225
226 sleep 0.25;
227
228 done_testing;