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 $i3 = i3(get_socket_path());
15 my $tmp = fresh_workspace;
19 #####################################################################
20 # Create two windows and make sure focus switching works
21 #####################################################################
23 my $top = open_standard_window($x);
25 my $mid = open_standard_window($x);
27 my $bottom = open_standard_window($x);
30 diag("top id = " . $top->id);
31 diag("mid id = " . $mid->id);
32 diag("bottom id = " . $bottom->id);
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
42 return $x->input_focus;
45 $focus = $x->input_focus;
46 is($focus, $bottom->id, "Latest window focused");
48 $focus = focus_after('focus left');
49 is($focus, $mid->id, "Middle window focused");
51 #####################################################################
52 # Now goto a mark which does not exist
53 #####################################################################
55 my $random_mark = sha1_base64(rand());
57 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
58 is($focus, $mid->id, "focus unchanged");
60 $i3->command("mark $random_mark")->recv;
62 $focus = focus_after('focus left');
63 is($focus, $top->id, "Top window focused");
65 $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
66 is($focus, $mid->id, "goto worked");
68 # check that we can specify multiple criteria
70 $focus = focus_after('focus left');
71 is($focus, $top->id, "Top window focused");
73 $focus = focus_after(qq|[con_mark="$random_mark" con_mark="$random_mark"] focus|);
74 is($focus, $mid->id, "goto worked");
76 #####################################################################
77 # Check whether the focus command will switch to a different
78 # workspace if necessary
79 #####################################################################
81 my $tmp2 = fresh_workspace;
83 is(focused_ws(), $tmp2, 'tmp2 now focused');
85 cmd qq|[con_mark="$random_mark"] focus|;
87 is(focused_ws(), $tmp, 'tmp now focused');