]> git.sur5r.net Git - i3/i3/blob - testcases/t/19-match.t
Merge branch 'master' 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: specify more match types
38 # we can match on any (non-empty) class here since that window does not have
39 # WM_CLASS set
40 cmd q|[class=".*"] kill|;
41 cmd q|[con_id="99999"] kill|;
42
43 $content = get_ws_content($tmp);
44 ok(@{$content} == 1, 'window still there');
45
46 # now kill the window
47 cmd 'nop now killing the window';
48 my $id = $win->{id};
49 cmd qq|[con_id="$id"] kill|;
50
51 # give i3 some time to pick up the UnmapNotify event
52 sleep 0.25;
53
54 cmd 'nop checking if its gone';
55 $content = get_ws_content($tmp);
56 ok(@{$content} == 0, 'window killed');
57
58 # TODO: same test, but with pcre expressions
59
60 ######################################################################
61 # check that multiple criteria work are checked with a logical AND,
62 # not a logical OR (that is, matching is not cancelled after the first
63 # criterion matches).
64 ######################################################################
65
66 $tmp = fresh_workspace;
67
68 # TODO: move to X11::XCB
69 sub set_wm_class {
70     my ($id, $class, $instance) = @_;
71
72     # Add a _NET_WM_STRUT_PARTIAL hint
73     my $atomname = $x->atom(name => 'WM_CLASS');
74     my $atomtype = $x->atom(name => 'STRING');
75
76     $x->change_property(
77         PROP_MODE_REPLACE,
78         $id,
79         $atomname->id,
80         $atomtype->id,
81         8,
82         length($class) + length($instance) + 2,
83         "$instance\x00$class\x00"
84     );
85 }
86
87 my $left = $x->root->create_child(
88     class => WINDOW_CLASS_INPUT_OUTPUT,
89     rect => [ 0, 0, 30, 30 ],
90     background_color => '#0000ff',
91 );
92
93 $left->_create;
94 set_wm_class($left->id, 'special', 'special');
95 $left->name('left');
96 $left->map;
97 sleep 0.25;
98
99 my $right = $x->root->create_child(
100     class => WINDOW_CLASS_INPUT_OUTPUT,
101     rect => [ 0, 0, 30, 30 ],
102     background_color => '#0000ff',
103 );
104
105 $right->_create;
106 set_wm_class($right->id, 'special', 'special');
107 $right->name('right');
108 $right->map;
109 sleep 0.25;
110
111 # two windows should be here
112 $content = get_ws_content($tmp);
113 ok(@{$content} == 2, 'two windows opened');
114
115 cmd '[class="special" title="left"] kill';
116
117 sleep 0.25;
118
119 $content = get_ws_content($tmp);
120 is(@{$content}, 1, 'one window still there');
121
122 ######################################################################
123 # check that regular expressions work
124 ######################################################################
125
126 $tmp = fresh_workspace;
127
128 $left = $x->root->create_child(
129     class => WINDOW_CLASS_INPUT_OUTPUT,
130     rect => [ 0, 0, 30, 30 ],
131     background_color => '#0000ff',
132 );
133
134 $left->_create;
135 set_wm_class($left->id, 'special7', 'special7');
136 $left->name('left');
137 $left->map;
138 sleep 0.25;
139
140 # two windows should be here
141 $content = get_ws_content($tmp);
142 ok(@{$content} == 1, 'window opened');
143
144 cmd '[class="^special[0-9]$"] kill';
145
146 sleep 0.25;
147
148 $content = get_ws_content($tmp);
149 is(@{$content}, 0, 'window killed');
150
151 ######################################################################
152 # check that UTF-8 works when matching
153 ######################################################################
154
155 $tmp = fresh_workspace;
156
157 $left = $x->root->create_child(
158     class => WINDOW_CLASS_INPUT_OUTPUT,
159     rect => [ 0, 0, 30, 30 ],
160     background_color => '#0000ff',
161 );
162
163 $left->_create;
164 set_wm_class($left->id, 'special7', 'special7');
165 $left->name('รค 3');
166 $left->map;
167 sleep 0.25;
168
169 # two windows should be here
170 $content = get_ws_content($tmp);
171 ok(@{$content} == 1, 'window opened');
172
173 cmd '[title="^\w [3]$"] kill';
174
175 sleep 0.25;
176
177 $content = get_ws_content($tmp);
178 is(@{$content}, 0, 'window killed');
179
180 done_testing;