From a545e1b13d9b788d4a1a0a2ea1eabbfa68240024 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 27 Oct 2026 04:11:07 +0300 Subject: [PATCH] Add --headless flag 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.rs | 6 ++++++ src/main.rs | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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);