chore: refactor throttle function

This commit is contained in:
Frederic Laing 2026-09-01 21:04:55 +02:00 • committed by Victoria Brekenfeld
parent e62e35e5cc
commit 0d75928579

View file

@ -139,14 +139,6 @@ struct Localizations;
pub static LANG_LOADER: LazyLock<FluentLanguageLoader> =
LazyLock::new(|| fluent_language_loader!());
fn xwayland_frame_throttle(throttle: Option<Duration>, is_xwayland: bool) -> Option<Duration> {
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<Duration> = Some(Duration::from_millis(995));
const SCREENCOPY_THROTTLE: Option<Duration> = Some(Duration::from_nanos(16_666_666));
fn throttle(session_holder: &impl SessionHolder) -> Option<Duration> {
if session_holder.sessions().is_empty() && session_holder.cursor_sessions().is_empty() {
fn throttle(session_holder: &impl SessionHolder, is_xwayland: bool) -> Option<Duration> {
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);
}
})