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);
103 subtest 'button 1 moves focus left', \&focus_subtest,
105 xtest_button_press(1, 3, 3);
106 xtest_button_release(1, 3, 3);
107 xtest_sync_with($i3bar_window);
110 'button 1 moves focus left';
112 subtest 'button 2 moves focus right', \&focus_subtest,
114 xtest_button_press(2, 3, 3);
115 xtest_button_release(2, 3, 3);
116 xtest_sync_with($i3bar_window);
119 'button 2 moves focus right';
121 subtest 'button 3 moves focus left', \&focus_subtest,
123 xtest_button_press(3, 3, 3);
124 xtest_button_release(3, 3, 3);
125 xtest_sync_with($i3bar_window);
128 'button 3 moves focus left';
130 subtest 'button 4 moves focus right', \&focus_subtest,
132 xtest_button_press(4, 3, 3);
133 xtest_button_release(4, 3, 3);
134 xtest_sync_with($i3bar_window);
137 'button 4 moves focus right';
139 subtest 'button 5 moves focus left', \&focus_subtest,
141 xtest_button_press(5, 3, 3);
142 xtest_button_release(5, 3, 3);
143 xtest_sync_with($i3bar_window);
146 'button 5 moves focus left';
148 # Test --release flag with bar bindsym.
151 my $old_focus = get_focused($ws);
152 subtest 'button 6 does not move focus while pressed', \&focus_subtest,
154 xtest_button_press(6, 3, 3);
155 xtest_sync_with($i3bar_window);
158 'button 6 does not move focus while pressed';
159 is(get_focused($ws), $old_focus, 'focus unchanged');
161 subtest 'button 6 release moves focus right', \&focus_subtest,
163 xtest_button_release(6, 3, 3);
164 xtest_sync_with($i3bar_window);
167 'button 6 release moves focus right';
169 # Test same bindsym button with and without --release.
171 subtest 'button 7 press moves focus left', \&focus_subtest,
173 xtest_button_press(7, 3, 3);
174 xtest_sync_with($i3bar_window);
177 'button 7 press moves focus left';
179 subtest 'button 7 release moves focus right', \&focus_subtest,
181 xtest_button_release(7, 3, 3);
182 xtest_sync_with($i3bar_window);
185 'button 7 release moves focus right';