]> git.sur5r.net Git - i3/i3/blob - testcases/t/525-i3bar-mouse-bindings.t
tests: replace http:// with https:// where appropriate
[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 ($cv, $timer);
38 sub reset_test {
39     $cv = AE::cv;
40     $timer = AE::timer(1, 0, sub { $cv->send(0); });
41 }
42
43 my $i3 = i3(get_socket_path());
44 $i3->connect()->recv;
45 my $ws = fresh_workspace;
46
47 reset_test;
48 $i3->subscribe({
49         window => sub {
50             my ($event) = @_;
51             if ($event->{change} eq 'focus') {
52                 $cv->send($event->{container});
53             }
54             if ($event->{change} eq 'new') {
55                 if (defined($event->{container}->{window_properties}->{class}) &&
56                     $event->{container}->{window_properties}->{class} eq 'i3bar') {
57                     $cv->send($event->{container});
58                 }
59             }
60         },
61     })->recv;
62
63 my $con;
64
65 sub i3bar_present {
66     my ($nodes) = @_;
67
68     for my $node (@{$nodes}) {
69         my $props = $node->{window_properties};
70         if (defined($props) && $props->{class} eq 'i3bar') {
71             return 1;
72         }
73     }
74
75     return 0 if !@{$nodes};
76
77     my @children = (map { @{$_->{nodes}} } @{$nodes},
78                     map { @{$_->{'floating_nodes'}} } @{$nodes});
79
80     return i3bar_present(\@children);
81 }
82
83 if (i3bar_present($i3->get_tree->recv->{nodes})) {
84     ok(1, 'i3bar present');
85 } else {
86     $con = $cv->recv;
87     ok($con, 'i3bar appeared');
88 }
89
90 my $left = open_window;
91 my $right = open_window;
92 sync_with_i3;
93 $con = $cv->recv;
94 is($con->{window}, $right->{id}, 'focus is initially on the right container');
95 reset_test;
96
97 xtest_button_press(1, 3, 3);
98 xtest_button_release(1, 3, 3);
99 sync_with_i3;
100 $con = $cv->recv;
101 is($con->{window}, $left->{id}, 'button 1 moves focus left');
102 reset_test;
103
104 xtest_button_press(2, 3, 3);
105 xtest_button_release(2, 3, 3);
106 sync_with_i3;
107 $con = $cv->recv;
108 is($con->{window}, $right->{id}, 'button 2 moves focus right');
109 reset_test;
110
111 xtest_button_press(3, 3, 3);
112 xtest_button_release(3, 3, 3);
113 sync_with_i3;
114 $con = $cv->recv;
115 is($con->{window}, $left->{id}, 'button 3 moves focus left');
116 reset_test;
117
118 xtest_button_press(4, 3, 3);
119 xtest_button_release(4, 3, 3);
120 sync_with_i3;
121 $con = $cv->recv;
122 is($con->{window}, $right->{id}, 'button 4 moves focus right');
123 reset_test;
124
125 xtest_button_press(5, 3, 3);
126 xtest_button_release(5, 3, 3);
127 sync_with_i3;
128 $con = $cv->recv;
129 is($con->{window}, $left->{id}, 'button 5 moves focus left');
130 reset_test;
131
132 done_testing;