feat: add native material backgrounds
This commit is contained in:
@@ -31,12 +31,12 @@ const TITLEBAR_HEIGHT_PX: f32 = 32.0;
|
||||
/// WinUI 11's default body text size, in pixels at 100% scaling.
|
||||
const ROOT_FONT_SIZE_PX: f32 = 14.0;
|
||||
|
||||
/// The `Personalize` registry values, read once at startup as the fallback
|
||||
/// when the WinRT surface is unavailable.
|
||||
/// The `Personalize` registry values and the OS build number.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
struct RegistrySettings {
|
||||
apps_use_light_theme: Option<bool>,
|
||||
enable_transparency: Option<bool>,
|
||||
current_build: Option<u32>,
|
||||
}
|
||||
|
||||
impl RegistrySettings {
|
||||
@@ -45,6 +45,9 @@ impl RegistrySettings {
|
||||
windows_registry::CURRENT_USER
|
||||
.open(r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")
|
||||
};
|
||||
let current_version = || {
|
||||
windows_registry::LOCAL_MACHINE.open(r"SOFTWARE\Microsoft\Windows NT\CurrentVersion")
|
||||
};
|
||||
Self {
|
||||
apps_use_light_theme: personalize()
|
||||
.and_then(|key| key.get_u32("AppsUseLightTheme"))
|
||||
@@ -54,6 +57,10 @@ impl RegistrySettings {
|
||||
.and_then(|key| key.get_u32("EnableTransparency"))
|
||||
.ok()
|
||||
.map(|value| value != 0),
|
||||
current_build: current_version()
|
||||
.and_then(|key| key.get_string("CurrentBuildNumber"))
|
||||
.ok()
|
||||
.and_then(|build| build.parse::<u32>().ok()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -130,6 +137,17 @@ impl WindowsSource {
|
||||
.unwrap_or(false),
|
||||
}
|
||||
}
|
||||
|
||||
/// The native backdrop: Mica on Windows 11, acrylic on Windows 10 1809+.
|
||||
fn window_material(&self) -> Option<gpui::WindowBackgroundAppearance> {
|
||||
match self.registry.current_build {
|
||||
// 22621: Windows 11 22H2, where the DWM backdrop types exist.
|
||||
Some(build) if build >= 22621 => Some(gpui::WindowBackgroundAppearance::MicaBackdrop),
|
||||
// 17763: Windows 10 1809, where acrylic blur-behind exists.
|
||||
Some(build) if build >= 17763 => Some(gpui::WindowBackgroundAppearance::Blurred),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ThemeSource for WindowsSource {
|
||||
@@ -180,6 +198,7 @@ impl ThemeSource for WindowsSource {
|
||||
titlebar_height: Some(gpui::px(TITLEBAR_HEIGHT_PX)),
|
||||
root_font_size: Some(gpui::px(ROOT_FONT_SIZE_PX * text_scale as f32)),
|
||||
accessibility: self.accessibility(),
|
||||
window_background: self.window_material(),
|
||||
source: SourceKind::Windows,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user