aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/102-dock.t
blob: 60352d6df7471f02f601182981a107f546f04210 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)

use i3test;
use X11::XCB 'PROP_MODE_REPLACE';
use List::Util qw(first);

#####################################################################
# verify that there is no dock window yet
#####################################################################

# Children of all dockareas
my @docked = get_dock_clients;
is(@docked, 0, 'no dock clients yet');

#####################################################################
# Create a dock window and see if it gets managed
#####################################################################

my $screens = $x->screens;

# Get the primary screen
my $primary = first { $_->primary } @{$screens};

# TODO: focus the primary screen before
my $window = open_window({
        window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
    });

my $rect = $window->rect;
is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
is($rect->height, 30, 'height is unchanged');

#####################################################################
# check that we can find it in the layout tree at the expected position
#####################################################################

@docked = get_dock_clients('top');
is(@docked, 1, 'one dock client found');

# verify the position/size
my $docknode = $docked[0];

is($docknode->{rect}->{x}, 0, 'dock node placed at x=0');
is($docknode->{rect}->{y}, 0, 'dock node placed at y=0');
is($docknode->{rect}->{width}, $primary->rect->width, 'dock node as wide as the screen');
is($docknode->{rect}->{height}, 30, 'dock node has unchanged height');

#####################################################################
# check that re-configuring the height works
#####################################################################

$window->rect(X11::XCB::Rect->new(x => 0, y => 0, width => 50, height => 40));

sync_with_i3;

@docked = get_dock_clients('top');
is(@docked, 1, 'one dock client found');

# verify the position/size
$docknode = $docked[0];

is($docknode->{rect}->{x}, 0, 'dock node placed at x=0');
is($docknode->{rect}->{y}, 0, 'dock node placed at y=0');
is($docknode->{rect}->{width}, $primary->rect->width, 'dock node as wide as the screen');
is($docknode->{rect}->{height}, 40, 'dock height changed');

$window->destroy;

wait_for_unmap $window;

@docked = get_dock_clients();
is(@docked, 0, 'no more dock clients');

#####################################################################
# check if it gets placed on bottom (by coordinates)
#####################################################################

$window = open_window({
        rect => [ 0, 1000, 30, 30 ],
        background_color => '#FF0000',
        window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
    });

$rect = $window->rect;
is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
is($rect->height, 30, 'height is unchanged');

@docked = get_dock_clients('bottom');
is(@docked, 1, 'dock client on bottom');

$window->destroy;

wait_for_unmap $window;

@docked = get_dock_clients();
is(@docked, 0, 'no more dock clients');

#####################################################################
# check if it gets placed on bottom (by hint)
#####################################################################

$window = open_window({
        dont_map => 1,
        rect => [ 0, 1000, 30, 30 ],
        background_color => '#FF0000',
        window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
    });

$window->_create();

# Add a _NET_WM_STRUT_PARTIAL hint
my $atomname = $x->atom(name => '_NET_WM_STRUT_PARTIAL');
my $atomtype = $x->atom(name => 'CARDINAL');

$x->change_property(
    PROP_MODE_REPLACE,
    $window->id,
    $atomname->id,
    $atomtype->id,
    32,         # 32 bit integer
    12,
    pack('L12', 0, 0, 16, 0, 0, 0, 0, 0, 0, 1280, 0, 0)
);

$window->map;

wait_for_map $window;

@docked = get_dock_clients('top');
is(@docked, 1, 'dock client on top');

# now change strut_partial to reserve space on the bottom and the dock should
# be moved to the bottom dock area
$x->change_property(
    PROP_MODE_REPLACE,
    $window->id,
    $atomname->id,
    $atomtype->id,
    32,         # 32 bit integer
    12,
    pack('L12', 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 1280, 0)
);

sync_with_i3;
@docked = get_dock_clients('bottom');
is(@docked, 1, 'dock client on bottom');

$window->destroy;

wait_for_unmap $window;

@docked = get_dock_clients();
is(@docked, 0, 'no more dock clients');

$window = open_window({
        dont_map => 1,
        rect => [ 0, 1000, 30, 30 ],
        background_color => '#FF0000',
        window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
    });

$window->_create();

# Add a _NET_WM_STRUT_PARTIAL hint
$atomname = $x->atom(name => '_NET_WM_STRUT_PARTIAL');
$atomtype = $x->atom(name => 'CARDINAL');

$x->change_property(
    PROP_MODE_REPLACE,
    $window->id,
    $atomname->id,
    $atomtype->id,
    32,         # 32 bit integer
    12,
    pack('L12', 0, 0, 0, 16, 0, 0, 0, 0, 0, 1280, 0, 0)
);

$window->map;

wait_for_map $window;

@docked = get_dock_clients('bottom');
is(@docked, 1, 'dock client on bottom');

$window->destroy;


#####################################################################
# regression test: transient dock client
#####################################################################

my $fwindow = open_window({
        dont_map => 1,
        background_color => '#FF0000',
        window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
    });

$fwindow->transient_for($window);
$fwindow->map;

wait_for_map $fwindow;

does_i3_live;

done_testing;