]> git.sur5r.net Git - i3/i3/blob - testcases/t/115-ipc-workspaces.t
Merge branch 'next'
[i3/i3] / testcases / t / 115-ipc-workspaces.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 use i3test;
18
19 my $i3 = i3(get_socket_path());
20 $i3->connect()->recv;
21
22 ################################
23 # Workspaces requests and events
24 ################################
25
26 my $focused = get_ws(focused_ws());
27
28 # Events
29
30 # We are switching to an empty workpspace from an empty workspace, so we expect
31 # to receive "init", "focus", and "empty".
32 my $init = AnyEvent->condvar;
33 my $focus = AnyEvent->condvar;
34 my $empty = AnyEvent->condvar;
35 $i3->subscribe({
36     workspace => sub {
37         my ($event) = @_;
38         if ($event->{change} eq 'init') {
39             $init->send(1);
40         } elsif ($event->{change} eq 'focus') {
41             # Check that we have the old and new workspace
42             $focus->send(
43                 $event->{current}->{name} == '2' &&
44                 $event->{old}->{name} == $focused->{name}
45             );
46         } elsif ($event->{change} eq 'empty') {
47             $empty->send(1);
48         }
49     }
50 })->recv;
51
52 cmd 'workspace 2';
53
54 my $t;
55 $t = AnyEvent->timer(
56     after => 0.5,
57     cb => sub {
58         $init->send(0);
59         $focus->send(0);
60         $empty->send(0);
61     }
62 );
63
64 ok($init->recv, 'Workspace "init" event received');
65 ok($focus->recv, 'Workspace "focus" event received');
66 ok($empty->recv, 'Workspace "empty" event received');
67
68 done_testing;