]> git.sur5r.net Git - i3/i3/blob - testcases/t/525-i3bar-mouse-bindings.t
57786deaf2f8bc6e727498f61268ce450ee4e88d
[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
91 sub focus_subtest {
92     my ($subscribecb, $want, $msg) = @_;
93     my @events = events_for(
94         $subscribecb,
95         'window');
96     my @focus = map { $_->{container}->{window} } grep { $_->{change} eq 'focus' } @events;
97     is_deeply(\@focus, $want, $msg);
98 }
99
100 subtest 'button 1 moves focus left', \&focus_subtest,
101     sub {
102         xtest_button_press(1, 3, 3);
103         xtest_button_release(1, 3, 3);
104         xtest_sync_with($i3bar_window);
105     },
106     [ $left->{id} ],
107     'button 1 moves focus left';
108
109 subtest 'button 2 moves focus right', \&focus_subtest,
110     sub {
111         xtest_button_press(2, 3, 3);
112         xtest_button_release(2, 3, 3);
113         xtest_sync_with($i3bar_window);
114     },
115     [ $right->{id} ],
116     'button 2 moves focus right';
117
118 subtest 'button 3 moves focus left', \&focus_subtest,
119     sub {
120         xtest_button_press(3, 3, 3);
121         xtest_button_release(3, 3, 3);
122         xtest_sync_with($i3bar_window);
123     },
124     [ $left->{id} ],
125     'button 3 moves focus left';
126
127 subtest 'button 4 moves focus right', \&focus_subtest,
128     sub {
129         xtest_button_press(4, 3, 3);
130         xtest_button_release(4, 3, 3);
131         xtest_sync_with($i3bar_window);
132     },
133     [ $right->{id} ],
134     'button 4 moves focus right';
135
136 subtest 'button 5 moves focus left', \&focus_subtest,
137     sub {
138         xtest_button_press(5, 3, 3);
139         xtest_button_release(5, 3, 3);
140         xtest_sync_with($i3bar_window);
141     },
142     [ $left->{id} ],
143     'button 5 moves focus left';
144
145 done_testing;