forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9ff2f83Ivan Molodetskikh1 year ago2099 commits

fullscreen.rs155 lines, 4.6 KiBHistoryRawDownload
1use client::ClientId;
2use insta::assert_snapshot;
3use wayland_client::protocol::wl_surface::WlSurface;
4
5use super::*;
6use crate::layout::LayoutElement as _;
7
8// Sets up a fixture with two outputs and 100×100 window.
9fn set_up() -> (Fixture, ClientId, WlSurface) {
10 let mut f = Fixture::new();
11 f.add_output(1, (1920, 1080));
12 f.add_output(2, (1280, 720));
13
14 let id = f.add_client();
15 let window = f.client(id).create_window();
16 let surface = window.surface.clone();
17 window.commit();
18 f.roundtrip(id);
19
20 let window = f.client(id).window(&surface);
21 window.attach_new_buffer();
22 window.set_size(100, 100);
23 window.ack_last_and_commit();
24 f.double_roundtrip(id);
25
26 (f, id, surface)
27}
28
29#[test]
30fn windowed_fullscreen() {
31 let (mut f, id, surface) = set_up();
32
33 let _ = f.client(id).window(&surface).recent_configures();
34
35 let niri = f.niri();
36 let mapped = niri.layout.windows().next().unwrap().1;
37 let window_id = mapped.window.clone();
38
39 // Enable windowed fullscreen.
40 niri.layout.toggle_windowed_fullscreen(&window_id);
41 f.double_roundtrip(id);
42
43 // Should request fullscreen state with the tiled size.
44 let window = f.client(id).window(&surface);
45 assert_snapshot!(
46 window.format_recent_configures(),
47 @"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]"
48 );
49
50 let mapped = f.niri().layout.windows().next().unwrap().1;
51 // Not committed yet.
52 assert!(!mapped.is_windowed_fullscreen());
53
54 // Commit in response.
55 let window = f.client(id).window(&surface);
56 window.ack_last_and_commit();
57 f.roundtrip(id);
58
59 let mapped = f.niri().layout.windows().next().unwrap().1;
60 // Now it is committed.
61 assert!(mapped.is_windowed_fullscreen());
62
63 // Disable windowed fullscreen.
64 f.niri().layout.toggle_windowed_fullscreen(&window_id);
65 f.double_roundtrip(id);
66
67 // Should request without fullscreen state with the tiled size.
68 let window = f.client(id).window(&surface);
69 assert_snapshot!(
70 window.format_recent_configures(),
71 @"size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]"
72 );
73
74 let mapped = f.niri().layout.windows().next().unwrap().1;
75 // Not commited yet.
76 assert!(mapped.is_windowed_fullscreen());
77
78 // Commit in response.
79 let window = f.client(id).window(&surface);
80 window.ack_last_and_commit();
81 f.roundtrip(id);
82
83 let mapped = f.niri().layout.windows().next().unwrap().1;
84 // Now it is committed.
85 assert!(!mapped.is_windowed_fullscreen());
86}
87
88#[test]
89fn windowed_fullscreen_chain() {
90 let (mut f, id, surface) = set_up();
91
92 let _ = f.client(id).window(&surface).recent_configures();
93
94 let mapped = f.niri().layout.windows().next().unwrap().1;
95 let window_id = mapped.window.clone();
96
97 f.niri().layout.toggle_windowed_fullscreen(&window_id);
98 f.roundtrip(id);
99 f.niri().layout.toggle_windowed_fullscreen(&window_id);
100 f.roundtrip(id);
101 f.niri().layout.toggle_windowed_fullscreen(&window_id);
102 f.roundtrip(id);
103 f.niri().layout.toggle_windowed_fullscreen(&window_id);
104 f.double_roundtrip(id);
105
106 // Should be four configures matching the four requests.
107 let window = f.client(id).window(&surface);
108 assert_snapshot!(
109 window.format_recent_configures(),
110 @r"
111 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
112 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
113 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated, Fullscreen]
114 size: 936 × 1048, bounds: 1888 × 1048, states: [Activated]
115 "
116 );
117
118 let window = f.client(id).window(&surface);
119 let serials = Vec::from_iter(
120 window.configures_received[window.configures_received.len() - 4..]
121 .iter()
122 .map(|(s, _c)| *s),
123 );
124
125 let get_state = |f: &mut Fixture| {
126 let mapped = f.niri().layout.windows().next().unwrap().1;
127 format!(
128 "fs {}, wfs {}",
129 mapped.is_fullscreen(),
130 mapped.is_windowed_fullscreen()
131 )
132 };
133
134 let mut states = vec![get_state(&mut f)];
135 for serial in serials {
136 let window = f.client(id).window(&surface);
137 window.xdg_surface.ack_configure(serial);
138 window.commit();
139 f.roundtrip(id);
140 states.push(get_state(&mut f));
141 }
142
143 // We expect fs to always be false (because each Fullscreen state request corresponded to a
144 // windowed fullscreen), and wfs to toggle on and off.
145 assert_snapshot!(
146 states.join("\n"),
147 @r"
148 fs false, wfs false
149 fs false, wfs true
150 fs false, wfs false
151 fs false, wfs true
152 fs false, wfs false
153 "
154 );
155}