]> git.sur5r.net Git - i3/i3/blob - testcases/t/111-goto.t
Merge branch 'master' into next
[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     return $x->input_focus;
28 }
29
30 my $focus = $x->input_focus;
31 is($focus, $bottom->id, "Latest window focused");
32
33 $focus = focus_after('focus left');
34 is($focus, $mid->id, "Middle window focused");
35
36 #####################################################################
37 # Now goto a mark which does not exist
38 #####################################################################
39
40 my $random_mark = mktemp('mark.XXXXXX');
41
42 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
43 is($focus, $mid->id, "focus unchanged");
44
45 cmd "mark $random_mark";
46
47 $focus = focus_after('focus left');
48 is($focus, $top->id, "Top window focused");
49
50 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
51 is($focus, $mid->id, "goto worked");
52
53 # check that we can specify multiple criteria
54
55 $focus = focus_after('focus left');
56 is($focus, $top->id, "Top window focused");
57
58 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
59 is($focus, $mid->id, "goto worked");
60
61 #####################################################################
62 # Set the same mark multiple times and see if focus works correctly
63 #####################################################################
64
65 $focus = focus_after('focus left');
66 is($focus, $top->id, "Top window focused");
67
68 cmd "mark $random_mark";
69
70 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
71 is($focus, $top->id, "focus unchanged after goto");
72
73 $focus = focus_after('focus right');
74 is($focus, $mid->id, "mid window focused");
75
76 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
77 is($focus, $top->id, "goto worked");
78
79 #####################################################################
80 # Check whether the focus command will switch to a different
81 # workspace if necessary
82 #####################################################################
83
84 my $tmp2 = fresh_workspace;
85
86 is(focused_ws(), $tmp2, 'tmp2 now focused');
87
88 cmd qq|[con_mark="$random_mark"] focus|;
89
90 is(focused_ws(), $tmp, 'tmp now focused');
91
92 done_testing;