2018-07-04 21:16:25 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
2018-09-29 21:06:55 +00:00
|
|
|
#include <QQmlContext>
|
2018-07-08 17:19:08 +00:00
|
|
|
#include <QIcon>
|
2018-07-09 06:24:26 +00:00
|
|
|
#include <QQuickStyle>
|
2018-07-26 06:25:17 +00:00
|
|
|
#include <QMutex>
|
|
|
|
#include <QtDebug>
|
2018-11-04 22:13:56 +00:00
|
|
|
#include <QNetworkProxyFactory>
|
2019-03-03 03:50:05 +00:00
|
|
|
#include <QPalette>
|
2019-03-23 03:53:02 +00:00
|
|
|
#include <QFont>
|
2019-03-31 20:58:27 +00:00
|
|
|
#include <QCursor>
|
2019-12-17 07:16:31 +00:00
|
|
|
#include <QElapsedTimer>
|
2020-02-09 20:39:42 +00:00
|
|
|
#include <QFile>
|
2018-04-28 22:39:50 +00:00
|
|
|
|
2018-06-24 05:16:59 +00:00
|
|
|
// Don't let SDL hook our main function, since Qt is already
|
2018-07-07 23:37:11 +00:00
|
|
|
// doing the same thing. This needs to be before any headers
|
|
|
|
// that might include SDL.h themselves.
|
2018-06-24 05:16:59 +00:00
|
|
|
#define SDL_MAIN_HANDLED
|
|
|
|
#include <SDL.h>
|
|
|
|
|
2018-09-07 22:53:10 +00:00
|
|
|
#ifdef HAVE_FFMPEG
|
|
|
|
#include "streaming/video/ffmpeg.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-14 02:35:21 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#include "antihookingprotection.h"
|
|
|
|
#endif
|
|
|
|
|
2018-12-06 02:45:28 +00:00
|
|
|
#include "cli/quitstream.h"
|
2018-09-29 21:06:55 +00:00
|
|
|
#include "cli/startstream.h"
|
|
|
|
#include "cli/commandlineparser.h"
|
2018-08-17 04:04:47 +00:00
|
|
|
#include "path.h"
|
2020-02-09 02:47:59 +00:00
|
|
|
#include "utils.h"
|
2018-07-07 23:37:11 +00:00
|
|
|
#include "gui/computermodel.h"
|
|
|
|
#include "gui/appmodel.h"
|
2018-08-10 05:51:27 +00:00
|
|
|
#include "backend/autoupdatechecker.h"
|
2019-03-23 19:05:08 +00:00
|
|
|
#include "backend/systemproperties.h"
|
2018-09-29 23:18:46 +00:00
|
|
|
#include "streaming/session.h"
|
2018-07-09 00:33:47 +00:00
|
|
|
#include "settings/streamingpreferences.h"
|
2018-09-30 20:41:32 +00:00
|
|
|
#include "gui/sdlgamepadkeynavigation.h"
|
2018-07-07 23:37:11 +00:00
|
|
|
|
2018-07-26 06:25:17 +00:00
|
|
|
#if !defined(QT_DEBUG) && defined(Q_OS_WIN32)
|
|
|
|
// Log to file for release Windows builds
|
|
|
|
#define USE_CUSTOM_LOGGER
|
|
|
|
#define LOG_TO_FILE
|
|
|
|
#elif defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN)
|
|
|
|
// Use stdout logger on all Linux/BSD builds
|
|
|
|
#define USE_CUSTOM_LOGGER
|
|
|
|
#elif !defined(QT_DEBUG) && defined(Q_OS_DARWIN)
|
|
|
|
// Log to file for release Mac builds
|
|
|
|
#define USE_CUSTOM_LOGGER
|
|
|
|
#define LOG_TO_FILE
|
|
|
|
#else
|
|
|
|
// For debug Windows and Mac builds, use default logger
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_CUSTOM_LOGGER
|
2019-12-17 07:16:31 +00:00
|
|
|
static QElapsedTimer s_LoggerTime;
|
2018-07-26 06:25:17 +00:00
|
|
|
static QTextStream s_LoggerStream(stdout);
|
|
|
|
static QMutex s_LoggerLock;
|
|
|
|
#ifdef LOG_TO_FILE
|
2018-07-26 07:21:26 +00:00
|
|
|
#define MAX_LOG_LINES 10000
|
|
|
|
static int s_LogLinesWritten = 0;
|
|
|
|
static bool s_LogLimitReached = false;
|
2018-07-26 06:25:17 +00:00
|
|
|
static QFile* s_LoggerFile;
|
|
|
|
#endif
|
|
|
|
|
2018-07-26 07:21:26 +00:00
|
|
|
void logToLoggerStream(QString& message)
|
|
|
|
{
|
|
|
|
QMutexLocker lock(&s_LoggerLock);
|
|
|
|
|
|
|
|
#ifdef LOG_TO_FILE
|
|
|
|
if (s_LogLimitReached) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (s_LogLinesWritten == MAX_LOG_LINES) {
|
2020-02-25 02:17:23 +00:00
|
|
|
s_LoggerStream << "Log size limit reached!";
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
|
|
|
s_LoggerStream << Qt::endl;
|
|
|
|
#else
|
|
|
|
s_LoggerStream << endl;
|
|
|
|
#endif
|
2018-07-26 07:21:26 +00:00
|
|
|
s_LogLimitReached = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s_LogLinesWritten++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-09-07 22:53:10 +00:00
|
|
|
s_LoggerStream << message;
|
|
|
|
s_LoggerStream.flush();
|
2018-07-26 07:21:26 +00:00
|
|
|
}
|
|
|
|
|
2018-07-26 06:25:17 +00:00
|
|
|
void sdlLogToDiskHandler(void*, int category, SDL_LogPriority priority, const char* message)
|
|
|
|
{
|
|
|
|
QString priorityTxt;
|
|
|
|
|
|
|
|
switch (priority) {
|
|
|
|
case SDL_LOG_PRIORITY_VERBOSE:
|
|
|
|
priorityTxt = "Verbose";
|
|
|
|
break;
|
|
|
|
case SDL_LOG_PRIORITY_DEBUG:
|
|
|
|
priorityTxt = "Debug";
|
|
|
|
break;
|
|
|
|
case SDL_LOG_PRIORITY_INFO:
|
|
|
|
priorityTxt = "Info";
|
|
|
|
break;
|
|
|
|
case SDL_LOG_PRIORITY_WARN:
|
|
|
|
priorityTxt = "Warn";
|
|
|
|
break;
|
|
|
|
case SDL_LOG_PRIORITY_ERROR:
|
|
|
|
priorityTxt = "Error";
|
|
|
|
break;
|
|
|
|
case SDL_LOG_PRIORITY_CRITICAL:
|
|
|
|
priorityTxt = "Critical";
|
|
|
|
break;
|
2018-07-26 07:21:26 +00:00
|
|
|
default:
|
|
|
|
priorityTxt = "Unknown";
|
|
|
|
break;
|
2018-07-26 06:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTime logTime = QTime::fromMSecsSinceStartOfDay(s_LoggerTime.elapsed());
|
2018-09-07 22:53:10 +00:00
|
|
|
QString txt = QString("%1 - SDL %2 (%3): %4\n").arg(logTime.toString()).arg(priorityTxt).arg(category).arg(message);
|
2018-07-26 06:25:17 +00:00
|
|
|
|
2018-07-26 07:21:26 +00:00
|
|
|
logToLoggerStream(txt);
|
2018-07-26 06:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void qtLogToDiskHandler(QtMsgType type, const QMessageLogContext&, const QString& msg)
|
|
|
|
{
|
|
|
|
QString typeTxt;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
typeTxt = "Debug";
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
typeTxt = "Info";
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
typeTxt = "Warning";
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
typeTxt = "Critical";
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
typeTxt = "Fatal";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTime logTime = QTime::fromMSecsSinceStartOfDay(s_LoggerTime.elapsed());
|
2018-09-07 22:53:10 +00:00
|
|
|
QString txt = QString("%1 - Qt %2: %3\n").arg(logTime.toString()).arg(typeTxt).arg(msg);
|
|
|
|
|
|
|
|
logToLoggerStream(txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_FFMPEG
|
|
|
|
|
|
|
|
void ffmpegLogToDiskHandler(void* ptr, int level, const char* fmt, va_list vl)
|
|
|
|
{
|
|
|
|
char lineBuffer[1024];
|
|
|
|
static int printPrefix = 1;
|
|
|
|
|
|
|
|
if ((level & 0xFF) > av_log_get_level()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
av_log_format_line(ptr, level, fmt, vl, lineBuffer, sizeof(lineBuffer), &printPrefix);
|
|
|
|
|
|
|
|
QTime logTime = QTime::fromMSecsSinceStartOfDay(s_LoggerTime.elapsed());
|
|
|
|
QString txt = QString("%1 - FFmpeg: %2").arg(logTime.toString()).arg(lineBuffer);
|
2018-07-26 06:25:17 +00:00
|
|
|
|
2018-07-26 07:21:26 +00:00
|
|
|
logToLoggerStream(txt);
|
2018-07-26 06:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-09-07 22:53:10 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-07 21:16:59 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <DbgHelp.h>
|
|
|
|
|
2018-09-07 22:45:35 +00:00
|
|
|
static UINT s_HitUnhandledException = 0;
|
|
|
|
|
2018-09-07 21:16:59 +00:00
|
|
|
LONG WINAPI UnhandledExceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo)
|
|
|
|
{
|
2018-09-07 22:45:35 +00:00
|
|
|
// Only write a dump for the first unhandled exception
|
|
|
|
if (InterlockedCompareExchange(&s_HitUnhandledException, 1, 0) != 0) {
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
2018-09-07 21:16:59 +00:00
|
|
|
WCHAR dmpFileName[MAX_PATH];
|
|
|
|
swprintf_s(dmpFileName, L"%ls\\Moonlight-%I64u.dmp",
|
|
|
|
(PWCHAR)QDir::toNativeSeparators(Path::getLogDir()).utf16(), QDateTime::currentSecsSinceEpoch());
|
|
|
|
QString qDmpFileName = QString::fromUtf16((unsigned short*)dmpFileName);
|
|
|
|
HANDLE dumpHandle = CreateFileW(dmpFileName, GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
|
|
if (dumpHandle != INVALID_HANDLE_VALUE) {
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION info;
|
|
|
|
|
|
|
|
info.ThreadId = GetCurrentThreadId();
|
|
|
|
info.ExceptionPointers = ExceptionInfo;
|
|
|
|
info.ClientPointers = FALSE;
|
|
|
|
|
|
|
|
DWORD typeFlags = MiniDumpWithIndirectlyReferencedMemory |
|
|
|
|
MiniDumpIgnoreInaccessibleMemory |
|
|
|
|
MiniDumpWithUnloadedModules |
|
|
|
|
MiniDumpWithThreadInfo;
|
|
|
|
|
|
|
|
if (MiniDumpWriteDump(GetCurrentProcess(),
|
|
|
|
GetCurrentProcessId(),
|
|
|
|
dumpHandle,
|
|
|
|
(MINIDUMP_TYPE)typeFlags,
|
|
|
|
&info,
|
|
|
|
nullptr,
|
|
|
|
nullptr)) {
|
|
|
|
qCritical() << "Unhandled exception! Minidump written to:" << qDmpFileName;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qCritical() << "Unhandled exception! Failed to write dump:" << GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(dumpHandle);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
qCritical() << "Unhandled exception! Failed to open dump file:" << qDmpFileName << "with error" << GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Let the program crash and WER collect a dump
|
|
|
|
return EXCEPTION_CONTINUE_SEARCH;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-04-28 22:39:50 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2019-03-23 04:11:17 +00:00
|
|
|
SDL_SetMainReady();
|
|
|
|
|
2018-12-06 06:01:22 +00:00
|
|
|
// Set the app version for the QCommandLineParser's showVersion() command
|
|
|
|
QCoreApplication::setApplicationVersion(VERSION_STR);
|
|
|
|
|
2018-09-05 22:45:10 +00:00
|
|
|
// Set these here to allow us to use the default QSettings constructor.
|
|
|
|
// These also ensure that our cache directory is named correctly. As such,
|
|
|
|
// it is critical that these be called before Path::initialize().
|
|
|
|
QCoreApplication::setOrganizationName("Moonlight Game Streaming Project");
|
|
|
|
QCoreApplication::setOrganizationDomain("moonlight-stream.com");
|
|
|
|
QCoreApplication::setApplicationName("Moonlight");
|
|
|
|
|
2018-08-17 04:04:47 +00:00
|
|
|
if (QFile(QDir::currentPath() + "/portable.dat").exists()) {
|
|
|
|
qInfo() << "Running in portable mode from:" << QDir::currentPath();
|
|
|
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
|
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, QDir::currentPath());
|
|
|
|
QSettings::setPath(QSettings::IniFormat, QSettings::SystemScope, QDir::currentPath());
|
|
|
|
|
|
|
|
// Initialize paths for portable mode
|
|
|
|
Path::initialize(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Initialize paths for standard installation
|
|
|
|
Path::initialize(false);
|
|
|
|
}
|
|
|
|
|
2018-07-26 06:25:17 +00:00
|
|
|
#ifdef USE_CUSTOM_LOGGER
|
|
|
|
#ifdef LOG_TO_FILE
|
2018-08-17 04:04:47 +00:00
|
|
|
QDir tempDir(Path::getLogDir());
|
2018-07-26 06:25:17 +00:00
|
|
|
s_LoggerFile = new QFile(tempDir.filePath(QString("Moonlight-%1.log").arg(QDateTime::currentSecsSinceEpoch())));
|
|
|
|
if (s_LoggerFile->open(QIODevice::WriteOnly)) {
|
|
|
|
qInfo() << "Redirecting log output to " << s_LoggerFile->fileName();
|
|
|
|
s_LoggerStream.setDevice(s_LoggerFile);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s_LoggerTime.start();
|
|
|
|
qInstallMessageHandler(qtLogToDiskHandler);
|
|
|
|
SDL_LogSetOutputFunction(sdlLogToDiskHandler, nullptr);
|
2018-09-07 22:53:10 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FFMPEG
|
|
|
|
av_log_set_callback(ffmpegLogToDiskHandler);
|
|
|
|
#endif
|
|
|
|
|
2018-07-26 06:25:17 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-07 21:16:59 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
// Create a crash dump when we crash on Windows
|
|
|
|
SetUnhandledExceptionFilter(UnhandledExceptionHandler);
|
|
|
|
#endif
|
|
|
|
|
2018-10-14 02:35:21 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
|
|
|
// Force AntiHooking.dll to be statically imported and loaded
|
|
|
|
// by ntdll by calling a dummy function.
|
|
|
|
AntiHookingDummyImport();
|
|
|
|
#endif
|
|
|
|
|
2020-02-09 02:11:33 +00:00
|
|
|
// Avoid using High DPI on EGLFS. It breaks font rendering.
|
|
|
|
// https://bugreports.qt.io/browse/QTBUG-64377
|
2020-02-09 02:47:59 +00:00
|
|
|
//
|
|
|
|
// NB: We can't use QGuiApplication::platformName() here because it is only
|
|
|
|
// set once the QGuiApplication is created, which is too late to enable High DPI :(
|
|
|
|
if (WMUtils::isRunningWindowManager()) {
|
2020-02-09 02:11:33 +00:00
|
|
|
// Enable High DPI support
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2018-07-04 21:16:25 +00:00
|
|
|
|
2019-12-13 04:36:23 +00:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
|
2020-02-09 02:11:33 +00:00
|
|
|
// Enable fractional High DPI scaling on Qt 5.14 and later
|
|
|
|
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
2019-12-13 04:36:23 +00:00
|
|
|
#endif
|
2020-02-09 02:11:33 +00:00
|
|
|
}
|
2020-02-09 05:37:17 +00:00
|
|
|
else {
|
2020-02-09 20:39:42 +00:00
|
|
|
#ifndef STEAM_LINK
|
2020-02-25 01:44:21 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) {
|
2020-02-09 05:37:17 +00:00
|
|
|
qInfo() << "Unable to detect Wayland or X11, so EGLFS will be used by default. Set QT_QPA_PLATFORM to override this.";
|
|
|
|
qputenv("QT_QPA_PLATFORM", "eglfs");
|
2020-02-09 20:39:42 +00:00
|
|
|
|
|
|
|
if (!QFile("/dev/dri").exists()) {
|
|
|
|
qWarning() << "Unable to find a KMSDRM display device!";
|
2020-02-09 20:52:11 +00:00
|
|
|
qWarning() << "On Raspberry Pi 2 and 3, you must enable the 'fake KMS' driver in raspi-config to use Moonlight outside of the GUI environment.";
|
2020-02-09 20:39:42 +00:00
|
|
|
}
|
2020-02-09 05:37:17 +00:00
|
|
|
}
|
2020-02-09 20:39:42 +00:00
|
|
|
#endif
|
2020-02-09 05:37:17 +00:00
|
|
|
}
|
2019-12-13 04:36:23 +00:00
|
|
|
|
2018-05-06 04:59:30 +00:00
|
|
|
// This avoids using the default keychain for SSL, which may cause
|
|
|
|
// password prompts on macOS.
|
2019-01-20 01:06:35 +00:00
|
|
|
qputenv("QT_SSL_USE_TEMPORARY_KEYCHAIN", "1");
|
2018-05-06 04:59:30 +00:00
|
|
|
|
2019-04-19 03:56:44 +00:00
|
|
|
#ifdef Q_OS_WIN32
|
2018-09-21 04:27:19 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("QT_OPENGL")) {
|
|
|
|
// On Windows, use ANGLE so we don't have to load OpenGL
|
|
|
|
// user-mode drivers into our app. OGL drivers (especially Intel)
|
|
|
|
// seem to crash Moonlight far more often than DirectX.
|
|
|
|
qputenv("QT_OPENGL", "angle");
|
|
|
|
}
|
2018-08-25 18:59:32 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-04 22:13:56 +00:00
|
|
|
// We don't want system proxies to apply to us
|
|
|
|
QNetworkProxyFactory::setUseSystemConfiguration(false);
|
|
|
|
|
|
|
|
// Clear any default application proxy
|
|
|
|
QNetworkProxy noProxy(QNetworkProxy::NoProxy);
|
|
|
|
QNetworkProxy::setApplicationProxy(noProxy);
|
|
|
|
|
2018-06-28 05:02:29 +00:00
|
|
|
// Register custom metatypes for use in signals
|
|
|
|
qRegisterMetaType<NvApp>("NvApp");
|
|
|
|
|
2019-06-29 22:43:45 +00:00
|
|
|
SDL_version compileVersion;
|
|
|
|
SDL_VERSION(&compileVersion);
|
|
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"Compiled with SDL %d.%d.%d",
|
|
|
|
compileVersion.major, compileVersion.minor, compileVersion.patch);
|
|
|
|
|
|
|
|
SDL_version runtimeVersion;
|
|
|
|
SDL_GetVersion(&runtimeVersion);
|
|
|
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"Running with SDL %d.%d.%d",
|
2019-07-01 01:48:11 +00:00
|
|
|
runtimeVersion.major, runtimeVersion.minor, runtimeVersion.patch);
|
2019-06-29 22:43:45 +00:00
|
|
|
|
2019-03-27 04:11:24 +00:00
|
|
|
// Allow the display to sleep by default. We will manually use SDL_DisableScreenSaver()
|
|
|
|
// and SDL_EnableScreenSaver() when appropriate. This hint must be set before
|
|
|
|
// initializing the SDL video subsystem to have any effect.
|
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
|
|
|
|
|
2020-02-09 19:54:09 +00:00
|
|
|
// For SDL backends that support it, use double buffering instead of triple buffering
|
|
|
|
// to save a frame of latency. This doesn't matter for MMAL or DRM renderers since they
|
|
|
|
// are drawing directly to the screen without involving SDL, but it may matter for other
|
|
|
|
// future KMSDRM platforms that use SDL for rendering.
|
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1");
|
|
|
|
|
2019-04-22 00:43:38 +00:00
|
|
|
if (SDL_InitSubSystem(SDL_INIT_TIMER) != 0) {
|
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
|
|
"SDL_InitSubSystem(SDL_INIT_TIMER) failed: %s",
|
|
|
|
SDL_GetError());
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef STEAM_LINK
|
2019-03-23 04:11:17 +00:00
|
|
|
// Steam Link requires that we initialize video before creating our
|
|
|
|
// QGuiApplication in order to configure the framebuffer correctly.
|
2019-04-22 00:43:38 +00:00
|
|
|
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
|
2019-03-23 04:11:17 +00:00
|
|
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
2019-04-22 00:43:38 +00:00
|
|
|
"SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s",
|
2019-03-23 04:11:17 +00:00
|
|
|
SDL_GetError());
|
2019-03-27 04:11:24 +00:00
|
|
|
return -1;
|
2019-03-23 04:11:17 +00:00
|
|
|
}
|
2019-04-22 00:43:38 +00:00
|
|
|
#endif
|
2019-03-23 04:11:17 +00:00
|
|
|
|
2019-03-27 04:11:24 +00:00
|
|
|
// Use atexit() to ensure SDL_Quit() is called. This avoids
|
|
|
|
// racing with object destruction where SDL may be used.
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
|
|
|
|
// Avoid the default behavior of changing the timer resolution to 1 ms.
|
|
|
|
// We don't want this all the time that Moonlight is open. We will set
|
|
|
|
// it manually when we start streaming.
|
|
|
|
SDL_SetHint(SDL_HINT_TIMER_RESOLUTION, "0");
|
|
|
|
|
|
|
|
// Disable minimize on focus loss by default. Users seem to want this off by default.
|
|
|
|
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
|
|
|
|
|
2020-02-25 01:44:56 +00:00
|
|
|
// SDL 2.0.12 changes the default behavior to use the button label rather than the button
|
|
|
|
// position as most other software does. Set this back to 0 to stay consistent with prior
|
|
|
|
// releases of Moonlight.
|
|
|
|
SDL_SetHint("SDL_GAMECONTROLLER_USE_BUTTON_LABELS", "0");
|
|
|
|
|
2019-05-14 00:54:03 +00:00
|
|
|
#ifdef QT_DEBUG
|
|
|
|
// Allow thread naming using exceptions on debug builds. SDL doesn't use SEH
|
|
|
|
// when throwing the exceptions, so we don't enable it for release builds out
|
|
|
|
// of caution.
|
2019-05-04 04:18:58 +00:00
|
|
|
SDL_SetHint(SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "0");
|
2019-05-14 00:54:03 +00:00
|
|
|
#endif
|
2019-05-04 04:18:58 +00:00
|
|
|
|
2018-07-04 21:16:25 +00:00
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
2019-04-22 01:31:11 +00:00
|
|
|
// After the QGuiApplication is created, the platform stuff will be initialized
|
|
|
|
// and we can set the SDL video driver to match Qt.
|
2020-02-09 05:31:04 +00:00
|
|
|
if (WMUtils::isRunningWayland() && QGuiApplication::platformName() == "xcb") {
|
2019-04-22 01:31:11 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2019-03-23 05:51:08 +00:00
|
|
|
#ifdef STEAM_LINK
|
2019-03-23 03:53:02 +00:00
|
|
|
// 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
|
|
|
|
// for. We know it has NotoSans so we will explicitly ask for that.
|
|
|
|
if (app.font().family().isEmpty()) {
|
|
|
|
qWarning() << "SL HACK: No default font - using NotoSans";
|
|
|
|
|
|
|
|
QFont fon("NotoSans");
|
|
|
|
app.setFont(fon);
|
|
|
|
}
|
2019-03-31 20:58:27 +00:00
|
|
|
|
|
|
|
// Move the mouse to the bottom right so it's invisible when using
|
|
|
|
// gamepad-only navigation.
|
|
|
|
QCursor().setPos(0xFFFF, 0xFFFF);
|
2020-02-09 06:34:07 +00:00
|
|
|
#elif defined(Q_OS_LINUX) && (defined(__arm__) || defined(__aarch64__))
|
|
|
|
if (qgetenv("SDL_VIDEO_GL_DRIVER").isEmpty() && QGuiApplication::platformName() == "eglfs") {
|
|
|
|
// Look for Raspberry Pi GLES libraries. SDL needs some help finding the correct
|
|
|
|
// libraries for the KMSDRM backend if not compiled with the RPI backend enabled.
|
|
|
|
if (SDL_LoadObject("libbrcmGLESv2.so") != nullptr) {
|
|
|
|
qputenv("SDL_VIDEO_GL_DRIVER", "libbrcmGLESv2.so");
|
|
|
|
}
|
|
|
|
else if (SDL_LoadObject("/opt/vc/lib/libbrcmGLESv2.so") != nullptr) {
|
|
|
|
qputenv("SDL_VIDEO_GL_DRIVER", "/opt/vc/lib/libbrcmGLESv2.so");
|
|
|
|
}
|
|
|
|
}
|
2019-03-23 03:53:02 +00:00
|
|
|
#endif
|
|
|
|
|
2018-07-15 21:59:26 +00:00
|
|
|
app.setWindowIcon(QIcon(":/res/moonlight.svg"));
|
2018-07-08 17:19:08 +00:00
|
|
|
|
2018-07-04 23:40:21 +00:00
|
|
|
// Register our C++ types for QML
|
|
|
|
qmlRegisterType<ComputerModel>("ComputerModel", 1, 0, "ComputerModel");
|
2018-07-06 03:07:05 +00:00
|
|
|
qmlRegisterType<AppModel>("AppModel", 1, 0, "AppModel");
|
2018-07-07 23:30:26 +00:00
|
|
|
qmlRegisterUncreatableType<Session>("Session", 1, 0, "Session", "Session cannot be created from QML");
|
2018-07-06 05:08:55 +00:00
|
|
|
qmlRegisterSingletonType<ComputerManager>("ComputerManager", 1, 0,
|
|
|
|
"ComputerManager",
|
|
|
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
|
|
|
return new ComputerManager();
|
|
|
|
});
|
2018-08-10 05:51:27 +00:00
|
|
|
qmlRegisterSingletonType<AutoUpdateChecker>("AutoUpdateChecker", 1, 0,
|
|
|
|
"AutoUpdateChecker",
|
|
|
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
|
|
|
return new AutoUpdateChecker();
|
|
|
|
});
|
2019-03-23 19:05:08 +00:00
|
|
|
qmlRegisterSingletonType<SystemProperties>("SystemProperties", 1, 0,
|
|
|
|
"SystemProperties",
|
|
|
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
|
|
|
return new SystemProperties();
|
|
|
|
});
|
2019-03-23 21:15:55 +00:00
|
|
|
qmlRegisterSingletonType<SdlGamepadKeyNavigation>("SdlGamepadKeyNavigation", 1, 0,
|
|
|
|
"SdlGamepadKeyNavigation",
|
|
|
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
|
|
|
return new SdlGamepadKeyNavigation();
|
|
|
|
});
|
2019-03-28 01:13:20 +00:00
|
|
|
qmlRegisterSingletonType<StreamingPreferences>("StreamingPreferences", 1, 0,
|
|
|
|
"StreamingPreferences",
|
|
|
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
|
|
|
return new StreamingPreferences();
|
|
|
|
});
|
2018-07-04 23:40:21 +00:00
|
|
|
|
2020-01-26 03:34:17 +00:00
|
|
|
// Create the identity manager on the main thread
|
|
|
|
IdentityManager::get();
|
|
|
|
|
2019-03-13 08:02:04 +00:00
|
|
|
#ifndef Q_OS_WINRT
|
2019-01-20 01:06:35 +00:00
|
|
|
// Use the dense material dark theme by default
|
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_STYLE", "Material");
|
|
|
|
}
|
2019-03-13 08:02:04 +00:00
|
|
|
#else
|
|
|
|
// Use universal dark on WinRT
|
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_STYLE")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_STYLE", "Universal");
|
|
|
|
}
|
|
|
|
#endif
|
2019-01-20 01:06:35 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MATERIAL_THEME")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", "Dark");
|
|
|
|
}
|
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MATERIAL_ACCENT")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_MATERIAL_ACCENT", "Purple");
|
|
|
|
}
|
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_MATERIAL_VARIANT")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_MATERIAL_VARIANT", "Dense");
|
|
|
|
}
|
|
|
|
if (!qEnvironmentVariableIsSet("QT_QUICK_CONTROLS_UNIVERSAL_THEME")) {
|
|
|
|
qputenv("QT_QUICK_CONTROLS_UNIVERSAL_THEME", "Dark");
|
|
|
|
}
|
2018-07-09 06:24:26 +00:00
|
|
|
|
2018-07-04 21:16:25 +00:00
|
|
|
QQmlApplicationEngine engine;
|
2018-09-29 21:06:55 +00:00
|
|
|
QString initialView;
|
|
|
|
|
|
|
|
GlobalCommandLineParser parser;
|
|
|
|
switch (parser.parse(app.arguments())) {
|
|
|
|
case GlobalCommandLineParser::NormalStartRequested:
|
2019-03-23 02:21:04 +00:00
|
|
|
initialView = "qrc:/gui/PcView.qml";
|
2018-09-29 21:06:55 +00:00
|
|
|
break;
|
|
|
|
case GlobalCommandLineParser::StreamRequested:
|
|
|
|
{
|
2019-03-23 02:21:04 +00:00
|
|
|
initialView = "qrc:/gui/CliStartStreamSegue.qml";
|
2018-09-29 21:06:55 +00:00
|
|
|
StreamingPreferences* preferences = new StreamingPreferences(&app);
|
|
|
|
StreamCommandLineParser streamParser;
|
|
|
|
streamParser.parse(app.arguments(), preferences);
|
|
|
|
QString host = streamParser.getHost();
|
|
|
|
QString appName = streamParser.getAppName();
|
|
|
|
auto launcher = new CliStartStream::Launcher(host, appName, preferences, &app);
|
|
|
|
engine.rootContext()->setContextProperty("launcher", launcher);
|
|
|
|
break;
|
|
|
|
}
|
2018-12-06 02:45:28 +00:00
|
|
|
case GlobalCommandLineParser::QuitRequested:
|
|
|
|
{
|
2019-03-23 02:21:04 +00:00
|
|
|
initialView = "qrc:/gui/CliQuitStreamSegue.qml";
|
2018-12-06 02:45:28 +00:00
|
|
|
QuitCommandLineParser quitParser;
|
|
|
|
quitParser.parse(app.arguments());
|
|
|
|
auto launcher = new CliQuitStream::Launcher(quitParser.getHost(), &app);
|
|
|
|
engine.rootContext()->setContextProperty("launcher", launcher);
|
|
|
|
break;
|
|
|
|
}
|
2018-09-29 21:06:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
engine.rootContext()->setContextProperty("initialView", initialView);
|
|
|
|
|
|
|
|
// Load the main.qml file
|
2018-07-04 21:16:25 +00:00
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/gui/main.qml")));
|
|
|
|
if (engine.rootObjects().isEmpty())
|
|
|
|
return -1;
|
2018-04-28 22:39:50 +00:00
|
|
|
|
2018-07-04 21:16:25 +00:00
|
|
|
int err = app.exec();
|
2018-06-24 05:16:59 +00:00
|
|
|
|
2018-12-06 02:45:28 +00:00
|
|
|
// Give worker tasks time to properly exit. Fixes PendingQuitTask
|
|
|
|
// sometimes freezing and blocking process exit.
|
|
|
|
QThreadPool::globalInstance()->waitForDone(30000);
|
|
|
|
|
2018-06-24 05:16:59 +00:00
|
|
|
return err;
|
2018-04-28 22:39:50 +00:00
|
|
|
}
|