mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:38:12 +00:00
Ladybird: Let WebContent know if the current system theme is dark
This means we now actually respect @media (prefers-color-scheme: dark) by default when in dark mode. :^)
This commit is contained in:
parent
fd9b6878f6
commit
72195ade9d
3 changed files with 19 additions and 13 deletions
|
@ -113,3 +113,16 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
return event_loop.exec();
|
||||
}
|
||||
|
||||
bool is_using_dark_system_theme(QWidget& widget)
|
||||
{
|
||||
// FIXME: Qt does not provide any method to query if the system is using a dark theme. We will have to implement
|
||||
// platform-specific methods if we wish to have better detection. For now, this inspects if Qt is using a
|
||||
// dark color for widget backgrounds using Rec. 709 luma coefficients.
|
||||
// https://en.wikipedia.org/wiki/Rec._709#Luma_coefficients
|
||||
|
||||
auto color = widget.palette().color(widget.backgroundRole());
|
||||
auto luma = 0.2126f * color.redF() + 0.7152f * color.greenF() + 0.0722f * color.blueF();
|
||||
|
||||
return luma <= 0.5f;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue