2 # vim:ts=4:sw=4:expandtab
4 # Tests if assignments work
6 use i3test i3_autostart => 0;
7 use X11::XCB qw(PROP_MODE_REPLACE);
9 # TODO: move to X11::XCB
11 my ($id, $class, $instance) = @_;
13 # Add a _NET_WM_STRUT_PARTIAL hint
14 my $atomname = $x->atom(name => 'WM_CLASS');
15 my $atomtype = $x->atom(name => 'STRING');
23 length($class) + length($instance) + 2,
24 "$instance\x00$class\x00"
30 my $wm_class = delete($args{wm_class}) || 'special';
31 $args{name} //= 'special window';
35 before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
39 #####################################################################
40 # start a window and see that it does not get assigned with an empty config
41 #####################################################################
45 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
48 my $pid = launch_with_config($config);
50 my $tmp = fresh_workspace;
52 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
54 my $window = open_special;
56 ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace');
58 exit_gracefully($pid);
62 #####################################################################
63 # start a window and see that it gets assigned to a formerly unused
65 #####################################################################
69 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
70 assign "special" → targetws
73 $pid = launch_with_config($config);
75 $tmp = fresh_workspace;
77 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
78 my $workspaces = get_workspace_names;
79 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
81 $window = open_special;
83 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
84 ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists');
88 exit_gracefully($pid);
92 #####################################################################
93 # start a window and see that it gets assigned to a workspace which has content
94 # already, next to the existing node.
95 #####################################################################
97 $pid = launch_with_config($config);
99 # initialize the target workspace, then go to a fresh one
100 ok(!("targetws" ~~ @{get_workspace_names()}), 'targetws does not exist yet');
101 cmd 'workspace targetws';
102 cmp_ok(@{get_ws_content('targetws')}, '==', 0, 'no containers on targetws yet');
104 cmp_ok(@{get_ws_content('targetws')}, '==', 1, 'one container on targetws');
105 $tmp = fresh_workspace;
107 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
108 ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet');
111 # We use sync_with_i3 instead of wait_for_map here because i3 will not actually
112 # map the window -- it will be assigned to a different workspace and will only
113 # be mapped once you switch to that workspace
114 $window = open_special(dont_map => 1);
118 ok(@{get_ws_content($tmp)} == 0, 'still no containers');
119 ok(@{get_ws_content('targetws')} == 2, 'two containers on targetws');
121 exit_gracefully($pid);
123 #####################################################################
124 # start a window and see that it gets assigned to a workspace which has content
125 # already, next to the existing node.
126 #####################################################################
129 # i3 config file (v4)
130 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
134 $pid = launch_with_config($config);
136 $tmp = fresh_workspace;
138 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
139 $workspaces = get_workspace_names;
140 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
142 $window = open_special;
144 my $content = get_ws($tmp);
145 ok(@{$content->{nodes}} == 0, 'no tiling cons');
146 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
150 exit_gracefully($pid);
154 #####################################################################
155 # make sure that assignments are case-insensitive in the old syntax.
156 #####################################################################
159 # i3 config file (v4)
160 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
164 $pid = launch_with_config($config);
166 $tmp = fresh_workspace;
168 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
169 $workspaces = get_workspace_names;
170 ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet');
172 $window = open_special(wm_class => 'SPEcial');
174 $content = get_ws($tmp);
175 ok(@{$content->{nodes}} == 0, 'no tiling cons');
176 ok(@{$content->{floating_nodes}} == 1, 'one floating con');
180 exit_gracefully($pid);
184 #####################################################################
185 # regression test: dock clients with floating assignments should not crash
186 # (instead, nothing should happen - dock clients can’t float)
188 #####################################################################
191 # i3 config file (v4)
192 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
196 $pid = launch_with_config($config);
198 # TODO: replace this with checking the process hierarchy
199 # XXX: give i3-nagbar some time to start up
202 $tmp = fresh_workspace;
204 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
205 my @docked = get_dock_clients;
206 # We expect i3-nagbar as the first dock client due to using the old assign
208 is(@docked, 1, 'one dock client yet');
210 $window = open_special(
211 window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
214 $content = get_ws($tmp);
215 ok(@{$content->{nodes}} == 0, 'no tiling cons');
216 ok(@{$content->{floating_nodes}} == 0, 'one floating con');
217 @docked = get_dock_clients;
218 is(@docked, 2, 'two dock clients now');
224 exit_gracefully($pid);