Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add detection for dark or light theme. #2204

Merged
merged 1 commit into from
Jun 29, 2022

Conversation

dristic
Copy link
Contributor

@dristic dristic commented Jun 12, 2022

From #2196 (comment)

The windows API does not actually detect dark mode but forces it on. This is the simplest way to detect dark mode without depending on UWP APIs that require windows-rs. If it fails to read the registry it defaults to a light theme.

I tested this locally and the app will use the dark theme if the user's OS is set to dark otherwise it uses a light theme.

It does not detect this if the settings change while running the app but without UWP APIs I believe I would have to poll the registry which does not feel like a great solution.

Thanks!

@xStrom xStrom added shell/win concerns the Windows backend S-needs-review waits for review labels Jun 15, 2022
@vprimachenko
Copy link

vprimachenko commented Jun 28, 2022

Consider checking whether a windows event signals the change. WM_THEMECHANGED and WM_SYSCOLORCHANGE come to mind.

Alternatively one can use RegNotifyChangeKeyValue to observe the key instead of polling.

Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is much better than always using dark mode and I've confirmed it working and double checked the unsafe code against Microsoft docs.

@xStrom xStrom removed the S-needs-review waits for review label Jun 29, 2022
@xStrom xStrom merged commit bc1877b into linebender:master Jun 29, 2022
@xStrom
Copy link
Member

xStrom commented Jun 29, 2022

@vprimachenko thanks for the specific pointers, I wrote those down in #2190 which tracks progress on this.

This PR here was just a quick follow-up to #2196 and thus limited in scope on purpose.

@dristic dristic deleted the detect-dark-mode branch July 1, 2022 03:56
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
xarvic pushed a commit to xarvic/druid that referenced this pull request Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell/win concerns the Windows backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants