From d6b314f573712687197f66401fa6ed87c4064dae Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 13 Mar 2021 15:20:58 -0600 Subject: [PATCH] Add option to build for embedded environments --- README.md | 2 ++ app/app.pro | 7 ++++++- app/backend/systemproperties.cpp | 8 ++------ app/backend/systemproperties.h | 4 ++-- app/gui/SettingsView.qml | 18 +++++++++--------- app/gui/main.qml | 2 +- app/streaming/input/input.cpp | 4 ++-- app/streaming/session.cpp | 6 +++--- app/utils.h | 1 + app/wm.cpp | 19 +++++++++++++++++++ 10 files changed, 47 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 7e8d3421..5aa22bf6 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ You can follow development on our [Discord server](https://moonlight-stream.org/ * For macOS builds, use `scripts/generate-dmg.sh`. Execute this script from the root of the repository and ensure Qt's `bin` folder is in your `$PATH`. * For Steam Link builds, run `scripts/build-steamlink-app.sh` from the root of the repository. * To build from the command line for development use, run `qmake moonlight-qt.pro` then `make debug` or `make release` + * To create an embedded build for a single-purpose device, use `qmake "CONFIG+=embedded" moonlight-qt.pro` and build normally. + * This build will lack windowed mode, Discord/Help links, and other features that don't make sense on an embedded device. ## Contribute 1. Fork us diff --git a/app/app.pro b/app/app.pro index 17656d8e..2d7cc079 100644 --- a/app/app.pro +++ b/app/app.pro @@ -271,7 +271,7 @@ config_EGL { config_SL { message(Steam Link build configuration selected) - DEFINES += STEAM_LINK HAVE_SLVIDEO HAVE_SLAUDIO + DEFINES += EMBEDDED_BUILD STEAM_LINK HAVE_SLVIDEO HAVE_SLAUDIO LIBS += -lSLVideo -lSLAudio SOURCES += \ @@ -314,6 +314,11 @@ discord-rpc { LIBS += -ldiscord-rpc DEFINES += HAVE_DISCORD } +embedded { + message(Embedded build) + + DEFINES += EMBEDDED_BUILD +} RESOURCES += \ resources.qrc \ diff --git a/app/backend/systemproperties.cpp b/app/backend/systemproperties.cpp index 3a71f51f..ccc885d3 100644 --- a/app/backend/systemproperties.cpp +++ b/app/backend/systemproperties.cpp @@ -14,7 +14,7 @@ SystemProperties::SystemProperties() { versionString = QString(VERSION_STR); - hasWindowManager = WMUtils::isRunningWindowManager(); + hasDesktopEnvironment = WMUtils::isRunningDesktopEnvironment(); isRunningWayland = WMUtils::isRunningWayland(); isRunningXWayland = isRunningWayland && QGuiApplication::platformName() == "xcb"; QString nativeArch = QSysInfo::currentCpuArchitecture(); @@ -55,12 +55,8 @@ SystemProperties::SystemProperties() friendlyNativeArchName = nativeArch.toUpper(); } -#ifndef STEAM_LINK // Assume we can probably launch a browser if we're in a GUI environment - hasBrowser = hasWindowManager; -#else - hasBrowser = false; -#endif + hasBrowser = hasDesktopEnvironment; #ifdef HAVE_DISCORD hasDiscordIntegration = true; diff --git a/app/backend/systemproperties.h b/app/backend/systemproperties.h index fcfd4841..539efbc0 100644 --- a/app/backend/systemproperties.h +++ b/app/backend/systemproperties.h @@ -19,7 +19,7 @@ public: Q_PROPERTY(bool isRunningXWayland MEMBER isRunningXWayland CONSTANT) Q_PROPERTY(bool isWow64 MEMBER isWow64 CONSTANT) Q_PROPERTY(QString friendlyNativeArchName MEMBER friendlyNativeArchName CONSTANT) - Q_PROPERTY(bool hasWindowManager MEMBER hasWindowManager CONSTANT) + Q_PROPERTY(bool hasDesktopEnvironment MEMBER hasDesktopEnvironment CONSTANT) Q_PROPERTY(bool hasBrowser MEMBER hasBrowser CONSTANT) Q_PROPERTY(bool hasDiscordIntegration MEMBER hasDiscordIntegration CONSTANT) Q_PROPERTY(QString unmappedGamepads MEMBER unmappedGamepads NOTIFY unmappedGamepadsChanged) @@ -45,7 +45,7 @@ private: bool isRunningXWayland; bool isWow64; QString friendlyNativeArchName; - bool hasWindowManager; + bool hasDesktopEnvironment; bool hasBrowser; bool hasDiscordIntegration; QString unmappedGamepads; diff --git a/app/gui/SettingsView.qml b/app/gui/SettingsView.qml index cb2d9a40..bfd9a43f 100644 --- a/app/gui/SettingsView.qml +++ b/app/gui/SettingsView.qml @@ -527,7 +527,7 @@ Flickable { text: qsTr("Display mode") font.pointSize: 12 wrapMode: Text.Wrap - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment } AutoResizingComboBox { @@ -563,7 +563,7 @@ Flickable { } id: windowModeComboBox - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment enabled: !SystemProperties.rendererAlwaysFullScreen hoverEnabled: true textRole: "text" @@ -708,7 +708,7 @@ Flickable { width: parent.width text: qsTr("Mute audio stream when Moonlight is not the active window") font.pointSize: 12 - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment checked: StreamingPreferences.muteOnFocusLoss onCheckedChanged: { StreamingPreferences.muteOnFocusLoss = checked @@ -806,7 +806,7 @@ Flickable { text: qsTr("GUI display mode") font.pointSize: 12 wrapMode: Text.Wrap - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment } AutoResizingComboBox { @@ -831,7 +831,7 @@ Flickable { } id: uiDisplayModeComboBox - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment textRole: "text" model: ListModel { id: uiDisplayModeListModel @@ -910,7 +910,7 @@ Flickable { width: parent.width text: qsTr("Optimize mouse for remote desktop instead of games") font.pointSize: 12 - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment checked: StreamingPreferences.absoluteMouseMode onCheckedChanged: { StreamingPreferences.absoluteMouseMode = checked @@ -933,8 +933,8 @@ Flickable { hoverEnabled: true text: qsTr("Capture system keyboard shortcuts") font.pointSize: 12 - enabled: SystemProperties.hasWindowManager - checked: StreamingPreferences.captureSysKeysMode !== StreamingPreferences.CSK_OFF || !SystemProperties.hasWindowManager + enabled: SystemProperties.hasDesktopEnvironment + checked: StreamingPreferences.captureSysKeysMode !== StreamingPreferences.CSK_OFF || !SystemProperties.hasDesktopEnvironment ToolTip.delay: 1000 ToolTip.timeout: 10000 @@ -1111,7 +1111,7 @@ Flickable { width: parent.width text: qsTr("Process gamepad input when Moonlight is in the background") font.pointSize: 12 - visible: SystemProperties.hasWindowManager + visible: SystemProperties.hasDesktopEnvironment checked: StreamingPreferences.backgroundGamepad onCheckedChanged: { StreamingPreferences.backgroundGamepad = checked diff --git a/app/gui/main.qml b/app/gui/main.qml index 34b52f36..bad73e7b 100644 --- a/app/gui/main.qml +++ b/app/gui/main.qml @@ -23,7 +23,7 @@ ApplicationWindow { height: 600 visibility: { - if (SystemProperties.hasWindowManager) { + if (SystemProperties.hasDesktopEnvironment) { if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_WINDOWED) return "Windowed" else if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_MAXIMIZED) return "Maximized" else if (StreamingPreferences.uiDisplayMode == StreamingPreferences.UI_FULLSCREEN) return "FullScreen" diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 2b6a36b6..58ae84b7 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -36,8 +36,8 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, NvComputer*, int s m_NumFingersDown(0), m_ClipboardData() { - // System keys are always captured when running without a WM - if (!WMUtils::isRunningWindowManager()) { + // System keys are always captured when running without a DE + if (!WMUtils::isRunningDesktopEnvironment()) { m_CaptureSystemKeysMode = StreamingPreferences::CSK_ALWAYS; } diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 941c8595..cd11d322 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -351,7 +351,7 @@ bool Session::populateDecoderProperties(SDL_Window* window) Session::Session(NvComputer* computer, NvApp& app, StreamingPreferences *preferences) : m_Preferences(preferences ? preferences : new StreamingPreferences(this)), - m_IsFullScreen(m_Preferences->windowMode != StreamingPreferences::WM_WINDOWED || !WMUtils::isRunningWindowManager()), + m_IsFullScreen(m_Preferences->windowMode != StreamingPreferences::WM_WINDOWED || !WMUtils::isRunningDesktopEnvironment()), m_Computer(computer), m_App(app), m_Window(nullptr), @@ -511,8 +511,8 @@ bool Session::initialize() { default: case StreamingPreferences::WM_FULLSCREEN_DESKTOP: - // Only use full-screen desktop mode if we're running a window manager - if (WMUtils::isRunningWindowManager()) { + // Only use full-screen desktop mode if we're running a desktop environment + if (WMUtils::isRunningDesktopEnvironment()) { m_FullScreenFlag = SDL_WINDOW_FULLSCREEN_DESKTOP; break; } diff --git a/app/utils.h b/app/utils.h index e2de9d42..c4e6a6ed 100644 --- a/app/utils.h +++ b/app/utils.h @@ -7,4 +7,5 @@ namespace WMUtils { bool isRunningX11(); bool isRunningWayland(); bool isRunningWindowManager(); + bool isRunningDesktopEnvironment(); } diff --git a/app/wm.cpp b/app/wm.cpp index dfc06c10..c244a377 100644 --- a/app/wm.cpp +++ b/app/wm.cpp @@ -77,3 +77,22 @@ bool WMUtils::isRunningWindowManager() return WMUtils::isRunningWayland() || WMUtils::isRunningX11(); #endif } + +bool WMUtils::isRunningDesktopEnvironment() +{ + if (qEnvironmentVariableIsSet("HAS_DESKTOP_ENVIRONMENT")) { + return qEnvironmentVariableIntValue("HAS_DESKTOP_ENVIRONMENT"); + } + +#if defined(Q_OS_WIN) || defined(Q_OS_DARWIN) + // Windows and macOS are always running a desktop environment + return true; +#elif defined(EMBEDDED_BUILD) + // Embedded systems don't run desktop environments + return false; +#else + // On non-embedded systems, assume we have a desktop environment + // if we have a WM running. + return isRunningWindowManager(); +#endif +}