diff options
Diffstat (limited to 'src/client/qwaylandintegration.cpp')
-rw-r--r-- | src/client/qwaylandintegration.cpp | 96 |
1 files changed, 54 insertions, 42 deletions
diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp index a874c55a3..eb19be45d 100644 --- a/src/client/qwaylandintegration.cpp +++ b/src/client/qwaylandintegration.cpp @@ -73,6 +73,8 @@ QT_BEGIN_NAMESPACE namespace QtWaylandClient { +QWaylandIntegration *QWaylandIntegration::sInstance = nullptr; + QWaylandIntegration::QWaylandIntegration() #if defined(Q_OS_MACOS) : mFontDb(new QCoreTextFontDatabaseEngineFactory<QCoreTextFontEngine>) @@ -81,30 +83,21 @@ QWaylandIntegration::QWaylandIntegration() #endif { mDisplay.reset(new QWaylandDisplay(this)); - if (!mDisplay->isInitialized()) { - mFailed = true; - return; - } QWaylandWindow::fixedToplevelPositions = !qEnvironmentVariableIsSet("QT_WAYLAND_DISABLE_FIXED_POSITIONS"); - // ### Not ideal... - // We don't want to use QPlatformWindow::requestActivate here, since that gives a warning - // for most shells. Also, we don't want to put this into the specific shells that can use - // it, since we want to support more than one shell in one client. - // In addition, this will send a new requestActivate when the focus object changes, even if - // the focus window stays the same. - QObject::connect(qApp, &QGuiApplication::focusObjectChanged, qApp, [](){ - QWindow *fw = QGuiApplication::focusWindow(); - auto *w = fw ? static_cast<QWaylandWindow*>(fw->handle()) : nullptr; - if (w && w->shellSurface()) - w->shellSurface()->requestActivate(); - }); + sInstance = this; } QWaylandIntegration::~QWaylandIntegration() { + sInstance = nullptr; +} + +bool QWaylandIntegration::init() +{ + return mDisplay->initialize(); } QPlatformNativeInterface * QWaylandIntegration::nativeInterface() const @@ -176,7 +169,7 @@ QPlatformNativeInterface *QWaylandIntegration::createPlatformNativeInterface() // Support platform specific initialization void QWaylandIntegration::initializePlatform() { - mDisplay->initialize(); + mDisplay->initEventThread(); mNativeInterface.reset(createPlatformNativeInterface()); initializeInputDeviceIntegration(); @@ -192,14 +185,9 @@ void QWaylandIntegration::initializePlatform() void QWaylandIntegration::initialize() { - mDisplay->initEventThread(); - - // Call this after initializing event thread for QWaylandDisplay::forceRoundTrip() initializePlatform(); - // But the aboutToBlock() and awake() should be connected after initializePlatform(). - // Otherwise the connected flushRequests() may consumes up all events before processEvents starts to wait, - // so that processEvents(QEventLoop::WaitForMoreEvents) may be blocked in the forceRoundTrip(). + // Call this after initializing event thread for QWaylandDisplay::flushRequests() QAbstractEventDispatcher *dispatcher = QGuiApplicationPrivate::eventDispatcher; QObject::connect(dispatcher, SIGNAL(aboutToBlock()), mDisplay.data(), SLOT(flushRequests())); QObject::connect(dispatcher, SIGNAL(awake()), mDisplay.data(), SLOT(flushRequests())); @@ -422,7 +410,7 @@ void QWaylandIntegration::initializeShellIntegration() preferredShells << QLatin1String("qt-shell"); } - for (const QString &preferredShell : qAsConst(preferredShells)) { + for (const QString &preferredShell : std::as_const(preferredShells)) { mShellIntegration.reset(createShellIntegration(preferredShell)); if (mShellIntegration) { qCDebug(lcQpaWayland, "Using the '%s' shell integration", qPrintable(preferredShell)); @@ -474,27 +462,35 @@ void QWaylandIntegration::reconfigureInputContext() return; } - const QString &requested = QPlatformInputContextFactory::requested(); - if (requested == QLatin1String("qtvirtualkeyboard")) + auto requested = QPlatformInputContextFactory::requested(); + if (requested.contains(QLatin1String("qtvirtualkeyboard"))) qCWarning(lcQpaWayland) << "qtvirtualkeyboard currently is not supported at client-side," - " use QT_IM_MODULE=qtvirtualkeyboard at compositor-side."; - - if (requested.isNull()) { - if (mDisplay->textInputMethodManager() != nullptr) - mInputContext.reset(new QWaylandInputMethodContext(mDisplay.data())); -#if QT_WAYLAND_TEXT_INPUT_V4_WIP - else if (mDisplay->textInputManagerv1() != nullptr || mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv4() != nullptr) -#else // QT_WAYLAND_TEXT_INPUT_V4_WIP - else if (mDisplay->textInputManagerv1() != nullptr || mDisplay->textInputManagerv2() != nullptr) -#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP - mInputContext.reset(new QWaylandInputContext(mDisplay.data())); - } else { - mInputContext.reset(QPlatformInputContextFactory::create(requested)); - } + " use QT_IM_MODULES=qtvirtualkeyboard at compositor-side."; + + if (mDisplay->isWaylandInputContextRequested() + && !requested.contains(QLatin1String(WAYLAND_IM_KEY))) + requested.append(QLatin1String(WAYLAND_IM_KEY)); const QString defaultInputContext(QStringLiteral("compose")); - if ((!mInputContext || !mInputContext->isValid()) && requested != defaultInputContext) - mInputContext.reset(QPlatformInputContextFactory::create(defaultInputContext)); + if (!requested.contains(defaultInputContext)) + requested.append(defaultInputContext); + + for (const QString &imKey : requested) { + if (imKey == QLatin1String(WAYLAND_IM_KEY)) { + Q_ASSERT(mDisplay->isWaylandInputContextRequested()); + if (mDisplay->textInputMethodManager() != nullptr) + mInputContext.reset(new QWaylandInputMethodContext(mDisplay.data())); + else if (mDisplay->textInputManagerv1() != nullptr + || mDisplay->textInputManagerv2() != nullptr + || mDisplay->textInputManagerv3() != nullptr) + mInputContext.reset(new QWaylandInputContext(mDisplay.data())); + } else { + mInputContext.reset(QPlatformInputContextFactory::create(imKey)); + } + + if (mInputContext && mInputContext->isValid()) + break; + } #if QT_CONFIG(xkbcommon) QXkbCommon::setXkbContext(mInputContext.data(), mDisplay->xkbContext()); @@ -516,6 +512,22 @@ QWaylandShellIntegration *QWaylandIntegration::createShellIntegration(const QStr } } +void QWaylandIntegration::reset() +{ + mServerBufferIntegration.reset(); + mServerBufferIntegrationInitialized = false; + + mInputDeviceIntegration.reset(); + + mClientBufferIntegration.reset(); + mClientBufferIntegrationInitialized = false; +} + +void QWaylandIntegration::setApplicationBadge(qint64 number) +{ + auto unixServices = mDisplay->windowManagerIntegration(); + unixServices->setApplicationBadge(number); +} } QT_END_NAMESPACE |