]> git.sur5r.net Git - i3/i3/blob - testcases/t/227-ipc-workspace-empty.t
Merge branch 'fix-tray-restart'
[i3/i3] / testcases / t / 227-ipc-workspace-empty.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 # Checks the workspace "empty" event semantics.
18 #
19 use i3test;
20
21 SKIP: {
22
23     skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
24
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();
34
35     cmd '[id="' . $w1->id . '"] kill';
36
37     my $cond = AnyEvent->condvar;
38     my $client = i3(get_socket_path(0));
39     $client->connect()->recv;
40     $client->subscribe({
41         workspace => sub {
42             my ($event) = @_;
43             $cond->send($event);
44         }
45     })->recv;
46
47     cmd "workspace $ws2";
48
49     sync_with_i3;
50
51     my $event = $cond->recv;
52     is($event->{change}, 'empty', '"Empty" event received upon workspace switch');
53 };
54
55 ################################################################################
56 # check that no workspace empty event is send upon workspace switch if the
57 # workspace is not empty
58 ################################################################################
59 subtest 'No workspace empty event', sub {
60     my $ws2 = fresh_workspace;
61     my $w2 = open_window();
62     my $ws1 = fresh_workspace;
63     my $w1 = open_window();
64
65     my @events;
66     my $cond = AnyEvent->condvar;
67     my $client = i3(get_socket_path(0));
68     $client->connect()->recv;
69     $client->subscribe({
70         workspace => sub {
71             my ($event) = @_;
72             push @events, $event;
73         }
74     })->recv;
75
76     # Wait for the workspace event on a new connection. Events will be delivered
77     # to older connections earlier, so by the time it arrives here, it should be
78     # in @events already.
79     my $ws_event_block_conn = i3(get_socket_path(0));
80     $ws_event_block_conn->connect()->recv;
81     $ws_event_block_conn->subscribe({ workspace => sub { $cond->send(1) }});
82
83     cmd "workspace $ws2";
84
85     sync_with_i3;
86
87     my @expected_events = grep { $_->{change} eq 'focus' } @events;
88     my @empty_events = grep { $_->{change} eq 'empty' } @events;
89     is(@expected_events, 1, '"Focus" event received');
90     is(@empty_events, 0, 'No "empty" events received');
91 };
92
93 ################################################################################
94 # check that workspace empty event is send when the last window has been closed
95 # on invisible workspace
96 ################################################################################
97 subtest 'Workspace empty event upon window close', sub {
98     my $ws1 = fresh_workspace;
99     my $w1 = open_window();
100     my $ws2 = fresh_workspace;
101     my $w2 = open_window();
102
103     my $cond = AnyEvent->condvar;
104     my $client = i3(get_socket_path(0));
105     $client->connect()->recv;
106     $client->subscribe({
107         workspace => sub {
108             my ($event) = @_;
109             $cond->send($event);
110         }
111     })->recv;
112
113     cmd '[id="' . $w1->id . '"] kill';
114
115     sync_with_i3;
116
117     my $event = $cond->recv;
118     is($event->{change}, 'empty', '"Empty" event received upon window close');
119 };
120
121 }
122
123 done_testing;