]> git.sur5r.net Git - i3/i3/blob - testcases/t/525-i3bar-mouse-bindings.t
Fix AnyEvent->timer call (#3008)
[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 }
34 EOT
35 use i3test::XTEST;
36
37 my $i3 = i3(get_socket_path());
38 $i3->connect()->recv;
39 my $ws = fresh_workspace;
40
41 my $cv = AnyEvent->condvar;
42 my $timer = AnyEvent->timer(after => 1, interval => 0, cb => sub { $cv->send(0) });
43 $i3->subscribe({
44         window => sub {
45             my ($event) = @_;
46             if ($event->{change} eq 'focus') {
47                 $cv->send($event->{container});
48             }
49             if ($event->{change} eq 'new') {
50                 if (defined($event->{container}->{window_properties}->{class}) &&
51                     $event->{container}->{window_properties}->{class} eq 'i3bar') {
52                     $cv->send($event->{container});
53                 }
54             }
55         },
56     })->recv;
57
58 sub i3bar_present {
59     my ($nodes) = @_;
60
61     for my $node (@{$nodes}) {
62         my $props = $node->{window_properties};
63         if (defined($props) && $props->{class} eq 'i3bar') {
64             return $node->{window};
65         }
66     }
67
68     return 0 if !@{$nodes};
69
70     my @children = (map { @{$_->{nodes}} } @{$nodes},
71                     map { @{$_->{'floating_nodes'}} } @{$nodes});
72
73     return i3bar_present(\@children);
74 }
75
76 my $i3bar_window = i3bar_present($i3->get_tree->recv->{nodes});
77 if ($i3bar_window) {
78     ok(1, 'i3bar present');
79 } else {
80     my $con = $cv->recv;
81     ok($con, 'i3bar appeared');
82     $i3bar_window = $con->{window};
83 }
84
85 diag('i3bar window = ' . $i3bar_window);
86
87 my $left = open_window;
88 my $right = open_window;
89 sync_with_i3;
90 my $con = $cv->recv;
91 is($con->{window}, $right->{id}, 'focus is initially on the right container');
92
93 sub focus_subtest {
94     my ($subscribecb, $want, $msg) = @_;
95     my @events = events_for(
96         $subscribecb,
97         'window');
98     my @focus = map { $_->{container}->{window} } grep { $_->{change} eq 'focus' } @events;
99     is_deeply(\@focus, $want, $msg);
100 }
101
102 subtest 'button 1 moves focus left', \&focus_subtest,
103     sub {
104         xtest_button_press(1, 3, 3);
105         xtest_button_release(1, 3, 3);
106         xtest_sync_with($i3bar_window);
107     },
108     [ $left->{id} ],
109     'button 1 moves focus left';
110
111 subtest 'button 2 moves focus right', \&focus_subtest,
112     sub {
113         xtest_button_press(2, 3, 3);
114         xtest_button_release(2, 3, 3);
115         xtest_sync_with($i3bar_window);
116     },
117     [ $right->{id} ],
118     'button 2 moves focus right';
119
120 subtest 'button 3 moves focus left', \&focus_subtest,
121     sub {
122         xtest_button_press(3, 3, 3);
123         xtest_button_release(3, 3, 3);
124         xtest_sync_with($i3bar_window);
125     },
126     [ $left->{id} ],
127     'button 3 moves focus left';
128
129 subtest 'button 4 moves focus right', \&focus_subtest,
130     sub {
131         xtest_button_press(4, 3, 3);
132         xtest_button_release(4, 3, 3);
133         xtest_sync_with($i3bar_window);
134     },
135     [ $right->{id} ],
136     'button 4 moves focus right';
137
138 subtest 'button 5 moves focus left', \&focus_subtest,
139     sub {
140         xtest_button_press(5, 3, 3);
141         xtest_button_release(5, 3, 3);
142         xtest_sync_with($i3bar_window);
143     },
144     [ $left->{id} ],
145     'button 5 moves focus left';
146
147 done_testing;