diff --git a/Ladybird/ConsoleWidget.cpp b/Ladybird/ConsoleWidget.cpp index e272ecd7eb..ce8abdf17d 100644 --- a/Ladybird/ConsoleWidget.cpp +++ b/Ladybird/ConsoleWidget.cpp @@ -19,21 +19,10 @@ #include #include +bool is_using_dark_system_theme(QWidget&); + namespace Ladybird { -static 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; -} - ConsoleWidget::ConsoleWidget() { setLayout(new QVBoxLayout); diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 84ca46ee62..f371dfa187 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -53,6 +53,8 @@ #include #include +bool is_using_dark_system_theme(QWidget&); + WebContentView::WebContentView(StringView webdriver_content_ipc_path, WebView::EnableCallgrindProfiling enable_callgrind_profiling) : m_webdriver_content_ipc_path(webdriver_content_ipc_path) { @@ -590,6 +592,8 @@ static Core::AnonymousBuffer make_system_theme_from_qt_palette(QWidget& widget, translate(Gfx::ColorRole::Selection, QPalette::ColorRole::Highlight); translate(Gfx::ColorRole::SelectionText, QPalette::ColorRole::HighlightedText); + palette.set_flag(Gfx::FlagRole::IsDark, is_using_dark_system_theme(widget)); + return theme; } diff --git a/Ladybird/main.cpp b/Ladybird/main.cpp index 1166568472..78ce8ba6ff 100644 --- a/Ladybird/main.cpp +++ b/Ladybird/main.cpp @@ -113,3 +113,16 @@ ErrorOr 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; +}