Skip to content

Commit

Permalink
feat(windows): add dark for mica (#90)
Browse files Browse the repository at this point in the history
* feat(windows): add `dark` for mica

* make it Option
  • Loading branch information
amrbashir committed Jul 8, 2023
1 parent 08ce764 commit a0f4712
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/mica_dark.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-vibrancy": "minor"
---

On Windows, Add option to specify dark for mica effect.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,22 @@ pub fn clear_acrylic(window: impl raw_window_handle::HasRawWindowHandle) -> Resu

/// Applies mica effect to window. Works only on Windows 11.
///
/// ## Arguments
///
/// - `dark`: If `None` is provide, it will match the system preference
///
/// ## Platform-specific
///
/// - **Linux / macOS**: Unsupported.
pub fn apply_mica(window: impl raw_window_handle::HasRawWindowHandle) -> Result<(), Error> {
pub fn apply_mica(
window: impl raw_window_handle::HasRawWindowHandle,
dark: Option<bool>,

Check warning on line 131 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build-and-test (macos-latest)

unused variable: `dark`
) -> Result<(), Error> {
match window.raw_window_handle() {
#[cfg(target_os = "windows")]
raw_window_handle::RawWindowHandle::Win32(handle) => windows::apply_mica(handle.hwnd as _),
raw_window_handle::RawWindowHandle::Win32(handle) => {
windows::apply_mica(handle.hwnd as _, dark)
}
_ => Err(Error::UnsupportedPlatform(
"\"apply_mica()\" is only supported on Windows.",
)),
Expand Down
13 changes: 12 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ pub fn clear_acrylic(hwnd: HWND) -> Result<(), Error> {
Ok(())
}

pub fn apply_mica(hwnd: HWND) -> Result<(), Error> {
pub fn apply_mica(hwnd: HWND, dark: Option<bool>) -> Result<(), Error> {
if let Some(dark) = dark {
unsafe {
DwmSetWindowAttribute(
hwnd,
DWMWA_USE_IMMERSIVE_DARK_MODE,
&(dark as u32) as *const _ as _,
4,
);
}
}

if is_backdroptype_supported() {
unsafe {
DwmSetWindowAttribute(
Expand Down

0 comments on commit a0f4712

Please sign in to comment.