From 3b65ba5c1da102ba3426e44ba56fd4e9910cdf4a Mon Sep 17 00:00:00 2001 From: Ottatop Date: Sat, 9 Sep 2023 16:28:58 -0500 Subject: [PATCH] Send frame callbacks when not rendering --- src/backend/winit.rs | 35 ++++++++++++++++++++++++++++++++--- src/input.rs | 1 - src/layout.rs | 4 ++-- src/state.rs | 4 ++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/backend/winit.rs b/src/backend/winit.rs index d8aa2a5..3d898c3 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -12,7 +12,10 @@ use smithay::{ }, winit::{WinitError, WinitEvent, WinitGraphicsBackend}, }, - desktop::{layer_map_for_output, utils::send_frames_surface_tree}, + desktop::{ + layer_map_for_output, + utils::{send_frames_surface_tree, surface_primary_scanout_output}, + }, input::pointer::CursorImageStatus, output::{Output, Subpixel}, reexports::{ @@ -32,7 +35,7 @@ use smithay::{ use crate::{ render::pointer::PointerElement, - state::{take_presentation_feedback, Backend, CalloopData, State}, + state::{take_presentation_feedback, Backend, CalloopData, State, WithState}, }; use super::BackendData; @@ -232,16 +235,42 @@ pub fn run_winit() -> anyhow::Result<()> { pointer_element.set_status(state.cursor_status.clone()); - if state.pause_rendering { + // TODO: make a pending_windows state, when pending_windows increases, + // | pause rendering. + // | If it goes down, push a frame, then repeat until no pending_windows are left. + + let pending_win_count = state + .windows + .iter() + .filter(|win| win.alive()) + .filter(|win| win.with_state(|state| !state.loc_request_state.is_idle())) + .count() as u32; + + if pending_win_count > 0 { + for win in state.windows.iter() { + win.send_frame( + &output, + state.clock.now(), + Some(Duration::ZERO), + surface_primary_scanout_output, + ); + } + state.space.refresh(); state.popup_manager.cleanup(); display .flush_clients() .expect("failed to flush client buffers"); + state.prev_pending_win_count = pending_win_count; + + // TODO: still draw the cursor here + return TimeoutAction::ToDuration(Duration::from_millis(1)); } + state.prev_pending_win_count = pending_win_count; + let Backend::Winit(backend) = &mut state.backend else { unreachable!() }; let full_redraw = &mut backend.full_redraw; *full_redraw = full_redraw.saturating_sub(1); diff --git a/src/input.rs b/src/input.rs index 176f932..d7b2482 100644 --- a/src/input.rs +++ b/src/input.rs @@ -20,7 +20,6 @@ use smithay::{ input::{ keyboard::{keysyms, FilterResult}, pointer::{AxisFrame, ButtonEvent, MotionEvent}, - SeatHandler, }, reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::ResizeEdge, utils::{Logical, Point, SERIAL_COUNTER}, diff --git a/src/layout.rs b/src/layout.rs index 933de52..0c1336b 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -161,7 +161,7 @@ impl State { // // This *will* cause everything to freeze for a few frames, but it shouldn't impact // anything meaningfully. - self.pause_rendering = true; + // self.pause_rendering = true; // schedule on all idle self.schedule( @@ -186,7 +186,7 @@ impl State { for (loc, win) in non_pending_wins { dt.state.space.map_element(win, loc, false); } - dt.state.pause_rendering = false; + // dt.state.pause_rendering = false; }, ); } diff --git a/src/state.rs b/src/state.rs index 41ad6fd..30c58ac 100644 --- a/src/state.rs +++ b/src/state.rs @@ -139,7 +139,7 @@ pub struct State { pub xwm: Option, pub xdisplay: Option, - pub pause_rendering: bool, + pub prev_pending_win_count: u32, } impl State { @@ -360,7 +360,7 @@ impl State { xwm: None, xdisplay: None, - pause_rendering: false, + prev_pending_win_count: 0, }) }