summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/client/qwaylanddisplay.cpp79
-rw-r--r--src/client/qwaylanddisplay_p.h2
-rw-r--r--src/client/qwaylandintegration.cpp2
3 files changed, 65 insertions, 18 deletions
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index c56351caa..199f5ad35 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -335,6 +335,7 @@ QWaylandWindowManagerIntegration *QWaylandDisplay::windowManagerIntegration() co
QWaylandDisplay::QWaylandDisplay(QWaylandIntegration *waylandIntegration)
: mWaylandIntegration(waylandIntegration)
+ , textInputProtocolChecked(true)
{
qRegisterMetaType<uint32_t>("uint32_t");
@@ -440,6 +441,11 @@ void QWaylandDisplay::blockingReadEvents()
void QWaylandDisplay::checkTextInputProtocol()
{
+ if (textInputProtocolChecked)
+ return;
+
+ textInputProtocolChecked = true;
+
if (mClientSideInputContextRequested) {
qCDebug(lcQpaWayland) << "mClientSideInputContextRequested is false, no need for text input.";
return;
@@ -454,19 +460,29 @@ void QWaylandDisplay::checkTextInputProtocol()
bool found = false;
QString tiProtocols = QString::fromLocal8Bit(qgetenv("QT_WAYLAND_TEXT_INPUT_PROTOCOL"));
qCDebug(lcQpaWayland) << "QT_WAYLAND_TEXT_INPUT_PROTOCOL=" << tiProtocols;
+ QStringList keys;
if (!tiProtocols.isEmpty()) {
- QStringList keys = tiProtocols.split(QLatin1Char(';'));
- for (const QString &k : keys) {
- int index = tips.indexOf(k);
- if (index >= 0 && hasRegistryGlobal(timps[index]) && registerTextInputManager(timps, index))
- found = true;
+ keys = tiProtocols.split(QLatin1Char(';'));
+ QList<QString>::iterator it = keys.begin();
+ while (it != keys.end()) {
+ if (!tips.contains(*it)) {
+ qCDebug(lcQpaWayland) << "text input: unknown protocol - " << *it;
+ it = keys.erase(it);
+ } else {
+ ++it;
+ }
}
}
+ if (keys.isEmpty())
+ keys = tips; // fallback
- if (!found) {
- for (int i = 0; i < timps.size(); i++) {
- if (hasRegistryGlobal(timps[i]) && registerTextInputManager(timps, i))
+ for (int k = 0; k < tips.size(); ++k) {
+ if (keys.contains(tips[k])) {
+ if (hasRegistryGlobal(timps[k]) && registerTextInputManager(timps, k))
found = true;
+ } else {
+ if (hasRegistryGlobal(timps[k]))
+ unregisterTextInputManager(timps, k);
}
}
@@ -480,21 +496,18 @@ bool QWaylandDisplay::registerTextInputManager(const QStringList &protocols, int
return false;
QString p = protocols.at(index);
- if (index == 0) {
- for (const RegistryGlobal &global : mGlobals) {
- if (global.interface == p) {
+ for (const RegistryGlobal &global : mGlobals) {
+ if (global.interface == p) {
+ if (index == 0) {
+ qCDebug(lcQpaWayland) << "text input: register qt_text_input_method_manager_v1";
mTextInputMethodManager.reset(new QtWayland::qt_text_input_method_manager_v1(global.registry, global.id, 1));
for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
inputDevice->setTextInputMethod(new QWaylandTextInputMethod(this, mTextInputMethodManager->get_text_input_method(inputDevice->wl_seat())));
mWaylandIntegration->reconfigureInputContext();
return true;
}
- }
- }
-
- if (index == 1) {
- for (const RegistryGlobal &global : mGlobals) {
- if (global.interface == p) {
+ if (index == 1) {
+ qCDebug(lcQpaWayland) << "text input: register zwp_text_input_manager_v2";
mTextInputManager.reset(new QtWayland::zwp_text_input_manager_v2(global.registry, global.id, 1));
for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
inputDevice->setTextInput(new QWaylandTextInput(this, mTextInputManager->get_text_input(inputDevice->wl_seat())));
@@ -507,6 +520,34 @@ bool QWaylandDisplay::registerTextInputManager(const QStringList &protocols, int
return false;
}
+void QWaylandDisplay::unregisterTextInputManager(const QStringList &protocols, int index)
+{
+ if (protocols.size() > 2 || index < 0 || index >= 2)
+ return;
+
+ QString p = protocols.at(index);
+ for (const RegistryGlobal &global : mGlobals) {
+ if (global.interface == p) {
+ if (index == 0) {
+ qCDebug(lcQpaWayland) << "text input: unregister qt_text_input_method_manager_v1";
+ mTextInputMethodManager.reset();
+ for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
+ inputDevice->setTextInputMethod(nullptr);
+ mWaylandIntegration->reconfigureInputContext();
+ return;
+ }
+ if (index == 1) {
+ qCDebug(lcQpaWayland) << "text input: unregister zwp_text_input_manager_v2";
+ mTextInputManager.reset();
+ for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
+ inputDevice->setTextInput(nullptr);
+ mWaylandIntegration->reconfigureInputContext();
+ return;
+ }
+ }
+ }
+}
+
QWaylandScreen *QWaylandDisplay::screenForOutput(struct wl_output *output) const
{
for (auto screen : qAsConst(mScreens)) {
@@ -562,6 +603,10 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
} else if (interface == QLatin1String(QWaylandPrimarySelectionDeviceManagerV1::interface()->name)) {
mPrimarySelectionManager.reset(new QWaylandPrimarySelectionDeviceManagerV1(this, id, 1));
#endif
+ } else if (interface == QLatin1String(QtWayland::qt_text_input_method_manager_v1::interface()->name) && !mClientSideInputContextRequested) {
+ textInputProtocolChecked = false;
+ } else if (interface == QLatin1String(QtWayland::zwp_text_input_manager_v2::interface()->name) && !mClientSideInputContextRequested) {
+ textInputProtocolChecked = false;
} else if (interface == QLatin1String(QWaylandHardwareIntegration::interface()->name)) {
bool disableHardwareIntegration = qEnvironmentVariableIntValue("QT_WAYLAND_DISABLE_HW_INTEGRATION");
if (!disableHardwareIntegration) {
diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index 6d655a66b..2104fa9b7 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/qwaylanddisplay_p.h
@@ -225,6 +225,7 @@ private:
void checkTextInputProtocol();
bool registerTextInputManager(const QStringList &protocols, int index);
+ void unregisterTextInputManager(const QStringList &protocols, int index);
struct Listener {
Listener() = default;
@@ -296,6 +297,7 @@ private:
static const wl_callback_listener syncCallbackListener;
bool mClientSideInputContextRequested = !QPlatformInputContextFactory::requested().isNull();
+ bool textInputProtocolChecked;
void registry_global(uint32_t id, const QString &interface, uint32_t version) override;
void registry_global_remove(uint32_t id) override;
diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp
index 5b712cab9..67af87cb2 100644
--- a/src/client/qwaylandintegration.cpp
+++ b/src/client/qwaylandintegration.cpp
@@ -497,7 +497,7 @@ void QWaylandIntegration::reconfigureInputContext()
if (requested.isNull()) {
if (mDisplay->textInputMethodManager() != nullptr)
mInputContext.reset(new QWaylandInputMethodContext(mDisplay.data()));
- else
+ else if (mDisplay->textInputManager() != nullptr)
mInputContext.reset(new QWaylandInputContext(mDisplay.data()));
} else {
mInputContext.reset(QPlatformInputContextFactory::create(requested));