diff --git a/src/cli.rs b/src/cli.rs index df69aa14..17d2677b 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -26,6 +26,12 @@ pub struct Cli { /// on a TTY as your non-main compositor instance, to avoid messing up the global environment. #[arg(long)] pub session: bool, + /// Run without a display, on a single virtual 1920x1080 output. + /// + /// Clients can connect to the Wayland socket as usual, and the output can be captured with + /// screenshot tools, for example to test clients without showing anything on screen. + #[arg(long, conflicts_with = "session")] + pub headless: bool, /// Command to run upon compositor startup. #[arg(last = true)] pub command: Vec, diff --git a/src/main.rs b/src/main.rs index f9563ae6..292b8ece 100644 --- a/src/main.rs +++ b/src/main.rs @@ -188,12 +188,22 @@ fn main() -> Result<(), Box> { event_loop.handle(), event_loop.get_signal(), display, - false, + cli.headless, true, cli.session, ) .unwrap(); + if cli.headless { + // The headless backend starts without a renderer or outputs (tests add them as needed). + let headless = state.backend.headless(); + if let Err(err) = headless.add_renderer() { + warn!("error creating the headless renderer: {err:?}"); + return Err(err.into()); + } + headless.add_output(&mut state.niri, 1, (1920, 1080)); + } + // Set WAYLAND_DISPLAY for children. let socket_name = state.niri.socket_name.as_deref().unwrap(); env::set_var("WAYLAND_DISPLAY", socket_name);