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 use i3test i3_config => <<EOT;
19 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
21 # fake-1 under fake-0 to not interfere with left/right wraping
22 fake-outputs 1024x768+0+0,1024x768+0+1024
23 workspace X output fake-1
26 ################################
28 ################################
30 my $ws = fresh_workspace(output => 0);
31 my $win0 = open_window;
32 my $win1 = open_window;
33 my $win2 = open_window;
35 # ensure the rightmost window contains input focus
36 cmd '[id="' . $win2->id . '"] focus';
37 is($x->input_focus, $win2->id, "Window 2 focused");
40 my ($cmd, $name) = @_;
42 my $focus = AnyEvent->condvar;
44 my @events = events_for(
48 is(scalar @events, 1, 'Received 1 event');
49 is($events[0]->{change}, 'focus', 'Focus event received');
50 is($events[0]->{container}->{name}, $name, "$name focused");
54 my ($cmd, $name) = @_;
56 my $focus = AnyEvent->condvar;
58 my @events = events_for(
62 is(scalar @events, 1, 'Received 1 event');
63 is($events[0]->{change}, 'close', 'Close event received');
64 is($events[0]->{container}->{name}, $name, "$name closed");
67 subtest 'focus left (1)', \&focus_subtest, 'focus left', $win1->name;
68 subtest 'focus left (2)', \&focus_subtest, 'focus left', $win0->name;
69 subtest 'focus right (1)', \&focus_subtest, 'focus right', $win1->name;
70 subtest 'focus right (2)', \&focus_subtest, 'focus right', $win2->name;
71 subtest 'focus right (3)', \&focus_subtest, 'focus right', $win0->name;
72 subtest 'focus left', \&focus_subtest, 'focus left', $win2->name;
73 subtest 'kill doesn\'t produce focus event', \&kill_subtest, '[id=' . $win1->id . '] kill', $win1->name;
75 # See issue #3562. We need to switch to an existing workspace on the second
76 # output to trigger the bug.
78 subtest 'workspace focus', \&focus_subtest, "workspace $ws", $win2->name;
80 sub scratchpad_subtest {
81 my ($cmd, $name) = @_;
83 my $focus = AnyEvent->condvar;
85 my @events = events_for(
89 is(scalar @events, 2, 'Received 2 events');
90 is($events[0]->{change}, 'move', 'Move event received');
91 is($events[0]->{container}->{nodes}->[0]->{name}, $name, "$name moved");
92 is($events[1]->{change}, 'focus', 'Focus event received');
93 is($events[1]->{container}->{name}, $name, "$name focused");
97 my $win = open_window;
98 cmd 'move scratchpad';
99 subtest 'scratchpad', \&scratchpad_subtest, '[id=' . $win->id . '] scratchpad show', $win->name;