]> git.sur5r.net Git - i3/i3/blob - testcases/t/11-goto.t
Implement mark/goto, modify testcase
[i3/i3] / testcases / t / 11-goto.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test tests => 6;
5 use X11::XCB qw(:all);
6 use Time::HiRes qw(sleep);
7 use Digest::SHA1 qw(sha1_base64);
8
9 BEGIN {
10     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
11 }
12
13 my $x = X11::XCB::Connection->new;
14
15 my $i3 = i3("/tmp/nestedcons");
16 my $tmp = get_unused_workspace();
17 $i3->command("workspace $tmp")->recv;
18
19 $i3->command('split h')->recv;
20
21 #####################################################################
22 # Create two windows and make sure focus switching works
23 #####################################################################
24
25 my $top = i3test::open_standard_window($x);
26 sleep 0.25;
27 my $mid = i3test::open_standard_window($x);
28 sleep 0.25;
29 my $bottom = i3test::open_standard_window($x);
30 sleep 0.25;
31
32 diag("top id = " . $top->id);
33 diag("mid id = " . $mid->id);
34 diag("bottom id = " . $bottom->id);
35
36 #
37 # Returns the input focus after sending the given command to i3 via IPC
38 # end sleeping for half a second to make sure i3 reacted
39 #
40 sub focus_after {
41     my $msg = shift;
42
43     $i3->command($msg)->recv;
44     return $x->input_focus;
45 }
46
47 $focus = $x->input_focus;
48 is($focus, $bottom->id, "Latest window focused");
49
50 $focus = focus_after("prev h");
51 is($focus, $mid->id, "Middle window focused");
52
53 #####################################################################
54 # Now goto a mark which does not exist
55 #####################################################################
56
57 my $random_mark = sha1_base64(rand());
58
59 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
60 is($focus, $mid->id, "focus unchanged");
61
62 $i3->command("mark $random_mark")->recv;
63
64 $focus = focus_after("prev h");
65 is($focus, $top->id, "Top window focused");
66
67 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
68 is($focus, $mid->id, "goto worked");
69