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 // Linux
SwitchableSetting<bool> enable_gamemode{linkage, true, "enable_gamemode", Category::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}; 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}; Setting<bool> gui_hide_backend_warning{linkage, false, "gui_hide_backend_warning", Category::Linux};
#endif
// Controls // Controls
InputSetting<std::array<PlayerInput, 10>> players; 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 "gui_settings.h"
#include "common/fs/fs.h" #include "common/fs/fs.h"
#include "common/fs/path_util.h" #include "common/fs/path_util.h"
#include <QSettings>
namespace FS = Common::FS; namespace FS = Common::FS;
namespace GUISettings { namespace GraphicsBackend {
Values values; QString GuiConfigPath() {
return QString::fromStdString(FS::PathToUTF8String(FS::GetEdenPath(FS::EdenPath::ConfigDir) / "gui_config.ini"));
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();
} }
void RestoreGUISettings() { void SetForceX11(bool state) {
const auto gui_config_path = (void)FS::CreateParentDir(GuiConfigPath().toStdString());
FS::PathToUTF8String(FS::GetEdenPath(FS::EdenPath::ConfigDir) / "gui_config.ini"); QSettings(GuiConfigPath(), QSettings::IniFormat).setValue("gui_force_x11", state);
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();
} }
} // 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 #pragma once
#include "common/settings.h"
namespace GUISettings { #include <QSettings>
#include <QString>
using namespace Settings; namespace GraphicsBackend {
struct Values { void SetForceX11(bool state);
Settings::Linkage gui_linkage; bool GetForceX11();
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
} // namespace GraphicsBackend

View file

@ -15,9 +15,6 @@
#include "common/settings_setting.h" #include "common/settings_setting.h"
#include "common/time_zone.h" #include "common/time_zone.h"
#include "qt_common/uisettings.h" #include "qt_common/uisettings.h"
#ifdef __unix__
#include "qt_common/gui_settings.h"
#endif
#include <map> #include <map>
#include <memory> #include <memory>
#include <utility> #include <utility>

View file

@ -546,7 +546,7 @@ GMainWindow::GMainWindow(bool has_broken_vulkan)
OnCheckFirmwareDecryption(); OnCheckFirmwareDecryption();
#ifdef __unix__ #ifdef __unix__
OnCheckBackend(); OnCheckGraphicsBackend();
#endif #endif
game_list->LoadCompatibilityList(); game_list->LoadCompatibilityList();
@ -3425,6 +3425,9 @@ void GMainWindow::OnConfigure() {
#ifdef __linux__ #ifdef __linux__
const bool old_gamemode = Settings::values.enable_gamemode.GetValue(); const bool old_gamemode = Settings::values.enable_gamemode.GetValue();
#endif #endif
#ifdef __unix__
const bool old_force_x11 = Settings::values.gui_force_x11.GetValue();
#endif
Settings::SetConfiguringGlobal(true); Settings::SetConfiguringGlobal(true);
ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(), ConfigureDialog configure_dialog(this, hotkey_registry, input_subsystem.get(),
@ -3489,6 +3492,11 @@ void GMainWindow::OnConfigure() {
SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue()); SetGamemodeEnabled(Settings::values.enable_gamemode.GetValue());
} }
#endif #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()) { if (!multiplayer_state->IsHostingPublicRoom()) {
multiplayer_state->UpdateCredentials(); multiplayer_state->UpdateCredentials();
@ -4454,22 +4462,26 @@ void GMainWindow::OnCheckFirmwareDecryption() {
} }
#ifdef __unix__ #ifdef __unix__
void GMainWindow::OnCheckBackend() { void GMainWindow::OnCheckGraphicsBackend() {
QByteArray qtPlatform = qgetenv("QT_QPA_PLATFORM"); const QString platformName = QGuiApplication::platformName();
bool isWayland = qtPlatform.isEmpty() || qtPlatform == "wayland" || qtPlatform == "wayland-egl"; 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) if (!isWayland)
return; 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) if (currently_hidden)
return; return;
QMessageBox msgbox(this); QMessageBox msgbox(this);
msgbox.setWindowTitle(tr("Wayland Detected")); msgbox.setWindowTitle(tr("Wayland Detected!"));
msgbox.setText(tr("You are running Eden under Wayland.\n" msgbox.setText(tr("You are running Eden under Wayland Graphics Backend.\n\n"
"Some features may not work correctly.\n" "It's recommended to use X11 for the best compatibility.\n\n"
"It is recommended to use X11 for the best compatibility.")); "There's no plan to support Wayland at moment\nExpect crashes!"));
msgbox.setIcon(QMessageBox::Warning); msgbox.setIcon(QMessageBox::Warning);
QPushButton* okButton = msgbox.addButton(tr("Use X11"), QMessageBox::AcceptRole); QPushButton* okButton = msgbox.addButton(tr("Use X11"), QMessageBox::AcceptRole);
@ -4484,14 +4496,12 @@ void GMainWindow::OnCheckBackend() {
const bool hide = cb->isChecked(); const bool hide = cb->isChecked();
if (hide != currently_hidden) { if (hide != currently_hidden) {
GUISettings::values.gui_hide_backend_warning.SetValue(hide); Settings::values.gui_hide_backend_warning.SetValue(hide);
GUISettings::SaveGUISettings();
} }
if (msgbox.clickedButton() == okButton) { if (msgbox.clickedButton() == okButton) {
GUISettings::values.gui_force_x11.SetValue(true); Settings::values.gui_force_x11.SetValue(true);
GUISettings::SaveGUISettings(); GraphicsBackend::SetForceX11(true);
QMessageBox::information(this, QMessageBox::information(this,
tr("Restart Required"), tr("Restart Required"),
tr("Restart Eden to apply the X11 backend.")); tr("Restart Eden to apply the X11 backend."));
@ -4988,8 +4998,7 @@ int main(int argc, char* argv[]) {
qputenv("DISPLAY", ":0"); qputenv("DISPLAY", ":0");
} }
GUISettings::RestoreGUISettings(); if (GraphicsBackend::GetForceX11())
if (GUISettings::values.gui_force_x11.GetValue())
qputenv("QT_QPA_PLATFORM", "xcb"); qputenv("QT_QPA_PLATFORM", "xcb");
// Fix the Wayland appId. This needs to match the name of the .desktop file without the .desktop // 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 OnCaptureScreenshot();
void OnCheckFirmwareDecryption(); void OnCheckFirmwareDecryption();
#ifdef __unix__ #ifdef __unix__
void OnCheckBackend(); void OnCheckGraphicsBackend();
#endif #endif
void OnLanguageChanged(const QString& locale); void OnLanguageChanged(const QString& locale);
void OnMouseActivity(); void OnMouseActivity();