[Runner] Make tray icon context menu theme aware#47871
Open
Knyrps wants to merge 1 commit into
Open
Conversation
Uses the undocumented uxtheme.dll ordinals (SetPreferredAppMode, FlushMenuThemes, ShouldAppsUseDarkMode) shipped with Windows 10 1903+ to opt the tray icon's right-click context menu into the system dark/light theme. Re-applies on theme change. Precedent: src/modules/ZoomIt/ZoomIt/Utility.cpp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes the PowerToys runner's system tray icon right-click context menu honor the OS dark / light theme. Previously the popup menu was always rendered in the default light Win32 style regardless of the system theme.
Closes #31813
Detail
DarkModeundersrc/common/Themes/dark_mode.{h,cpp}that loads the undocumenteduxtheme.dllordinals shipped on Windows 10 1903+ / Windows 11:ShouldAppsUseDarkModeSetPreferredAppMode(applied asForceDark/ForceLight)FlushMenuThemesApplyToMenu(HMENU)setsMIM_BACKGROUNDwithMIM_APPLYTOSUBMENUSso the popup and any future submenus pick up the right background brush.src/runner/tray_icon.cpp:DarkMode::Initialize()once at the end ofstart_tray_icon.DarkMode::ApplyToMenu(h_menu)inside theWM_RBUTTONUP/WM_CONTEXTMENUbranch, immediately beforeTrackPopupMenu, so the theme is re-evaluated every time the menu opens.DarkMode::Refresh()from the existinghandle_theme_changeso a live OS theme switch is picked up without restarting PowerToys.src/modules/ZoomIt/ZoomIt/Utility.cpp(InitializeDarkModeSupport,ApplyDarkModeToMenu). The helper is intentionally minimal and only exposes what the tray menu needs.Screenshots
Before: white menu background on a dark Windows theme (per issue #31813).
After: menu background matches the OS theme; tested live in both dark and light mode with a runtime theme switch (no restart required).
How tested
MSBuild src\common\Themes\Themes.vcxproj /p:Configuration=Release /p:Platform=x64 /m /restore— green, 0 warnings, 0 errors.MSBuild src\runner\runner.vcxproj /p:Configuration=Release /p:Platform=x64 /m /restore— green, 0 warnings, 0 errors.src\runner\x64\Release\PowerToys.exe: