]> git.sur5r.net Git - i3/i3/blob - testcases/t/240-focus-on-window-activation.t
Remove trailing whitespace from Perl scripts
[i3/i3] / testcases / t / 240-focus-on-window-activation.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Tests for the focus_on_window_activation directive
18 # Ticket: #1426
19 use i3test i3_autostart => 0;
20 use List::Util qw(first);
21
22 my ($config, $pid, $first, $second, $ws1, $ws2);
23
24 sub send_net_active_window {
25     my ($id) = @_;
26
27     my $msg = pack "CCSLLLLLLL",
28         X11::XCB::CLIENT_MESSAGE, # response_type
29         32, # format
30         0, # sequence
31         $id, # destination window
32         $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
33         0, # source
34         0, 0, 0, 0;
35
36     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
37 }
38
39 sub get_urgency_for_window_on_workspace {
40     my ($ws, $con) = @_;
41
42     my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
43     return $current->{urgent};
44 }
45
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 #####################################################################
50
51 $config = <<EOT;
52 # i3 config file (v4)
53 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
54
55 focus_on_window_activation urgent
56 EOT
57
58 $pid = launch_with_config($config);
59
60 my $ws = fresh_workspace;
61 $first = open_window;
62 $second = open_window;
63
64 send_net_active_window($first->id);
65 sync_with_i3;
66
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');
69
70 exit_gracefully($pid);
71
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 #####################################################################
76
77 $config = <<EOT;
78 # i3 config file (v4)
79 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
80
81 focus_on_window_activation urgent
82 EOT
83
84 $pid = launch_with_config($config);
85
86 $ws1 = fresh_workspace;
87 $first = open_window;
88 $ws2 = fresh_workspace;
89 $second = open_window;
90
91 send_net_active_window($first->id);
92 sync_with_i3;
93
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');
97
98 exit_gracefully($pid);
99
100 #####################################################################
101 # 3: If mode is set to 'focus' and the target workspace is visible,
102 #    check that the focus is switched.
103 #####################################################################
104
105 $config = <<EOT;
106 # i3 config file (v4)
107 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
108
109 focus_on_window_activation focus
110 EOT
111
112 $pid = launch_with_config($config);
113
114 $ws = fresh_workspace;
115 $first = open_window;
116 $second = open_window;
117
118 send_net_active_window($first->id);
119 sync_with_i3;
120
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');
123
124 exit_gracefully($pid);
125
126 #####################################################################
127 # 4: If mode is set to 'focus' and the target workspace is not
128 #    visible, check that the focus switched.
129 #####################################################################
130
131 $config = <<EOT;
132 # i3 config file (v4)
133 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
134
135 focus_on_window_activation focus
136 EOT
137
138 $pid = launch_with_config($config);
139
140 $ws1 = fresh_workspace;
141 $first = open_window;
142 $ws2 = fresh_workspace;
143 $second = open_window;
144
145 send_net_active_window($first->id);
146 sync_with_i3;
147
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');
151
152 exit_gracefully($pid);
153
154 #####################################################################
155 # 5: If mode is set to 'none' and the target workspace is visible,
156 #    check that nothing happens.
157 #####################################################################
158
159 $config = <<EOT;
160 # i3 config file (v4)
161 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
162
163 focus_on_window_activation none
164 EOT
165
166 $pid = launch_with_config($config);
167
168 $ws = fresh_workspace;
169 $first = open_window;
170 $second = open_window;
171
172 send_net_active_window($first->id);
173 sync_with_i3;
174
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');
177
178 exit_gracefully($pid);
179
180 #####################################################################
181 # 6: If mode is set to 'none' and the target workspace is not
182 #    visible, check that nothing happens.
183 #####################################################################
184
185 $config = <<EOT;
186 # i3 config file (v4)
187 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
188
189 focus_on_window_activation none
190 EOT
191
192 $pid = launch_with_config($config);
193
194 $ws1 = fresh_workspace;
195 $first = open_window;
196 $ws2 = fresh_workspace;
197 $second = open_window;
198
199 send_net_active_window($first->id);
200 sync_with_i3;
201
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');
205
206 exit_gracefully($pid);
207
208 done_testing;