Add support for Windows Dark Mode#1217
Add support for Windows Dark Mode#1217goddessfreya merged 14 commits intorust-windowing:masterfrom davidhewitt:windows_dark_mode
Conversation
|
(I rebased onto master to fix the merge conflict) |
|
For the most part, this seems good. Could you add a function to EDIT: Ideally, we'd expose some sort of event that would notify users when the theme change has occurred, but we don't currently expose any mechanism for platform-specific messages and I don't know if this can be abstracted across multiple platforms. Neither of those are unsolvable problems, but I don't know if we want to solve them here. |
|
Thanks for the review! I've added a field to Regarding the event, I was also wondering about such. I know MacOS also has a dark mode though know nothing about its integration in APIs. So the message might be relevant on at least two platforms. |
Dark mode on macOS is enabled by setting a property in the info.plist file. I'm not sure how you query for it as an application, but to support it there's no support necessary from winit (Alacritty already sets this property). |
|
A quick google for macOS suggests we might be able to recieve a system broadcast for it on that platform too: https://stackoverflow.com/questions/39048894/how-to-detect-switch-between-macos-default-dark-mode-using-swift-3 So it might be appropriate to add a I don't have a mac so can't do the implementation for that platform. If you agree we should add a new |
|
@davidhewitt I'm fine with taking that approach. |
|
Great - have now added an event |
|
Just a heads up; I recently updated my system to the latest Windows Insiders and it appears that this definition: The windows terminal source doesn't appear to have changed from |
Osspial
left a comment
There was a problem hiding this comment.
This should be good to merge once my comment below and your issue have been addressed. Sorry about taking so long to review this.
|
I've updated the to use a |
|
@Osspial This is, afaik, good for merge? |
|
@davidhewitt Sorry it took so long to get back to you on this. I have no idea what's going on with dark mode on your system, since
I'm inclined to remove the windows version check and publish this with |
I would happily undo the version check! Strange about my system then. Are you on a stable windows 10 release or an insiders build? |
|
Rebased on master. @Osspial I've changed the method used for querying the Windows 10 build version. Does this new method now return a build version within the expected range on your machine? (I'm currently on Windows 10 insiders build 19018, and If this new method doesn't work on your box, then I'll remove the version checking and hard-code I will also try downgrading my system to the Windows 10 November 2019 update (build number So I think there's still a little bit of research to do before we can merge this :( |
|
On my machine |
|
I had access to a machine with windows build 17763 on it, tried this out and it works as intended, A tiny thing that I noticed: it doesn't change theme when the window isn't focused, but it will switch to the correct one as soon as it's focused again. |
|
Thanks guys. Anyone else also on Windows 10 insiders builds greater than
Interesting. Did you happen to notice at what time the |
It fires as soon as I change the system setting, even though it will only actually switch theme when I focus the window again. Same behaviour as on your system. |
Cool. So we can probably make it switch theme sooner if we force Windows to redraw the title bar. Past experiments I've had into trying to do that have never been very successful... anyone know a nice API to force the title bar to redraw? 😄 |
I was playing around with this for a bit and as far as I could find, using So the only workaround I could come up with, is if the window isn't focused, we want to resize the window by one pixel and than back again. |
Yeah that's similar to the only thing I could find too. Feels rather hacky to me. Given that this focus issue only applies to an out-of-date Windows 10 build, my vote would probably be to not introduce such a workaround. :( |
I didn't know this issue is not present in newer builds? I will try on a newer build now and report back. |
I'm now doubting myself. Pretty sure on my system (most recent Windows Insiders build) the frame changes whether focussed or not. I'll check later. |
|
Just tried it on the newest build, works as intended. You were right, this only affects older versions of windows. I would consider this a bug on windows, not our problem. |
Hahaha, that would be epic! 😄 |
daxpedda
left a comment
There was a problem hiding this comment.
Looks good to me, I'm not sure if we should stop using LoadLibraryExW here or start using it everywhere else in the codebase too.
|
Thanks; I switched to use |
daxpedda
left a comment
There was a problem hiding this comment.
A couple of tiny improvements.
Not sure if reducing the amount of as is actually desired.
|
Thanks again, have addressed all those suggestions. |
|
Looking really good now. Great work @davidhewitt |
|
Sorry about the delay reviewing this. Once my nit is addressed this should be good to go. Thank you for researching and implementing this! |
Co-Authored-By: daxpedda <daxpedda@gmail.com>
|
Nit fixed, and rebased - expecting the CI to be green and fingers crossed this is good to merge! |
I had a go at adding simple support for Windows 10's "Dark Mode". The moment the title bar will set to light / dark automatically according to system theme. I did not add an option for users of
winitto disable this behaviour, as I felt it's likely desirable for most use cases. I can change that if you prefer otherwise!Please advise on any documentation you'd like me to update.
The "window" example when Dark Mode is enabled:
cargo fmthas been run on this branchCHANGELOG.mdif knowledge of this change could be valuable to usersCloses #1193