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

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

@ -73,6 +73,21 @@ bool Utils::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 isPhytium = false;

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