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