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 # Ensures that mouse bindings on the i3bar work correctly.
19 use i3test i3_config => <<EOT;
21 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
22 focus_follows_mouse no
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
28 bindsym button1 focus left
29 bindsym button2 focus right
30 bindsym button3 focus left
31 bindsym button4 focus right
32 bindsym button5 focus left
33 bindsym --release button6 focus right
34 bindsym button7 focus left
35 bindsym button7 --release focus right
40 my $i3 = i3(get_socket_path());
42 my $ws = fresh_workspace;
44 my $cv = AnyEvent->condvar;
45 my $timer = AnyEvent->timer(after => 1, interval => 0, cb => sub { $cv->send(0) });
49 if ($event->{change} eq 'focus') {
50 $cv->send($event->{container});
52 if ($event->{change} eq 'new') {
53 if (defined($event->{container}->{window_properties}->{class}) &&
54 $event->{container}->{window_properties}->{class} eq 'i3bar') {
55 $cv->send($event->{container});
64 for my $node (@{$nodes}) {
65 my $props = $node->{window_properties};
66 if (defined($props) && $props->{class} eq 'i3bar') {
67 return $node->{window};
71 return 0 if !@{$nodes};
73 my @children = (map { @{$_->{nodes}} } @{$nodes},
74 map { @{$_->{'floating_nodes'}} } @{$nodes});
76 return i3bar_present(\@children);
79 my $i3bar_window = i3bar_present($i3->get_tree->recv->{nodes});
81 ok(1, 'i3bar present');
84 ok($con, 'i3bar appeared');
85 $i3bar_window = $con->{window};
88 diag('i3bar window = ' . $i3bar_window);
90 my $left = open_window;
91 my $right = open_window;
95 my ($subscribecb, $want, $msg) = @_;
96 my @events = events_for(
99 my @focus = map { $_->{container}->{window} } grep { $_->{change} eq 'focus' } @events;
100 is_deeply(\@focus, $want, $msg);
104 # Ensure XTEST events were sent to i3, which grabs and hence needs to
105 # forward any events to i3bar:
107 # Ensure any pending i3bar IPC messages were handled by i3:
108 xtest_sync_with($i3bar_window);
111 subtest 'button 1 moves focus left', \&focus_subtest,
113 xtest_button_press(1, 3, 3);
114 xtest_button_release(1, 3, 3);
118 'button 1 moves focus left';
120 subtest 'button 2 moves focus right', \&focus_subtest,
122 xtest_button_press(2, 3, 3);
123 xtest_button_release(2, 3, 3);
127 'button 2 moves focus right';
129 subtest 'button 3 moves focus left', \&focus_subtest,
131 xtest_button_press(3, 3, 3);
132 xtest_button_release(3, 3, 3);
136 'button 3 moves focus left';
138 subtest 'button 4 moves focus right', \&focus_subtest,
140 xtest_button_press(4, 3, 3);
141 xtest_button_release(4, 3, 3);
145 'button 4 moves focus right';
147 subtest 'button 5 moves focus left', \&focus_subtest,
149 xtest_button_press(5, 3, 3);
150 xtest_button_release(5, 3, 3);
154 'button 5 moves focus left';
156 # Test --release flag with bar bindsym.
159 my $old_focus = get_focused($ws);
160 subtest 'button 6 does not move focus while pressed', \&focus_subtest,
162 xtest_button_press(6, 3, 3);
166 'button 6 does not move focus while pressed';
167 is(get_focused($ws), $old_focus, 'focus unchanged');
169 subtest 'button 6 release moves focus right', \&focus_subtest,
171 xtest_button_release(6, 3, 3);
175 'button 6 release moves focus right';
177 # Test same bindsym button with and without --release.
179 subtest 'button 7 press moves focus left', \&focus_subtest,
181 xtest_button_press(7, 3, 3);
185 'button 7 press moves focus left';
187 subtest 'button 7 release moves focus right', \&focus_subtest,
189 xtest_button_release(7, 3, 3);
193 'button 7 release moves focus right';