2 # vim:ts=4:sw=4:expandtab
4 # Tests all kinds of matching methods
7 use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT);
9 my $tmp = fresh_workspace;
11 ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
14 my $window = open_window;
15 my $content = get_ws_content($tmp);
16 ok(@{$content} == 1, 'window mapped');
17 my $win = $content->[0];
19 ######################################################################
20 # first test that matches which should not match this window really do
22 ######################################################################
23 # TODO: specify more match types
24 # we can match on any (non-empty) class here since that window does not have
26 cmd q|[class=".*"] kill|;
27 cmd q|[con_id="99999"] kill|;
29 $content = get_ws_content($tmp);
30 ok(@{$content} == 1, 'window still there');
33 cmd 'nop now killing the window';
35 cmd qq|[con_id="$id"] kill|;
37 wait_for_unmap $window;
39 cmd 'nop checking if its gone';
40 $content = get_ws_content($tmp);
41 ok(@{$content} == 0, 'window killed');
43 # TODO: same test, but with pcre expressions
45 ######################################################################
46 # check that multiple criteria work are checked with a logical AND,
47 # not a logical OR (that is, matching is not cancelled after the first
49 ######################################################################
51 $tmp = fresh_workspace;
53 # TODO: move to X11::XCB
55 my ($id, $class, $instance) = @_;
57 # Add a _NET_WM_STRUT_PARTIAL hint
58 my $atomname = $x->atom(name => 'WM_CLASS');
59 my $atomtype = $x->atom(name => 'STRING');
67 length($class) + length($instance) + 2,
68 "$instance\x00$class\x00"
72 my $left = $x->root->create_child(
73 class => WINDOW_CLASS_INPUT_OUTPUT,
74 rect => [ 0, 0, 30, 30 ],
75 background_color => '#0000ff',
76 event_mask => [ 'structure_notify' ],
80 set_wm_class($left->id, 'special', 'special');
83 ok(wait_for_map($left), 'left window mapped');
85 my $right = $x->root->create_child(
86 class => WINDOW_CLASS_INPUT_OUTPUT,
87 rect => [ 0, 0, 30, 30 ],
88 background_color => '#0000ff',
89 event_mask => [ 'structure_notify' ],
93 set_wm_class($right->id, 'special', 'special');
94 $right->name('right');
96 ok(wait_for_map($right), 'right window mapped');
98 # two windows should be here
99 $content = get_ws_content($tmp);
100 ok(@{$content} == 2, 'two windows opened');
102 cmd '[class="special" title="left"] kill';
106 $content = get_ws_content($tmp);
107 is(@{$content}, 1, 'one window still there');
109 ######################################################################
110 # check that regular expressions work
111 ######################################################################
113 $tmp = fresh_workspace;
115 $left = $x->root->create_child(
116 class => WINDOW_CLASS_INPUT_OUTPUT,
117 rect => [ 0, 0, 30, 30 ],
118 background_color => '#0000ff',
119 event_mask => [ 'structure_notify' ],
123 set_wm_class($left->id, 'special7', 'special7');
126 ok(wait_for_map($left), 'left window mapped');
128 # two windows should be here
129 $content = get_ws_content($tmp);
130 ok(@{$content} == 1, 'window opened');
132 cmd '[class="^special[0-9]$"] kill';
134 wait_for_unmap $left;
136 $content = get_ws_content($tmp);
137 is(@{$content}, 0, 'window killed');
139 ######################################################################
140 # check that UTF-8 works when matching
141 ######################################################################
143 $tmp = fresh_workspace;
145 $left = $x->root->create_child(
146 class => WINDOW_CLASS_INPUT_OUTPUT,
147 rect => [ 0, 0, 30, 30 ],
148 background_color => '#0000ff',
149 event_mask => [ 'structure_notify' ],
153 set_wm_class($left->id, 'special7', 'special7');
156 ok(wait_for_map($left), 'left window mapped');
158 # two windows should be here
159 $content = get_ws_content($tmp);
160 ok(@{$content} == 1, 'window opened');
162 cmd '[title="^\w [3]$"] kill';
164 wait_for_unmap $left;
166 $content = get_ws_content($tmp);
167 is(@{$content}, 0, 'window killed');