From 22569fc0a50ff4a3773bf6418a3cc6d44a65df8f Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 20 Sep 2024 14:52:46 +0800 Subject: [PATCH 1/3] Fix changing theme activates the window --- src/platform_impl/windows/dark_mode.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index b12f98b4b..aad0d7f99 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -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::*}, }, }; @@ -188,8 +188,13 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool) { std::mem::size_of::() as u32, ); } - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) }; - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) }; + if unsafe { GetActiveWindow() } == hwnd { + unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) }; + unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) }; + } else { + unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) }; + unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) }; + } } } } From 75303caf83cae9ecabac31d6c78e4e3be650428d Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 20 Sep 2024 14:53:45 +0800 Subject: [PATCH 2/3] Add change file --- .changes/windows-theme-active-state.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changes/windows-theme-active-state.md diff --git a/.changes/windows-theme-active-state.md b/.changes/windows-theme-active-state.md new file mode 100644 index 000000000..4471fd7bd --- /dev/null +++ b/.changes/windows-theme-active-state.md @@ -0,0 +1,5 @@ +--- +tao: patch +--- + +Fix changing the theme activates the window on Windows From 4f95cb4b44515350ece478fff294ead1c8ed1310 Mon Sep 17 00:00:00 2001 From: Tony Date: Fri, 20 Sep 2024 14:55:38 +0800 Subject: [PATCH 3/3] Combine unsafe blocks --- src/platform_impl/windows/dark_mode.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/platform_impl/windows/dark_mode.rs b/src/platform_impl/windows/dark_mode.rs index aad0d7f99..85a907c0c 100644 --- a/src/platform_impl/windows/dark_mode.rs +++ b/src/platform_impl/windows/dark_mode.rs @@ -187,13 +187,13 @@ fn refresh_titlebar_theme_color(hwnd: HWND, is_dark_mode: bool) { &dark_mode as *const BOOL as *const c_void, std::mem::size_of::() as u32, ); - } - if unsafe { GetActiveWindow() } == hwnd { - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) }; - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) }; - } else { - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, WPARAM(true.into()), None) }; - unsafe { DefWindowProcW(hwnd, WM_NCACTIVATE, None, None) }; + 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); + } } } }