Compare commits

..

1 commit

Author SHA1 Message Date
7717b20ff4
[meta] Add option to FORCE X11 as Graphics Backend
All checks were successful
eden-license / license-header (pull_request) Successful in 25s
* save the option on a external file because settings
  are loaded AFTER Qt window is created and then
  the graphics backend is already applied

Signed-off-by: Caio Oliveira <caiooliveirafarias0@gmail.com>
2025-09-28 19:19:20 -03:00
6 changed files with 50 additions and 73 deletions

View file

@ -643,8 +643,10 @@ struct Values {
// Linux
SwitchableSetting<bool> enable_gamemode{linkage, true, "enable_gamemode", Category::Linux};
#ifdef __unix__
SwitchableSetting<bool> gui_force_x11{linkage, false, "gui_force_x11", Category::Linux};
Setting<bool> gui_hide_backend_warning{linkage, false, "gui_hide_backend_warning", Category::Linux};
#endif
// Controls
InputSetting<std::array<PlayerInput, 10>> players;

View file

@ -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 <QSettings>
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

View file

@ -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 <QSettings>
#include <QString>
using namespace Settings;
namespace GraphicsBackend {
struct Values {
Settings::Linkage gui_linkage;
SwitchableSetting<bool> gui_force_x11;
Setting<bool> 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

View file

@ -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 <map>
#include <memory>
#include <utility>

View file

@ -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

View file

@ -412,7 +412,7 @@ private slots:
void OnCaptureScreenshot();
void OnCheckFirmwareDecryption();
#ifdef __unix__
void OnCheckBackend();
void OnCheckGraphicsBackend();
#endif
void OnLanguageChanged(const QString& locale);
void OnMouseActivity();