]> git.sur5r.net Git - i3/i3/blob - testcases/t/11-goto.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 11-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use X11::XCB qw(:all);
6 use Digest::SHA1 qw(sha1_base64);
7
8 BEGIN {
9     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
10 }
11
12 my $x = X11::XCB::Connection->new;
13
14 my $i3 = i3(get_socket_path());
15 my $tmp = fresh_workspace;
16
17 cmd 'split h';
18
19 #####################################################################
20 # Create two windows and make sure focus switching works
21 #####################################################################
22
23 my $top = open_standard_window($x);
24 sleep 0.25;
25 my $mid = open_standard_window($x);
26 sleep 0.25;
27 my $bottom = open_standard_window($x);
28 sleep 0.25;
29
30 diag("top id = " . $top->id);
31 diag("mid id = " . $mid->id);
32 diag("bottom id = " . $bottom->id);
33
34 #
35 # Returns the input focus after sending the given command to i3 via IPC
36 # end sleeping for half a second to make sure i3 reacted
37 #
38 sub focus_after {
39     my $msg = shift;
40
41     cmd $msg;
42     return $x->input_focus;
43 }
44
45 $focus = $x->input_focus;
46 is($focus, $bottom->id, "Latest window focused");
47
48 $focus = focus_after('focus left');
49 is($focus, $mid->id, "Middle window focused");
50
51 #####################################################################
52 # Now goto a mark which does not exist
53 #####################################################################
54
55 my $random_mark = sha1_base64(rand());
56
57 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
58 is($focus, $mid->id, "focus unchanged");
59
60 $i3->command("mark $random_mark")->recv;
61
62 $focus = focus_after('focus left');
63 is($focus, $top->id, "Top window focused");
64
65 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
66 is($focus, $mid->id, "goto worked");
67
68 # check that we can specify multiple criteria
69
70 $focus = focus_after('focus left');
71 is($focus, $top->id, "Top window focused");
72
73 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
74 is($focus, $mid->id, "goto worked");
75
76 #####################################################################
77 # Check whether the focus command will switch to a different
78 # workspace if necessary
79 #####################################################################
80
81 my $tmp2 = fresh_workspace;
82
83 is(focused_ws(), $tmp2, 'tmp2 now focused');
84
85 cmd qq|[con_mark="$random_mark"] focus|;
86
87 is(focused_ws(), $tmp, 'tmp now focused');
88
89 done_testing;