]> git.sur5r.net Git - i3/i3/blob - testcases/t/06-focus.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 06-focus.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use X11::XCB qw(:all);
6
7 BEGIN {
8     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
9 }
10
11 my $x = X11::XCB::Connection->new;
12
13 my $i3 = i3(get_socket_path());
14 my $tmp = fresh_workspace;
15
16 #####################################################################
17 # Create two windows and make sure focus switching works
18 #####################################################################
19
20 # Change mode of the container to "default" for following tests
21 cmd 'layout default';
22 cmd 'split v';
23
24 my $top = open_standard_window($x);
25 my $mid = open_standard_window($x);
26 my $bottom = open_standard_window($x);
27 sleep 0.25;
28
29 diag("top id = " . $top->id);
30 diag("mid id = " . $mid->id);
31 diag("bottom id = " . $bottom->id);
32
33 #
34 # Returns the input focus after sending the given command to i3 via IPC
35 # end sleeping for half a second to make sure i3 reacted
36 #
37 sub focus_after {
38     my $msg = shift;
39
40     $i3->command($msg)->recv;
41     return $x->input_focus;
42 }
43
44 $focus = $x->input_focus;
45 is($focus, $bottom->id, "Latest window focused");
46
47 $focus = focus_after('focus up');
48 is($focus, $mid->id, "Middle window focused");
49
50 $focus = focus_after('focus up');
51 is($focus, $top->id, "Top window focused");
52
53 #####################################################################
54 # Test focus wrapping
55 #####################################################################
56
57 $focus = focus_after('focus up');
58 is($focus, $bottom->id, "Bottom window focused (wrapping to the top works)");
59
60 $focus = focus_after('focus down');
61 is($focus, $top->id, "Top window focused (wrapping to the bottom works)");
62
63 ###############################################
64 # Test focus with empty containers and colspan
65 ###############################################
66
67 #my $otmp = get_unused_workspace();
68 #$i3->command("workspace $otmp")->recv;
69 #
70 #$top = i3test::open_standard_window($x);
71 #$bottom = i3test::open_standard_window($x);
72 #sleep 0.25;
73 #
74 #$focus = focus_after("mj");
75 #$focus = focus_after("mh");
76 #$focus = focus_after("k");
77 #is($focus, $bottom->id, "Selecting top window without snapping doesn't work");
78 #
79 #$focus = focus_after("sl");
80 #is($focus, $bottom->id, "Bottom window focused");
81 #
82 #$focus = focus_after("k");
83 #is($focus, $top->id, "Top window focused");
84 #
85 ## Same thing, but left/right instead of top/bottom
86 #
87 #my $o2tmp = get_unused_workspace();
88 #$i3->command("workspace $o2tmp")->recv;
89 #
90 #my $left = i3test::open_standard_window($x);
91 #my $right = i3test::open_standard_window($x);
92 #sleep 0.25;
93 #
94 #$focus = focus_after("ml");
95 #$focus = focus_after("h");
96 #$focus = focus_after("mk");
97 #$focus = focus_after("l");
98 #is($focus, $left->id, "Selecting right window without snapping doesn't work");
99 #
100 #$focus = focus_after("sj");
101 #is($focus, $left->id, "left window focused");
102 #
103 #$focus = focus_after("l");
104 #is($focus, $right->id, "right window focused");
105
106
107 done_testing;