]> git.sur5r.net Git - i3/i3/blob - testcases/t/502-focus-output.t
Merge branch 'fix-resize'
[i3/i3] / testcases / t / 502-focus-output.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Verifies the 'focus output' command works properly.
18
19 use i3test i3_autostart => 0;
20 use List::Util qw(first);
21
22 my $config = <<EOT;
23 # i3 config file (v4)
24 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25
26 fake-outputs 1024x768+0+0,1024x768+1024+0
27 EOT
28 my $pid = launch_with_config($config);
29
30 my $tmp = fresh_workspace;
31 my $i3 = i3(get_socket_path());
32
33 ################################################################################
34 # use 'focus output' and verify that focus gets changed appropriately
35 ################################################################################
36
37 sub focused_output {
38     my $tree = $i3->get_tree->recv;
39     my $focused = $tree->{focus}->[0];
40     my $output = first { $_->{id} == $focused } @{$tree->{nodes}};
41     return $output->{name};
42 }
43
44 $x->root->warp_pointer(0, 0);
45 sync_with_i3;
46
47 is(focused_output, 'fake-0', 'focus on first output');
48
49 cmd 'focus output right';
50 is(focused_output, 'fake-1', 'focus on second output');
51
52 # focus should wrap when we focus to the right again.
53 cmd 'focus output right';
54 is(focused_output, 'fake-0', 'focus on first output again');
55
56 cmd 'focus output left';
57 is(focused_output, 'fake-1', 'focus back on second output');
58
59 cmd 'focus output left';
60 is(focused_output, 'fake-0', 'focus on first output again');
61
62 cmd 'focus output up';
63 is(focused_output, 'fake-0', 'focus still on first output');
64
65 cmd 'focus output down';
66 is(focused_output, 'fake-0', 'focus still on first output');
67
68 cmd 'focus output fake-1';
69 is(focused_output, 'fake-1', 'focus on second output');
70
71 cmd 'focus output fake-0';
72 is(focused_output, 'fake-0', 'focus on first output');
73
74 ################################################################################
75 # use 'focus output' and verify that i3 does not crash when the currently
76 # focused window is floating and is only partially mapped on an output screen
77 ################################################################################
78
79 is(focused_output, 'fake-0', 'focus on first output');
80
81 my $floating_win = open_window;
82 cmd 'floating toggle';
83 cmd 'move to absolute position -10 -10';
84
85 cmd 'focus output right';
86 is(focused_output, 'fake-1', 'focus on second output');
87
88 cmd 'focus output fake-0';
89 is(focused_output, 'fake-0', 'focus on first output');
90
91 exit_gracefully($pid);
92
93 done_testing;