yuzu:configuration: Add "Always On" dark mode option to Windows
- Use the default dark palette for Windows, like on Linux
This commit is contained in:
parent
2d3a404490
commit
2bda317d7d
@ -134,16 +134,30 @@ ConfigureUi::ConfigureUi(Core::System& system_, QWidget* parent)
|
|||||||
ui->theme_combobox->addItem(theme_name, theme_dir);
|
ui->theme_combobox->addItem(theme_name, theme_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->dark_mode_combobox->addItem(tr("Auto"), QVariant::fromValue(DarkModeState::Auto));
|
QByteArray current_qt_qpa = qgetenv("QT_QPA_PLATFORM");
|
||||||
// Windows dark mode is based on palette swap made by OS, so the "Always On" option disabled.
|
|
||||||
// We could check if the dark mode state is "On" and force a dark palette like on Linux to support
|
|
||||||
// "Always On"
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
ui->dark_mode_label->setText(tr("Dark mode (needs restart)"));
|
// Indicate which option needs a restart to be applied, depending on current environment
|
||||||
|
// variable
|
||||||
|
if (current_qt_qpa.contains("darkmode=2")) {
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Auto"), QVariant::fromValue(DarkModeState::Auto));
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Always On") + QStringLiteral(" (") +
|
||||||
|
tr("Needs restart") + QStringLiteral(")"),
|
||||||
|
QVariant::fromValue(DarkModeState::On));
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Always Off") + QStringLiteral(" (") +
|
||||||
|
tr("Needs restart") + QStringLiteral(")"),
|
||||||
|
QVariant::fromValue(DarkModeState::Off));
|
||||||
|
} else {
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Auto") + QStringLiteral(" (") + tr("Needs restart") +
|
||||||
|
QStringLiteral(")"),
|
||||||
|
QVariant::fromValue(DarkModeState::Auto));
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Always On"), QVariant::fromValue(DarkModeState::On));
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Always Off"), QVariant::fromValue(DarkModeState::Off));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
|
ui->dark_mode_combobox->addItem(tr("Auto"), QVariant::fromValue(DarkModeState::Auto));
|
||||||
ui->dark_mode_combobox->addItem(tr("Always On"), QVariant::fromValue(DarkModeState::On));
|
ui->dark_mode_combobox->addItem(tr("Always On"), QVariant::fromValue(DarkModeState::On));
|
||||||
#endif
|
|
||||||
ui->dark_mode_combobox->addItem(tr("Always Off"), QVariant::fromValue(DarkModeState::Off));
|
ui->dark_mode_combobox->addItem(tr("Always Off"), QVariant::fromValue(DarkModeState::Off));
|
||||||
|
#endif
|
||||||
|
|
||||||
InitializeIconSizeComboBox();
|
InitializeIconSizeComboBox();
|
||||||
InitializeRowComboBoxes();
|
InitializeRowComboBoxes();
|
||||||
|
@ -4916,12 +4916,33 @@ void GMainWindow::UpdateThemePalette() {
|
|||||||
QPalette themePalette(qApp->palette());
|
QPalette themePalette(qApp->palette());
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
QColor dark(25, 25, 25);
|
QColor dark(25, 25, 25);
|
||||||
QColor darkGray(100, 100, 100);
|
QString style_name;
|
||||||
QColor gray(150, 150, 150);
|
|
||||||
QColor light(230, 230, 230);
|
|
||||||
// By default, revert fusion style set for Windows dark theme
|
|
||||||
QString style;
|
|
||||||
if (CheckDarkMode()) {
|
if (CheckDarkMode()) {
|
||||||
|
// We check that the dark mode state is "On" and force a dark palette
|
||||||
|
if (UISettings::values.dark_mode_state == DarkModeState::On) {
|
||||||
|
// Set Default Windows Dark palette on Windows platforms to force Dark mode
|
||||||
|
themePalette.setColor(QPalette::Window, Qt::black);
|
||||||
|
themePalette.setColor(QPalette::WindowText, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::Disabled, QPalette::WindowText, QColor(127, 127, 127));
|
||||||
|
themePalette.setColor(QPalette::Base, Qt::black);
|
||||||
|
themePalette.setColor(QPalette::AlternateBase, dark);
|
||||||
|
themePalette.setColor(QPalette::ToolTipBase, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::ToolTipText, Qt::black);
|
||||||
|
themePalette.setColor(QPalette::Text, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
|
||||||
|
themePalette.setColor(QPalette::Dark, QColor(128, 128, 128));
|
||||||
|
themePalette.setColor(QPalette::Shadow, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::Button, Qt::black);
|
||||||
|
themePalette.setColor(QPalette::ButtonText, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
|
||||||
|
themePalette.setColor(QPalette::BrightText, QColor(192, 192, 192));
|
||||||
|
themePalette.setColor(QPalette::Link, QColor(0, 140, 200));
|
||||||
|
themePalette.setColor(QPalette::Highlight, QColor(0, 85, 255));
|
||||||
|
themePalette.setColor(QPalette::Disabled, QPalette::Highlight, QColor(0, 85, 255));
|
||||||
|
themePalette.setColor(QPalette::HighlightedText, Qt::white);
|
||||||
|
themePalette.setColor(QPalette::Disabled, QPalette::HighlightedText, Qt::white);
|
||||||
|
}
|
||||||
|
|
||||||
// AlternateBase is kept at rgb(233, 231, 227) or rgb(245, 245, 245) on Windows dark
|
// AlternateBase is kept at rgb(233, 231, 227) or rgb(245, 245, 245) on Windows dark
|
||||||
// palette, fix this. Sometimes, it even is rgb(0, 0, 0), but uses a very light gray for
|
// palette, fix this. Sometimes, it even is rgb(0, 0, 0), but uses a very light gray for
|
||||||
// alternate rows, do not know why
|
// alternate rows, do not know why
|
||||||
@ -4932,18 +4953,20 @@ void GMainWindow::UpdateThemePalette() {
|
|||||||
alternate_base_modified = true;
|
alternate_base_modified = true;
|
||||||
}
|
}
|
||||||
// Use fusion theme, since its close to windowsvista, but works well with a dark palette
|
// Use fusion theme, since its close to windowsvista, but works well with a dark palette
|
||||||
style = QStringLiteral("fusion");
|
style_name = QStringLiteral("fusion");
|
||||||
} else {
|
} else {
|
||||||
// Reset AlternateBase if it has been modified
|
// Reset AlternateBase if it has been modified
|
||||||
if (alternate_base_modified) {
|
if (alternate_base_modified) {
|
||||||
themePalette.setColor(QPalette::AlternateBase, QColor(245, 245, 245));
|
themePalette.setColor(QPalette::AlternateBase, QColor(245, 245, 245));
|
||||||
alternate_base_modified = false;
|
alternate_base_modified = false;
|
||||||
}
|
}
|
||||||
|
// Reset light palette
|
||||||
|
themePalette = this->style()->standardPalette();
|
||||||
// Reset Windows theme to the default
|
// Reset Windows theme to the default
|
||||||
style = QStringLiteral("windowsvista");
|
style_name = QStringLiteral("windowsvista");
|
||||||
}
|
}
|
||||||
LOG_DEBUG(Frontend, "Using style: {}", style.toStdString());
|
LOG_DEBUG(Frontend, "Using style: {}", style_name.toStdString());
|
||||||
qApp->setStyle(style);
|
qApp->setStyle(style_name);
|
||||||
#else
|
#else
|
||||||
if (CheckDarkMode()) {
|
if (CheckDarkMode()) {
|
||||||
// Set Dark palette on non Windows platforms (that may not have a dark palette)
|
// Set Dark palette on non Windows platforms (that may not have a dark palette)
|
||||||
@ -4968,7 +4991,7 @@ void GMainWindow::UpdateThemePalette() {
|
|||||||
themePalette.setColor(QPalette::HighlightedText, Qt::white);
|
themePalette.setColor(QPalette::HighlightedText, Qt::white);
|
||||||
themePalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127));
|
themePalette.setColor(QPalette::Disabled, QPalette::HighlightedText, QColor(127, 127, 127));
|
||||||
} else {
|
} else {
|
||||||
// Reset light palette on non Windows platforms
|
// Reset light palette
|
||||||
themePalette = this->style()->standardPalette();
|
themePalette = this->style()->standardPalette();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -5295,11 +5318,29 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
QByteArray current_qt_qpa = qgetenv("QT_QPA_PLATFORM");
|
QByteArray current_qt_qpa = qgetenv("QT_QPA_PLATFORM");
|
||||||
// Follow dark mode setting, if the "-platform" launch option is not set
|
// Follow dark mode setting, if the "-platform" launch option is not set.
|
||||||
if (UISettings::values.dark_mode_state == DarkModeState::Auto && current_qt_qpa.isEmpty()) {
|
// Otherwise, just follow dark mode for the window decoration (title bar).
|
||||||
// When setting is Auto, force adapting window decoration and stylesheet palette to use
|
if (!current_qt_qpa.contains(":darkmode=")) {
|
||||||
// Windows theme. Default is darkmode:0, which always uses light palette
|
if (UISettings::values.dark_mode_state == DarkModeState::Auto) {
|
||||||
qputenv("QT_QPA_PLATFORM", QByteArray("windows:darkmode=2"));
|
// When setting is Auto, force adapting window decoration and stylesheet palette to use
|
||||||
|
// Windows theme. Default is darkmode:0, which always uses light palette
|
||||||
|
if (current_qt_qpa.isEmpty()) {
|
||||||
|
// Set the value
|
||||||
|
qputenv("QT_QPA_PLATFORM", QByteArray("windows:darkmode=2"));
|
||||||
|
} else {
|
||||||
|
// Concatenate to the existing value
|
||||||
|
qputenv("QT_QPA_PLATFORM", current_qt_qpa + ",darkmode=2");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// When setting is no Auto, adapt window decoration to the palette used
|
||||||
|
if (current_qt_qpa.isEmpty()) {
|
||||||
|
// Set the value
|
||||||
|
qputenv("QT_QPA_PLATFORM", QByteArray("windows:darkmode=1"));
|
||||||
|
} else {
|
||||||
|
// Concatenate to the existing value
|
||||||
|
qputenv("QT_QPA_PLATFORM", current_qt_qpa + ",darkmode=1");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Increases the maximum open file limit to 8192
|
// Increases the maximum open file limit to 8192
|
||||||
_setmaxstdio(8192);
|
_setmaxstdio(8192);
|
||||||
|
Loading…
Reference in New Issue
Block a user