]> git.sur5r.net Git - i3/i3/blob - testcases/t/219-ipc-window-focus.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 219-ipc-window-focus.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 SKIP: {
20
21     skip "AnyEvent::I3 too old (need >= 0.15)", 1 if $AnyEvent::I3::VERSION < 0.15;
22
23 my $i3 = i3(get_socket_path());
24 $i3->connect()->recv;
25
26 ################################
27 # Window focus event
28 ################################
29
30 cmd 'split h';
31
32 my $win0 = open_window;
33 my $win1 = open_window;
34 my $win2 = open_window;
35
36 my $focus = AnyEvent->condvar;
37
38 $i3->subscribe({
39     window => sub {
40         my ($event) = @_;
41         $focus->send($event);
42     }
43 })->recv;
44
45 my $t;
46 $t = AnyEvent->timer(
47     after => 0.5,
48     cb => sub {
49         $focus->send(0);
50     }
51 );
52
53 # ensure the rightmost window contains input focus
54 $i3->command('[id="' . $win2->id . '"] focus')->recv;
55 is($x->input_focus, $win2->id, "Window 2 focused");
56
57 cmd 'focus left';
58 my $event = $focus->recv;
59 is($event->{change}, 'focus', 'Focus event received');
60 is($focus->recv->{container}->{name}, 'Window 1', 'Window 1 focused');
61
62 $focus = AnyEvent->condvar;
63 cmd 'focus left';
64 $event = $focus->recv;
65 is($event->{change}, 'focus', 'Focus event received');
66 is($event->{container}->{name}, 'Window 0', 'Window 0 focused');
67
68 $focus = AnyEvent->condvar;
69 cmd 'focus right';
70 $event = $focus->recv;
71 is($event->{change}, 'focus', 'Focus event received');
72 is($event->{container}->{name}, 'Window 1', 'Window 1 focused');
73
74 $focus = AnyEvent->condvar;
75 cmd 'focus right';
76 $event = $focus->recv;
77 is($event->{change}, 'focus', 'Focus event received');
78 is($event->{container}->{name}, 'Window 2', 'Window 2 focused');
79
80 $focus = AnyEvent->condvar;
81 cmd 'focus right';
82 $event = $focus->recv;
83 is($event->{change}, 'focus', 'Focus event received');
84 is($event->{container}->{name}, 'Window 0', 'Window 0 focused');
85
86 $focus = AnyEvent->condvar;
87 cmd 'focus left';
88 $event = $focus->recv;
89 is($event->{change}, 'focus', 'Focus event received');
90 is($event->{container}->{name}, 'Window 2', 'Window 2 focused');
91
92 }
93
94 done_testing;