forge
Explore
Log in

Don't you dare go Hollow

Add --headless flag

Browse files at this commit

a545e1b13d9b788d4a1a0a2ea1eabbfa68240024Ahmet Kaan GümüşParent: 9d8f4f8
Runs niri on the headless backend with one virtual 1920x1080 output, so
clients can be run and captured without showing anything on screen.
src/cli.rsmodified+6 -0
@@ -26,6 +26,12 @@ pub struct Cli {
26 /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.26 /// on a TTY as your non-main compositor instance, to avoid messing up the global environment.
27 #[arg(long)]27 #[arg(long)]
28 pub session: bool,28 pub session: bool,
29+ /// Run without a display, on a single virtual 1920x1080 output.
30+ ///
31+ /// Clients can connect to the Wayland socket as usual, and the output can be captured with
32+ /// screenshot tools, for example to test clients without showing anything on screen.
33+ #[arg(long, conflicts_with = "session")]
34+ pub headless: bool,
29 /// Command to run upon compositor startup.35 /// Command to run upon compositor startup.
30 #[arg(last = true)]36 #[arg(last = true)]
31 pub command: Vec<OsString>,37 pub command: Vec<OsString>,
src/main.rsmodified+11 -1
@@ -188,12 +188,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
188 event_loop.handle(),188 event_loop.handle(),
189 event_loop.get_signal(),189 event_loop.get_signal(),
190 display,190 display,
191- false,191+ cli.headless,
192 true,192 true,
193 cli.session,193 cli.session,
194 )194 )
195 .unwrap();195 .unwrap();
196 196
197+ if cli.headless {
198+ // The headless backend starts without a renderer or outputs (tests add them as needed).
199+ let headless = state.backend.headless();
200+ if let Err(err) = headless.add_renderer() {
201+ warn!("error creating the headless renderer: {err:?}");
202+ return Err(err.into());
203+ }
204+ headless.add_output(&mut state.niri, 1, (1920, 1080));
205+ }
206+
197 // Set WAYLAND_DISPLAY for children.207 // Set WAYLAND_DISPLAY for children.
198 let socket_name = state.niri.socket_name.as_deref().unwrap();208 let socket_name = state.niri.socket_name.as_deref().unwrap();
199 env::set_var("WAYLAND_DISPLAY", socket_name);209 env::set_var("WAYLAND_DISPLAY", socket_name);