]> git.sur5r.net Git - i3/i3/blob - testcases/t/19-match.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 19-match.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests all kinds of matching methods
5 #
6 use i3test;
7 use X11::XCB qw(:all);
8
9 my $tmp = fresh_workspace;
10
11 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
12
13 # Open a new window
14 my $x = X11::XCB::Connection->new;
15 my $window = $x->root->create_child(
16     class => WINDOW_CLASS_INPUT_OUTPUT,
17     rect => [ 0, 0, 30, 30 ],
18     background_color => '#C0C0C0',
19 );
20
21 $window->map;
22 # give it some time to be picked up by the window manager
23 # TODO: better check for $window->mapped or something like that?
24 # maybe we can even wait for getting mapped?
25 my $c = 0;
26 while (@{get_ws_content($tmp)} == 0 and $c++ < 5) {
27     sleep 0.25;
28 }
29 my $content = get_ws_content($tmp);
30 ok(@{$content} == 1, 'window mapped');
31 my $win = $content->[0];
32
33 ######################################################################
34 # first test that matches which should not match this window really do
35 # not match it
36 ######################################################################
37 # TODO: use PCRE expressions
38 # TODO: specify more match types
39 cmd q|[class="*"] kill|;
40 cmd q|[con_id="99999"] kill|;
41
42 $content = get_ws_content($tmp);
43 ok(@{$content} == 1, 'window still there');
44
45 # now kill the window
46 cmd 'nop now killing the window';
47 my $id = $win->{id};
48 cmd qq|[con_id="$id"] kill|;
49
50 # give i3 some time to pick up the UnmapNotify event
51 sleep 0.25;
52
53 cmd 'nop checking if its gone';
54 $content = get_ws_content($tmp);
55 ok(@{$content} == 0, 'window killed');
56
57 # TODO: same test, but with pcre expressions
58
59 ######################################################################
60 # check that multiple criteria work are checked with a logical AND,
61 # not a logical OR (that is, matching is not cancelled after the first
62 # criterion matches).
63 ######################################################################
64
65 $tmp = fresh_workspace;
66
67 # TODO: move to X11::XCB
68 sub set_wm_class {
69     my ($id, $class, $instance) = @_;
70
71     # Add a _NET_WM_STRUT_PARTIAL hint
72     my $atomname = $x->atom(name => 'WM_CLASS');
73     my $atomtype = $x->atom(name => 'STRING');
74
75     $x->change_property(
76         PROP_MODE_REPLACE,
77         $id,
78         $atomname->id,
79         $atomtype->id,
80         8,
81         length($class) + length($instance) + 2,
82         "$instance\x00$class\x00"
83     );
84 }
85
86 my $left = $x->root->create_child(
87     class => WINDOW_CLASS_INPUT_OUTPUT,
88     rect => [ 0, 0, 30, 30 ],
89     background_color => '#0000ff',
90 );
91
92 $left->_create;
93 set_wm_class($left->id, 'special', 'special');
94 $left->name('left');
95 $left->map;
96 sleep 0.25;
97
98 my $right = $x->root->create_child(
99     class => WINDOW_CLASS_INPUT_OUTPUT,
100     rect => [ 0, 0, 30, 30 ],
101     background_color => '#0000ff',
102 );
103
104 $right->_create;
105 set_wm_class($right->id, 'special', 'special');
106 $right->name('right');
107 $right->map;
108 sleep 0.25;
109
110 # two windows should be here
111 $content = get_ws_content($tmp);
112 ok(@{$content} == 2, 'two windows opened');
113
114 cmd '[class="special" title="left"] kill';
115
116 sleep 0.25;
117
118 $content = get_ws_content($tmp);
119 is(@{$content}, 1, 'one window still there');
120
121 done_testing;