]> git.sur5r.net Git - i3/i3/blob - testcases/t/119-match.t
Merge branch 'master' into next
[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);
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 is_num_children($tmp, 1, 'window still there');
30
31 # now kill the window
32 cmd 'nop now killing the window';
33 my $id = $win->{id};
34 cmd qq|[con_id="$id"] kill|;
35
36 wait_for_unmap $window;
37
38 cmd 'nop checking if its gone';
39 is_num_children($tmp, 0, 'window killed');
40
41 # TODO: same test, but with pcre expressions
42
43 ######################################################################
44 # check that multiple criteria work are checked with a logical AND,
45 # not a logical OR (that is, matching is not cancelled after the first
46 # criterion matches).
47 ######################################################################
48
49 $tmp = fresh_workspace;
50
51 # TODO: move to X11::XCB
52 sub set_wm_class {
53     my ($id, $class, $instance) = @_;
54
55     # Add a _NET_WM_STRUT_PARTIAL hint
56     my $atomname = $x->atom(name => 'WM_CLASS');
57     my $atomtype = $x->atom(name => 'STRING');
58
59     $x->change_property(
60         PROP_MODE_REPLACE,
61         $id,
62         $atomname->id,
63         $atomtype->id,
64         8,
65         length($class) + length($instance) + 2,
66         "$instance\x00$class\x00"
67     );
68 }
69
70 sub open_special {
71     my %args = @_;
72     my $wm_class = delete($args{wm_class}) || 'special';
73
74     return open_window(
75         %args,
76         before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) },
77     );
78 }
79
80 my $left = open_special(name => 'left');
81 ok($left->mapped, 'left window mapped');
82
83 my $right = open_special(name => 'right');
84 ok($right->mapped, 'right window mapped');
85
86 # two windows should be here
87 is_num_children($tmp, 2, 'two windows opened');
88
89 cmd '[class="special" title="left"] kill';
90
91 sync_with_i3;
92
93 is_num_children($tmp, 1, 'one window still there');
94
95 ######################################################################
96 # check that regular expressions work
97 ######################################################################
98
99 $tmp = fresh_workspace;
100
101 $left = open_special(name => 'left', wm_class => 'special7');
102 ok($left->mapped, 'left window mapped');
103 is_num_children($tmp, 1, 'window opened');
104
105 cmd '[class="^special[0-9]$"] kill';
106 wait_for_unmap $left;
107 is_num_children($tmp, 0, 'window killed');
108
109 ######################################################################
110 # check that UTF-8 works when matching
111 ######################################################################
112
113 $tmp = fresh_workspace;
114
115 $left = open_special(name => 'รค 3', wm_class => 'special7');
116 ok($left->mapped, 'left window mapped');
117 is_num_children($tmp, 1, 'window opened');
118
119 cmd '[title="^\w [3]$"] kill';
120 wait_for_unmap $left;
121 is_num_children($tmp, 0, 'window killed');
122
123 done_testing;