2 # vim:ts=4:sw=4:expandtab
3 # !NO_I3_INSTANCE! will prevent complete-run.pl from starting i3
5 # Tests if assignments work
10 use File::Temp qw(tempfile tempdir);
11 use X11::XCB qw(:all);
12 use X11::XCB::Connection;
15 my $x = X11::XCB::Connection->new;
17 # assuming we are run by complete-run.pl
18 my $i3_path = abs_path("../i3");
20 # TODO: move to X11::XCB
22 my ($id, $class, $instance) = @_;
24 # Add a _NET_WM_STRUT_PARTIAL hint
25 my $atomname = $x->atom(name => 'WM_CLASS');
26 my $atomtype = $x->atom(name => 'STRING');
34 length($class) + length($instance) + 2,
35 "$instance\x00$class\x00"
40 #####################################################################
41 # start a window and see that it does not get assigned with an empty config
42 #####################################################################
44 my $socketpath = File::Temp::tempnam('/tmp', 'i3-test-socket-');
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";
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);
57 # force update of the cached socket path in lib/i3test
60 diag("pid = " . $process->pid);
62 my $tmp = fresh_workspace;
64 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
66 my $window = $x->root->create_child(
67 class => WINDOW_CLASS_INPUT_OUTPUT,
68 rect => [ 0, 0, 30, 30 ],
69 background_color => '#0000ff',
73 set_wm_class($window->id, 'special', 'special');
74 $window->name('special window');
78 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
80 exit_gracefully($process->pid);
86 #####################################################################
87 # start a window and see that it gets assigned to a formerly unused
89 #####################################################################
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|;
99 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
100 $process = Proc::Background->new($i3cmd);
103 # force update of the cached socket path in lib/i3test
106 diag("pid = " . $process->pid);
108 $tmp = fresh_workspace;
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');
114 my $window = $x->root->create_child(
115 class => WINDOW_CLASS_INPUT_OUTPUT,
116 rect => [ 0, 0, 30, 30 ],
117 background_color => '#0000ff',
121 set_wm_class($window->id, 'special', 'special');
122 $window->name('special window');
126 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
127 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
131 exit_gracefully($process->pid);
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 #####################################################################
141 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
142 $process = Proc::Background->new($i3cmd);
145 # force update of the cached socket path in lib/i3test
148 diag("pid = " . $process->pid);
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');
155 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
156 $tmp = fresh_workspace;
158 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
159 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
161 my $window = $x->root->create_child(
162 class => WINDOW_CLASS_INPUT_OUTPUT,
163 rect => [ 0, 0, 30, 30 ],
164 background_color => '#0000ff',
168 set_wm_class($window->id, 'special', 'special');
169 $window->name('special window');
173 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
174 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
176 exit_gracefully($process->pid);
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 #####################################################################
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" → ~|;
191 $i3cmd = "exec " . abs_path("../i3") . " -V -d all --disable-signalhandler -c $tmpfile >/dev/null 2>/dev/null";
192 $process = Proc::Background->new($i3cmd);
195 # force update of the cached socket path in lib/i3test
198 diag("pid = " . $process->pid);
200 $tmp = fresh_workspace;
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');
206 my $window = $x->root->create_child(
207 class => WINDOW_CLASS_INPUT_OUTPUT,
208 rect => [ 0, 0, 30, 30 ],
209 background_color => '#0000ff',
213 set_wm_class($window->id, 'special', 'special');
214 $window->name('special window');
218 my $content = get_ws($tmp);
219 ok(@{$content->{nodes}} == 0, 'no tiling cons');
220 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
224 exit_gracefully($process->pid);