forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiBfcd10feRoss Smyth1 year ago2398 commits

layer_shell.rs258 lines, 8.4 KiBHistoryRawDownload
1use insta::assert_snapshot;
2use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_shell_v1::Layer;
3use smithay::reexports::wayland_protocols_wlr::layer_shell::v1::client::zwlr_layer_surface_v1::{
4 Anchor, KeyboardInteractivity,
5};
6
7use super::*;
8use crate::tests::client::{LayerConfigureProps, LayerMargin};
9
10#[test]
11fn simple_top_anchor() {
12 let mut f = Fixture::new();
13 f.add_output(1, (1920, 1080));
14 let id = f.add_client();
15
16 let layer = f.client(id).create_layer(None, Layer::Top, "");
17 let surface = layer.surface.clone();
18 layer.set_configure_props(LayerConfigureProps {
19 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
20 size: Some((0, 50)),
21 ..Default::default()
22 });
23 layer.commit();
24 f.roundtrip(id);
25
26 let layer = f.client(id).layer(&surface);
27 layer.attach_new_buffer();
28 layer.set_size(100, 100);
29 layer.ack_last_and_commit();
30 f.double_roundtrip(id);
31
32 let layer = f.client(id).layer(&surface);
33 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
34}
35
36#[test]
37fn margin_overflow() {
38 let mut f = Fixture::new();
39 f.add_output(1, (1920, 1080));
40 let id = f.add_client();
41
42 let layer = f.client(id).create_layer(None, Layer::Top, "");
43 let surface = layer.surface.clone();
44 layer.set_configure_props(LayerConfigureProps {
45 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom),
46 margin: Some(LayerMargin {
47 top: i32::MAX,
48 right: i32::MAX,
49 bottom: i32::MAX,
50 left: i32::MAX,
51 }),
52 exclusive_zone: Some(i32::MAX),
53 ..Default::default()
54 });
55 layer.commit();
56 f.roundtrip(id);
57
58 let layer = f.client(id).layer(&surface);
59 layer.attach_new_buffer();
60 layer.set_size(100, 100);
61 layer.ack_last_and_commit();
62 f.double_roundtrip(id);
63
64 let layer = f.client(id).layer(&surface);
65 assert_snapshot!(layer.format_recent_configures(), @"size: 0 × 0");
66
67 // Add a second one for good measure.
68 let layer = f.client(id).create_layer(None, Layer::Top, "");
69 let surface = layer.surface.clone();
70 layer.set_configure_props(LayerConfigureProps {
71 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top | Anchor::Bottom),
72 margin: Some(LayerMargin {
73 top: i32::MAX,
74 right: i32::MAX,
75 bottom: i32::MAX,
76 left: i32::MAX,
77 }),
78 exclusive_zone: Some(i32::MAX),
79 ..Default::default()
80 });
81 layer.commit();
82 f.roundtrip(id);
83
84 let layer = f.client(id).layer(&surface);
85 layer.attach_new_buffer();
86 layer.set_size(100, 100);
87 layer.ack_last_and_commit();
88 f.double_roundtrip(id);
89
90 let layer = f.client(id).layer(&surface);
91 assert_snapshot!(layer.format_recent_configures(), @"size: 0 × 0");
92}
93
94#[test]
95fn unmap_through_null_buffer() {
96 let mut f = Fixture::new();
97 f.add_output(1, (1920, 1080));
98 let id = f.add_client();
99
100 let layer = f.client(id).create_layer(None, Layer::Top, "");
101 let surface = layer.surface.clone();
102 layer.set_configure_props(LayerConfigureProps {
103 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
104 size: Some((0, 50)),
105 ..Default::default()
106 });
107 layer.commit();
108 f.double_roundtrip(id);
109
110 let layer = f.client(id).layer(&surface);
111 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
112
113 layer.attach_new_buffer();
114 layer.set_size(100, 100);
115 layer.ack_last_and_commit();
116 f.double_roundtrip(id);
117
118 let layer = f.client(id).layer(&surface);
119 // No new configure since nothing changed.
120 assert_snapshot!(layer.format_recent_configures(), @"");
121
122 // Unmap by attaching a null buffer. This moves the surface back to pre-initial-commit stage.
123 layer.attach_null();
124 layer.commit();
125 f.double_roundtrip(id);
126
127 let layer = f.client(id).layer(&surface);
128 // Configures must be empty because we haven't done an initial commit yet.
129 assert_snapshot!(layer.format_recent_configures(), @"");
130
131 // Do the initial commit again.
132 layer.set_configure_props(LayerConfigureProps {
133 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
134 size: Some((0, 100)),
135 ..Default::default()
136 });
137 layer.commit();
138 f.double_roundtrip(id);
139
140 let layer = f.client(id).layer(&surface);
141 // This is the new initial configure.
142 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
143
144 layer.attach_new_buffer();
145 layer.set_size(100, 100);
146 layer.ack_last_and_commit();
147 f.double_roundtrip(id);
148
149 let layer = f.client(id).layer(&surface);
150 assert_snapshot!(layer.format_recent_configures(), @"");
151}
152
153#[test]
154fn multiple_commits_before_mapping() {
155 let mut f = Fixture::new();
156 f.add_output(1, (1920, 1080));
157 let id = f.add_client();
158
159 let layer = f.client(id).create_layer(None, Layer::Top, "");
160 let surface = layer.surface.clone();
161 layer.set_configure_props(LayerConfigureProps {
162 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
163 size: Some((0, 50)),
164 ..Default::default()
165 });
166 layer.commit();
167 f.double_roundtrip(id);
168
169 let layer = f.client(id).layer(&surface);
170 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
171
172 // Change something that won't cause a configure.
173 layer.set_configure_props(LayerConfigureProps {
174 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
175 size: Some((0, 50)),
176 kb_interactivity: Some(KeyboardInteractivity::OnDemand),
177 ..Default::default()
178 });
179 layer.ack_last_and_commit();
180 f.double_roundtrip(id);
181
182 let layer = f.client(id).layer(&surface);
183 // No new configure since the size hasn't changed.
184 assert_snapshot!(layer.format_recent_configures(), @"");
185
186 // Change something that will cause a configure.
187 layer.set_configure_props(LayerConfigureProps {
188 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
189 size: Some((0, 100)),
190 ..Default::default()
191 });
192 layer.commit();
193 f.double_roundtrip(id);
194
195 let layer = f.client(id).layer(&surface);
196 // Configure with new size.
197 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
198
199 // Map.
200 layer.attach_new_buffer();
201 layer.set_size(100, 100);
202 layer.ack_last_and_commit();
203 f.double_roundtrip(id);
204
205 let layer = f.client(id).layer(&surface);
206 // No new configure since nothing changed.
207 assert_snapshot!(layer.format_recent_configures(), @"");
208
209 // Unmap by attaching a null buffer. This moves the surface back to pre-initial-commit stage.
210 layer.attach_null();
211 layer.commit();
212 f.double_roundtrip(id);
213
214 let layer = f.client(id).layer(&surface);
215 // Configures must be empty because we haven't done an initial commit yet.
216 assert_snapshot!(layer.format_recent_configures(), @"");
217
218 // Same configure props as before, but since we unmapped, we should get a new initial
219 // configure (that will happen to match the previous configure we had got while mapped).
220 let surface = layer.surface.clone();
221 layer.set_configure_props(LayerConfigureProps {
222 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
223 size: Some((0, 100)),
224 ..Default::default()
225 });
226 layer.commit();
227 f.double_roundtrip(id);
228
229 let layer = f.client(id).layer(&surface);
230 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 100");
231
232 // Change something that won't cause a configure.
233 layer.set_configure_props(LayerConfigureProps {
234 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
235 size: Some((0, 100)),
236 kb_interactivity: Some(KeyboardInteractivity::OnDemand),
237 ..Default::default()
238 });
239 layer.ack_last_and_commit();
240 f.double_roundtrip(id);
241
242 let layer = f.client(id).layer(&surface);
243 // No new configure since the size hasn't changed.
244 assert_snapshot!(layer.format_recent_configures(), @"");
245
246 // Change something that will cause a configure.
247 layer.set_configure_props(LayerConfigureProps {
248 anchor: Some(Anchor::Left | Anchor::Right | Anchor::Top),
249 size: Some((0, 50)),
250 ..Default::default()
251 });
252 layer.commit();
253 f.double_roundtrip(id);
254
255 let layer = f.client(id).layer(&surface);
256 // Configure with new size.
257 assert_snapshot!(layer.format_recent_configures(), @"size: 1920 × 50");
258}