Skip to content

Commit 74b1f4f

Browse files
authored
feat(core): add dark/light mica option (#7384)
* feat(core): add dark/light mica option * Update .changes/dark-light-mica-effect.md * fix macos build
1 parent fd5dc78 commit 74b1f4f

7 files changed

Lines changed: 67 additions & 11 deletions

File tree

.changes/dark-light-mica-effect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri-utils': 'patch:feat'
3+
---
4+
5+
Add `WindowEffect::MicaDark` and `WindowEffect::MicaLight`

core/tauri-config-schema/schema.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,26 @@
771771
]
772772
},
773773
{
774-
"description": "*Windows 11 Only**",
774+
"description": "Mica effect that matches the system dark perefence **Windows 11 Only**",
775775
"type": "string",
776776
"enum": [
777777
"mica"
778778
]
779779
},
780+
{
781+
"description": "Mica effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**",
782+
"type": "string",
783+
"enum": [
784+
"micaDark"
785+
]
786+
},
787+
{
788+
"description": "Mica effect with light mode **Windows 11 Only**",
789+
"type": "string",
790+
"enum": [
791+
"micaLight"
792+
]
793+
},
780794
{
781795
"description": "**Windows 7/10/11(22H1) Only**\n\n## Notes\n\nThis effect has bad performance when resizing/dragging the window on Windows 11 build 22621.",
782796
"type": "string",

core/tauri-utils/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,8 @@ mod build {
21112111
WindowEffect::UnderWindowBackground => quote! { #prefix::UnderWindowBackground},
21122112
WindowEffect::UnderPageBackground => quote! { #prefix::UnderPageBackground},
21132113
WindowEffect::Mica => quote! { #prefix::Mica},
2114+
WindowEffect::MicaDark => quote! { #prefix::MicaDark},
2115+
WindowEffect::MicaLight => quote! { #prefix::MicaLight},
21142116
WindowEffect::Blur => quote! { #prefix::Blur},
21152117
WindowEffect::Acrylic => quote! { #prefix::Acrylic},
21162118
})

core/tauri-utils/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,12 @@ mod window_effects {
118118
UnderWindowBackground,
119119
/// **macOS 10.14+**
120120
UnderPageBackground,
121-
/// **Windows 11 Only**
121+
/// Mica effect that matches the system dark perefence **Windows 11 Only**
122122
Mica,
123+
/// Mica effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**
124+
MicaDark,
125+
/// Mica effect with light mode **Windows 11 Only**
126+
MicaLight,
123127
/// **Windows 7/10/11(22H1) Only**
124128
///
125129
/// ## Notes

core/tauri/src/vibrancy/macos.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl From<crate::window::Effect> for NSVisualEffectMaterial {
283283
Effect::ContentBackground => NSVisualEffectMaterial::ContentBackground,
284284
Effect::UnderWindowBackground => NSVisualEffectMaterial::UnderWindowBackground,
285285
Effect::UnderPageBackground => NSVisualEffectMaterial::UnderPageBackground,
286-
Effect::Mica | Effect::Blur | Effect::Acrylic => unreachable!(),
286+
_ => unreachable!(),
287287
}
288288
}
289289
}

core/tauri/src/vibrancy/windows.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use std::ffi::c_void;
1212
use crate::utils::config::WindowEffectsConfig;
1313
use crate::window::{Color, Effect};
1414
use tauri_utils::platform::{get_function_impl, is_windows_7, windows_version};
15-
use windows::Win32::Graphics::Dwm::{DwmSetWindowAttribute, DWMWINDOWATTRIBUTE};
15+
use windows::Win32::Graphics::Dwm::{
16+
DwmSetWindowAttribute, DWMWA_USE_IMMERSIVE_DARK_MODE, DWMWINDOWATTRIBUTE,
17+
};
1618
use windows::Win32::{
1719
Foundation::{BOOL, HWND},
1820
Graphics::{
@@ -23,10 +25,12 @@ use windows::Win32::{
2325

2426
pub fn apply_effects(window: HWND, effects: WindowEffectsConfig) {
2527
let WindowEffectsConfig { effects, color, .. } = effects;
26-
let effect = if let Some(effect) = effects
27-
.iter()
28-
.find(|e| matches!(e, Effect::Mica | Effect::Acrylic | Effect::Blur))
29-
{
28+
let effect = if let Some(effect) = effects.iter().find(|e| {
29+
matches!(
30+
e,
31+
Effect::Mica | Effect::MicaDark | Effect::MicaLight | Effect::Acrylic | Effect::Blur
32+
)
33+
}) {
3034
effect
3135
} else {
3236
return;
@@ -35,7 +39,9 @@ pub fn apply_effects(window: HWND, effects: WindowEffectsConfig) {
3539
match effect {
3640
Effect::Blur => apply_blur(window, color),
3741
Effect::Acrylic => apply_acrylic(window, color),
38-
Effect::Mica => apply_mica(window),
42+
Effect::Mica => apply_mica(window, None),
43+
Effect::MicaDark => apply_mica(window, Some(true)),
44+
Effect::MicaLight => apply_mica(window, Some(false)),
3945
_ => unreachable!(),
4046
}
4147
}
@@ -114,7 +120,18 @@ pub fn clear_acrylic(hwnd: HWND) {
114120
}
115121
}
116122

117-
pub fn apply_mica(hwnd: HWND) {
123+
pub fn apply_mica(hwnd: HWND, dark: Option<bool>) {
124+
if let Some(dark) = dark {
125+
unsafe {
126+
DwmSetWindowAttribute(
127+
hwnd,
128+
DWMWA_USE_IMMERSIVE_DARK_MODE,
129+
&(dark as u32) as *const _ as _,
130+
4,
131+
);
132+
}
133+
}
134+
118135
if is_backdroptype_supported() {
119136
unsafe {
120137
let _ = DwmSetWindowAttribute(

tooling/cli/schema.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,26 @@
771771
]
772772
},
773773
{
774-
"description": "*Windows 11 Only**",
774+
"description": "Mica effect that matches the system dark perefence **Windows 11 Only**",
775775
"type": "string",
776776
"enum": [
777777
"mica"
778778
]
779779
},
780+
{
781+
"description": "Mica effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**",
782+
"type": "string",
783+
"enum": [
784+
"micaDark"
785+
]
786+
},
787+
{
788+
"description": "Mica effect with light mode **Windows 11 Only**",
789+
"type": "string",
790+
"enum": [
791+
"micaLight"
792+
]
793+
},
780794
{
781795
"description": "**Windows 7/10/11(22H1) Only**\n\n## Notes\n\nThis effect has bad performance when resizing/dragging the window on Windows 11 build 22621.",
782796
"type": "string",

0 commit comments

Comments
 (0)