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