]> git.sur5r.net Git - i3/i3/blob - testcases/t/240-focus-on-window-activation.t
Merge pull request #1630 from Deiz/consistent-mouse-actions
[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 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 sub send_net_active_window {
23     my ($id) = @_; 
24
25     my $msg = pack "CCSLLLLLLL",
26         X11::XCB::CLIENT_MESSAGE, # response_type
27         32, # format
28         0, # sequence
29         $id, # destination window
30         $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
31         0, # source
32         0, 0, 0, 0;
33
34     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
35 }
36
37 sub get_urgency_for_window_on_workspace {
38     my ($ws, $con) = @_;
39
40     my $current = first { $_->{window} == $con->{id} } @{get_ws_content($ws)};
41     return $current->{urgent};
42 }
43
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 #####################################################################
48
49 my $config = <<EOT;
50 # i3 config file (v4)
51 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
52
53 focus_on_window_activation urgent
54 EOT
55
56 my $pid = launch_with_config($config);
57
58 my $ws = fresh_workspace;
59 my $first = open_window;
60 my $second = open_window;
61
62 send_net_active_window($first->id);
63 sync_with_i3;
64
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');
67
68 exit_gracefully($pid);
69
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 #####################################################################
74
75 my $config = <<EOT;
76 # i3 config file (v4)
77 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
78
79 focus_on_window_activation urgent
80 EOT
81
82 my $pid = launch_with_config($config);
83
84 my $ws1 = fresh_workspace;
85 my $first = open_window;
86 my $ws2 = fresh_workspace;
87 my $second = open_window;
88
89 send_net_active_window($first->id);
90 sync_with_i3;
91
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');
95
96 exit_gracefully($pid);
97
98 #####################################################################
99 # 3: If mode is set to 'focus' and the target workspace is visible,
100 #    check that the focus is switched.
101 #####################################################################
102
103 my $config = <<EOT;
104 # i3 config file (v4)
105 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
106
107 focus_on_window_activation focus
108 EOT
109
110 my $pid = launch_with_config($config);
111
112 my $ws = fresh_workspace;
113 my $first = open_window;
114 my $second = open_window;
115
116 send_net_active_window($first->id);
117 sync_with_i3;
118
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');
121
122 exit_gracefully($pid);
123
124 #####################################################################
125 # 4: If mode is set to 'focus' and the target workspace is not
126 #    visible, check that the focus switched.
127 #####################################################################
128
129 my $config = <<EOT;
130 # i3 config file (v4)
131 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
132
133 focus_on_window_activation focus
134 EOT
135
136 my $pid = launch_with_config($config);
137
138 my $ws1 = fresh_workspace;
139 my $first = open_window;
140 my $ws2 = fresh_workspace;
141 my $second = open_window;
142
143 send_net_active_window($first->id);
144 sync_with_i3;
145
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');
149
150 exit_gracefully($pid);
151
152 #####################################################################
153 # 5: If mode is set to 'none' and the target workspace is visible,
154 #    check that nothing happens.
155 #####################################################################
156
157 my $config = <<EOT;
158 # i3 config file (v4)
159 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
160
161 focus_on_window_activation none
162 EOT
163
164 my $pid = launch_with_config($config);
165
166 my $ws = fresh_workspace;
167 my $first = open_window;
168 my $second = open_window;
169
170 send_net_active_window($first->id);
171 sync_with_i3;
172
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');
175
176 exit_gracefully($pid);
177
178 #####################################################################
179 # 6: If mode is set to 'none' and the target workspace is not
180 #    visible, check that nothing happens.
181 #####################################################################
182
183 my $config = <<EOT;
184 # i3 config file (v4)
185 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
186
187 focus_on_window_activation none
188 EOT
189
190 my $pid = launch_with_config($config);
191
192 my $ws1 = fresh_workspace;
193 my $first = open_window;
194 my $ws2 = fresh_workspace;
195 my $second = open_window;
196
197 send_net_active_window($first->id);
198 sync_with_i3;
199
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');
203
204 exit_gracefully($pid);
205
206 done_testing;