]> git.sur5r.net Git - i3/i3/blob - testcases/t/173-regress-focus-assign.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 173-regress-focus-assign.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 # Regression: Checks if focus is stolen when a window is managed which is
18 # assigned to an invisible workspace
19 #
20 use i3test i3_autostart => 0;
21 use X11::XCB qw(PROP_MODE_REPLACE);
22
23 # TODO: move to X11::XCB
24 sub set_wm_class {
25     my ($id, $class, $instance) = @_;
26
27     # Add a _NET_WM_STRUT_PARTIAL hint
28     my $atomname = $x->atom(name => 'WM_CLASS');
29     my $atomtype = $x->atom(name => 'STRING');
30
31     $x->change_property(
32         PROP_MODE_REPLACE,
33         $id,
34         $atomname->id,
35         $atomtype->id,
36         8,
37         length($class) + length($instance) + 2,
38         "$instance\x00$class\x00"
39     );
40 }
41
42 sub open_special {
43     my %args = @_;
44     my $wm_class = delete($args{wm_class}) || 'special';
45     $args{name} //= 'special window';
46
47     # We use dont_map because i3 will not map the window on the current
48     # workspace. Thus, open_window would time out in wait_for_map (2 seconds).
49     my $window = open_window(
50         %args,
51         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
52         dont_map => 1,
53     );
54     $window->map;
55     return $window;
56 }
57
58 #####################################################################
59 # start a window and see that it does not get assigned with an empty config
60 #####################################################################
61
62 my $config = <<EOT;
63 # i3 config file (v4)
64 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
65 assign "special" → targetws
66 EOT
67
68 my $pid = launch_with_config($config);
69
70 my $tmp = fresh_workspace;
71
72 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
73 ok(get_ws($tmp)->{focused}, 'current workspace focused');
74
75 my $window = open_special;
76
77 ok(@{get_ws_content($tmp)} == 0, 'special window not on current workspace');
78 ok(@{get_ws_content('targetws')} == 1, 'special window on targetws');
79 ok(get_ws($tmp)->{focused}, 'current workspace still focused');
80
81 #####################################################################
82 # the same test, but with a floating window
83 #####################################################################
84
85 $window = open_special(
86     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
87 );
88
89 ok(@{get_ws_content($tmp)} == 0, 'special window not on current workspace');
90 ok(@{get_ws_content('targetws')} == 1, 'special window on targetws');
91 ok(get_ws($tmp)->{focused}, 'current workspace still focused');
92
93 exit_gracefully($pid);
94
95 $window->destroy;
96
97 done_testing;