diff --git a/scripts/build.py b/scripts/build.py index 2f33b95ff56..8195459006d 100755 --- a/scripts/build.py +++ b/scripts/build.py @@ -173,6 +173,7 @@ def build_qtcreator(args, paths): '-DBUILD_QBS=' + cmake_option(build_qbs), '-DBUILD_DEVELOPER_DOCS=' + cmake_option(not args.no_docs), '-DBUILD_EXECUTABLE_SDKTOOL=OFF', + '-DQTC_FORCE_XCB=ON', '-DCMAKE_INSTALL_PREFIX=' + common.to_posix_path(paths.install), '-DWITH_TESTS=' + cmake_option(args.with_tests)] cmake_args += common_cmake_arguments(args) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index ad9ef52f49d..b77138468e2 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -92,6 +92,13 @@ if (APPLE) ) endif() +option(QTC_FORCE_XCB "Enables that Qt Creator forces XCB on Linux if QT_QPA_PLATFORM is not set." OFF) +extend_qtc_executable(qtcreator + CONDITION QTC_FORCE_XCB + DEFINES + QTC_FORCE_XCB +) + extend_qtc_executable(qtcreator CONDITION BUILD_WITH_CRASHPAD DEFINES diff --git a/src/app/main.cpp b/src/app/main.cpp index d9e91f21d17..42557c3d2b7 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -500,6 +500,26 @@ int main(int argc, char **argv) qputenv("QT_ENABLE_REGEXP_JIT", "0"); } +#if defined(QTC_FORCE_XCB) + if (Utils::HostOsInfo::isLinuxHost() && !qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) { + // Enforce XCB on Linux/Gnome, if the user didn't override via QT_QPA_PLATFORM + // This was previously done in Qt, but removed in Qt 6.3. We found that bad things can still happen, + // like the Wayland session simply crashing when starting Qt Creator. + // TODO: Reconsider when Qt/Wayland is reliably working on the supported distributions + const bool hasWaylandDisplay = qEnvironmentVariableIsSet("WAYLAND_DISPLAY"); + const bool isWaylandSessionType = qgetenv("XDG_SESSION_TYPE") == "wayland"; + const QByteArray currentDesktop = qgetenv("XDG_CURRENT_DESKTOP").toLower(); + const QByteArray sessionDesktop = qgetenv("XDG_SESSION_DESKTOP").toLower(); + const bool isGnome = currentDesktop.contains("gnome") || sessionDesktop.contains("gnome"); + const bool isWayland = hasWaylandDisplay || isWaylandSessionType; + if (isGnome && isWayland) { + qInfo() << "Warning: Ignoring WAYLAND_DISPLAY on Gnome." + << "Use QT_QPA_PLATFORM=wayland to run on Wayland anyway."; + qputenv("QT_QPA_PLATFORM", "xcb"); + } + } +#endif + Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath() + "/" + Core::Constants::IDE_CASED_ID + "-XXXXXX"); #ifdef Q_OS_MACOS