2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://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 sub send_net_active_window {
25 my $msg = pack "CCSLLLLLLL",
26 X11::XCB::CLIENT_MESSAGE, # response_type
29 $id, # destination window
30 $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
34 $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
37 sub get_urgency_for_window_on_workspace {
40 my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
41 return $current->{urgent};
44 #####################################################################
45 # 1: If mode is set to 'urgent' and the target workspace is visible,
46 # check that the urgent flag is set and focus is not lost.
47 #####################################################################
51 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
53 focus_on_window_activation urgent
56 my $pid = launch_with_config($config);
58 my $ws = fresh_workspace;
59 my $first = open_window;
60 my $second = open_window;
62 send_net_active_window($first->id);
65 is($x->input_focus, $second->id, 'second window is still focused');
66 is(get_urgency_for_window_on_workspace($ws, $first), 1, 'first window is marked urgent');
68 exit_gracefully($pid);
70 #####################################################################
71 # 2: If mode is set to 'urgent' and the target workspace is not
72 # visible, check that the urgent flag is set and focus is not lost.
73 #####################################################################
77 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
79 focus_on_window_activation urgent
82 my $pid = launch_with_config($config);
84 my $ws1 = fresh_workspace;
85 my $first = open_window;
86 my $ws2 = fresh_workspace;
87 my $second = open_window;
89 send_net_active_window($first->id);
92 is(focused_ws(), $ws2, 'second workspace is still focused');
93 is($x->input_focus, $second->id, 'second window is still focused');
94 is(get_urgency_for_window_on_workspace($ws1, $first), 1, 'first window is marked urgent');
96 exit_gracefully($pid);
98 #####################################################################
99 # 3: If mode is set to 'focus' and the target workspace is visible,
100 # check that the focus is switched.
101 #####################################################################
104 # i3 config file (v4)
105 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
107 focus_on_window_activation focus
110 my $pid = launch_with_config($config);
112 my $ws = fresh_workspace;
113 my $first = open_window;
114 my $second = open_window;
116 send_net_active_window($first->id);
119 is($x->input_focus, $first->id, 'first window is now focused');
120 ok(!get_urgency_for_window_on_workspace($ws, $first), 'first window is not marked urgent');
122 exit_gracefully($pid);
124 #####################################################################
125 # 4: If mode is set to 'focus' and the target workspace is not
126 # visible, check that the focus switched.
127 #####################################################################
130 # i3 config file (v4)
131 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
133 focus_on_window_activation focus
136 my $pid = launch_with_config($config);
138 my $ws1 = fresh_workspace;
139 my $first = open_window;
140 my $ws2 = fresh_workspace;
141 my $second = open_window;
143 send_net_active_window($first->id);
146 is(focused_ws(), $ws1, 'first workspace is now focused');
147 is($x->input_focus, $first->id, 'first window is now focused');
148 ok(!get_urgency_for_window_on_workspace($ws1, $first), 'first window is not marked urgent');
150 exit_gracefully($pid);
152 #####################################################################
153 # 5: If mode is set to 'none' and the target workspace is visible,
154 # check that nothing happens.
155 #####################################################################
158 # i3 config file (v4)
159 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
161 focus_on_window_activation none
164 my $pid = launch_with_config($config);
166 my $ws = fresh_workspace;
167 my $first = open_window;
168 my $second = open_window;
170 send_net_active_window($first->id);
173 is($x->input_focus, $second->id, 'second window is still focused');
174 ok(!get_urgency_for_window_on_workspace($ws, $first), 'first window is not marked urgent');
176 exit_gracefully($pid);
178 #####################################################################
179 # 6: If mode is set to 'none' and the target workspace is not
180 # visible, check that nothing happens.
181 #####################################################################
184 # i3 config file (v4)
185 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
187 focus_on_window_activation none
190 my $pid = launch_with_config($config);
192 my $ws1 = fresh_workspace;
193 my $first = open_window;
194 my $ws2 = fresh_workspace;
195 my $second = open_window;
197 send_net_active_window($first->id);
200 is(focused_ws(), $ws2, 'second workspace is still focused');
201 is($x->input_focus, $second->id, 'second window is still focused');
202 ok(!get_urgency_for_window_on_workspace($ws1, $first), 'first window is not marked urgent');
204 exit_gracefully($pid);