Skip to content

Commit

Permalink
fix(windows): changing the theme activates the window (#978)
Browse files Browse the repository at this point in the history
* Fix changing theme activates the window

* Add change file

* Combine unsafe blocks
  • Loading branch information
Legend-Master authored Sep 23, 2024
1 parent 16b7d52 commit 016e122
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-theme-active-state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tao: patch
---

Fix changing the theme activates the window on Windows
11 changes: 8 additions & 3 deletions src/platform_impl/windows/dark_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use windows::{
Foundation::{BOOL, HANDLE, HMODULE, HWND, WPARAM},
Graphics::Dwm::{DwmSetWindowAttribute, DWMWINDOWATTRIBUTE},
System::LibraryLoader::*,
UI::{Accessibility::*, WindowsAndMessaging::*},
UI::{Accessibility::*, Input::KeyboardAndMouse::GetActiveWindow, WindowsAndMessaging::*},
},
};

Expand Down Expand Up @@ -187,9 +187,14 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool) {
&dark_mode as *const BOOL as *const c_void,
std::mem::size_of::<BOOL>() as u32,
);
if GetActiveWindow() == hwnd {
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
} else {
DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None);
DefWindowProcW(hwnd, WM_NCACTIVATE, None, None);
}
}
unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) };
unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) };
}
}
}
Expand Down

0 comments on commit 016e122

Please sign in to comment.