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