diff --git a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp index 2a761cfcdd..f7a90b9b48 100644 --- a/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp +++ b/Source/Core/Core/HW/EXI/EXI_DeviceIPL.cpp @@ -420,9 +420,7 @@ u32 CEXIIPL::GetEmulatedTime(Core::System& system, u32 epoch) } else { - ASSERT(!Core::WantsDeterminism()); - ltime = Common::Timer::GetLocalTimeSinceJan1970() - - system.GetSystemTimers().GetLocalTimeRTCOffset(); + ltime = Common::Timer::GetLocalTimeSinceJan1970() - system.GetSystemTimers().GetLocalTimeRTCOffset(); } return static_cast(ltime) - epoch; diff --git a/Source/Core/DolphinQt/Main.cpp b/Source/Core/DolphinQt/Main.cpp index 14f51e3ad4..6951faee2f 100644 --- a/Source/Core/DolphinQt/Main.cpp +++ b/Source/Core/DolphinQt/Main.cpp @@ -5,7 +5,7 @@ #include #include #include - +#include #include #endif @@ -257,6 +257,14 @@ int main(int argc, char* argv[]) Settings::Instance().InitDefaultPalette(); Settings::Instance().UpdateSystemDark(); + #ifdef _WIN32 + auto current = QOperatingSystemVersion::current(); + if (current >= QOperatingSystemVersion::Windows11) + { + Settings::Instance().ApplyStyleWin10(); + } + #endif + MainWindow win{std::move(boot), static_cast(options.get("movie"))}; win.Show(); diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index 43fc3f17fa..51f5eab81d 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -32,6 +32,8 @@ #ifndef _WIN32 #include +#include +#include #endif #include "Common/ScopeGuard.h" @@ -146,6 +148,7 @@ #endif #include +#include #if defined(__unix__) || defined(__unix) || defined(__APPLE__) void MainWindow::OnSignal() @@ -241,6 +244,15 @@ MainWindow::MainWindow(std::unique_ptr boot_parameters, ConnectMenuBar(); ConnectHotkeys(); + #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + auto current = QOperatingSystemVersion::current(); + if (current >= QOperatingSystemVersion::Windows11) + { + connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this, + [](Qt::ColorScheme colorScheme) { Settings::Instance().ApplyStyleWin10(); }); + } + #endif + connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this, &MainWindow::ShowGeneralWindow); @@ -1858,9 +1870,37 @@ QSize MainWindow::sizeHint() const } #ifdef _WIN32 + bool MainWindow::nativeEvent(const QByteArray& eventType, void* message, qintptr* result) { - return false; + MSG* msg = reinterpret_cast(message); + auto current = QOperatingSystemVersion::current(); + if (msg && msg->message == WM_SETTINGCHANGE && + (current >= QOperatingSystemVersion::Windows11) && + msg->lParam != NULL && + std::wstring_view(L"ImmersiveColorSet") + .compare(reinterpret_cast(msg->lParam)) == 0) + { + // Windows light/dark theme has changed. Update our flag and refresh the theme. + auto& settings = Settings::Instance(); + const bool was_dark_before = settings.IsSystemDark(); + settings.UpdateSystemDark(); + if (settings.IsSystemDark() != was_dark_before) + { + auto current = QOperatingSystemVersion::current(); + if (current >= QOperatingSystemVersion::Windows11) + { + settings.ApplyStyleWin10(); + + // force the colors in the Skylander window to update + if (m_skylander_window) + m_skylander_window->RefreshList(); + } + } + return true; // Event was handled + } + + return false; // Event was not handled } #endif diff --git a/Source/Core/DolphinQt/MainWindow.h b/Source/Core/DolphinQt/MainWindow.h index e13dbbd257..ff4c6f673b 100644 --- a/Source/Core/DolphinQt/MainWindow.h +++ b/Source/Core/DolphinQt/MainWindow.h @@ -78,6 +78,10 @@ public: const std::string& movie_path); ~MainWindow(); + #ifdef _WIN32 + bool IsWindows10OrLower(); + #endif + void Show(); WindowSystemInfo GetWindowSystemInfo() const; diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index 61f74d5638..0d626d5a1d 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -124,6 +124,20 @@ void Settings::SetThemeName(const QString& theme_name) emit ThemeChanged(); } +QString Settings::GetUserStyleName() const +{ + if (GetQSettings().contains(QStringLiteral("userstyle/name"))) + return GetQSettings().value(QStringLiteral("userstyle/name")).toString(); + + // Migration code for the old way of storing this setting + return QFileInfo(GetQSettings().value(QStringLiteral("userstyle/path")).toString()).fileName(); +} + +void Settings::SetUserStyleName(const QString& stylesheet_name) +{ + GetQSettings().setValue(QStringLiteral("userstyle/name"), stylesheet_name); +} + void Settings::InitDefaultPalette() { s_default_palette = std::make_unique(qApp->palette()); @@ -158,7 +172,111 @@ bool Settings::IsSystemDark() bool Settings::IsThemeDark() { return qApp->palette().color(QPalette::Base).valueF() < 0.5; +} +// Calling this before the main window has been created breaks the style of some widgets. +void Settings::ApplyStyleWin10() +{ + const StyleType style_type = GetStyleType(); + const QString stylesheet_name = GetUserStyleName(); + QString stylesheet_contents; + + // If we haven't found one, we continue with an empty (default) style + if (!stylesheet_name.isEmpty() && style_type == StyleType::User) + { + // Load custom user stylesheet + QDir directory = QDir(QString::fromStdString(File::GetUserPath(D_STYLES_IDX))); + QFile stylesheet(directory.filePath(stylesheet_name)); + + if (stylesheet.open(QFile::ReadOnly)) + stylesheet_contents = QString::fromUtf8(stylesheet.readAll().data()); + } + +#ifdef _WIN32 + if (stylesheet_contents.isEmpty()) + { + // No theme selected or found. Usually we would just fallthrough and set an empty stylesheet + // which would select Qt's default theme, but unlike other OSes we don't automatically get a + // default dark theme on Windows when the user has selected dark mode in the Windows settings. + // So manually check if the user wants dark mode and, if yes, load our embedded dark theme. + if (style_type == StyleType::Dark || (style_type != StyleType::Light && IsSystemDark())) + { + QFile file(QStringLiteral(":/dolphin_dark_win/dark.qss")); + if (file.open(QFile::ReadOnly)) + stylesheet_contents = QString::fromUtf8(file.readAll().data()); + + QPalette palette = qApp->style()->standardPalette(); + palette.setColor(QPalette::Window, QColor(32, 32, 32)); + palette.setColor(QPalette::WindowText, QColor(220, 220, 220)); + palette.setColor(QPalette::Base, QColor(32, 32, 32)); + palette.setColor(QPalette::AlternateBase, QColor(48, 48, 48)); + palette.setColor(QPalette::PlaceholderText, QColor(126, 126, 126)); + palette.setColor(QPalette::Text, QColor(220, 220, 220)); + palette.setColor(QPalette::Button, QColor(48, 48, 48)); + palette.setColor(QPalette::ButtonText, QColor(220, 220, 220)); + palette.setColor(QPalette::BrightText, QColor(255, 255, 255)); + palette.setColor(QPalette::Highlight, QColor(0, 120, 215)); + palette.setColor(QPalette::HighlightedText, QColor(255, 255, 255)); + palette.setColor(QPalette::Link, QColor(100, 160, 220)); + palette.setColor(QPalette::LinkVisited, QColor(100, 160, 220)); + qApp->setPalette(palette); + } + else + { + // reset any palette changes that may exist from a previously set dark mode + if (s_default_palette) + qApp->setPalette(*s_default_palette); + } + } +#endif + + // Define tooltips style if not already defined + if (!stylesheet_contents.contains(QStringLiteral("QToolTip"), Qt::CaseSensitive)) + { + const QPalette& palette = qApp->palette(); + QColor window_color; + QColor text_color; + QColor unused_text_emphasis_color; + QColor border_color; + GetToolTipStyle(window_color, text_color, unused_text_emphasis_color, border_color, palette, + palette); + + const auto tooltip_stylesheet = + QStringLiteral("QToolTip { background-color: #%1; color: #%2; padding: 8px; " + "border: 1px; border-style: solid; border-color: #%3; }") + .arg(window_color.rgba(), 0, 16) + .arg(text_color.rgba(), 0, 16) + .arg(border_color.rgba(), 0, 16); + stylesheet_contents.append(QStringLiteral("%1").arg(tooltip_stylesheet)); + } + + qApp->setStyleSheet(stylesheet_contents); +} + +Settings::StyleType Settings::GetStyleType() const +{ + if (GetQSettings().contains(QStringLiteral("userstyle/styletype"))) + { + bool ok = false; + const int type_int = GetQSettings().value(QStringLiteral("userstyle/styletype")).toInt(&ok); + if (ok && type_int >= static_cast(StyleType::MinValue) && + type_int <= static_cast(StyleType::MaxValue)) + { + return static_cast(type_int); + } + } + + // if the style type is unset or invalid, try the old enabled flag instead + const bool enabled = GetQSettings().value(QStringLiteral("userstyle/enabled"), false).toBool(); + return enabled ? StyleType::User : StyleType::System; +} + +void Settings::SetStyleType(StyleType type) +{ + GetQSettings().setValue(QStringLiteral("userstyle/styletype"), static_cast(type)); + + // also set the old setting so that the config is correctly intepreted by older Dolphin builds + GetQSettings().setValue(QStringLiteral("userstyle/enabled"), type == StyleType::User); } void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color, diff --git a/Source/Core/DolphinQt/Settings.h b/Source/Core/DolphinQt/Settings.h index 27325b141b..e6b51ef962 100644 --- a/Source/Core/DolphinQt/Settings.h +++ b/Source/Core/DolphinQt/Settings.h @@ -76,7 +76,7 @@ public: StyleType GetStyleType() const; // this evaluates the current stylesheet settings and refreshes the GUI with them - void ApplyStyle(); + void ApplyStyleWin10(); void GetToolTipStyle(QColor& window_color, QColor& text_color, QColor& emphasis_text_color, QColor& border_color, const QPalette& palette,