-
Notifications
You must be signed in to change notification settings - Fork 6k
Conversation
Check whether the window text color is light or dark, or whether the theme name contains 'dark' (fallback). This detects dark mode also for other themes than the dark variants of Yaru & Adwaita.
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. 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. |
5d0526f
to
b9c06bc
Compare
@cbracken @robert-ancell This looks good to me but I am not familiar with GTK. Can someone take a pass over this review please? |
If accessing the top-level window to get ahold of the style context is a problem (e.g. in headless mode?), we could revert to checking if the theme name ends with "-dark", which is a pretty common convention for GTK themes. |
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.
Thanks for taking a look at this. Added a couple comments.
Thanks! Looks good! /cc @robert-ancell should we keep the "-dark" heuristic, or do you think this is adequate as-is? In particular, @jpnurmi have you verified this works for the adwaita-dark and yaru-dark themes? |
I had a "-dark" check as a fallback at first just in case a window wouldn't exist, but then I realized that
Yes, I have tested the light and dark variants of Adwaita, Yaru, and Materia. |
Perfect -- thanks! When you merge, can you udpate the description to remove the bit about -dark detection?
|
Oops, done!🙂 |
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.
It's such a shame we have to jump though these hoops to determine if a theme is dark :(
Changes look fine to me, thanks @jpnurmi!
* ccaae8d Roll Skia from 537293bf155f to adadb95a9f1e (1 revision) (flutter/engine#25905) * 2e3a7f8 Roll buildroot to pick change to cppwinrt invocation (flutter/engine#25993) * 1c22286 [Linux] revise dark theme detection (flutter/engine#25535) * 7424400 Moved PlatformMessage's to unique_ptrs (flutter/engine#25860) * 406c4da Ensure that AutoIsolateShutdown drops its reference to the DartIsolate on the intended task runner (flutter/engine#25899) * 72c2fda [web] Fix incorrect physical size due to visualviewport api on iOS (flutter/engine#25895) * a712ffe Roll Dart SDK from b8f4018535fa to 86c749398b3a (16 revisions) (flutter/engine#25999) * edbbb12 Roll Fuchsia Mac SDK from uQgs5ZmFq... to aCsEHpnS0... (flutter/engine#26001) * afbbeac Implement smooth resizing for Linux (flutter/engine#25884) * 3ffb8ef Roll Dart SDK from 86c749398b3a to b4210cc43086 (2 revisions) (flutter/engine#26006) * 039dcd9 pull googletest from github instead of fuchsia.googlesource (flutter/engine#25907) * 9c793f1 Roll Skia from adadb95a9f1e to 1dc2d0fe0fa0 (98 revisions) (flutter/engine#26009) * 82efb9a Roll Skia from 1dc2d0fe0fa0 to 115645ee9b1b (2 revisions) (flutter/engine#26012) * 91a4c72 Delete unused method from engine_layer.h (flutter/engine#25924) * 619f82f fuchsia: Fix multi-views fallout (flutter/engine#25984) * 0b4bf7e Fixes BUILD.gn if is_fuchsia (legacy embedder) and is_debug (flutter/engine#25858) * 2e9de09 Streamline frame timings recording (flutter/engine#25892) * 1077da8 [vsync_waiter] add AwaitVSyncForSecondaryCallback() (flutter/engine#25787) * 0053bef [build_fuchsia_artifacts] Move license copying into BuildBucket(). (flutter/engine#25815) * e8b80e7 Roll Skia from 115645ee9b1b to c411429239e9 (7 revisions) (flutter/engine#26018) * d3353b2 Move more parts to libraries. (flutter/engine#25863) * d1a1182 Roll Dart SDK from b4210cc43086 to 04e55dad908d (2 revisions) (flutter/engine#26020) * f631f5b Exclude third_party/dart/third_party/devtools from the license script (flutter/engine#25918) * 304539b Roll Fuchsia Mac SDK from aCsEHpnS0... to OyXxehV6e... (flutter/engine#26022) * c3e28ae Roll Fuchsia Linux SDK from 4numS0K6T... to -FIIsjZj2... (flutter/engine#26023) * 6cacb53 Roll Skia from c411429239e9 to 72de83df3a03 (1 revision) (flutter/engine#26024) * bfccba5 Add dependency on Windows SDK CIPD package (flutter/engine#26003) * 06cbf1e Roll Dart SDK from 04e55dad908d to 094c9024373c (1 revision) (flutter/engine#26027) * 73aaeea Roll Skia from 72de83df3a03 to dabb2891c4a1 (4 revisions) (flutter/engine#26025) * e229649 Extract Windows string_conversion target (flutter/engine#26029) * 3d73e06 Extract FML command_line target (flutter/engine#26028) * 4aace54 Make SceneBuilder.push* not return nullable objects (flutter/engine#25991) * 0d62a56 Roll Dart SDK from 094c9024373c to 2ea89ef8f6de (1 revision) (flutter/engine#26030) * 5a26c1f Use string_view inputs for conversion functions (flutter/engine#26031) * 4f28de4 Support windows registry access (flutter/engine#26032) * 234fae1 Roll Fuchsia Linux SDK from -FIIsjZj2... to KZCe5FqMb... (flutter/engine#26034) * 7a47d3b Roll Fuchsia Mac SDK from OyXxehV6e... to DSk0IzBHv... (flutter/engine#26035) * 01f9bd8 Roll Skia from dabb2891c4a1 to 686dd910dd6c (1 revision) (flutter/engine#26036) * 1825bef Revert Dart SDK to b8f4018535fa792891e2add3a475f35e3ec156ab (flutter/engine#26037)
Some users have reported that toggling between light and dark system theme results in Flutter detecting the opposite theme. This is because the window text color, which is used to calculate the brightness, may not have been yet refreshed when the theme change signal is emitted. This commit replaces the unreliable (and untestable) window text color -based theme detection with the simpler alternative proposed in flutter#25535 to check for a "-dark" suffix in the theme name, which is used by convention in dark GTK theme names (Yaru vs. Yaru-dark, Adwaita vs. Adwaita-dark, Pop vs. Pop-dark, ...). Ref: flutter/flutter#101438
Some users have reported that toggling between light and dark system theme results in Flutter detecting the opposite theme. This is because the window text color, which is used to calculate the brightness, may not have been yet refreshed when the theme change signal is emitted. This commit replaces the unreliable (and untestable) window text color -based theme detection with the simpler alternative proposed in flutter#25535 to check for a "-dark" suffix in the theme name, which is used by convention in dark GTK theme names (Yaru vs. Yaru-dark, Adwaita vs. Adwaita-dark, Pop vs. Pop-dark, ...). Ref: flutter/flutter#101438
Some users have reported that toggling between light and dark system theme results in Flutter detecting the opposite theme. This is because the window text color, which is used to calculate the brightness, may not have been yet refreshed when the theme change signal is emitted. This commit replaces the unreliable (and untestable) window text color -based theme detection with the simpler alternative proposed in flutter#25535 to check for a "-dark" suffix in the theme name, which is used by convention in dark GTK theme names (Yaru vs. Yaru-dark, Adwaita vs. Adwaita-dark, Pop vs. Pop-dark, ...). Ref: flutter/flutter#101438
Some users have reported that toggling between light and dark system theme results in Flutter detecting the opposite theme. This is because the window text color, which is used to calculate the brightness, may not have been yet refreshed when the theme change signal is emitted. This commit replaces the unreliable (and untestable) window text color -based theme detection with the simpler alternative proposed in flutter#25535 to check for a "-dark" suffix in the theme name, which is used by convention in dark GTK theme names (Yaru vs. Yaru-dark, Adwaita vs. Adwaita-dark, Pop vs. Pop-dark, ...). Ref: flutter/flutter#101438
Check whether the window text color is light or dark. This detects dark mode also for other themes than the dark variants of Yaru & Adwaita.
Fixes: flutter/flutter#80199
Pre-launch Checklist
writing and running engine tests.
///
).