]> git.sur5r.net Git - i3/i3/blob - testcases/t/111-goto.t
testcases: drop sync_with_i3()s $x parameter, use global
[i3/i3] / testcases / t / 111-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use File::Temp;
6
7 my $tmp = fresh_workspace;
8
9 cmd 'split h';
10
11 #####################################################################
12 # Create two windows and make sure focus switching works
13 #####################################################################
14
15 my $top = open_window;
16 my $mid = open_window;
17 my $bottom = open_window;
18
19 #
20 # Returns the input focus after sending the given command to i3 via IPC
21 # and syncing with i3
22 #
23 sub focus_after {
24     my $msg = shift;
25
26     cmd $msg;
27     sync_with_i3;
28     return $x->input_focus;
29 }
30
31 my $focus = $x->input_focus;
32 is($focus, $bottom->id, "Latest window focused");
33
34 $focus = focus_after('focus left');
35 is($focus, $mid->id, "Middle window focused");
36
37 #####################################################################
38 # Now goto a mark which does not exist
39 #####################################################################
40
41 my $random_mark = mktemp('mark.XXXXXX');
42
43 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
44 is($focus, $mid->id, "focus unchanged");
45
46 cmd "mark $random_mark";
47
48 $focus = focus_after('focus left');
49 is($focus, $top->id, "Top window focused");
50
51 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
52 is($focus, $mid->id, "goto worked");
53
54 # check that we can specify multiple criteria
55
56 $focus = focus_after('focus left');
57 is($focus, $top->id, "Top window focused");
58
59 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
60 is($focus, $mid->id, "goto worked");
61
62 #####################################################################
63 # Check whether the focus command will switch to a different
64 # workspace if necessary
65 #####################################################################
66
67 my $tmp2 = fresh_workspace;
68
69 is(focused_ws(), $tmp2, 'tmp2 now focused');
70
71 cmd qq|[con_mark="$random_mark"] focus|;
72
73 is(focused_ws(), $tmp, 'tmp now focused');
74
75 done_testing;