]> git.sur5r.net Git - i3/i3/blob - testcases/t/119-match.t
testcases: drop sync_with_i3()s $x parameter, use global
[i3/i3] / testcases / t / 119-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(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT);
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 $window = open_window;
15 my $content = get_ws_content($tmp);
16 ok(@{$content} == 1, 'window mapped');
17 my $win = $content->[0];
18
19 ######################################################################
20 # first test that matches which should not match this window really do
21 # not match it
22 ######################################################################
23 # TODO: specify more match types
24 # we can match on any (non-empty) class here since that window does not have
25 # WM_CLASS set
26 cmd q|[class=".*"] kill|;
27 cmd q|[con_id="99999"] kill|;
28
29 $content = get_ws_content($tmp);
30 ok(@{$content} == 1, 'window still there');
31
32 # now kill the window
33 cmd 'nop now killing the window';
34 my $id = $win->{id};
35 cmd qq|[con_id="$id"] kill|;
36
37 wait_for_unmap $window;
38
39 cmd 'nop checking if its gone';
40 $content = get_ws_content($tmp);
41 ok(@{$content} == 0, 'window killed');
42
43 # TODO: same test, but with pcre expressions
44
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
48 # criterion matches).
49 ######################################################################
50
51 $tmp = fresh_workspace;
52
53 # TODO: move to X11::XCB
54 sub set_wm_class {
55     my ($id, $class, $instance) = @_;
56
57     # Add a _NET_WM_STRUT_PARTIAL hint
58     my $atomname = $x->atom(name => 'WM_CLASS');
59     my $atomtype = $x->atom(name => 'STRING');
60
61     $x->change_property(
62         PROP_MODE_REPLACE,
63         $id,
64         $atomname->id,
65         $atomtype->id,
66         8,
67         length($class) + length($instance) + 2,
68         "$instance\x00$class\x00"
69     );
70 }
71
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' ],
77 );
78
79 $left->_create;
80 set_wm_class($left->id, 'special', 'special');
81 $left->name('left');
82 $left->map;
83 ok(wait_for_map($left), 'left window mapped');
84
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' ],
90 );
91
92 $right->_create;
93 set_wm_class($right->id, 'special', 'special');
94 $right->name('right');
95 $right->map;
96 ok(wait_for_map($right), 'right window mapped');
97
98 # two windows should be here
99 $content = get_ws_content($tmp);
100 ok(@{$content} == 2, 'two windows opened');
101
102 cmd '[class="special" title="left"] kill';
103
104 sync_with_i3;
105
106 $content = get_ws_content($tmp);
107 is(@{$content}, 1, 'one window still there');
108
109 ######################################################################
110 # check that regular expressions work
111 ######################################################################
112
113 $tmp = fresh_workspace;
114
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' ],
120 );
121
122 $left->_create;
123 set_wm_class($left->id, 'special7', 'special7');
124 $left->name('left');
125 $left->map;
126 ok(wait_for_map($left), 'left window mapped');
127
128 # two windows should be here
129 $content = get_ws_content($tmp);
130 ok(@{$content} == 1, 'window opened');
131
132 cmd '[class="^special[0-9]$"] kill';
133
134 wait_for_unmap $left;
135
136 $content = get_ws_content($tmp);
137 is(@{$content}, 0, 'window killed');
138
139 ######################################################################
140 # check that UTF-8 works when matching
141 ######################################################################
142
143 $tmp = fresh_workspace;
144
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' ],
150 );
151
152 $left->_create;
153 set_wm_class($left->id, 'special7', 'special7');
154 $left->name('รค 3');
155 $left->map;
156 ok(wait_for_map($left), 'left window mapped');
157
158 # two windows should be here
159 $content = get_ws_content($tmp);
160 ok(@{$content} == 1, 'window opened');
161
162 cmd '[title="^\w [3]$"] kill';
163
164 wait_for_unmap $left;
165
166 $content = get_ws_content($tmp);
167 is(@{$content}, 0, 'window killed');
168
169 done_testing;