diff --git a/src/common/settings.h b/src/common/settings.h index db6a2d549a..6279088909 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -643,8 +643,10 @@ struct Values { // Linux SwitchableSetting enable_gamemode{linkage, true, "enable_gamemode", Category::Linux}; +#ifdef __unix__ SwitchableSetting gui_force_x11{linkage, false, "gui_force_x11", Category::Linux}; Setting gui_hide_backend_warning{linkage, false, "gui_hide_backend_warning", Category::Linux}; +#endif // Controls InputSetting> players; diff --git a/src/qt_common/gui_settings.cpp b/src/qt_common/gui_settings.cpp index cd5124b2b1..982d28bbcb 100644 --- a/src/qt_common/gui_settings.cpp +++ b/src/qt_common/gui_settings.cpp @@ -1,43 +1,25 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + #include "gui_settings.h" #include "common/fs/fs.h" #include "common/fs/path_util.h" -#include namespace FS = Common::FS; -namespace GUISettings { +namespace GraphicsBackend { -Values values; - -void SaveGUISettings() { - const auto gui_config_path = - FS::PathToUTF8String(FS::GetEdenPath(FS::EdenPath::ConfigDir) / "gui_config.ini"); - - (void)FS::CreateParentDir(gui_config_path); - QSettings config(QString::fromStdString(gui_config_path), QSettings::IniFormat); - - config.beginGroup(QStringLiteral("Linux")); - config.setValue(QStringLiteral("gui_force_x11"), values.gui_force_x11.GetValue()); - config.setValue(QStringLiteral("gui_hide_backend_warning"), values.gui_hide_backend_warning.GetValue()); - config.endGroup(); - - config.sync(); +QString GuiConfigPath() { + return QString::fromStdString(FS::PathToUTF8String(FS::GetEdenPath(FS::EdenPath::ConfigDir) / "gui_config.ini")); } -void RestoreGUISettings() { - const auto gui_config_path = - FS::PathToUTF8String(FS::GetEdenPath(FS::EdenPath::ConfigDir) / "gui_config.ini"); - - if (!FS::Exists(gui_config_path)) - return; - - QSettings config(QString::fromStdString(gui_config_path), QSettings::IniFormat); - - config.beginGroup(QStringLiteral("GUILinux")); - values.gui_force_x11.SetValue(config.value(QStringLiteral("gui_force_x11"), false).toBool()); - values.gui_hide_backend_warning.SetValue(config.value(QStringLiteral("gui_hide_backend_warning"), false).toBool()); - config.endGroup(); +void SetForceX11(bool state) { + (void)FS::CreateParentDir(GuiConfigPath().toStdString()); + QSettings(GuiConfigPath(), QSettings::IniFormat).setValue("gui_force_x11", state); } -} // namespace GUISettings +bool GetForceX11() { + return QSettings(GuiConfigPath(), QSettings::IniFormat).value("gui_force_x11", false).toBool(); +} +} // namespace GraphicsBackend diff --git a/src/qt_common/gui_settings.h b/src/qt_common/gui_settings.h index 9bd1b63444..f37572bb71 100644 --- a/src/qt_common/gui_settings.h +++ b/src/qt_common/gui_settings.h @@ -1,27 +1,14 @@ +// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + #pragma once -#include "common/settings.h" -namespace GUISettings { +#include +#include -using namespace Settings; +namespace GraphicsBackend { -struct Values { - Settings::Linkage gui_linkage; - - SwitchableSetting gui_force_x11; - Setting gui_hide_backend_warning; - - Values() - : gui_force_x11(gui_linkage, false, "gui_force_x11", Settings::Category::Linux), - gui_hide_backend_warning(gui_linkage, false, "gui_hide_backend_warning", Settings::Category::Linux) - { - } -}; - -extern Values values; - -void SaveGUISettings(); -void RestoreGUISettings(); - -} // namespace GUISettings +void SetForceX11(bool state); +bool GetForceX11(); +} // namespace GraphicsBackend diff --git a/src/qt_common/shared_translation.cpp b/src/qt_common/shared_translation.cpp index 507b022b6c..d450681e79 100644 --- a/src/qt_common/shared_translation.cpp +++ b/src/qt_common/shared_translation.cpp @@ -15,9 +15,6 @@ #include "common/settings_setting.h" #include "common/time_zone.h" #include "qt_common/uisettings.h" -#ifdef __unix__ -#include "qt_common/gui_settings.h" -#endif #include #include #include diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4d5a0ff327..948ed0601d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -546,7 +546,7 @@ GMainWindow::GMainWindow(bool has_broken_vulkan) OnCheckFirmwareDecryption(); #ifdef __unix__ - OnCheckBackend(); + OnCheckGraphicsBackend(); #endif game_list->LoadCompatibilityList(); @@ -3425,6 +3425,9 @@ void GMainWindow::OnConfigure() { #ifdef __linux__ const bool old_gamemode = Settings::values.enable_gamemode.GetValue(); #endif +#ifdef __unix__ + const bool old_force_x11 = Settings::values.gui_force_x11.GetValue(); +#endif Settings::SetConfiguringGlobal(true); ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), @@ -3489,6 +3492,11 @@ void GMainWindow::OnConfigure() { SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); } #endif +#ifdef __unix__ + if (Settings::values.gui_force_x11.GetValue() != old_force_x11) { + GraphicsBackend::SetForceX11(Settings::values.gui_force_x11.GetValue()); + } +#endif if (!multiplayer_state->IsHostingPublicRoom()) { multiplayer_state->UpdateCredentials(); @@ -4454,22 +4462,26 @@ void GMainWindow::OnCheckFirmwareDecryption() { } #ifdef __unix__ -void GMainWindow::OnCheckBackend() { - QByteArray qtPlatform = qgetenv("QT_QPA_PLATFORM"); - bool isWayland = qtPlatform.isEmpty() || qtPlatform == "wayland" || qtPlatform == "wayland-egl"; +void GMainWindow::OnCheckGraphicsBackend() { + const QString platformName = QGuiApplication::platformName(); + const QByteArray qtPlatform = qgetenv("QT_QPA_PLATFORM"); + if (platformName == QStringLiteral("xcb") || qtPlatform == "xcb") + return; + + const bool isWayland = platformName.startsWith(QStringLiteral("wayland"), Qt::CaseInsensitive) || qtPlatform.startsWith("wayland"); if (!isWayland) return; - const bool currently_hidden = GUISettings::values.gui_hide_backend_warning.GetValue(); + const bool currently_hidden = Settings::values.gui_hide_backend_warning.GetValue(); if (currently_hidden) return; QMessageBox msgbox(this); - msgbox.setWindowTitle(tr("Wayland Detected")); - msgbox.setText(tr("You are running Eden under Wayland.\n" - "Some features may not work correctly.\n" - "It is recommended to use X11 for the best compatibility.")); + msgbox.setWindowTitle(tr("Wayland Detected!")); + msgbox.setText(tr("You are running Eden under Wayland Graphics Backend.\n\n" + "It's recommended to use X11 for the best compatibility.\n\n" + "There's no plan to support Wayland at moment\nExpect crashes!")); msgbox.setIcon(QMessageBox::Warning); QPushButton* okButton = msgbox.addButton(tr("Use X11"), QMessageBox::AcceptRole); @@ -4484,14 +4496,12 @@ void GMainWindow::OnCheckBackend() { const bool hide = cb->isChecked(); if (hide != currently_hidden) { - GUISettings::values.gui_hide_backend_warning.SetValue(hide); - GUISettings::SaveGUISettings(); + Settings::values.gui_hide_backend_warning.SetValue(hide); } if (msgbox.clickedButton() == okButton) { - GUISettings::values.gui_force_x11.SetValue(true); - GUISettings::SaveGUISettings(); - + Settings::values.gui_force_x11.SetValue(true); + GraphicsBackend::SetForceX11(true); QMessageBox::information(this, tr("Restart Required"), tr("Restart Eden to apply the X11 backend.")); @@ -4988,8 +4998,7 @@ int main(int argc, char* argv[]) { qputenv("DISPLAY", ":0"); } - GUISettings::RestoreGUISettings(); - if (GUISettings::values.gui_force_x11.GetValue()) + if (GraphicsBackend::GetForceX11()) qputenv("QT_QPA_PLATFORM", "xcb"); // Fix the Wayland appId. This needs to match the name of the .desktop file without the .desktop diff --git a/src/yuzu/main.h b/src/yuzu/main.h index b700d89911..3515238280 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -412,7 +412,7 @@ private slots: void OnCaptureScreenshot(); void OnCheckFirmwareDecryption(); #ifdef __unix__ - void OnCheckBackend(); + void OnCheckGraphicsBackend(); #endif void OnLanguageChanged(const QString& locale); void OnMouseActivity();