]> git.sur5r.net Git - i3/i3/blob - testcases/t/65-for_window.t
Merge branch 'tree' into next
[i3/i3] / testcases / t / 65-for_window.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 #
5 use X11::XCB qw(:all);
6 use X11::XCB::Connection;
7 use i3test;
8
9 my $x = X11::XCB::Connection->new;
10
11 my $tmp = fresh_workspace;
12
13 ##############################################################
14 # 1: test the following directive:
15 #    for_window [class="borderless"] border none
16 # by first creating a window with a different class (should get
17 # the normal border), then creating a window with the class
18 # "borderless" (should get no border)
19 ##############################################################
20
21 my $window = $x->root->create_child(
22     class => WINDOW_CLASS_INPUT_OUTPUT,
23     rect => [ 0, 0, 30, 30 ],
24     background_color => '#00ff00',
25 );
26
27 $window->name('Border window');
28 $window->map;
29 sleep 0.25;
30
31 my @content = @{get_ws_content($tmp)};
32 cmp_ok(@content, '==', 1, 'one node on this workspace now');
33 is($content[0]->{border}, 'normal', 'normal border');
34
35 $window->unmap;
36 sleep 0.25;
37
38 my @content = @{get_ws_content($tmp)};
39 cmp_ok(@content, '==', 0, 'no more nodes');
40 diag('content = '. Dumper(\@content));
41
42 $window = $x->root->create_child(
43     class => WINDOW_CLASS_INPUT_OUTPUT,
44     rect => [ 0, 0, 30, 30 ],
45     background_color => '#00ff00',
46 );
47
48 $window->_create;
49
50 # TODO: move this to X11::XCB::Window
51 sub set_wm_class {
52     my ($id, $class, $instance) = @_;
53
54     # Add a _NET_WM_STRUT_PARTIAL hint
55     my $atomname = $x->atom(name => 'WM_CLASS');
56     my $atomtype = $x->atom(name => 'STRING');
57
58     $x->change_property(
59         PROP_MODE_REPLACE,
60         $id,
61         $atomname->id,
62         $atomtype->id,
63         8,
64         length($class) + length($instance) + 2,
65         "$instance\x00$class\x00"
66     );
67 }
68
69 set_wm_class($window->id, 'borderless', 'borderless');
70 $window->name('Borderless window');
71 $window->map;
72 sleep 0.25;
73
74 @content = @{get_ws_content($tmp)};
75 cmp_ok(@content, '==', 1, 'one node on this workspace now');
76 is($content[0]->{border}, 'none', 'no border');
77
78 $window->unmap;
79 sleep 0.25;
80
81 @content = @{get_ws_content($tmp)};
82 cmp_ok(@content, '==', 0, 'no more nodes');
83
84 ##############################################################
85 # 2: match on the title, check if for_window is really executed
86 # only once
87 ##############################################################
88
89 $window = $x->root->create_child(
90     class => WINDOW_CLASS_INPUT_OUTPUT,
91     rect => [ 0, 0, 30, 30 ],
92     background_color => '#00ff00',
93 );
94
95 $window->name('special title');
96 $window->map;
97 sleep 0.25;
98
99 @content = @{get_ws_content($tmp)};
100 cmp_ok(@content, '==', 1, 'one node on this workspace now');
101 is($content[0]->{border}, 'normal', 'normal border');
102
103 $window->name('special borderless title');
104 sleep 0.25;
105
106 @content = @{get_ws_content($tmp)};
107 is($content[0]->{border}, 'none', 'no border');
108
109 $window->name('special title');
110 sleep 0.25;
111
112 cmd 'border normal';
113
114 @content = @{get_ws_content($tmp)};
115 is($content[0]->{border}, 'normal', 'border reset to normal');
116
117 $window->name('special borderless title');
118 sleep 0.25;
119
120 @content = @{get_ws_content($tmp)};
121 is($content[0]->{border}, 'normal', 'still normal border');
122
123 $window->unmap;
124 sleep 0.25;
125
126 @content = @{get_ws_content($tmp)};
127 cmp_ok(@content, '==', 0, 'no more nodes');
128
129 ##############################################################
130 # 3: match on the title, set border style *and* a mark
131 ##############################################################
132
133 $window = $x->root->create_child(
134     class => WINDOW_CLASS_INPUT_OUTPUT,
135     rect => [ 0, 0, 30, 30 ],
136     background_color => '#00ff00',
137 );
138
139 $window->name('special mark title');
140 $window->map;
141 sleep 0.25;
142
143 @content = @{get_ws_content($tmp)};
144 cmp_ok(@content, '==', 1, 'one node on this workspace now');
145 is($content[0]->{border}, 'none', 'no border');
146
147 my $other = open_standard_window($x);
148
149 @content = @{get_ws_content($tmp)};
150 cmp_ok(@content, '==', 2, 'two nodes');
151 is($content[0]->{border}, 'none', 'no border');
152 is($content[1]->{border}, 'normal', 'normal border');
153 ok(!$content[0]->{focused}, 'first one not focused');
154
155 cmd qq|[con_mark="bleh"] focus|;
156
157 @content = @{get_ws_content($tmp)};
158 ok($content[0]->{focused}, 'first node focused');
159
160 done_testing;