From 0d7592857964fe1061440b2b4504dbc4d3ec826d Mon Sep 17 00:00:00 2001 From: Frederic Laing Date: Tue, 1 Sep 2026 21:04:55 +0200 Subject: [PATCH] chore: refactor throttle function --- src/state.rs | 52 ++++++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/state.rs b/src/state.rs index 76c4c098..28ed8fd4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -139,14 +139,6 @@ struct Localizations; pub static LANG_LOADER: LazyLock = LazyLock::new(|| fluent_language_loader!()); -fn xwayland_frame_throttle(throttle: Option, is_xwayland: bool) -> Option { - if is_xwayland { - Some(Duration::ZERO) - } else { - throttle - } -} - #[macro_export] macro_rules! fl { ($message_id:literal) => {{ @@ -1336,8 +1328,12 @@ impl Common { const THROTTLE: Option = Some(Duration::from_millis(995)); const SCREENCOPY_THROTTLE: Option = Some(Duration::from_nanos(16_666_666)); - fn throttle(session_holder: &impl SessionHolder) -> Option { - if session_holder.sessions().is_empty() && session_holder.cursor_sessions().is_empty() { + fn throttle(session_holder: &impl SessionHolder, is_xwayland: bool) -> Option { + if is_xwayland { + Some(Duration::ZERO) + } else if session_holder.sessions().is_empty() + && session_holder.cursor_sessions().is_empty() + { THROTTLE } else { SCREENCOPY_THROTTLE @@ -1373,8 +1369,7 @@ impl Common { && let Some(grab_state) = move_grab.lock().unwrap().as_ref() { for (window, _) in grab_state.element().windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } } @@ -1399,24 +1394,19 @@ impl Common { .mapped() .for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } }); if let Some(active) = shell.active_space(output) { if let Some(fs) = active.get_fullscreen(shell.seats.last_active()) { - let throttle = xwayland_frame_throttle( - throttle(&fs.surface), - fs.surface.x11_surface().is_some(), - ); + let throttle = throttle(&fs.surface, fs.surface.x11_surface().is_some()); fs.surface.send_frame(output, time, throttle, should_send); } active.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, should_send); } }); @@ -1424,8 +1414,7 @@ impl Common { // other (throttled) windows active.minimized_windows.iter().for_each(|m| { for window in m.windows() { - let throttle = - xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some()); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, |_, _| None); } }); @@ -1436,25 +1425,24 @@ impl Common { .filter(|w| w.handle != active.handle) { if let Some(fs) = space.get_fullscreen(shell.seats.last_active()) { - let throttle = min(throttle(space), throttle(&fs.surface)); - let throttle = - xwayland_frame_throttle(throttle, fs.surface.x11_surface().is_some()); + let throttle = min( + throttle(space, false), + throttle(&fs.surface, fs.surface.x11_surface().is_some()), + ); fs.surface.send_frame(output, time, throttle, |_, _| None); } space.mapped().for_each(|mapped| { for (window, _) in mapped.windows() { - let throttle = min(throttle(space), throttle(&window)); - let throttle = - xwayland_frame_throttle(throttle, window.x11_surface().is_some()); + let throttle = min( + throttle(space, false), + throttle(&window, window.x11_surface().is_some()), + ); window.send_frame(output, time, throttle, |_, _| None); } }); space.minimized_windows.iter().for_each(|m| { for window in m.windows() { - let throttle = xwayland_frame_throttle( - throttle(&window), - window.x11_surface().is_some(), - ); + let throttle = throttle(&window, window.x11_surface().is_some()); window.send_frame(output, time, throttle, |_, _| None); } })