]> git.sur5r.net Git - i3/i3/blob - testcases/t/101-focus.t
Merge pull request #2953 from CyberShadow/focus_wrapping
[i3/i3] / testcases / t / 101-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;
18
19 my $tmp = fresh_workspace;
20
21 #####################################################################
22 # Create two windows and make sure focus switching works
23 #####################################################################
24
25 # Change mode of the container to "default" for following tests
26 cmd 'layout default';
27 cmd 'split v';
28
29 my $top = open_window;
30 my $mid = open_window;
31 my $bottom = open_window;
32
33 #
34 # Returns the input focus after sending the given command to i3 via IPC
35 # end sleeping for half a second to make sure i3 reacted
36 #
37 sub focus_after {
38     my $msg = shift;
39
40     cmd $msg;
41     return $x->input_focus;
42 }
43
44 my $focus = $x->input_focus;
45 is($focus, $bottom->id, "Latest window focused");
46
47 $focus = focus_after('focus up');
48 is($focus, $mid->id, "Middle window focused");
49
50 $focus = focus_after('focus up');
51 is($focus, $top->id, "Top window focused");
52
53 #####################################################################
54 # Test focus wrapping
55 #####################################################################
56
57 $focus = focus_after('focus up');
58 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
59
60 $focus = focus_after('focus down');
61 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
62
63 #####################################################################
64 # Test focus is only successful if there was a window that could be
65 # matched.
66 #####################################################################
67
68 my $result = cmd '[con_mark=__does_not_exist] focus';
69 is($result->[0]->{success}, 0, 'focus is unsuccessful if no window was matched');
70
71 #####################################################################
72
73 done_testing;