-
Notifications
You must be signed in to change notification settings - Fork 28.7k
[Windows] Use dark title bar on dark system theme #110615
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
Conversation
#include <flutter_windows.h> | ||
|
||
#include "resource.h" | ||
|
||
namespace { | ||
|
||
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE | ||
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20 | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a TODO to remove this define when we bump our Windows SDK on the bots.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry since this is code that lives on the developer's machine, this is going to be dependent on which SDK they have installed. This is probably fine as-is, but add a comment about why we're defining it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment!
Just tried this and there's a problem in that the window bar will be dark if the system is using dark mode, regardless of whether the Flutter app actually uses dark theme or not (many apps typically allow to override the system setting). There's a fair question here.
With the changes from this PR, with the 1st set to dark and the 2nd set to light, I was still getting a dark window bar in the Flutter app. |
@@ -126,6 +131,9 @@ bool Win32Window::Create(const std::wstring& title, | |||
return false; | |||
} | |||
|
|||
BOOL honorDarkMode = TRUE; | |||
DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE, &honorDarkMode, sizeof(honorDarkMode)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does setting this window attribute allow the Flutter app context to use the specified dark mode theme instead of its default if provided, or does it affect only the part of the window outside of the Flutter app content?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good questions! I added more details to the pull request's description to clarify.
does it affect only the part of the window outside of the Flutter app content?
Yup, that's correct.
Does setting this window attribute allow the Flutter app context to use the specified dark mode theme instead
This will be done in a future change. We'll need to respond to Windows settings change message in the top-level message handler. EDIT: It looks like this feature was implemented but later regressed. Fix is tracked by: #110700
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
That's correct. Flutter doesn't have the concept of an app theme that's shared between the Dart code and the underlying native code. This is likely something we'll want to add in the future, but it's out-of-scope for this pull request. Apps that don't want to follow the system theme will need to remove this code.
Thanks for the heads up! I'll mark this PR as a draft while I investigate this. |
dev/integration_tests/windows_startup_test/windows/runner/flutter_window.cpp
Outdated
Show resolved
Hide resolved
dc133b9
to
edc7f4e
Compare
edc7f4e
to
6dd8e4b
Compare
@tgucio @yaakovschectman @cbracken Please take another look! :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, the app should follow the system theme:
This change makes Flutter apps have a dark title bar if Windows's theme is set to dark mode. This does nothing on older versions of Windows - like Windows 7 - that don't support dark mode.
Making the app's content follow the system theme will be fixed in subsequent changes and is tracked by #110700
Fixes #107926
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.