Skip to main content

theme/
platform.rs

1//! What the renderer and the compositor will do behind our paint.
2
3/// Whether this build has the backdrop-blur primitive behind it — the lens a
4/// glass surface refracts through, and the frost a card lays over the content
5/// it covers. Metal's and wgpu's; it tracks the gpui in use rather than the
6/// platform, and the DirectX renderer carries no such primitive.
7pub const LENSED: bool = cfg!(any(target_os = "macos", target_family = "wasm"));
8
9/// Whether the compositor puts anything behind a translucent window — AppKit's
10/// vibrancy, and Mica on Windows.
11///
12/// Read at runtime rather than from a `cfg`, because the Windows answer is a
13/// build number: `DWMWA_SYSTEMBACKDROP_TYPE` lands in build 22621, and below it
14/// gpui's backend applies no backdrop while its renderer still clears the
15/// window transparent — the desktop then shows through unblurred. The build is
16/// read once.
17pub fn frosted_window() -> bool {
18    #[cfg(target_os = "windows")]
19    {
20        static MICA: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
21        *MICA.get_or_init(|| windows::build() >= windows::MICA_BUILD)
22    }
23    #[cfg(not(target_os = "windows"))]
24    {
25        cfg!(any(target_os = "macos", target_family = "wasm"))
26    }
27}
28
29#[cfg(target_os = "windows")]
30mod windows {
31    use windows_sys::{
32        Wdk::System::SystemServices::RtlGetVersion,
33        Win32::System::SystemInformation::OSVERSIONINFOW,
34    };
35
36    /// The build `DWMWA_SYSTEMBACKDROP_TYPE` lands in — Windows 11 22H2. gpui's
37    /// backend reads the same number and returns without applying a backdrop
38    /// below it.
39    pub(super) const MICA_BUILD: u32 = 22621;
40
41    /// The running build, or 0 where it cannot be read. `RtlGetVersion` rather
42    /// than `GetVersionEx`, which reports 6.2 to a process whose manifest does
43    /// not claim a later version.
44    pub(super) fn build() -> u32 {
45        let mut version = OSVERSIONINFOW {
46            dwOSVersionInfoSize: size_of::<OSVERSIONINFOW>() as u32,
47            ..Default::default()
48        };
49        // NTSTATUS: negative is a failure.
50        if unsafe { RtlGetVersion(&mut version) } < 0 {
51            return 0;
52        }
53        version.dwBuildNumber
54    }
55}