]> git.sur5r.net Git - i3/i3/blob - testcases/t/525-i3bar-mouse-bindings.t
3593ea0b54cc70f72da6dc1b82336cd2dfe219cc
[i3/i3] / testcases / t / 525-i3bar-mouse-bindings.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 # Ensures that mouse bindings on the i3bar work correctly.
18 # Ticket: #1695
19 use i3test i3_config => <<EOT;
20 # i3 config file (v4)
21 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
22 focus_follows_mouse no
23
24 bar {
25     font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
26     position top
27
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
36 }
37 EOT
38 use i3test::XTEST;
39
40 my $i3 = i3(get_socket_path());
41 $i3->connect()->recv;
42 my $ws = fresh_workspace;
43
44 my $cv = AnyEvent->condvar;
45 my $timer = AnyEvent->timer(after => 1, interval => 0, cb => sub { $cv->send(0) });
46 $i3->subscribe({
47         window => sub {
48             my ($event) = @_;
49             if ($event->{change} eq 'focus') {
50                 $cv->send($event->{container});
51             }
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});
56                 }
57             }
58         },
59     })->recv;
60
61 sub i3bar_present {
62     my ($nodes) = @_;
63
64     for my $node (@{$nodes}) {
65         my $props = $node->{window_properties};
66         if (defined($props) && $props->{class} eq 'i3bar') {
67             return $node->{window};
68         }
69     }
70
71     return 0 if !@{$nodes};
72
73     my @children = (map { @{$_->{nodes}} } @{$nodes},
74                     map { @{$_->{'floating_nodes'}} } @{$nodes});
75
76     return i3bar_present(\@children);
77 }
78
79 my $i3bar_window = i3bar_present($i3->get_tree->recv->{nodes});
80 if ($i3bar_window) {
81     ok(1, 'i3bar present');
82 } else {
83     my $con = $cv->recv;
84     ok($con, 'i3bar appeared');
85     $i3bar_window = $con->{window};
86 }
87
88 diag('i3bar window = ' . $i3bar_window);
89
90 my $left = open_window;
91 my $right = open_window;
92 sync_with_i3;
93
94 sub focus_subtest {
95     my ($subscribecb, $want, $msg) = @_;
96     my @events = events_for(
97         $subscribecb,
98         'window');
99     my @focus = map { $_->{container}->{window} } grep { $_->{change} eq 'focus' } @events;
100     is_deeply(\@focus, $want, $msg);
101 }
102
103 sub sync {
104     # Ensure XTEST events were sent to i3, which grabs and hence needs to
105     # forward any events to i3bar:
106     xtest_sync_with_i3;
107     # Ensure any pending i3bar IPC messages were handled by i3:
108     xtest_sync_with($i3bar_window);
109 }
110
111 subtest 'button 1 moves focus left', \&focus_subtest,
112     sub {
113         xtest_button_press(1, 3, 3);
114         xtest_button_release(1, 3, 3);
115         sync;
116     },
117     [ $left->{id} ],
118     'button 1 moves focus left';
119
120 subtest 'button 2 moves focus right', \&focus_subtest,
121     sub {
122         xtest_button_press(2, 3, 3);
123         xtest_button_release(2, 3, 3);
124         sync;
125     },
126     [ $right->{id} ],
127     'button 2 moves focus right';
128
129 subtest 'button 3 moves focus left', \&focus_subtest,
130     sub {
131         xtest_button_press(3, 3, 3);
132         xtest_button_release(3, 3, 3);
133         sync;
134     },
135     [ $left->{id} ],
136     'button 3 moves focus left';
137
138 subtest 'button 4 moves focus right', \&focus_subtest,
139     sub {
140         xtest_button_press(4, 3, 3);
141         xtest_button_release(4, 3, 3);
142         sync;
143     },
144     [ $right->{id} ],
145     'button 4 moves focus right';
146
147 subtest 'button 5 moves focus left', \&focus_subtest,
148     sub {
149         xtest_button_press(5, 3, 3);
150         xtest_button_release(5, 3, 3);
151         sync;
152     },
153     [ $left->{id} ],
154     'button 5 moves focus left';
155
156 # Test --release flag with bar bindsym.
157 # See issue: #3068.
158
159 my $old_focus = get_focused($ws);
160 subtest 'button 6 does not move focus while pressed', \&focus_subtest,
161     sub {
162         xtest_button_press(6, 3, 3);
163         sync;
164     },
165     [],
166     'button 6 does not move focus while pressed';
167 is(get_focused($ws), $old_focus, 'focus unchanged');
168
169 subtest 'button 6 release moves focus right', \&focus_subtest,
170     sub {
171         xtest_button_release(6, 3, 3);
172         sync;
173     },
174     [ $right->{id} ],
175     'button 6 release moves focus right';
176
177 # Test same bindsym button with and without --release.
178
179 subtest 'button 7 press moves focus left', \&focus_subtest,
180     sub {
181         xtest_button_press(7, 3, 3);
182         sync;
183     },
184     [ $left->{id} ],
185     'button 7 press moves focus left';
186
187 subtest 'button 7 release moves focus right', \&focus_subtest,
188     sub {
189         xtest_button_release(7, 3, 3);
190         sync;
191     },
192     [ $right->{id} ],
193     'button 7 release moves focus right';
194
195 done_testing;