diff --git a/UI/Qt/main.cpp b/UI/Qt/main.cpp index af3c312b1f43..cee83fed1d91 100644 --- a/UI/Qt/main.cpp +++ b/UI/Qt/main.cpp @@ -22,6 +22,10 @@ #include #include +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) +# include +#endif + #if defined(AK_OS_MACOS) # include #endif @@ -32,15 +36,20 @@ namespace Ladybird { bool is_using_dark_system_theme(QWidget&); 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 - +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + // We use that only for fallback mode + Q_UNUSED(widget); + // Use the new Qt API available from version 6.5.0 + auto color_scheme = QGuiApplication::styleHints()->colorScheme(); + return color_scheme == Qt::ColorScheme::Dark; +#else + // Fallback for older Qt versions + // Calculate luma based on Rec. 709 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; +#endif } }