From 9c5d847daeea32479fab86b6bcdf4cf8d199dad6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 21 Apr 2019 18:31:11 -0700 Subject: [PATCH] Autodetect a Wayland environment and configure SDL correctly. Fixes #211 --- app/backend/systemproperties.cpp | 3 +++ app/backend/systemproperties.h | 2 ++ app/gui/main.qml | 18 ++++++++++-------- app/main.cpp | 11 +++++++++++ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/backend/systemproperties.cpp b/app/backend/systemproperties.cpp index d458d28b..1f01591e 100644 --- a/app/backend/systemproperties.cpp +++ b/app/backend/systemproperties.cpp @@ -1,11 +1,14 @@ #include "systemproperties.h" +#include + #include "streaming/session.h" #include "streaming/streamutils.h" SystemProperties::SystemProperties() { isRunningWayland = qgetenv("XDG_SESSION_TYPE") == "wayland"; + isRunningXWayland = qgetenv("XDG_SESSION_TYPE") == "wayland" && QGuiApplication::platformName() == "xcb"; #ifdef Q_OS_WIN32 isWow64 = QSysInfo::currentCpuArchitecture() != QSysInfo::buildCpuArchitecture(); diff --git a/app/backend/systemproperties.h b/app/backend/systemproperties.h index 23ee70a4..351bbb16 100644 --- a/app/backend/systemproperties.h +++ b/app/backend/systemproperties.h @@ -12,6 +12,7 @@ public: Q_PROPERTY(bool hasHardwareAcceleration MEMBER hasHardwareAcceleration CONSTANT) Q_PROPERTY(bool isRunningWayland MEMBER isRunningWayland CONSTANT) + Q_PROPERTY(bool isRunningXWayland MEMBER isRunningXWayland CONSTANT) Q_PROPERTY(bool isWow64 MEMBER isWow64 CONSTANT) Q_PROPERTY(bool hasBrowser MEMBER hasBrowser CONSTANT) Q_PROPERTY(QString unmappedGamepads MEMBER unmappedGamepads NOTIFY unmappedGamepadsChanged) @@ -28,6 +29,7 @@ private: bool hasHardwareAcceleration; bool isRunningWayland; + bool isRunningXWayland; bool isWow64; bool hasBrowser; QString unmappedGamepads; diff --git a/app/gui/main.qml b/app/gui/main.qml index c9e85208..e4c3ade1 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -138,14 +138,16 @@ ApplicationWindow { // onAfterRendering call and potentially reenter this code. initialized = true; - if (SystemProperties.isRunningWayland) { - waylandDialog.open() - } - else if (SystemProperties.isWow64) { + if (SystemProperties.isWow64) { wow64Dialog.open() } else if (!SystemProperties.hasHardwareAcceleration) { - noHwDecoderDialog.open() + if (SystemProperties.isRunningXWayland) { + xWaylandDialog.open() + } + else { + noHwDecoderDialog.open() + } } if (SystemProperties.unmappedGamepads) { @@ -385,9 +387,9 @@ ApplicationWindow { } ErrorMessageDialog { - id: waylandDialog - text: "Moonlight does not support hardware acceleration on Wayland. Continuing on Wayland may result in poor streaming performance. " + - "Please switch to an X session for optimal performance." + id: xWaylandDialog + text: "Hardware acceleration doesn't work on XWayland. Continuing on XWayland may result in poor streaming performance. " + + "Try running with QT_QPA_PLATFORM=wayland or switch to X11." helpText: "Click the Help button for more information." helpUrl: "https://github.com/moonlight-stream/moonlight-docs/wiki/Fixing-Hardware-Decoding-Problems" } diff --git a/app/main.cpp b/app/main.cpp index db35d182..18406823 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -346,6 +346,17 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); + // After the QGuiApplication is created, the platform stuff will be initialized + // and we can set the SDL video driver to match Qt. + if (qgetenv("XDG_SESSION_TYPE") == "wayland" && QGuiApplication::platformName() == "xcb") { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Detected XWayland. This will probably break hardware decoding! Try running with QT_QPA_PLATFORM=wayland or switch to X11."); + } + else if (QGuiApplication::platformName().startsWith("wayland")) { + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Detected Wayland. Performance may be worse than X11."); + qputenv("SDL_VIDEODRIVER", "wayland"); + } + #ifdef STEAM_LINK // Qt 5.9 from the Steam Link SDK is not able to load any fonts // since the Steam Link doesn't include any of the ones it looks