]> git.sur5r.net Git - i3/i3/blob - testcases/t/219-ipc-window-focus.t
Merge pull request #3563 from CyberShadow/doc-mark-todo
[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 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 i3_config => <<EOT;
18 # i3 config file (v4)
19 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
20
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
24 EOT
25
26 ################################
27 # Window focus event
28 ################################
29
30 my $ws = fresh_workspace(output => 0);
31 my $win0 = open_window;
32 my $win1 = open_window;
33 my $win2 = open_window;
34
35 # ensure the rightmost window contains input focus
36 cmd '[id="' . $win2->id . '"] focus';
37 is($x->input_focus, $win2->id, "Window 2 focused");
38
39 sub focus_subtest {
40     my ($cmd, $name) = @_;
41
42     my $focus = AnyEvent->condvar;
43
44     my @events = events_for(
45         sub { cmd $cmd },
46         'window');
47
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");
51 }
52
53 sub kill_subtest {
54     my ($cmd, $name) = @_;
55
56     my $focus = AnyEvent->condvar;
57
58     my @events = events_for(
59         sub { cmd $cmd },
60         'window');
61
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");
65 }
66
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;
74
75 # See issue #3562. We need to switch to an existing workspace on the second
76 # output to trigger the bug.
77 cmd 'workspace X';
78 subtest 'workspace focus', \&focus_subtest, "workspace $ws", $win2->name;
79
80 sub scratchpad_subtest {
81     my ($cmd, $name) = @_;
82
83     my $focus = AnyEvent->condvar;
84
85     my @events = events_for(
86         sub { cmd $cmd },
87         'window');
88
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");
94 }
95
96 fresh_workspace;
97 my $win = open_window;
98 cmd 'move scratchpad';
99 subtest 'scratchpad', \&scratchpad_subtest, '[id=' . $win->id . '] scratchpad show', $win->name;
100
101 done_testing;