2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests for the focus_on_window_activation directive
19 use i3test i3_autostart => 0;
20 use List::Util qw(first);
22 my ($config, $pid, $first, $second, $ws1, $ws2);
24 sub send_net_active_window {
27 my $msg = pack "CCSLLLLLLL",
28 X11::XCB::CLIENT_MESSAGE, # response_type
31 $id, # destination window
32 $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
36 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
39 sub get_urgency_for_window_on_workspace {
42 my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
43 return $current->{urgent};
46 #####################################################################
47 # 1: If mode is set to 'urgent' and the target workspace is visible,
48 # check that the urgent flag is set and focus is not lost.
49 #####################################################################
53 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
55 focus_on_window_activation urgent
58 $pid = launch_with_config($config);
60 my $ws = fresh_workspace;
62 $second = open_window;
64 send_net_active_window($first->id);
67 is($x->input_focus, $second->id, 'second window is still focused');
68 is(get_urgency_for_window_on_workspace($ws, $first), 1, 'first window is marked urgent');
70 exit_gracefully($pid);
72 #####################################################################
73 # 2: If mode is set to 'urgent' and the target workspace is not
74 # visible, check that the urgent flag is set and focus is not lost.
75 #####################################################################
79 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
81 focus_on_window_activation urgent
84 $pid = launch_with_config($config);
86 $ws1 = fresh_workspace;
88 $ws2 = fresh_workspace;
89 $second = open_window;
91 send_net_active_window($first->id);
94 is(focused_ws(), $ws2, 'second workspace is still focused');
95 is($x->input_focus, $second->id, 'second window is still focused');
96 is(get_urgency_for_window_on_workspace($ws1, $first), 1, 'first window is marked urgent');
98 exit_gracefully($pid);
100 #####################################################################
101 # 3: If mode is set to 'focus' and the target workspace is visible,
102 # check that the focus is switched.
103 #####################################################################
106 # i3 config file (v4)
107 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
109 focus_on_window_activation focus
112 $pid = launch_with_config($config);
114 $ws = fresh_workspace;
115 $first = open_window;
116 $second = open_window;
118 send_net_active_window($first->id);
121 is($x->input_focus, $first->id, 'first window is now focused');
122 ok(!get_urgency_for_window_on_workspace($ws, $first), 'first window is not marked urgent');
124 exit_gracefully($pid);
126 #####################################################################
127 # 4: If mode is set to 'focus' and the target workspace is not
128 # visible, check that the focus switched.
129 #####################################################################
132 # i3 config file (v4)
133 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
135 focus_on_window_activation focus
138 $pid = launch_with_config($config);
140 $ws1 = fresh_workspace;
141 $first = open_window;
142 $ws2 = fresh_workspace;
143 $second = open_window;
145 send_net_active_window($first->id);
148 is(focused_ws(), $ws1, 'first workspace is now focused');
149 is($x->input_focus, $first->id, 'first window is now focused');
150 ok(!get_urgency_for_window_on_workspace($ws1, $first), 'first window is not marked urgent');
152 exit_gracefully($pid);
154 #####################################################################
155 # 5: If mode is set to 'none' and the target workspace is visible,
156 # check that nothing happens.
157 #####################################################################
160 # i3 config file (v4)
161 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
163 focus_on_window_activation none
166 $pid = launch_with_config($config);
168 $ws = fresh_workspace;
169 $first = open_window;
170 $second = open_window;
172 send_net_active_window($first->id);
175 is($x->input_focus, $second->id, 'second window is still focused');
176 ok(!get_urgency_for_window_on_workspace($ws, $first), 'first window is not marked urgent');
178 exit_gracefully($pid);
180 #####################################################################
181 # 6: If mode is set to 'none' and the target workspace is not
182 # visible, check that nothing happens.
183 #####################################################################
186 # i3 config file (v4)
187 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
189 focus_on_window_activation none
192 $pid = launch_with_config($config);
194 $ws1 = fresh_workspace;
195 $first = open_window;
196 $ws2 = fresh_workspace;
197 $second = open_window;
199 send_net_active_window($first->id);
202 is(focused_ws(), $ws2, 'second workspace is still focused');
203 is($x->input_focus, $second->id, 'second window is still focused');
204 ok(!get_urgency_for_window_on_workspace($ws1, $first), 'first window is not marked urgent');
206 exit_gracefully($pid);