]> git.sur5r.net Git - i3/i3/blob - testcases/t/525-i3bar-mouse-bindings.t
8755278508e0391563ee8f0ae96ab8db7ff12898
[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 subtest 'button 1 moves focus left', \&focus_subtest,
104     sub {
105         xtest_button_press(1, 3, 3);
106         xtest_button_release(1, 3, 3);
107         xtest_sync_with($i3bar_window);
108     },
109     [ $left->{id} ],
110     'button 1 moves focus left';
111
112 subtest 'button 2 moves focus right', \&focus_subtest,
113     sub {
114         xtest_button_press(2, 3, 3);
115         xtest_button_release(2, 3, 3);
116         xtest_sync_with($i3bar_window);
117     },
118     [ $right->{id} ],
119     'button 2 moves focus right';
120
121 subtest 'button 3 moves focus left', \&focus_subtest,
122     sub {
123         xtest_button_press(3, 3, 3);
124         xtest_button_release(3, 3, 3);
125         xtest_sync_with($i3bar_window);
126     },
127     [ $left->{id} ],
128     'button 3 moves focus left';
129
130 subtest 'button 4 moves focus right', \&focus_subtest,
131     sub {
132         xtest_button_press(4, 3, 3);
133         xtest_button_release(4, 3, 3);
134         xtest_sync_with($i3bar_window);
135     },
136     [ $right->{id} ],
137     'button 4 moves focus right';
138
139 subtest 'button 5 moves focus left', \&focus_subtest,
140     sub {
141         xtest_button_press(5, 3, 3);
142         xtest_button_release(5, 3, 3);
143         xtest_sync_with($i3bar_window);
144     },
145     [ $left->{id} ],
146     'button 5 moves focus left';
147
148 # Test --release flag with bar bindsym.
149 # See issue: #3068.
150
151 my $old_focus = get_focused($ws);
152 subtest 'button 6 does not move focus while pressed', \&focus_subtest,
153     sub {
154         xtest_button_press(6, 3, 3);
155         xtest_sync_with($i3bar_window);
156     },
157     [],
158     'button 6 does not move focus while pressed';
159 is(get_focused($ws), $old_focus, 'focus unchanged');
160
161 subtest 'button 6 release moves focus right', \&focus_subtest,
162     sub {
163         xtest_button_release(6, 3, 3);
164         xtest_sync_with($i3bar_window);
165     },
166     [ $right->{id} ],
167     'button 6 release moves focus right';
168
169 # Test same bindsym button with and without --release.
170
171 subtest 'button 7 press moves focus left', \&focus_subtest,
172     sub {
173         xtest_button_press(7, 3, 3);
174         xtest_sync_with($i3bar_window);
175     },
176     [ $left->{id} ],
177     'button 7 press moves focus left';
178
179 subtest 'button 7 release moves focus right', \&focus_subtest,
180     sub {
181         xtest_button_release(7, 3, 3);
182         xtest_sync_with($i3bar_window);
183     },
184     [ $right->{id} ],
185     'button 7 release moves focus right';
186
187 done_testing;