fix: 修复使用 TreeLand 混合器时启动崩溃问题

适配麒麟 CPU Wayland 环境时,强制设置环境变量 QT_WAYLAND_SHELL_INTEGRATION 为 kwayland-shell,在 TreeLand 混合器下崩溃

Log: 添加环境变量判断,DDE_CURRENT_COMPOSITER=TreeLand 或 DESKTOP_SESSION=treeland 时不执行上述设置环境变量操作
This commit is contained in:
zty199 2023-12-30 00:17:01 +08:00
parent a9264b8cb9
commit 62e23facfb
3 changed files with 57 additions and 55 deletions

View File

@ -140,26 +140,43 @@ int main(int argc, char *argv[])
// Set display backend // Set display backend
Utils::setQPAPlatform(); Utils::setQPAPlatform();
// 龙芯机器配置,使得 DApplication 能正确加载 QTWEBENGINE // 龙芯机器配置,使得 DApplication 能正确加载 QtWebEngine
qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE"); qputenv("DTK_FORCE_RASTER_WIDGETS", "FALSE");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security");
// 浏览器开启 GPU 支持 // 浏览器开启 GPU 支持
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-features=UseModernMediaControls");
// qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--disable-web-security");
#ifdef __sw_64__ #ifdef __sw_64__
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox"); qputenv("QTWEBENGINE_CHROMIUM_FLAGS", "--no-sandbox");
#elif __aarch64__ #elif __aarch64__
if (!Utils::isWayland()) {
QString env = QString::fromUtf8(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS")); QString env = QString::fromUtf8(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
env = env.trimmed(); env = env.trimmed();
/** /**
* NOTE: ARM CPU * NOTE: ARM CPU
* --disable-gpu X11 * --disable-gpu
* --single-process X11 QtWebEngine * --single-process QtWebEngine
*/ */
env += " --disable-gpu"; env += " --disable-gpu";
if (Utils::isPhytium()) {
env += " --single-process";
}
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", env.trimmed().toUtf8()); qputenv("QTWEBENGINE_CHROMIUM_FLAGS", env.trimmed().toUtf8());
if (Utils::isWayland()) {
/**
* WARNING: DDM TreeLand
* QT_WAYLAND_SHELL_INTEGRATION
* By justforlxz
*/
if (!Utils::isTreeLand()) {
/**
* NOTE: CPU
* wayland QtWebEngine
*/
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell");
}
}
QSurfaceFormat format; QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGLES); format.setRenderableType(QSurfaceFormat::OpenGLES);
QSurfaceFormat::setDefaultFormat(format); QSurfaceFormat::setDefaultFormat(format);
@ -168,39 +185,10 @@ int main(int argc, char *argv[])
* NOTE: https://zhuanlan.zhihu.com/p/550285855 * NOTE: https://zhuanlan.zhihu.com/p/550285855
* X11 QtWebEngine 退 QWidget * X11 QtWebEngine 退 QWidget
*/ */
if (!Utils::isWayland()) {
qputenv("QMLSCENE_DEVICE", "softwarecontext"); qputenv("QMLSCENE_DEVICE", "softwarecontext");
DApplication::setAttribute(Qt::AA_UseSoftwareOpenGL); DApplication::setAttribute(Qt::AA_UseSoftwareOpenGL);
} }
/**
* FIXME: CPU QtWebEngine
* CPU wayland
*/
else {
QString env = QString::fromUtf8(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
env = env.trimmed();
/**
* NOTE: CPU
* --disable-gpu wayland
* --single-process wayland QtWebEngine
*/
env += " --disable-gpu";
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", env.trimmed().toUtf8());
/**
* NOTE: CPU
* wayland QtWebEngine
*/
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "kwayland-shell");
QSurfaceFormat format;
format.setRenderableType(QSurfaceFormat::OpenGLES);
QSurfaceFormat::setDefaultFormat(format);
}
if (Utils::isPhytium()){
QString env = QString::fromUtf8(qgetenv("QTWEBENGINE_CHROMIUM_FLAGS"));
env = env.trimmed();
env += " --single-process";
qputenv("QTWEBENGINE_CHROMIUM_FLAGS", env.trimmed().toUtf8());
}
#endif #endif
/** /**
@ -215,12 +203,10 @@ int main(int argc, char *argv[])
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
{
// 开启 Hidpi 支持 // 开启 Hidpi 支持
qDebug() << "Enable HiDPI Support."; qDebug() << "Enable HiDPI Support.";
DApplication::setAttribute(Qt::AA_EnableHighDpiScaling); DApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
DApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); DApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
}
#endif #endif
// 强制使用 DTK 平台插件 // 强制使用 DTK 平台插件

View File

@ -73,6 +73,21 @@ bool Utils::isWayland()
return isWayland; return isWayland;
} }
/**
* @brief 使 TreeLand
* @return bool true: 使 TreeLand false: TreeLand
*/
bool Utils::isTreeLand()
{
bool isTreeLand = false;
if (qgetenv("DDE_CURRENT_COMPOSITER").toLower() == "treeland"
|| qgetenv("DESKTOP_SESSION").toLower() == "treeland") {
isTreeLand = true;
}
return isTreeLand;
}
bool Utils::isPhytium() bool Utils::isPhytium()
{ {
bool isPhytium = false; bool isPhytium = false;

View File

@ -10,6 +10,7 @@ public:
static void sendNotification(const QString &icon, const QString &title, const QString &body); static void sendNotification(const QString &icon, const QString &title, const QString &body);
static bool isDDE(); static bool isDDE();
static bool isWayland(); static bool isWayland();
static bool isTreeLand();
static void initConfig(); static void initConfig();
static bool isUOS(); static bool isUOS();
static bool isPhytium(); static bool isPhytium();