2 # vim:ts=4:sw=4:expandtab
4 # Tests all kinds of matching methods
9 my $tmp = fresh_workspace;
11 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
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',
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?
26 while (@{get_ws_content($tmp)} == 0 and $c++ < 5) {
29 my $content = get_ws_content($tmp);
30 ok(@{$content} == 1, 'window mapped');
31 my $win = $content->[0];
33 ######################################################################
34 # first test that matches which should not match this window really do
36 ######################################################################
37 # TODO: specify more match types
38 # we can match on any (non-empty) class here since that window does not have
40 cmd q|[class=".*"] kill|;
41 cmd q|[con_id="99999"] kill|;
43 $content = get_ws_content($tmp);
44 ok(@{$content} == 1, 'window still there');
47 cmd 'nop now killing the window';
49 cmd qq|[con_id="$id"] kill|;
51 # give i3 some time to pick up the UnmapNotify event
54 cmd 'nop checking if its gone';
55 $content = get_ws_content($tmp);
56 ok(@{$content} == 0, 'window killed');
58 # TODO: same test, but with pcre expressions
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
64 ######################################################################
66 $tmp = fresh_workspace;
68 # TODO: move to X11::XCB
70 my ($id, $class, $instance) = @_;
72 # Add a _NET_WM_STRUT_PARTIAL hint
73 my $atomname = $x->atom(name => 'WM_CLASS');
74 my $atomtype = $x->atom(name => 'STRING');
82 length($class) + length($instance) + 2,
83 "$instance\x00$class\x00"
87 my $left = $x->root->create_child(
88 class => WINDOW_CLASS_INPUT_OUTPUT,
89 rect => [ 0, 0, 30, 30 ],
90 background_color => '#0000ff',
94 set_wm_class($left->id, 'special', 'special');
99 my $right = $x->root->create_child(
100 class => WINDOW_CLASS_INPUT_OUTPUT,
101 rect => [ 0, 0, 30, 30 ],
102 background_color => '#0000ff',
106 set_wm_class($right->id, 'special', 'special');
107 $right->name('right');
111 # two windows should be here
112 $content = get_ws_content($tmp);
113 ok(@{$content} == 2, 'two windows opened');
115 cmd '[class="special" title="left"] kill';
119 $content = get_ws_content($tmp);
120 is(@{$content}, 1, 'one window still there');
122 ######################################################################
123 # check that regular expressions work
124 ######################################################################
126 $tmp = fresh_workspace;
128 $left = $x->root->create_child(
129 class => WINDOW_CLASS_INPUT_OUTPUT,
130 rect => [ 0, 0, 30, 30 ],
131 background_color => '#0000ff',
135 set_wm_class($left->id, 'special7', 'special7');
140 # two windows should be here
141 $content = get_ws_content($tmp);
142 ok(@{$content} == 1, 'window opened');
144 cmd '[class="^special[0-9]$"] kill';
148 $content = get_ws_content($tmp);
149 is(@{$content}, 0, 'window killed');
151 ######################################################################
152 # check that UTF-8 works when matching
153 ######################################################################
155 $tmp = fresh_workspace;
157 $left = $x->root->create_child(
158 class => WINDOW_CLASS_INPUT_OUTPUT,
159 rect => [ 0, 0, 30, 30 ],
160 background_color => '#0000ff',
164 set_wm_class($left->id, 'special7', 'special7');
169 # two windows should be here
170 $content = get_ws_content($tmp);
171 ok(@{$content} == 1, 'window opened');
173 cmd '[title="^\w [3]$"] kill';
177 $content = get_ws_content($tmp);
178 is(@{$content}, 0, 'window killed');