Skip to content

[Runner] Make tray icon context menu theme aware#47871

Open
Knyrps wants to merge 1 commit into
microsoft:mainfrom
Knyrps:feat/tray-context-menu-dark-mode-31813
Open

[Runner] Make tray icon context menu theme aware#47871
Knyrps wants to merge 1 commit into
microsoft:mainfrom
Knyrps:feat/tray-context-menu-dark-mode-31813

Conversation

@Knyrps
Copy link
Copy Markdown
Contributor

@Knyrps Knyrps commented May 14, 2026

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

  • Adds a small native helper DarkMode under src/common/Themes/dark_mode.{h,cpp} that loads the undocumented uxtheme.dll ordinals shipped on Windows 10 1903+ / Windows 11:
    • 132 ShouldAppsUseDarkMode
    • 135 SetPreferredAppMode (applied as ForceDark / ForceLight)
    • 136 FlushMenuThemes
    • ApplyToMenu(HMENU) sets MIM_BACKGROUND with MIM_APPLYTOSUBMENUS so the popup and any future submenus pick up the right background brush.
  • Wires it into src/runner/tray_icon.cpp:
    • DarkMode::Initialize() once at the end of start_tray_icon.
    • DarkMode::ApplyToMenu(h_menu) inside the WM_RBUTTONUP / WM_CONTEXTMENU branch, immediately before TrackPopupMenu, so the theme is re-evaluated every time the menu opens.
    • DarkMode::Refresh() from the existing handle_theme_change so a live OS theme switch is picked up without restarting PowerToys.
  • Precedent: this is the same approach already used by ZoomIt — see 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).

image image

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.
  • Ran the freshly-built src\runner\x64\Release\PowerToys.exe:
    • System in dark mode → right-clicked tray icon → context menu rendered with dark background.
    • Switched Windows to light mode → re-opened menu → rendered with light background, no restart needed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make taskbar icon context menu theme aware (aka enable dark mode)

1 participant