2015-06-04 15:55:39 +02:00
|
|
|
#!perl
|
|
|
|
# vim:ts=4:sw=4:expandtab
|
|
|
|
#
|
|
|
|
# Please read the following documents before working on tests:
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/testsuite.html
|
2015-06-04 15:55:39 +02:00
|
|
|
# (or docs/testsuite)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/lib-i3test.html
|
2015-06-04 15:55:39 +02:00
|
|
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
|
|
|
#
|
2017-09-24 10:19:50 +02:00
|
|
|
# • https://build.i3wm.org/docs/ipc.html
|
2015-06-04 15:55:39 +02:00
|
|
|
# (or docs/ipc)
|
|
|
|
#
|
|
|
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
|
|
|
# (unless you are already familiar with Perl)
|
|
|
|
#
|
|
|
|
# Ensures that mouse bindings on the i3bar work correctly.
|
|
|
|
# Ticket: #1695
|
2017-09-14 12:30:42 +02:00
|
|
|
use i3test i3_config => <<EOT;
|
2015-06-04 15:55:39 +02:00
|
|
|
# i3 config file (v4)
|
|
|
|
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
|
|
|
focus_follows_mouse no
|
|
|
|
|
|
|
|
bar {
|
|
|
|
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
|
|
|
|
position top
|
|
|
|
|
|
|
|
bindsym button1 focus left
|
|
|
|
bindsym button2 focus right
|
|
|
|
bindsym button3 focus left
|
|
|
|
bindsym button4 focus right
|
|
|
|
bindsym button5 focus left
|
2017-12-08 01:23:15 +01:00
|
|
|
bindsym --release button6 focus right
|
|
|
|
bindsym button7 focus left
|
|
|
|
bindsym button7 --release focus right
|
2015-06-04 15:55:39 +02:00
|
|
|
}
|
|
|
|
EOT
|
2017-09-14 12:30:42 +02:00
|
|
|
use i3test::XTEST;
|
|
|
|
|
2016-01-04 03:48:39 +01:00
|
|
|
my $i3 = i3(get_socket_path());
|
|
|
|
$i3->connect()->recv;
|
|
|
|
my $ws = fresh_workspace;
|
2015-06-04 15:55:39 +02:00
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
my $cv = AnyEvent->condvar;
|
2017-10-05 22:03:33 +02:00
|
|
|
my $timer = AnyEvent->timer(after => 1, interval => 0, cb => sub { $cv->send(0) });
|
2016-01-04 03:48:39 +01:00
|
|
|
$i3->subscribe({
|
2015-06-04 15:55:39 +02:00
|
|
|
window => sub {
|
|
|
|
my ($event) = @_;
|
|
|
|
if ($event->{change} eq 'focus') {
|
|
|
|
$cv->send($event->{container});
|
|
|
|
}
|
2016-01-09 12:47:00 +01:00
|
|
|
if ($event->{change} eq 'new') {
|
|
|
|
if (defined($event->{container}->{window_properties}->{class}) &&
|
|
|
|
$event->{container}->{window_properties}->{class} eq 'i3bar') {
|
|
|
|
$cv->send($event->{container});
|
|
|
|
}
|
|
|
|
}
|
2015-06-04 15:55:39 +02:00
|
|
|
},
|
|
|
|
})->recv;
|
|
|
|
|
2017-09-14 12:30:42 +02:00
|
|
|
sub i3bar_present {
|
|
|
|
my ($nodes) = @_;
|
|
|
|
|
|
|
|
for my $node (@{$nodes}) {
|
|
|
|
my $props = $node->{window_properties};
|
|
|
|
if (defined($props) && $props->{class} eq 'i3bar') {
|
2017-09-30 13:04:20 +02:00
|
|
|
return $node->{window};
|
2017-09-14 12:30:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0 if !@{$nodes};
|
|
|
|
|
|
|
|
my @children = (map { @{$_->{nodes}} } @{$nodes},
|
|
|
|
map { @{$_->{'floating_nodes'}} } @{$nodes});
|
|
|
|
|
|
|
|
return i3bar_present(\@children);
|
|
|
|
}
|
|
|
|
|
2017-09-30 13:04:20 +02:00
|
|
|
my $i3bar_window = i3bar_present($i3->get_tree->recv->{nodes});
|
|
|
|
if ($i3bar_window) {
|
2017-09-14 12:30:42 +02:00
|
|
|
ok(1, 'i3bar present');
|
|
|
|
} else {
|
2017-09-24 15:40:30 +02:00
|
|
|
my $con = $cv->recv;
|
2017-09-14 12:30:42 +02:00
|
|
|
ok($con, 'i3bar appeared');
|
2017-09-30 13:04:20 +02:00
|
|
|
$i3bar_window = $con->{window};
|
2017-09-14 12:30:42 +02:00
|
|
|
}
|
2016-01-09 12:47:00 +01:00
|
|
|
|
2017-09-30 13:04:20 +02:00
|
|
|
diag('i3bar window = ' . $i3bar_window);
|
|
|
|
|
2016-01-04 03:48:39 +01:00
|
|
|
my $left = open_window;
|
|
|
|
my $right = open_window;
|
|
|
|
sync_with_i3;
|
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
sub focus_subtest {
|
|
|
|
my ($subscribecb, $want, $msg) = @_;
|
|
|
|
my @events = events_for(
|
|
|
|
$subscribecb,
|
|
|
|
'window');
|
|
|
|
my @focus = map { $_->{container}->{window} } grep { $_->{change} eq 'focus' } @events;
|
|
|
|
is_deeply(\@focus, $want, $msg);
|
|
|
|
}
|
2016-01-04 03:48:39 +01:00
|
|
|
|
2017-09-24 15:40:30 +02:00
|
|
|
subtest 'button 1 moves focus left', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(1, 3, 3);
|
|
|
|
xtest_button_release(1, 3, 3);
|
2017-09-30 13:04:20 +02:00
|
|
|
xtest_sync_with($i3bar_window);
|
2017-09-24 15:40:30 +02:00
|
|
|
},
|
|
|
|
[ $left->{id} ],
|
|
|
|
'button 1 moves focus left';
|
|
|
|
|
|
|
|
subtest 'button 2 moves focus right', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(2, 3, 3);
|
|
|
|
xtest_button_release(2, 3, 3);
|
2017-09-30 13:04:20 +02:00
|
|
|
xtest_sync_with($i3bar_window);
|
2017-09-24 15:40:30 +02:00
|
|
|
},
|
|
|
|
[ $right->{id} ],
|
|
|
|
'button 2 moves focus right';
|
|
|
|
|
|
|
|
subtest 'button 3 moves focus left', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(3, 3, 3);
|
|
|
|
xtest_button_release(3, 3, 3);
|
2017-09-30 13:04:20 +02:00
|
|
|
xtest_sync_with($i3bar_window);
|
2017-09-24 15:40:30 +02:00
|
|
|
},
|
|
|
|
[ $left->{id} ],
|
|
|
|
'button 3 moves focus left';
|
|
|
|
|
|
|
|
subtest 'button 4 moves focus right', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(4, 3, 3);
|
|
|
|
xtest_button_release(4, 3, 3);
|
2017-09-30 13:04:20 +02:00
|
|
|
xtest_sync_with($i3bar_window);
|
2017-09-24 15:40:30 +02:00
|
|
|
},
|
|
|
|
[ $right->{id} ],
|
|
|
|
'button 4 moves focus right';
|
|
|
|
|
|
|
|
subtest 'button 5 moves focus left', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(5, 3, 3);
|
|
|
|
xtest_button_release(5, 3, 3);
|
2017-09-30 13:04:20 +02:00
|
|
|
xtest_sync_with($i3bar_window);
|
2017-09-24 15:40:30 +02:00
|
|
|
},
|
|
|
|
[ $left->{id} ],
|
|
|
|
'button 5 moves focus left';
|
2016-01-04 03:48:39 +01:00
|
|
|
|
2017-12-08 01:23:15 +01:00
|
|
|
# Test --release flag with bar bindsym.
|
|
|
|
# See issue: #3068.
|
|
|
|
|
|
|
|
my $old_focus = get_focused($ws);
|
|
|
|
subtest 'button 6 does not move focus while pressed', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(6, 3, 3);
|
|
|
|
xtest_sync_with($i3bar_window);
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
'button 6 does not move focus while pressed';
|
|
|
|
is(get_focused($ws), $old_focus, 'focus unchanged');
|
|
|
|
|
|
|
|
subtest 'button 6 release moves focus right', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_release(6, 3, 3);
|
|
|
|
xtest_sync_with($i3bar_window);
|
|
|
|
},
|
|
|
|
[ $right->{id} ],
|
|
|
|
'button 6 release moves focus right';
|
|
|
|
|
|
|
|
# Test same bindsym button with and without --release.
|
|
|
|
|
|
|
|
subtest 'button 7 press moves focus left', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_press(7, 3, 3);
|
|
|
|
xtest_sync_with($i3bar_window);
|
|
|
|
},
|
|
|
|
[ $left->{id} ],
|
|
|
|
'button 7 press moves focus left';
|
|
|
|
|
|
|
|
subtest 'button 7 release moves focus right', \&focus_subtest,
|
|
|
|
sub {
|
|
|
|
xtest_button_release(7, 3, 3);
|
|
|
|
xtest_sync_with($i3bar_window);
|
|
|
|
},
|
|
|
|
[ $right->{id} ],
|
|
|
|
'button 7 release moves focus right';
|
|
|
|
|
2015-06-04 15:55:39 +02:00
|
|
|
done_testing;
|