]> git.sur5r.net Git - i3/i3/blob - testcases/t/111-goto.t
Merge pull request #2953 from CyberShadow/focus_wrapping
[i3/i3] / testcases / t / 111-goto.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 use File::Temp;
19
20 my $tmp = fresh_workspace;
21
22 cmd 'split h';
23
24 #####################################################################
25 # Create two windows and make sure focus switching works
26 #####################################################################
27
28 my $top = open_window;
29 my $mid = open_window;
30 my $bottom = open_window;
31
32 #
33 # Returns the input focus after sending the given command to i3 via IPC
34 # and syncing with i3
35 #
36 sub focus_after {
37     my $msg = shift;
38
39     cmd $msg;
40     return $x->input_focus;
41 }
42
43 my $focus = $x->input_focus;
44 is($focus, $bottom->id, "Latest window focused");
45
46 $focus = focus_after('focus left');
47 is($focus, $mid->id, "Middle window focused");
48
49 #####################################################################
50 # Now goto a mark which does not exist
51 #####################################################################
52
53 my $random_mark = mktemp('mark.XXXXXX');
54
55 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
56 is($focus, $mid->id, "focus unchanged");
57
58 cmd "mark $random_mark";
59
60 $focus = focus_after('focus left');
61 is($focus, $top->id, "Top window focused");
62
63 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
64 is($focus, $mid->id, "goto worked");
65
66 # check that we can specify multiple criteria
67
68 $focus = focus_after('focus left');
69 is($focus, $top->id, "Top window focused");
70
71 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
72 is($focus, $mid->id, "goto worked");
73
74 #####################################################################
75 # Set the same mark multiple times and see if focus works correctly
76 #####################################################################
77
78 $focus = focus_after('focus left');
79 is($focus, $top->id, "Top window focused");
80
81 cmd "mark $random_mark";
82
83 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
84 is($focus, $top->id, "focus unchanged after goto");
85
86 $focus = focus_after('focus right');
87 is($focus, $mid->id, "mid window focused");
88
89 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
90 is($focus, $top->id, "goto worked");
91
92 #####################################################################
93 # Check whether the focus command will switch to a different
94 # workspace if necessary
95 #####################################################################
96
97 my $tmp2 = fresh_workspace;
98
99 is(focused_ws(), $tmp2, 'tmp2 now focused');
100
101 cmd qq|[con_mark="$random_mark"] focus|;
102
103 is(focused_ws(), $tmp, 'tmp now focused');
104
105 done_testing;