]> git.sur5r.net Git - i3/i3/blob - testcases/t/10-dock.t
tests: use wait_for_{map,unmap} to eliminate more sleep()s
[i3/i3] / testcases / t / 10-dock.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use X11::XCB qw(:all);
6 use List::Util qw(first);
7
8 BEGIN {
9     use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
10 }
11
12 my $x = X11::XCB::Connection->new;
13
14 #####################################################################
15 # verify that there is no dock window yet
16 #####################################################################
17
18 # Children of all dockareas
19 my @docked = get_dock_clients;
20 is(@docked, 0, 'no dock clients yet');
21
22 #####################################################################
23 # Create a dock window and see if it gets managed
24 #####################################################################
25
26 my $screens = $x->screens;
27
28 # Get the primary screen
29 my $primary = first { $_->primary } @{$screens};
30
31 # TODO: focus the primary screen before
32
33 my $window = $x->root->create_child(
34     class => WINDOW_CLASS_INPUT_OUTPUT,
35     rect => [ 0, 0, 30, 30],
36     background_color => '#FF0000',
37     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
38     event_mask => [ 'structure_notify' ],
39 );
40
41 $window->map;
42
43 wait_for_map $x;
44
45 my $rect = $window->rect;
46 is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
47 is($rect->height, 30, 'height is unchanged');
48
49 #####################################################################
50 # check that we can find it in the layout tree at the expected position
51 #####################################################################
52
53 @docked = get_dock_clients('top');
54 is(@docked, 1, 'one dock client found');
55
56 # verify the position/size
57 my $docknode = $docked[0];
58
59 is($docknode->{rect}->{x}, 0, 'dock node placed at x=0');
60 is($docknode->{rect}->{y}, 0, 'dock node placed at y=0');
61 is($docknode->{rect}->{width}, $primary->rect->width, 'dock node as wide as the screen');
62 is($docknode->{rect}->{height}, 30, 'dock node has unchanged height');
63
64 #####################################################################
65 # check that re-configuring the height works
66 #####################################################################
67
68 $window->rect(X11::XCB::Rect->new(x => 0, y => 0, width => 50, height => 40));
69
70 sync_with_i3 $x;
71
72 @docked = get_dock_clients('top');
73 is(@docked, 1, 'one dock client found');
74
75 # verify the position/size
76 $docknode = $docked[0];
77
78 is($docknode->{rect}->{x}, 0, 'dock node placed at x=0');
79 is($docknode->{rect}->{y}, 0, 'dock node placed at y=0');
80 is($docknode->{rect}->{width}, $primary->rect->width, 'dock node as wide as the screen');
81 is($docknode->{rect}->{height}, 40, 'dock height changed');
82
83 $window->destroy;
84
85 wait_for_unmap $x;
86
87 @docked = get_dock_clients();
88 is(@docked, 0, 'no more dock clients');
89
90 #####################################################################
91 # check if it gets placed on bottom (by coordinates)
92 #####################################################################
93
94 $window = $x->root->create_child(
95     class => WINDOW_CLASS_INPUT_OUTPUT,
96     rect => [ 0, 1000, 30, 30],
97     background_color => '#FF0000',
98     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
99     event_mask => [ 'structure_notify' ],
100 );
101
102 $window->map;
103
104 wait_for_map $x;
105
106 my $rect = $window->rect;
107 is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
108 is($rect->height, 30, 'height is unchanged');
109
110 @docked = get_dock_clients('bottom');
111 is(@docked, 1, 'dock client on bottom');
112
113 $window->destroy;
114
115 wait_for_unmap $x;
116
117 @docked = get_dock_clients();
118 is(@docked, 0, 'no more dock clients');
119
120 #####################################################################
121 # check if it gets placed on bottom (by hint)
122 #####################################################################
123
124 $window = $x->root->create_child(
125     class => WINDOW_CLASS_INPUT_OUTPUT,
126     rect => [ 0, 1000, 30, 30],
127     background_color => '#FF0000',
128     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
129     event_mask => [ 'structure_notify' ],
130 );
131
132 $window->_create();
133
134 # Add a _NET_WM_STRUT_PARTIAL hint
135 my $atomname = $x->atom(name => '_NET_WM_STRUT_PARTIAL');
136 my $atomtype = $x->atom(name => 'CARDINAL');
137
138 $x->change_property(
139     PROP_MODE_REPLACE,
140     $window->id,
141     $atomname->id,
142     $atomtype->id,
143     32,         # 32 bit integer
144     12,
145     pack('L12', 0, 0, 16, 0, 0, 0, 0, 0, 0, 1280, 0, 0)
146 );
147
148 $window->map;
149
150 wait_for_map $x;
151
152 @docked = get_dock_clients('top');
153 is(@docked, 1, 'dock client on top');
154
155 $window->destroy;
156
157 wait_for_unmap $x;
158
159 @docked = get_dock_clients();
160 is(@docked, 0, 'no more dock clients');
161
162 $window = $x->root->create_child(
163     class => WINDOW_CLASS_INPUT_OUTPUT,
164     rect => [ 0, 1000, 30, 30],
165     background_color => '#FF0000',
166     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
167     event_mask => [ 'structure_notify' ],
168 );
169
170 $window->_create();
171
172 # Add a _NET_WM_STRUT_PARTIAL hint
173 my $atomname = $x->atom(name => '_NET_WM_STRUT_PARTIAL');
174 my $atomtype = $x->atom(name => 'CARDINAL');
175
176 $x->change_property(
177     PROP_MODE_REPLACE,
178     $window->id,
179     $atomname->id,
180     $atomtype->id,
181     32,         # 32 bit integer
182     12,
183     pack('L12', 0, 0, 0, 16, 0, 0, 0, 0, 0, 1280, 0, 0)
184 );
185
186 $window->map;
187
188 wait_for_map $x;
189
190 @docked = get_dock_clients('bottom');
191 is(@docked, 1, 'dock client on bottom');
192
193 $window->destroy;
194
195
196 #####################################################################
197 # regression test: transient dock client
198 #####################################################################
199
200 my $fwindow = $x->root->create_child(
201     class => WINDOW_CLASS_INPUT_OUTPUT,
202     rect => [ 0, 0, 30, 30],
203     background_color => '#FF0000',
204     window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
205     event_mask => [ 'structure_notify' ],
206 );
207
208 $fwindow->transient_for($window);
209 $fwindow->map;
210
211 wait_for_map $x;
212
213 does_i3_live;
214
215 done_testing;