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