From 3007069592c5d359513d465b5ee5206fd895590d Mon Sep 17 00:00:00 2001 From: rankun Date: Fri, 28 Feb 2020 17:47:00 +0800 Subject: [PATCH] fix: opengl set on application before --- QtScrcpy/main.cpp | 56 +++++++++++++++++++++------------------- QtScrcpy/util/config.cpp | 3 ++- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/QtScrcpy/main.cpp b/QtScrcpy/main.cpp index b80156b..a21e791 100644 --- a/QtScrcpy/main.cpp +++ b/QtScrcpy/main.cpp @@ -18,6 +18,35 @@ void installTranslator(); int main(int argc, char *argv[]) { + // set env +#ifdef Q_OS_WIN32 + qputenv("QTSCRCPY_ADB_PATH", "../../../../third_party/adb/win/adb.exe"); + qputenv("QTSCRCPY_SERVER_PATH", "../../../../third_party/scrcpy-server"); + qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../keymap"); + qputenv("QTSCRCPY_CONFIG_PATH", "../../../../config"); +#endif + +#ifdef Q_OS_OSX + qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../../../keymap"); +#endif + +#ifdef Q_OS_LINUX + qputenv("QTSCRCPY_ADB_PATH", "../../../third_party/adb/linux/adb"); + qputenv("QTSCRCPY_SERVER_PATH", "../../../third_party/scrcpy-server"); + qputenv("QTSCRCPY_CONFIG_PATH", "../../../config"); + qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap"); +#endif + + // set on QApplication before + int opengl = Config::getInstance().getDesktopOpenGL(); + if (0 == opengl) { + QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); + } else if (1 == opengl){ + QApplication::setAttribute(Qt::AA_UseOpenGLES); + } else if (2 == opengl) { + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + } + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); g_oldMessageHandler = qInstallMessageHandler(myMessageOutput); @@ -41,24 +70,6 @@ int main(int argc, char *argv[]) MouseTap::getInstance()->initMouseEventTap(); #endif -#ifdef Q_OS_WIN32 - qputenv("QTSCRCPY_ADB_PATH", "../../../../third_party/adb/win/adb.exe"); - qputenv("QTSCRCPY_SERVER_PATH", "../../../../third_party/scrcpy-server"); - qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../keymap"); - qputenv("QTSCRCPY_CONFIG_PATH", "../../../../config"); -#endif - -#ifdef Q_OS_OSX - qputenv("QTSCRCPY_KEYMAP_PATH", "../../../../../../keymap"); -#endif - -#ifdef Q_OS_LINUX - qputenv("QTSCRCPY_ADB_PATH", "../../../third_party/adb/linux/adb"); - qputenv("QTSCRCPY_SERVER_PATH", "../../../third_party/scrcpy-server"); - qputenv("QTSCRCPY_CONFIG_PATH", "../../../config"); - qputenv("QTSCRCPY_KEYMAP_PATH", "../../../keymap"); -#endif - //加载样式表 QFile file(":/qss/psblack.css"); if (file.open(QFile::ReadOnly)) { @@ -69,15 +80,6 @@ int main(int argc, char *argv[]) file.close(); } - int opengl = Config::getInstance().getDesktopOpenGL(); - if (0 == opengl) { - QApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); - } else if (1 == opengl){ - QApplication::setAttribute(Qt::AA_UseOpenGLES); - } else if (2 == opengl) { - QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); - } - g_mainDlg = new Dialog; g_mainDlg->setWindowTitle(Config::getInstance().getTitle()); g_mainDlg->show(); diff --git a/QtScrcpy/util/config.cpp b/QtScrcpy/util/config.cpp index 9050461..6fb2e52 100644 --- a/QtScrcpy/util/config.cpp +++ b/QtScrcpy/util/config.cpp @@ -69,7 +69,8 @@ const QString& Config::getConfigPath() s_configPath = QString::fromLocal8Bit(qgetenv("QTSCRCPY_CONFIG_PATH")); QFileInfo fileInfo(s_configPath); if (s_configPath.isEmpty() || !fileInfo.isDir()) { - s_configPath = QCoreApplication::applicationDirPath() + "/config"; + // default application dir + s_configPath = "config"; } } return s_configPath;