Files
zed/crates/gpui_linux/src/linux.rs
T
Lukas Wirth fdcb198110 gpui: Smooth frame pacing in macOS Low Power Mode (#63477)
# Objective

On macOS, Low Power Mode reduces the CPU and GPU performance available
to applications. GPUI continued requesting animation frames at the
normal cadence, so work that no longer fit inside every refresh produced
irregular frame drops instead of a deliberate lower frame rate.

Frame throttling could also reject a display-link callback that arrived
a fraction of a millisecond before the mathematically exact target
interval. On a 120 Hz display, for example, a measured 16.666 ms
interval missed a 16.667 ms threshold and delayed the frame until
roughly 25 ms, intermittently turning a 60 fps cap into 40 fps.

## Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- [GPUI] Improved animation smoothness on macOS when Low Power Mode is
enabled.

---------

Co-authored-by: Anthony Eid <hello@anthonyeid.me>
2026-10-27 12:20:11 +00:00

55 lines
1.7 KiB
Rust

mod dispatcher;
mod display_connection;
mod headless;
mod keyboard;
mod platform;
#[cfg(any(feature = "wayland", feature = "x11"))]
mod power;
mod system_notifications;
#[cfg(any(feature = "wayland", feature = "x11"))]
mod text_system;
#[cfg(feature = "wayland")]
mod wayland;
#[cfg(feature = "x11")]
mod x11;
#[cfg(any(feature = "wayland", feature = "x11"))]
mod xdg_desktop_portal;
pub use dispatcher::*;
pub(crate) use display_connection::{Backend, DisplayConnection, select_backend};
pub(crate) use headless::*;
pub(crate) use keyboard::*;
pub(crate) use platform::*;
#[cfg(any(feature = "wayland", feature = "x11"))]
pub(crate) use text_system::*;
#[cfg(feature = "wayland")]
pub(crate) use wayland::*;
#[cfg(feature = "x11")]
pub(crate) use x11::*;
use std::rc::Rc;
use gpui::WindowingModes;
/// Returns the default platform implementation for the current OS.
///
/// A windowed platform connects to the display server the process environment names, or starts
/// headless when it names none, and can switch between those modes later. A headless platform
/// stays headless.
pub fn current_platform(headless: bool) -> Rc<dyn gpui::Platform> {
if headless || std::env::var_os("ZED_HEADLESS").is_some() {
linux_platform(WindowingModes::HEADLESS)
} else {
linux_platform(WindowingModes::all())
}
}
/// Returns a platform that may switch among `allowed_modes`.
///
/// It starts windowed in the process's own environment, or headless if that names no allowed
/// display server. Set another initial mode with [`gpui::Application::with_windowing`].
pub fn linux_platform(allowed_modes: WindowingModes) -> Rc<dyn gpui::Platform> {
Rc::new(LinuxPlatform::new(allowed_modes))
}