rust-windowing / rust-windowing/winit

Dark/light theme detection sometimes isn't working

Open
#4,161 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

B - bug DS - win32
Dominant language
Rust
Stars
6.2k
Forks
1.3k
Avg merge
2d 19h
Merged PRs (30d)
9

Description

Description

On Windows, dark/light mode can be set separately for apps and the system itself. Sometimes changing the default app mode will mess with the theme detection mechanism:

https://github.com/user-attachments/assets/e05c05c3-94d1-40c7-945f-728aa5dc5873

To reproduce, create a window (I'm running the window example in that video), and try changing the default app mode in Personalization > Colors. When the dark mode is active, the window's title bar should be dark (or the current accent color, if Show accent color in title bars and window borders is enabled and the window is active).

It seems that should_apps_use_dark_mode sometimes doesn't detect the picked app mode. But by the time the next WM_SETTINGCHANGE message is processed (after the system accent color was changed, for example), should_apps_use_dark_mode detects the theme correctly.

As far as I know, the default app theme can be somewhat reliably determined by reading AppsUseLightTheme value from the HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize registry key. After modifying should_apps_use_dark_mode to query the registry everything seems to work as it should:

https://github.com/user-attachments/assets/ad1e0434-c8b5-4579-b4dd-c65cf08e4a29

The other way to determine the app theme is to call the GetColorValue method of the UISettings class.

Windows version
Win11 Pro 26100.2161
Winit version

5cada36a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/platform_impl/windows/dark_mode.rs, especially should_apps_use_dark_mode, and trace the WM_SETTINGCHANGE handling in src/platform_impl/windows/event_loop.rs. Reproduce with the examples/window.rs example on Windows while changing the default app mode in Personalization > Colors. Done means the title bar reliably follows the selected app theme, including the accent-color case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.