forge
Explore
Log in

Don't you dare go Hollow

headless: keep redrawing while animations are ongoing

Browse files at this commit

135f0a1bfc3795cfba15547044341d7e02e3dff9Ahmet Kaan GümüşParent: a545e1b
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.rsmodified+31 -1
@@ -5,6 +5,7 @@
5 5
6 use std::mem;6 use std::mem;
7 use std::sync::{Arc, Mutex};7 use std::sync::{Arc, Mutex};
8+use std::time::Duration;
8 9
9 use anyhow::Context as _;10 use anyhow::Context as _;
10 use niri_config::OutputName;11 use niri_config::OutputName;
@@ -15,6 +16,7 @@ use smithay::backend::egl::{EGLContext, EGLDisplay};
15 use smithay::backend::renderer::element::RenderElementStates;16 use smithay::backend::renderer::element::RenderElementStates;
16 use smithay::backend::renderer::gles::GlesRenderer;17 use smithay::backend::renderer::gles::GlesRenderer;
17 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};18 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
19+use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
18 use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;20 use smithay::reexports::wayland_protocols::wp::presentation_time::server::wp_presentation_feedback;
19 use smithay::utils::Size;21 use smithay::utils::Size;
20 use smithay::wayland::presentation::Refresh;22 use smithay::wayland::presentation::Refresh;
@@ -27,6 +29,9 @@ use crate::utils::{get_monotonic_time, logical_output};
27 pub struct Headless {29 pub struct Headless {
28 renderer: Option<GlesRenderer>,30 renderer: Option<GlesRenderer>,
29 ipc_outputs: Arc<Mutex<IpcOutputMap>>,31 ipc_outputs: Arc<Mutex<IpcOutputMap>>,
32+ /// Keep redrawing at the output refresh rate while animations are ongoing, like a real display
33+ /// would.
34+ redraw_animations: bool,
30 }35 }
31 36
32 impl Headless {37 impl Headless {
@@ -34,9 +39,16 @@ impl Headless {
34 Self {39 Self {
35 renderer: None,40 renderer: None,
36 ipc_outputs: Default::default(),41 ipc_outputs: Default::default(),
42+ redraw_animations: false,
37 }43 }
38 }44 }
39 45
46+ /// Keeps redrawing while animations are ongoing, instead of only when something queues a
47+ /// redraw. Not used in tests, which drive redraws themselves.
48+ pub fn enable_animation_redraws(&mut self) {
49+ self.redraw_animations = true;
50+ }
51+
40 pub fn init(&mut self, _niri: &mut Niri) {}52 pub fn init(&mut self, _niri: &mut Niri) {}
41 53
42 pub fn add_renderer(&mut self) -> anyhow::Result<()> {54 pub fn add_renderer(&mut self) -> anyhow::Result<()> {
@@ -153,7 +165,25 @@ impl Headless {
153 165
154 output_state.frame_callback_sequence = output_state.frame_callback_sequence.wrapping_add(1);166 output_state.frame_callback_sequence = output_state.frame_callback_sequence.wrapping_add(1);
155 167
156- // FIXME: request redraw on unfinished animations remain168+ let unfinished_animations_remain = output_state.unfinished_animations_remain;
169+
170+ // There's no vblank, so emulate one to drive ongoing animations.
171+ if self.redraw_animations && unfinished_animations_remain {
172+ let refresh = output.current_mode().map_or(60_000, |mode| mode.refresh);
173+ let interval =
174+ Duration::from_micros(1_000_000_000 / u64::from(refresh.max(1).unsigned_abs()));
175+ let output = output.clone();
176+ let timer = Timer::from_duration(interval);
177+ niri.event_loop
178+ .insert_source(timer, move |_, _, state| {
179+ // The output may be gone by now.
180+ if state.niri.output_state.contains_key(&output) {
181+ state.niri.queue_redraw(&output);
182+ }
183+ TimeoutAction::Drop
184+ })
185+ .unwrap();
186+ }
157 187
158 RenderResult::Submitted188 RenderResult::Submitted
159 }189 }
src/main.rsmodified+1 -0
@@ -202,6 +202,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
202 return Err(err.into());202 return Err(err.into());
203 }203 }
204 headless.add_output(&mut state.niri, 1, (1920, 1080));204 headless.add_output(&mut state.niri, 1, (1920, 1080));
205+ headless.enable_animation_redraws();
205 }206 }
206 207
207 // Set WAYLAND_DISPLAY for children.208 // Set WAYLAND_DISPLAY for children.