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 = open_window($x);
16 my $content = get_ws_content($tmp);
17 ok(@{$content} == 1, 'window mapped');
18 my $win = $content->[0];
20 ######################################################################
21 # first test that matches which should not match this window really do
23 ######################################################################
24 # TODO: specify more match types
25 # we can match on any (non-empty) class here since that window does not have
27 cmd q|[class=".*"] kill|;
28 cmd q|[con_id="99999"] kill|;
30 $content = get_ws_content($tmp);
31 ok(@{$content} == 1, 'window still there');
34 cmd 'nop now killing the window';
36 cmd qq|[con_id="$id"] kill|;
40 cmd 'nop checking if its gone';
41 $content = get_ws_content($tmp);
42 ok(@{$content} == 0, 'window killed');
44 # TODO: same test, but with pcre expressions
46 ######################################################################
47 # check that multiple criteria work are checked with a logical AND,
48 # not a logical OR (that is, matching is not cancelled after the first
50 ######################################################################
52 $tmp = fresh_workspace;
54 # TODO: move to X11::XCB
56 my ($id, $class, $instance) = @_;
58 # Add a _NET_WM_STRUT_PARTIAL hint
59 my $atomname = $x->atom(name => 'WM_CLASS');
60 my $atomtype = $x->atom(name => 'STRING');
68 length($class) + length($instance) + 2,
69 "$instance\x00$class\x00"
73 my $left = $x->root->create_child(
74 class => WINDOW_CLASS_INPUT_OUTPUT,
75 rect => [ 0, 0, 30, 30 ],
76 background_color => '#0000ff',
77 event_mask => [ 'structure_notify' ],
81 set_wm_class($left->id, 'special', 'special');
84 ok(wait_for_map($x), 'left window mapped');
86 my $right = $x->root->create_child(
87 class => WINDOW_CLASS_INPUT_OUTPUT,
88 rect => [ 0, 0, 30, 30 ],
89 background_color => '#0000ff',
90 event_mask => [ 'structure_notify' ],
94 set_wm_class($right->id, 'special', 'special');
95 $right->name('right');
97 ok(wait_for_map($x), 'right window mapped');
99 # two windows should be here
100 $content = get_ws_content($tmp);
101 ok(@{$content} == 2, 'two windows opened');
103 cmd '[class="special" title="left"] kill';
107 $content = get_ws_content($tmp);
108 is(@{$content}, 1, 'one window still there');
110 ######################################################################
111 # check that regular expressions work
112 ######################################################################
114 $tmp = fresh_workspace;
116 $left = $x->root->create_child(
117 class => WINDOW_CLASS_INPUT_OUTPUT,
118 rect => [ 0, 0, 30, 30 ],
119 background_color => '#0000ff',
120 event_mask => [ 'structure_notify' ],
124 set_wm_class($left->id, 'special7', 'special7');
127 ok(wait_for_map($x), 'left window mapped');
129 # two windows should be here
130 $content = get_ws_content($tmp);
131 ok(@{$content} == 1, 'window opened');
133 cmd '[class="^special[0-9]$"] kill';
137 $content = get_ws_content($tmp);
138 is(@{$content}, 0, 'window killed');
140 ######################################################################
141 # check that UTF-8 works when matching
142 ######################################################################
144 $tmp = fresh_workspace;
146 $left = $x->root->create_child(
147 class => WINDOW_CLASS_INPUT_OUTPUT,
148 rect => [ 0, 0, 30, 30 ],
149 background_color => '#0000ff',
150 event_mask => [ 'structure_notify' ],
154 set_wm_class($left->id, 'special7', 'special7');
157 ok(wait_for_map($x), 'left window mapped');
159 # two windows should be here
160 $content = get_ws_content($tmp);
161 ok(@{$content} == 1, 'window opened');
163 cmd '[title="^\w [3]$"] kill';
167 $content = get_ws_content($tmp);
168 is(@{$content}, 0, 'window killed');