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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
use client::ClientId;
use insta::assert_snapshot;
use smithay::utils::Point;
use wayland_client::protocol::wl_surface::WlSurface;
use super::*;
use crate::layout::LayoutElement as _;
// Sets up a fixture with two outputs and 100×100 window.
fn set_up() -> (Fixture, ClientId, WlSurface) {
let mut f = Fixture::new();
f.add_output(1, (1920, 1080));
f.add_output(2, (1280, 720));
let id = f.add_client();
let window = f.client(id).create_window();
let surface = window.surface.clone();
window.commit();
f.roundtrip(id);
let window = f.client(id).window(&surface);
window.attach_new_buffer();
window.set_size(100, 100);
window.ack_last_and_commit();
f.double_roundtrip(id);
(f, id, surface)
}
#[test]
fn windowed_fullscreen() {
let (mut f, id, surface) = set_up();
let _ = f.client(id).window(&surface).recent_configures();
let niri = f.niri();
let mapped = niri.layout.windows().next().unwrap().1;
let window_id = mapped.window.clone();
// Enable windowed fullscreen.
niri.layout.toggle_windowed_fullscreen(&window_id);
f.double_roundtrip(id);
// Should request fullscreen state with the tiled size.
let window = f.client(id).window(&surface);
assert_snapshot!(
window.format_recent_configures(),
@"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
);
let mapped = f.niri().layout.windows().next().unwrap().1;
// Not committed yet.
assert!(!mapped.is_windowed_fullscreen());
// Commit in response.
let window = f.client(id).window(&surface);
window.ack_last_and_commit();
f.roundtrip(id);
let mapped = f.niri().layout.windows().next().unwrap().1;
// Now it is committed.
assert!(mapped.is_windowed_fullscreen());
// Disable windowed fullscreen.
f.niri().layout.toggle_windowed_fullscreen(&window_id);
f.double_roundtrip(id);
// Should request without fullscreen state with the tiled size.
let window = f.client(id).window(&surface);
assert_snapshot!(
window.format_recent_configures(),
@"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]"
);
let mapped = f.niri().layout.windows().next().unwrap().1;
// Not committed yet.
assert!(mapped.is_windowed_fullscreen());
// Commit in response.
let window = f.client(id).window(&surface);
window.ack_last_and_commit();
f.roundtrip(id);
let mapped = f.niri().layout.windows().next().unwrap().1;
// Now it is committed.
assert!(!mapped.is_windowed_fullscreen());
}
#[test]
fn windowed_fullscreen_chain() {
let (mut f, id, surface) = set_up();
let _ = f.client(id).window(&surface).recent_configures();
let mapped = f.niri().layout.windows().next().unwrap().1;
let window_id = mapped.window.clone();
f.niri().layout.toggle_windowed_fullscreen(&window_id);
f.roundtrip(id);
f.niri().layout.toggle_windowed_fullscreen(&window_id);
f.roundtrip(id);
f.niri().layout.toggle_windowed_fullscreen(&window_id);
f.roundtrip(id);
f.niri().layout.toggle_windowed_fullscreen(&window_id);
f.double_roundtrip(id);
// Should be four configures matching the four requests.
let window = f.client(id).window(&surface);
assert_snapshot!(
window.format_recent_configures(),
@r"
size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
"
);
let window = f.client(id).window(&surface);
let serials = Vec::from_iter(
window.configures_received[window.configures_received.len() - 4..]
.iter()
.map(|(s, _c)| *s),
);
let get_state = |f: &mut Fixture| {
let mapped = f.niri().layout.windows().next().unwrap().1;
format!(
"fs {}, wfs {}",
mapped.sizing_mode().is_fullscreen(),
mapped.is_windowed_fullscreen()
)
};
let mut states = vec![get_state(&mut f)];
for serial in serials {
let window = f.client(id).window(&surface);
window.xdg_surface.ack_configure(serial);
window.commit();
f.roundtrip(id);
states.push(get_state(&mut f));
}
// We expect fs to always be false (because each Fullscreen state request corresponded to a
// windowed fullscreen), and wfs to toggle on and off.
assert_snapshot!(
states.join("\n"),
@r"
fs false, wfs false
fs false, wfs true
fs false, wfs false
fs false, wfs true
fs false, wfs false
"
);
}
#[test]
fn unfullscreen_before_fullscreen_ack_doesnt_prevent_view_offset_save_restore() {
let (mut f, id, _surface) = set_up();
let window2 = f.client(id).create_window();
let surface2 = window2.surface.clone();
window2.commit();
f.roundtrip(id);
let window2 = f.client(id).window(&surface2);
window2.attach_new_buffer();
window2.set_size(200, 200);
window2.ack_last_and_commit();
f.double_roundtrip(id);
let _ = f.client(id).window(&surface2).recent_configures();
let niri = f.niri();
let mapped2 = niri.layout.windows().last().unwrap().1;
let window2_id = mapped2.window.clone();
// The view position is at the first window.
assert_snapshot!(niri.layout.active_workspace().unwrap().scrolling().view_pos(), @"-16");
// Fullscreen window2 and send the configure so we can clear pending.
niri.layout.set_fullscreen(&window2_id, true);
f.double_roundtrip(id);
// Before acking, unfullscreen the column, clearing the pending fullscreen flag.
f.niri().layout.set_fullscreen(&window2_id, false);
// Now, window2 receives the fullscreen configure and resizes in response.
let window2 = f.client(id).window(&surface2);
assert_snapshot!(
window2.format_recent_configures(),
@"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
);
let (_, configure) = window2.configures_received.last().unwrap();
window2.set_size(configure.size.0 as u16, configure.size.1 as u16);
window2.ack_last_and_commit();
f.double_roundtrip(id);
f.niri_complete_animations();
// The view position is now at the fullscreen-sized window2.
assert_snapshot!(f.niri().layout.active_workspace().unwrap().scrolling().view_pos(), @"116");
// Now, window2 receives the unfullscreen configure and resizes in response.
let window2 = f.client(id).window(&surface2);
assert_snapshot!(
window2.format_recent_configures(),
@"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]"
);
window2.set_size(200, 200);
window2.ack_last_and_commit();
f.roundtrip(id);
f.niri_complete_animations();
// The view position should restore to the first window.
assert_snapshot!(f.niri().layout.active_workspace().unwrap().scrolling().view_pos(), @"-16");
}
#[test]
fn interactive_move_unfullscreen_to_scrolling_restores_size() {
let (mut f, id, surface) = set_up();
let _ = f.client(id).window(&surface).recent_configures();
let niri = f.niri();
let mapped = niri.layout.windows().next().unwrap().1;
let window = mapped.window.clone();
niri.layout.set_fullscreen(&window, true);
f.double_roundtrip(id);
// This should request a fullscreen size.
assert_snapshot!(
f.client(id).window(&surface).format_recent_configures(),
@"size: 1920 × 1080, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
);
// Start an interactive move which causes an unfullscreen.
let output = f.niri_output(1);
let niri = f.niri();
let mapped = niri.layout.windows().next().unwrap().1;
let window = mapped.window.clone();
niri.layout
.interactive_move_begin(window.clone(), &output, Point::default());
niri.layout.interactive_move_update(
&window,
Point::from((1000., 0.)),
output
|