2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Checks the workspace "empty" event semantics.
23 skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
25 ################################################################################
26 # check that the workspace empty event is send upon workspace switch when the
27 # old workspace is empty
28 ################################################################################
29 subtest 'Workspace empty event upon switch', sub {
30 my $ws2 = fresh_workspace;
31 my $w2 = open_window();
32 my $ws1 = fresh_workspace;
33 my $w1 = open_window();
35 cmd '[id="' . $w1->id . '"] kill';
37 my $cond = AnyEvent->condvar;
38 my $client = i3(get_socket_path(0));
39 $client->connect()->recv;
51 my $event = $cond->recv;
52 is($event->{change}, 'empty', '"Empty" event received upon workspace switch');
53 is($event->{current}->{name}, $ws1, '"current" property should be set to the workspace con');
56 ################################################################################
57 # check that no workspace empty event is send upon workspace switch if the
58 # workspace is not empty
59 ################################################################################
60 subtest 'No workspace empty event', sub {
61 my $ws2 = fresh_workspace;
62 my $w2 = open_window();
63 my $ws1 = fresh_workspace;
64 my $w1 = open_window();
67 my $cond = AnyEvent->condvar;
68 my $client = i3(get_socket_path(0));
69 $client->connect()->recv;
77 # Wait for the workspace event on a new connection. Events will be delivered
78 # to older connections earlier, so by the time it arrives here, it should be
80 my $ws_event_block_conn = i3(get_socket_path(0));
81 $ws_event_block_conn->connect()->recv;
82 $ws_event_block_conn->subscribe({ workspace => sub { $cond->send(1) }});
88 my @expected_events = grep { $_->{change} eq 'focus' } @events;
89 my @empty_events = grep { $_->{change} eq 'empty' } @events;
90 is(@expected_events, 1, '"Focus" event received');
91 is(@empty_events, 0, 'No "empty" events received');
94 ################################################################################
95 # check that workspace empty event is send when the last window has been closed
96 # on invisible workspace
97 ################################################################################
98 subtest 'Workspace empty event upon window close', sub {
99 my $ws1 = fresh_workspace;
100 my $w1 = open_window();
101 my $ws2 = fresh_workspace;
102 my $w2 = open_window();
104 my $cond = AnyEvent->condvar;
105 my $client = i3(get_socket_path(0));
106 $client->connect()->recv;
114 cmd '[id="' . $w1->id . '"] kill';
118 my $event = $cond->recv;
119 is($event->{change}, 'empty', '"Empty" event received upon window close');
120 is($event->{current}->{name}, $ws1, '"current" property should be set to the workspace con');