2 # vim:ts=4:sw=4:expandtab
6 use Digest::SHA1 qw(sha1_base64);
9 use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
12 my $x = X11::XCB::Connection->new;
14 my $tmp = fresh_workspace;
18 #####################################################################
19 # Create two windows and make sure focus switching works
20 #####################################################################
22 my $top = open_window($x);
23 my $mid = open_window($x);
24 my $bottom = open_window($x);
27 # Returns the input focus after sending the given command to i3 via IPC
28 # end sleeping for half a second to make sure i3 reacted
35 return $x->input_focus;
38 $focus = $x->input_focus;
39 is($focus, $bottom->id, "Latest window focused");
41 $focus = focus_after('focus left');
42 is($focus, $mid->id, "Middle window focused");
44 #####################################################################
45 # Now goto a mark which does not exist
46 #####################################################################
48 my $random_mark = sha1_base64(rand());
50 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
51 is($focus, $mid->id, "focus unchanged");
53 cmd "mark $random_mark";
55 $focus = focus_after('focus left');
56 is($focus, $top->id, "Top window focused");
58 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
59 is($focus, $mid->id, "goto worked");
61 # check that we can specify multiple criteria
63 $focus = focus_after('focus left');
64 is($focus, $top->id, "Top window focused");
66 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
67 is($focus, $mid->id, "goto worked");
69 #####################################################################
70 # Check whether the focus command will switch to a different
71 # workspace if necessary
72 #####################################################################
74 my $tmp2 = fresh_workspace;
76 is(focused_ws(), $tmp2, 'tmp2 now focused');
78 cmd qq|[con_mark="$random_mark"] focus|;
80 is(focused_ws(), $tmp, 'tmp now focused');