Skip to main content

theme/
platform.rs

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