From 135f0a1bfc3795cfba15547044341d7e02e3dff9 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 05:30:18 +0300 Subject: [PATCH] headless: keep redrawing while animations are ongoing With --headless there is no vblank, so emulate one with a timer at the output refresh rate while animations remain. Tests are unaffected. --- src/backend/headless.rs | 32 +++++++++++++++++++++++++++++++- src/main.rs | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/backend/headless.rs b/src/backend/headless.rs index 53bfe2ee..6891108e 100644 --- a/src/backend/headless.rs +++ b/src/backend/headless.rs @@ -5,6 +5,7 @@ use std::mem; use std::sync::{Arc, Mutex}; +use std::time::Duration; use anyhow::Context as _; use niri_config::OutputName; @@ -15,6 +16,7 @@ use smithay::backend::egl::{EGLContext, EGLDisplay}; use smithay::backend::renderer::element::RenderElementStates; use smithay::backend::renderer::gles::GlesRenderer; use smithay::output::{Mode, Output, PhysicalProperties, Subpixel}; +use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback; use smithay::utils::Size; use smithay::wayland::presentation::Refresh; @@ -27,6 +29,9 @@ use crate::utils::{get_monotonic_time, logical_output}; pub struct Headless { renderer: Option, ipc_outputs: Arc>, + /// Keep redrawing at the output refresh rate while animations are ongoing, like a real display + /// would. + redraw_animations: bool, } impl Headless { @@ -34,9 +39,16 @@ impl Headless { Self { renderer: None, ipc_outputs: Default::default(), + redraw_animations: false, } } + /// Keeps redrawing while animations are ongoing, instead of only when something queues a + /// redraw. Not used in tests, which drive redraws themselves. + pub fn enable_animation_redraws(&mut self) { + self.redraw_animations = true; + } + pub fn init(&mut self, _niri: &mut Niri) {} pub fn add_renderer(&mut self) -> anyhow::Result<()> { @@ -153,7 +165,25 @@ impl Headless { output_state.frame_callback_sequence = output_state.frame_callback_sequence.wrapping_add(1); - // FIXME: request redraw on unfinished animations remain + let unfinished_animations_remain = output_state.unfinished_animations_remain; + + // There's no vblank, so emulate one to drive ongoing animations. + if self.redraw_animations && unfinished_animations_remain { + let refresh = output.current_mode().map_or(60_000, |mode| mode.refresh); + let interval = + Duration::from_micros(1_000_000_000 / u64::from(refresh.max(1).unsigned_abs())); + let output = output.clone(); + let timer = Timer::from_duration(interval); + niri.event_loop + .insert_source(timer, move |_, _, state| { + // The output may be gone by now. + if state.niri.output_state.contains_key(&output) { + state.niri.queue_redraw(&output); + } + TimeoutAction::Drop + }) + .unwrap(); + } RenderResult::Submitted } diff --git a/src/main.rs b/src/main.rs index 292b8ece..10581a4d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -202,6 +202,7 @@ fn main() -> Result<(), Box> { return Err(err.into()); } headless.add_output(&mut state.niri, 1, (1920, 1080)); + headless.enable_animation_redraws(); } // Set WAYLAND_DISPLAY for children.