chore: refactor throttle function
This commit is contained in:
parent
e62e35e5cc
commit
0d75928579
1 changed files with 20 additions and 32 deletions
52
src/state.rs
52
src/state.rs
|
|
@ -139,14 +139,6 @@ struct Localizations;
|
||||||
pub static LANG_LOADER: LazyLock<FluentLanguageLoader> =
|
pub static LANG_LOADER: LazyLock<FluentLanguageLoader> =
|
||||||
LazyLock::new(|| fluent_language_loader!());
|
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_export]
|
||||||
macro_rules! fl {
|
macro_rules! fl {
|
||||||
($message_id:literal) => {{
|
($message_id:literal) => {{
|
||||||
|
|
@ -1336,8 +1328,12 @@ impl Common {
|
||||||
const THROTTLE: Option<Duration> = Some(Duration::from_millis(995));
|
const THROTTLE: Option<Duration> = Some(Duration::from_millis(995));
|
||||||
const SCREENCOPY_THROTTLE: Option<Duration> = Some(Duration::from_nanos(16_666_666));
|
const SCREENCOPY_THROTTLE: Option<Duration> = Some(Duration::from_nanos(16_666_666));
|
||||||
|
|
||||||
fn throttle(session_holder: &impl SessionHolder) -> Option<Duration> {
|
fn throttle(session_holder: &impl SessionHolder, is_xwayland: bool) -> Option<Duration> {
|
||||||
if session_holder.sessions().is_empty() && session_holder.cursor_sessions().is_empty() {
|
if is_xwayland {
|
||||||
|
Some(Duration::ZERO)
|
||||||
|
} else if session_holder.sessions().is_empty()
|
||||||
|
&& session_holder.cursor_sessions().is_empty()
|
||||||
|
{
|
||||||
THROTTLE
|
THROTTLE
|
||||||
} else {
|
} else {
|
||||||
SCREENCOPY_THROTTLE
|
SCREENCOPY_THROTTLE
|
||||||
|
|
@ -1373,8 +1369,7 @@ impl Common {
|
||||||
&& let Some(grab_state) = move_grab.lock().unwrap().as_ref()
|
&& let Some(grab_state) = move_grab.lock().unwrap().as_ref()
|
||||||
{
|
{
|
||||||
for (window, _) in grab_state.element().windows() {
|
for (window, _) in grab_state.element().windows() {
|
||||||
let throttle =
|
let throttle = throttle(&window, window.x11_surface().is_some());
|
||||||
xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some());
|
|
||||||
window.send_frame(output, time, throttle, should_send);
|
window.send_frame(output, time, throttle, should_send);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1399,24 +1394,19 @@ impl Common {
|
||||||
.mapped()
|
.mapped()
|
||||||
.for_each(|mapped| {
|
.for_each(|mapped| {
|
||||||
for (window, _) in mapped.windows() {
|
for (window, _) in mapped.windows() {
|
||||||
let throttle =
|
let throttle = throttle(&window, window.x11_surface().is_some());
|
||||||
xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some());
|
|
||||||
window.send_frame(output, time, throttle, should_send);
|
window.send_frame(output, time, throttle, should_send);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(active) = shell.active_space(output) {
|
if let Some(active) = shell.active_space(output) {
|
||||||
if let Some(fs) = active.get_fullscreen(shell.seats.last_active()) {
|
if let Some(fs) = active.get_fullscreen(shell.seats.last_active()) {
|
||||||
let throttle = xwayland_frame_throttle(
|
let throttle = throttle(&fs.surface, fs.surface.x11_surface().is_some());
|
||||||
throttle(&fs.surface),
|
|
||||||
fs.surface.x11_surface().is_some(),
|
|
||||||
);
|
|
||||||
fs.surface.send_frame(output, time, throttle, should_send);
|
fs.surface.send_frame(output, time, throttle, should_send);
|
||||||
}
|
}
|
||||||
active.mapped().for_each(|mapped| {
|
active.mapped().for_each(|mapped| {
|
||||||
for (window, _) in mapped.windows() {
|
for (window, _) in mapped.windows() {
|
||||||
let throttle =
|
let throttle = throttle(&window, window.x11_surface().is_some());
|
||||||
xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some());
|
|
||||||
window.send_frame(output, time, throttle, should_send);
|
window.send_frame(output, time, throttle, should_send);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1424,8 +1414,7 @@ impl Common {
|
||||||
// other (throttled) windows
|
// other (throttled) windows
|
||||||
active.minimized_windows.iter().for_each(|m| {
|
active.minimized_windows.iter().for_each(|m| {
|
||||||
for window in m.windows() {
|
for window in m.windows() {
|
||||||
let throttle =
|
let throttle = throttle(&window, window.x11_surface().is_some());
|
||||||
xwayland_frame_throttle(throttle(&window), window.x11_surface().is_some());
|
|
||||||
window.send_frame(output, time, throttle, |_, _| None);
|
window.send_frame(output, time, throttle, |_, _| None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -1436,25 +1425,24 @@ impl Common {
|
||||||
.filter(|w| w.handle != active.handle)
|
.filter(|w| w.handle != active.handle)
|
||||||
{
|
{
|
||||||
if let Some(fs) = space.get_fullscreen(shell.seats.last_active()) {
|
if let Some(fs) = space.get_fullscreen(shell.seats.last_active()) {
|
||||||
let throttle = min(throttle(space), throttle(&fs.surface));
|
let throttle = min(
|
||||||
let throttle =
|
throttle(space, false),
|
||||||
xwayland_frame_throttle(throttle, fs.surface.x11_surface().is_some());
|
throttle(&fs.surface, fs.surface.x11_surface().is_some()),
|
||||||
|
);
|
||||||
fs.surface.send_frame(output, time, throttle, |_, _| None);
|
fs.surface.send_frame(output, time, throttle, |_, _| None);
|
||||||
}
|
}
|
||||||
space.mapped().for_each(|mapped| {
|
space.mapped().for_each(|mapped| {
|
||||||
for (window, _) in mapped.windows() {
|
for (window, _) in mapped.windows() {
|
||||||
let throttle = min(throttle(space), throttle(&window));
|
let throttle = min(
|
||||||
let throttle =
|
throttle(space, false),
|
||||||
xwayland_frame_throttle(throttle, window.x11_surface().is_some());
|
throttle(&window, window.x11_surface().is_some()),
|
||||||
|
);
|
||||||
window.send_frame(output, time, throttle, |_, _| None);
|
window.send_frame(output, time, throttle, |_, _| None);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
space.minimized_windows.iter().for_each(|m| {
|
space.minimized_windows.iter().for_each(|m| {
|
||||||
for window in m.windows() {
|
for window in m.windows() {
|
||||||
let throttle = xwayland_frame_throttle(
|
let throttle = throttle(&window, window.x11_surface().is_some());
|
||||||
throttle(&window),
|
|
||||||
window.x11_surface().is_some(),
|
|
||||||
);
|
|
||||||
window.send_frame(output, time, throttle, |_, _| None);
|
window.send_frame(output, time, throttle, |_, _| None);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue