Skip to content

Commit

Permalink
fix: set_theme_for_hwnd always resulting dark on Windows (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master authored Sep 23, 2024
1 parent 5a9c37f commit 63c9f28
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changes/set-theme-dark-windows.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"muda": patch
---

Fix `set_theme_for_hwnd` always resulting in dark on Windows, and doesn't refresh until losing and regaining focus
26 changes: 18 additions & 8 deletions src/platform_impl/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,20 @@ use windows_sys::Win32::{
Foundation::{LPARAM, LRESULT, POINT, WPARAM},
Graphics::Gdi::{ClientToScreen, HBITMAP},
UI::{
Input::KeyboardAndMouse::{SendInput, INPUT, INPUT_KEYBOARD, KEYEVENTF_KEYUP, VK_CONTROL},
Input::KeyboardAndMouse::{
GetActiveWindow, SendInput, INPUT, INPUT_KEYBOARD, KEYEVENTF_KEYUP, VK_CONTROL,
},
Shell::{DefSubclassProc, RemoveWindowSubclass, SetWindowSubclass},
WindowsAndMessaging::{
AppendMenuW, CreateAcceleratorTableW, CreateMenu, CreatePopupMenu,
DestroyAcceleratorTable, DestroyMenu, DrawMenuBar, EnableMenuItem, GetCursorPos,
GetMenu, GetMenuItemInfoW, InsertMenuW, PostQuitMessage, RemoveMenu, SendMessageW,
SetForegroundWindow, SetMenu, SetMenuItemInfoW, ShowWindow, TrackPopupMenu, HACCEL,
HMENU, MENUITEMINFOW, MFS_CHECKED, MFS_DISABLED, MF_BYCOMMAND, MF_BYPOSITION,
MF_CHECKED, MF_DISABLED, MF_ENABLED, MF_GRAYED, MF_POPUP, MF_SEPARATOR, MF_STRING,
MF_UNCHECKED, MIIM_BITMAP, MIIM_STATE, MIIM_STRING, SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE,
TPM_LEFTALIGN, TPM_RETURNCMD, WM_CLOSE, WM_COMMAND, WM_NCACTIVATE, WM_NCPAINT,
GetMenu, GetMenuItemInfoW, InsertMenuW, PostMessageW, PostQuitMessage, RemoveMenu,
SendMessageW, SetForegroundWindow, SetMenu, SetMenuItemInfoW, ShowWindow,
TrackPopupMenu, HACCEL, HMENU, MENUITEMINFOW, MFS_CHECKED, MFS_DISABLED, MF_BYCOMMAND,
MF_BYPOSITION, MF_CHECKED, MF_DISABLED, MF_ENABLED, MF_GRAYED, MF_POPUP, MF_SEPARATOR,
MF_STRING, MF_UNCHECKED, MIIM_BITMAP, MIIM_STATE, MIIM_STRING, SW_HIDE, SW_MAXIMIZE,
SW_MINIMIZE, TPM_LEFTALIGN, TPM_RETURNCMD, WM_CLOSE, WM_COMMAND, WM_NCACTIVATE,
WM_NCPAINT,
},
},
};
Expand Down Expand Up @@ -1065,8 +1068,15 @@ unsafe extern "system" fn menu_subclass_proc(
match msg {
MENU_UPDATE_THEME if uidsubclass == MENU_SUBCLASS_ID => {
let menu = obj_from_dwrefdata::<Menu>(dwrefdata);
let theme: MenuTheme = std::mem::transmute(wparam);
let theme: MenuTheme = std::mem::transmute(lparam);
menu.hwnds.insert(hwnd as _, theme);
if GetActiveWindow() == hwnd {
PostMessageW(hwnd, WM_NCACTIVATE, 0, 0);
PostMessageW(hwnd, WM_NCACTIVATE, true.into(), 0);
} else {
PostMessageW(hwnd, WM_NCACTIVATE, true.into(), 0);
PostMessageW(hwnd, WM_NCACTIVATE, 0, 0);
}
0
}

Expand Down

0 comments on commit 63c9f28

Please sign in to comment.