forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

fullscreen.rs297 lines, 9.5 KiBHistoryRawDownload
1use client::ClientId;
2use insta::assert_snapshot;
3use smithay::utils::Point;
4use wayland_client::protocol::wl_surface::WlSurface;
5
6use super::*;
7use crate::layout::LayoutElement as _;
8
9// Sets up a fixture with two outputs and 100×100 window.
10fn set_up() -> (Fixture, ClientId, WlSurface) {
11 let mut f = Fixture::new();
12 f.add_output(1, (1920, 1080));
13 f.add_output(2, (1280, 720));
14
15 let id = f.add_client();
16 let window = f.client(id).create_window();
17 let surface = window.surface.clone();
18 window.commit();
19 f.roundtrip(id);
20
21 let window = f.client(id).window(&surface);
22 window.attach_new_buffer();
23 window.set_size(100, 100);
24 window.ack_last_and_commit();
25 f.double_roundtrip(id);
26
27 (f, id, surface)
28}
29
30#[test]
31fn windowed_fullscreen() {
32 let (mut f, id, surface) = set_up();
33
34 let _ = f.client(id).window(&surface).recent_configures();
35
36 let niri = f.niri();
37 let mapped = niri.layout.windows().next().unwrap().1;
38 let window_id = mapped.window.clone();
39
40 // Enable windowed fullscreen.
41 niri.layout.toggle_windowed_fullscreen(&window_id);
42 f.double_roundtrip(id);
43
44 // Should request fullscreen state with the tiled size.
45 let window = f.client(id).window(&surface);
46 assert_snapshot!(
47 window.format_recent_configures(),
48 @"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
49 );
50
51 let mapped = f.niri().layout.windows().next().unwrap().1;
52 // Not committed yet.
53 assert!(!mapped.is_windowed_fullscreen());
54
55 // Commit in response.
56 let window = f.client(id).window(&surface);
57 window.ack_last_and_commit();
58 f.roundtrip(id);
59
60 let mapped = f.niri().layout.windows().next().unwrap().1;
61 // Now it is committed.
62 assert!(mapped.is_windowed_fullscreen());
63
64 // Disable windowed fullscreen.
65 f.niri().layout.toggle_windowed_fullscreen(&window_id);
66 f.double_roundtrip(id);
67
68 // Should request without fullscreen state with the tiled size.
69 let window = f.client(id).window(&surface);
70 assert_snapshot!(
71 window.format_recent_configures(),
72 @"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]"
73 );
74
75 let mapped = f.niri().layout.windows().next().unwrap().1;
76 // Not committed yet.
77 assert!(mapped.is_windowed_fullscreen());
78
79 // Commit in response.
80 let window = f.client(id).window(&surface);
81 window.ack_last_and_commit();
82 f.roundtrip(id);
83
84 let mapped = f.niri().layout.windows().next().unwrap().1;
85 // Now it is committed.
86 assert!(!mapped.is_windowed_fullscreen());
87}
88
89#[test]
90fn windowed_fullscreen_chain() {
91 let (mut f, id, surface) = set_up();
92
93 let _ = f.client(id).window(&surface).recent_configures();
94
95 let mapped = f.niri().layout.windows().next().unwrap().1;
96 let window_id = mapped.window.clone();
97
98 f.niri().layout.toggle_windowed_fullscreen(&window_id);
99 f.roundtrip(id);
100 f.niri().layout.toggle_windowed_fullscreen(&window_id);
101 f.roundtrip(id);
102 f.niri().layout.toggle_windowed_fullscreen(&window_id);
103 f.roundtrip(id);
104 f.niri().layout.toggle_windowed_fullscreen(&window_id);
105 f.double_roundtrip(id);
106
107 // Should be four configures matching the four requests.
108 let window = f.client(id).window(&surface);
109 assert_snapshot!(
110 window.format_recent_configures(),
111 @r"
112 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
113 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
114 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
115 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
116 "
117 );
118
119 let window = f.client(id).window(&surface);
120 let serials = Vec::from_iter(
121 window.configures_received[window.configures_received.len() - 4..]
122 .iter()
123 .map(|(s, _c)| *s),
124 );
125
126 let get_state = |f: &mut Fixture| {
127 let mapped = f.niri().layout.windows().next().unwrap().1;
128 format!(
129 "fs {}, wfs {}",
130 mapped.sizing_mode().is_fullscreen(),
131 mapped.is_windowed_fullscreen()
132 )
133 };
134
135 let mut states = vec![get_state(&mut f)];
136 for serial in serials {
137 let window = f.client(id).window(&surface);
138 window.xdg_surface.ack_configure(serial);
139 window.commit();
140 f.roundtrip(id);
141 states.push(get_state(&mut f));
142 }
143
144 // We expect fs to always be false (because each Fullscreen state request corresponded to a
145 // windowed fullscreen), and wfs to toggle on and off.
146 assert_snapshot!(
147 states.join("\n"),
148 @r"
149 fs false, wfs false
150 fs false, wfs true
151 fs false, wfs false
152 fs false, wfs true
153 fs false, wfs false
154 "
155 );
156}
157
158#[test]
159fn unfullscreen_before_fullscreen_ack_doesnt_prevent_view_offset_save_restore() {
160 let (mut f, id, _surface) = set_up();
161
162 let window2 = f.client(id).create_window();
163 let surface2 = window2.surface.clone();
164 window2.commit();
165 f.roundtrip(id);
166
167 let window2 = f.client(id).window(&surface2);
168 window2.attach_new_buffer();
169 window2.set_size(200, 200);
170 window2.ack_last_and_commit();
171 f.double_roundtrip(id);
172
173 let _ = f.client(id).window(&surface2).recent_configures();
174
175 let niri = f.niri();
176 let mapped2 = niri.layout.windows().last().unwrap().1;
177 let window2_id = mapped2.window.clone();
178
179 // The view position is at the first window.
180 assert_snapshot!(niri.layout.active_workspace().unwrap().scrolling().view_pos(), @"-16");
181
182 // Fullscreen window2 and send the configure so we can clear pending.
183 niri.layout.set_fullscreen(&window2_id, true);
184 f.double_roundtrip(id);
185
186 // Before acking, unfullscreen the column, clearing the pending fullscreen flag.
187 f.niri().layout.set_fullscreen(&window2_id, false);
188
189 // Now, window2 receives the fullscreen configure and resizes in response.
190 let window2 = f.client(id).window(&surface2);
191 assert_snapshot!(
192 window2.format_recent_configures(),
193 @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
194 );
195 let (_, configure) = window2.configures_received.last().unwrap();
196 window2.set_size(configure.size.0 as u16, configure.size.1 as u16);
197 window2.ack_last_and_commit();
198 f.double_roundtrip(id);
199 f.niri_complete_animations();
200
201 // The view position is now at the fullscreen-sized window2.
202 assert_snapshot!(f.niri().layout.active_workspace().unwrap().scrolling().view_pos(), @"116");
203
204 // Now, window2 receives the unfullscreen configure and resizes in response.
205 let window2 = f.client(id).window(&surface2);
206 assert_snapshot!(
207 window2.format_recent_configures(),
208 @"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]"
209 );
210 window2.set_size(200, 200);
211 window2.ack_last_and_commit();
212 f.roundtrip(id);
213 f.niri_complete_animations();
214
215 // The view position should restore to the first window.
216 assert_snapshot!(f.niri().layout.active_workspace().unwrap().scrolling().view_pos(), @"-16");
217}
218
219#[test]
220fn interactive_move_unfullscreen_to_scrolling_restores_size() {
221 let (mut f, id, surface) = set_up();
222
223 let _ = f.client(id).window(&surface).recent_configures();
224
225 let niri = f.niri();
226 let mapped = niri.layout.windows().next().unwrap().1;
227 let window = mapped.window.clone();
228 niri.layout.set_fullscreen(&window, true);
229 f.double_roundtrip(id);
230
231 // This should request a fullscreen size.
232 assert_snapshot!(
233 f.client(id).window(&surface).format_recent_configures(),
234 @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
235 );
236
237 // Start an interactive move which causes an unfullscreen.
238 let output = f.niri_output(1);
239 let niri = f.niri();
240 let mapped = niri.layout.windows().next().unwrap().1;
241 let window = mapped.window.clone();
242 niri.layout
243 .interactive_move_begin(window.clone(), &output, Point::default());
244 niri.layout.interactive_move_update(
245 &window,
246 Point::from((1000., 0.)),
247 output,
248 Point::default(),
249 );
250 f.double_roundtrip(id);
251
252 // This should request the tiled size.
253 assert_snapshot!(
254 f.client(id).window(&surface).format_recent_configures(),
255 @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]"
256 );
257}
258
259#[test]
260fn interactive_move_unmaximize_to_scrolling_restores_size() {
261 let (mut f, id, surface) = set_up();
262
263 let _ = f.client(id).window(&surface).recent_configures();
264
265 let niri = f.niri();
266 let mapped = niri.layout.windows().next().unwrap().1;
267 let window = mapped.window.clone();
268 niri.layout.set_maximized(&window, true);
269 f.double_roundtrip(id);
270
271 // This should request a maximized size.
272 assert_snapshot!(
273 f.client(id).window(&surface).format_recent_configures(),
274 @"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Maximized]"
275 );
276
277 // Start an interactive move which causes an unmaximize.
278 let output = f.niri_output(1);
279 let niri = f.niri();
280 let mapped = niri.layout.windows().next().unwrap().1;
281 let window = mapped.window.clone();
282 niri.layout
283 .interactive_move_begin(window.clone(), &output, Point::default());
284 niri.layout.interactive_move_update(
285 &window,
286 Point::from((1000., 0.)),
287 output,
288 Point::default(),
289 );
290 f.double_roundtrip(id);
291
292 // This should request the tiled size.
293 assert_snapshot!(
294 f.client(id).window(&surface).format_recent_configures(),
295 @"size: 936 × 1048, bounds: 1920 × 1080, states: [Activated]"
296 );
297}