summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@qt.io>2022-01-19 11:17:19 +0100
committerDominik Holland <dominik.holland@qt.io>2022-02-02 13:02:17 +0000
commite68f0f05daca454a2c793c5862b78f78d100a805 (patch)
tree1bbd38e3af6c20f0ae43a5246ec2389cc5502f42 /src/client
parent1eded03865193d95fab7fd9279e34fb0dbe0cb45 (diff)
Add client support for the text-input-unstable-v1 protocol
This is used by weston for forwarding virtualkeyboard related event from keyboard applications to a Qt client. Right now Qt only supports text-input-unstable-v2, v4 and the special qt-input-method protocol, while weston only supports text-input-unstable-v1. Without this, a virtual-keyboard application can't be used with a Qt client within weston. Change-Id: I9a34a87100854bb0b0f76762ced56419e70c297e Reviewed-by: Inho Lee <inho.lee@qt.io> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/client')
-rw-r--r--src/client/CMakeLists.txt2
-rw-r--r--src/client/qwaylanddisplay.cpp38
-rw-r--r--src/client/qwaylanddisplay_p.h3
-rw-r--r--src/client/qwaylandinputcontext.cpp4
-rw-r--r--src/client/qwaylandinputdevice.cpp7
-rw-r--r--src/client/qwaylandintegration.cpp4
-rw-r--r--src/client/qwaylandtextinputv1.cpp395
-rw-r--r--src/client/qwaylandtextinputv1_p.h149
8 files changed, 596 insertions, 6 deletions
diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt
index 7bcb65c86..1041f31e1 100644
--- a/src/client/CMakeLists.txt
+++ b/src/client/CMakeLists.txt
@@ -29,6 +29,7 @@ qt_internal_add_module(WaylandClient
qwaylanddisplay.cpp qwaylanddisplay_p.h
qwaylandextendedsurface.cpp qwaylandextendedsurface_p.h
qwaylandinputcontext.cpp qwaylandinputcontext_p.h
+ qwaylandtextinputv1.cpp qwaylandtextinputv1_p.h
qwaylandtextinputv2.cpp qwaylandtextinputv2_p.h
qwaylandtextinputinterface.cpp qwaylandtextinputinterface_p.h
qwaylandinputdevice.cpp qwaylandinputdevice_p.h
@@ -75,6 +76,7 @@ qt6_generate_wayland_protocol_client_sources(WaylandClient
FILES
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/pointer-gestures-unstable-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/tablet-unstable-v2.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/text-input-unstable-v1.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/text-input-unstable-v2.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/text-input-unstable-v4-wip.xml
${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty/protocol/wayland.xml
diff --git a/src/client/qwaylanddisplay.cpp b/src/client/qwaylanddisplay.cpp
index 4e0a90b7a..5937172f0 100644
--- a/src/client/qwaylanddisplay.cpp
+++ b/src/client/qwaylanddisplay.cpp
@@ -60,6 +60,7 @@
#include <wayland-cursor.h>
#endif
#include "qwaylandhardwareintegration_p.h"
+#include "qwaylandtextinputv1_p.h"
#include "qwaylandtextinputv2_p.h"
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
#include "qwaylandtextinputv4_p.h"
@@ -80,6 +81,7 @@
#endif
#include "qwaylandqtkey_p.h"
+#include <QtWaylandClient/private/qwayland-text-input-unstable-v1.h>
#include <QtWaylandClient/private/qwayland-text-input-unstable-v2.h>
#include <QtWaylandClient/private/qwayland-text-input-unstable-v4-wip.h>
#include <QtWaylandClient/private/qwayland-wp-primary-selection-unstable-v1.h>
@@ -453,9 +455,11 @@ void QWaylandDisplay::checkTextInputProtocol()
{
QStringList tips, timps; // for text input protocols and text input manager protocols
tips << QLatin1String(QtWayland::qt_text_input_method_v1::interface()->name)
- << QLatin1String(QtWayland::zwp_text_input_v2::interface()->name);
+ << QLatin1String(QtWayland::zwp_text_input_v2::interface()->name)
+ << QLatin1String(QtWayland::zwp_text_input_v1::interface()->name);
timps << QLatin1String(QtWayland::qt_text_input_method_manager_v1::interface()->name)
- << QLatin1String(QtWayland::zwp_text_input_manager_v2::interface()->name);
+ << QLatin1String(QtWayland::zwp_text_input_manager_v2::interface()->name)
+ << QLatin1String(QtWayland::zwp_text_input_manager_v1::interface()->name);
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
tips << QLatin1String(QtWayland::zwp_text_input_v4::interface()->name);
timps << QLatin1String(QtWayland::zwp_text_input_manager_v4::interface()->name);
@@ -540,6 +544,7 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
&& (mTextInputManagerList.contains(interface) && mTextInputManagerList.indexOf(interface) < mTextInputManagerIndex)) {
qCDebug(lcQpaWayland) << "text input: register qt_text_input_method_manager_v1";
if (mTextInputManagerIndex < INT_MAX) {
+ mTextInputManagerv1.reset();
mTextInputManagerv2.reset();
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
mTextInputManagerv4.reset();
@@ -553,11 +558,34 @@ void QWaylandDisplay::registry_global(uint32_t id, const QString &interface, uin
inputDevice->setTextInputMethod(new QWaylandTextInputMethod(this, mTextInputMethodManager->get_text_input_method(inputDevice->wl_seat())));
mWaylandIntegration->reconfigureInputContext();
mTextInputManagerIndex = mTextInputManagerList.indexOf(interface);
+ } else if (interface == QLatin1String(QtWayland::zwp_text_input_manager_v1::interface()->name)
+ && (mTextInputManagerList.contains(interface) && mTextInputManagerList.indexOf(interface) < mTextInputManagerIndex)) {
+ qCDebug(lcQpaWayland) << "text input: register zwp_text_input_v1";
+ if (mTextInputManagerIndex < INT_MAX) {
+ mTextInputMethodManager.reset();
+ mTextInputManagerv2.reset();
+#if QT_WAYLAND_TEXT_INPUT_V4_WIP
+ mTextInputManagerv4.reset();
+#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP
+ for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
+ inputDevice->setTextInputMethod(nullptr);
+ }
+
+ mTextInputManagerv1.reset(new QtWayland::zwp_text_input_manager_v1(registry, id, 1));
+ for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices)) {
+ auto textInput = new QWaylandTextInputv1(this, mTextInputManagerv1->create_text_input());
+ textInput->setSeat(inputDevice->wl_seat());
+ inputDevice->setTextInput(textInput);
+ }
+
+ mWaylandIntegration->reconfigureInputContext();
+ mTextInputManagerIndex = mTextInputManagerList.indexOf(interface);
} else if (interface == QLatin1String(QtWayland::zwp_text_input_manager_v2::interface()->name)
&& (mTextInputManagerList.contains(interface) && mTextInputManagerList.indexOf(interface) < mTextInputManagerIndex)) {
qCDebug(lcQpaWayland) << "text input: register zwp_text_input_v2";
if (mTextInputManagerIndex < INT_MAX) {
mTextInputMethodManager.reset();
+ mTextInputManagerv1.reset();
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
mTextInputManagerv4.reset();
#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP
@@ -633,6 +661,12 @@ void QWaylandDisplay::registry_global_remove(uint32_t id)
}
}
}
+ if (global.interface == QLatin1String(QtWayland::zwp_text_input_manager_v1::interface()->name)) {
+ mTextInputManagerv1.reset();
+ for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
+ inputDevice->setTextInput(nullptr);
+ mWaylandIntegration->reconfigureInputContext();
+ }
if (global.interface == QLatin1String(QtWayland::zwp_text_input_manager_v2::interface()->name)) {
mTextInputManagerv2.reset();
for (QWaylandInputDevice *inputDevice : qAsConst(mInputDevices))
diff --git a/src/client/qwaylanddisplay_p.h b/src/client/qwaylanddisplay_p.h
index 8d8000d2a..cf123cba3 100644
--- a/src/client/qwaylanddisplay_p.h
+++ b/src/client/qwaylanddisplay_p.h
@@ -82,6 +82,7 @@ class QPlatformPlaceholderScreen;
namespace QtWayland {
class qt_surface_extension;
+ class zwp_text_input_manager_v1;
class zwp_text_input_manager_v2;
class zwp_text_input_manager_v4;
class qt_text_input_method_manager_v1;
@@ -176,6 +177,7 @@ public:
QWaylandPointerGestures *pointerGestures() const { return mPointerGestures.data(); }
QWaylandTouchExtension *touchExtension() const { return mTouchExtension.data(); }
QtWayland::qt_text_input_method_manager_v1 *textInputMethodManager() const { return mTextInputMethodManager.data(); }
+ QtWayland::zwp_text_input_manager_v1 *textInputManagerv1() const { return mTextInputManagerv1.data(); }
QtWayland::zwp_text_input_manager_v2 *textInputManagerv2() const { return mTextInputManagerv2.data(); }
QtWayland::zwp_text_input_manager_v4 *textInputManagerv4() const { return mTextInputManagerv4.data(); }
QWaylandHardwareIntegration *hardwareIntegration() const { return mHardwareIntegration.data(); }
@@ -289,6 +291,7 @@ private:
QScopedPointer<QWaylandPrimarySelectionDeviceManagerV1> mPrimarySelectionManager;
#endif
QScopedPointer<QtWayland::qt_text_input_method_manager_v1> mTextInputMethodManager;
+ QScopedPointer<QtWayland::zwp_text_input_manager_v1> mTextInputManagerv1;
QScopedPointer<QtWayland::zwp_text_input_manager_v2> mTextInputManagerv2;
QScopedPointer<QtWayland::zwp_text_input_manager_v4> mTextInputManagerv4;
QScopedPointer<QWaylandHardwareIntegration> mHardwareIntegration;
diff --git a/src/client/qwaylandinputcontext.cpp b/src/client/qwaylandinputcontext.cpp
index c59485277..32433cdc0 100644
--- a/src/client/qwaylandinputcontext.cpp
+++ b/src/client/qwaylandinputcontext.cpp
@@ -71,9 +71,9 @@ QWaylandInputContext::~QWaylandInputContext()
bool QWaylandInputContext::isValid() const
{
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
- return mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv4() != nullptr;
+ return mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv1() != nullptr || mDisplay->textInputManagerv4() != nullptr;
#else // QT_WAYLAND_TEXT_INPUT_V4_WIP
- return mDisplay->textInputManagerv2() != nullptr;
+ return mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv1() != nullptr;
#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP
}
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp
index 4c32a534d..34ca328a6 100644
--- a/src/client/qwaylandinputdevice.cpp
+++ b/src/client/qwaylandinputdevice.cpp
@@ -59,6 +59,7 @@
#include "qwaylandcursor_p.h"
#include "qwaylanddisplay_p.h"
#include "qwaylandshmbackingstore_p.h"
+#include "qwaylandtextinputv1_p.h"
#include "qwaylandtextinputv2_p.h"
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
#include "qwaylandtextinputv4_p.h"
@@ -426,6 +427,12 @@ QWaylandInputDevice::QWaylandInputDevice(QWaylandDisplay *display, int version,
setPrimarySelectionDevice(psm->createDevice(this));
#endif
+ if (mQDisplay->textInputManagerv1()) {
+ auto textInput = new QWaylandTextInputv1(mQDisplay, mQDisplay->textInputManagerv1()->create_text_input());
+ textInput->setSeat(wl_seat());
+ mTextInput.reset(textInput);
+ }
+
if (mQDisplay->textInputManagerv2())
mTextInput.reset(new QWaylandTextInputv2(mQDisplay, mQDisplay->textInputManagerv2()->get_text_input(wl_seat())));
diff --git a/src/client/qwaylandintegration.cpp b/src/client/qwaylandintegration.cpp
index 274ae9a9d..721af8347 100644
--- a/src/client/qwaylandintegration.cpp
+++ b/src/client/qwaylandintegration.cpp
@@ -514,9 +514,9 @@ void QWaylandIntegration::reconfigureInputContext()
if (mDisplay->textInputMethodManager() != nullptr)
mInputContext.reset(new QWaylandInputMethodContext(mDisplay.data()));
#if QT_WAYLAND_TEXT_INPUT_V4_WIP
- else if (mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv4() != nullptr)
+ else if (mDisplay->textInputManagerv1() != nullptr || mDisplay->textInputManagerv2() != nullptr || mDisplay->textInputManagerv4() != nullptr)
#else // QT_WAYLAND_TEXT_INPUT_V4_WIP
- else if (mDisplay->textInputManagerv2() != nullptr)
+ else if (mDisplay->textInputManagerv1() != nullptr || mDisplay->textInputManagerv2() != nullptr)
#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP
mInputContext.reset(new QWaylandInputContext(mDisplay.data()));
} else {
diff --git a/src/client/qwaylandtextinputv1.cpp b/src/client/qwaylandtextinputv1.cpp
new file mode 100644
index 000000000..5e204a7ff
--- /dev/null
+++ b/src/client/qwaylandtextinputv1.cpp
@@ -0,0 +1,395 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWaylandClient module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <qpa/qplatforminputcontext.h>
+
+#include "qwaylandtextinputv1_p.h"
+
+#include "qwaylandwindow_p.h"
+#include "qwaylandinputmethodeventbuilder_p.h"
+
+#include <QtCore/qloggingcategory.h>
+#include <QtGui/QGuiApplication>
+#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/qpa/qplatformintegration.h>
+#include <QtGui/qevent.h>
+#include <QtGui/qwindow.h>
+#include <QTextCharFormat>
+#include <QList>
+#include <QRectF>
+#include <QLocale>
+
+QT_BEGIN_NAMESPACE
+
+Q_DECLARE_LOGGING_CATEGORY(qLcQpaInputMethods)
+
+namespace QtWaylandClient {
+
+namespace {
+
+const Qt::InputMethodQueries supportedQueries = Qt::ImEnabled |
+ Qt::ImSurroundingText |
+ Qt::ImCursorPosition |
+ Qt::ImAnchorPosition |
+ Qt::ImHints |
+ Qt::ImCursorRectangle |
+ Qt::ImPreferredLanguage;
+}
+
+QWaylandTextInputv1::QWaylandTextInputv1(QWaylandDisplay *display, struct ::zwp_text_input_v1 *text_input)
+ : QtWayland::zwp_text_input_v1(text_input)
+ , m_display(display)
+{
+}
+
+QWaylandTextInputv1::~QWaylandTextInputv1()
+{
+ if (m_resetCallback)
+ wl_callback_destroy(m_resetCallback);
+}
+
+void QWaylandTextInputv1::reset()
+{
+ m_builder.reset();
+ m_preeditCommit = QString();
+ updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_reset);
+}
+
+void QWaylandTextInputv1::commit()
+{
+ if (QObject *o = QGuiApplication::focusObject()) {
+ QInputMethodEvent event;
+ event.setCommitString(m_preeditCommit);
+ QCoreApplication::sendEvent(o, &event);
+ }
+
+ reset();
+}
+
+const wl_callback_listener QWaylandTextInputv1::callbackListener = {
+ QWaylandTextInputv1::resetCallback
+};
+
+void QWaylandTextInputv1::resetCallback(void *data, wl_callback *, uint32_t)
+{
+ QWaylandTextInputv1 *self = static_cast<QWaylandTextInputv1*>(data);
+
+ if (self->m_resetCallback) {
+ wl_callback_destroy(self->m_resetCallback);
+ self->m_resetCallback = nullptr;
+ }
+}
+
+void QWaylandTextInputv1::updateState(Qt::InputMethodQueries queries, uint32_t flags)
+{
+ if (!QGuiApplication::focusObject())
+ return;
+
+ if (!QGuiApplication::focusWindow() || !QGuiApplication::focusWindow()->handle())
+ return;
+
+ auto *window = static_cast<QWaylandWindow *>(QGuiApplication::focusWindow()->handle());
+ auto *surface = window->wlSurface();
+ if (!surface || (surface != m_surface))
+ return;
+
+ queries &= supportedQueries;
+
+ // Surrounding text, cursor and anchor positions are transferred together
+ if ((queries & Qt::ImSurroundingText) || (queries & Qt::ImCursorPosition) || (queries & Qt::ImAnchorPosition))
+ queries |= Qt::ImSurroundingText | Qt::ImCursorPosition | Qt::ImAnchorPosition;
+
+ QInputMethodQueryEvent event(queries);
+ QCoreApplication::sendEvent(QGuiApplication::focusObject(), &event);
+
+ if ((queries & Qt::ImSurroundingText) || (queries & Qt::ImCursorPosition) || (queries & Qt::ImAnchorPosition)) {
+ QString text = event.value(Qt::ImSurroundingText).toString();
+ int cursor = event.value(Qt::ImCursorPosition).toInt();
+ int anchor = event.value(Qt::ImAnchorPosition).toInt();
+
+ // Make sure text is not too big
+ if (text.toUtf8().size() > 2048) {
+ int c = qAbs(cursor - anchor) <= 512 ? qMin(cursor, anchor) + qAbs(cursor - anchor) / 2: cursor;
+
+ const int offset = c - qBound(0, c, 512 - qMin(text.size() - c, 256));
+ text = text.mid(offset + c - 256, 512);
+ cursor -= offset;
+ anchor -= offset;
+ }
+
+ set_surrounding_text(text, QWaylandInputMethodEventBuilder::indexToWayland(text, cursor), QWaylandInputMethodEventBuilder::indexToWayland(text, anchor));
+ }
+
+ if (queries & Qt::ImHints) {
+ QWaylandInputMethodContentType contentType = QWaylandInputMethodContentType::convert(static_cast<Qt::InputMethodHints>(event.value(Qt::ImHints).toInt()));
+ set_content_type(contentType.hint, contentType.purpose);
+ }
+
+ if (queries & Qt::ImCursorRectangle) {
+ const QRect &cRect = event.value(Qt::ImCursorRectangle).toRect();
+ const QRect &windowRect = QGuiApplication::inputMethod()->inputItemTransform().mapRect(cRect);
+ const QMargins margins = window->frameMargins();
+ const QRect &surfaceRect = windowRect.translated(margins.left(), margins.top());
+ set_cursor_rectangle(surfaceRect.x(), surfaceRect.y(), surfaceRect.width(), surfaceRect.height());
+ }
+
+ if (queries & Qt::ImPreferredLanguage) {
+ const QString &language = event.value(Qt::ImPreferredLanguage).toString();
+ set_preferred_language(language);
+ }
+
+ if (flags == QWaylandTextInputInterface::update_state_reset)
+ QtWayland::zwp_text_input_v1::reset();
+ else
+ commit_state(m_serial);
+}
+
+void QWaylandTextInputv1::setCursorInsidePreedit(int)
+{
+ // Not supported yet
+}
+
+bool QWaylandTextInputv1::isInputPanelVisible() const
+{
+ return m_inputPanelVisible;
+}
+
+QRectF QWaylandTextInputv1::keyboardRect() const
+{
+ return m_keyboardRectangle;
+}
+
+QLocale QWaylandTextInputv1::locale() const
+{
+ return m_locale;
+}
+
+Qt::LayoutDirection QWaylandTextInputv1::inputDirection() const
+{
+ return m_inputDirection;
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_enter(::wl_surface *surface)
+{
+ m_surface = surface;
+
+ updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_reset);
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_leave()
+{
+ m_surface = nullptr;
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_modifiers_map(wl_array *map)
+{
+ const QList<QByteArray> modifiersMap = QByteArray::fromRawData(static_cast<const char*>(map->data), map->size).split('\0');
+
+ m_modifiersMap.clear();
+
+ for (const QByteArray &modifier : modifiersMap) {
+ if (modifier == "Shift")
+ m_modifiersMap.append(Qt::ShiftModifier);
+ else if (modifier == "Control")
+ m_modifiersMap.append(Qt::ControlModifier);
+ else if (modifier == "Alt")
+ m_modifiersMap.append(Qt::AltModifier);
+ else if (modifier == "Mod1")
+ m_modifiersMap.append(Qt::AltModifier);
+ else if (modifier == "Mod4")
+ m_modifiersMap.append(Qt::MetaModifier);
+ else
+ m_modifiersMap.append(Qt::NoModifier);
+ }
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_input_panel_state(uint32_t visible)
+{
+ const bool inputPanelVisible = (visible == 1);
+ if (m_inputPanelVisible != inputPanelVisible) {
+ m_inputPanelVisible = inputPanelVisible;
+ QGuiApplicationPrivate::platformIntegration()->inputContext()->emitInputPanelVisibleChanged();
+ }
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_preedit_string(uint32_t serial, const QString &text, const QString &commit)
+{
+ m_serial = serial;
+
+ if (m_resetCallback) {
+ qCDebug(qLcQpaInputMethods()) << "discard preedit_string: reset not confirmed";
+ m_builder.reset();
+ return;
+ }
+
+ if (!QGuiApplication::focusObject())
+ return;
+
+ QInputMethodEvent *event = m_builder.buildPreedit(text);
+
+ m_builder.reset();
+ m_preeditCommit = commit;
+
+ QCoreApplication::sendEvent(QGuiApplication::focusObject(), event);
+ delete event;
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_preedit_styling(uint32_t index, uint32_t length, uint32_t style)
+{
+ m_builder.addPreeditStyling(index, length, style);
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_preedit_cursor(int32_t index)
+{
+ m_builder.setPreeditCursor(index);
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_commit_string(uint32_t serial, const QString &text)
+{
+ m_serial = serial;
+
+ if (m_resetCallback) {
+ qCDebug(qLcQpaInputMethods()) << "discard commit_string: reset not confirmed";
+ m_builder.reset();
+ return;
+ }
+
+ if (!QGuiApplication::focusObject())
+ return;
+
+ // When committing the text, the preeditString needs to be reset, to prevent it to be
+ // send again in the commit() function
+ m_preeditCommit.clear();
+
+ QInputMethodEvent *event = m_builder.buildCommit(text);
+
+ m_builder.reset();
+
+ QCoreApplication::sendEvent(QGuiApplication::focusObject(), event);
+ delete event;
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_cursor_position(int32_t index, int32_t anchor)
+{
+ m_builder.setCursorPosition(index, anchor);
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_delete_surrounding_text(int32_t before_length, uint32_t after_length)
+{
+ //before_length is negative, but the builder expects it to be positive
+ m_builder.setDeleteSurroundingText(-before_length, after_length);
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_keysym(uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers)
+{
+ m_serial = serial;
+
+#if QT_CONFIG(xkbcommon)
+ if (m_resetCallback) {
+ qCDebug(qLcQpaInputMethods()) << "discard keysym: reset not confirmed";
+ return;
+ }
+
+ if (!QGuiApplication::focusWindow())
+ return;
+
+ Qt::KeyboardModifiers qtModifiers = modifiersToQtModifiers(modifiers);
+
+ QEvent::Type type = state == WL_KEYBOARD_KEY_STATE_PRESSED ? QEvent::KeyPress : QEvent::KeyRelease;
+ QString text = QXkbCommon::lookupStringNoKeysymTransformations(sym);
+ int qtkey = QXkbCommon::keysymToQtKey(sym, qtModifiers);
+
+ QWindowSystemInterface::handleKeyEvent(QGuiApplication::focusWindow(),
+ time, type, qtkey, qtModifiers, text);
+#else
+ Q_UNUSED(time);
+ Q_UNUSED(sym);
+ Q_UNUSED(state);
+ Q_UNUSED(modifiers);
+#endif
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_language(uint32_t serial, const QString &language)
+{
+ m_serial = serial;
+
+ if (m_resetCallback) {
+ qCDebug(qLcQpaInputMethods()) << "discard language: reset not confirmed";
+ return;
+ }
+
+ const QLocale locale(language);
+ if (m_locale != locale) {
+ m_locale = locale;
+ QGuiApplicationPrivate::platformIntegration()->inputContext()->emitLocaleChanged();
+ }
+}
+
+void QWaylandTextInputv1::zwp_text_input_v1_text_direction(uint32_t serial, uint32_t direction)
+{
+ m_serial = serial;
+
+ if (m_resetCallback) {
+ qCDebug(qLcQpaInputMethods()) << "discard text_direction: reset not confirmed";
+ return;
+ }
+
+ const Qt::LayoutDirection inputDirection = (direction == text_direction_auto) ? Qt::LayoutDirectionAuto :
+ (direction == text_direction_ltr) ? Qt::LeftToRight :
+ (direction == text_direction_rtl) ? Qt::RightToLeft : Qt::LayoutDirectionAuto;
+ if (m_inputDirection != inputDirection) {
+ m_inputDirection = inputDirection;
+ QGuiApplicationPrivate::platformIntegration()->inputContext()->emitInputDirectionChanged(m_inputDirection);
+ }
+}
+
+Qt::KeyboardModifiers QWaylandTextInputv1::modifiersToQtModifiers(uint32_t modifiers)
+{
+ Qt::KeyboardModifiers ret = Qt::NoModifier;
+ for (int i = 0; i < m_modifiersMap.size(); ++i) {
+ if (modifiers & (1 << i)) {
+ ret |= m_modifiersMap[i];
+ }
+ }
+ return ret;
+}
+
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/client/qwaylandtextinputv1_p.h b/src/client/qwaylandtextinputv1_p.h
new file mode 100644
index 000000000..238db0b8a
--- /dev/null
+++ b/src/client/qwaylandtextinputv1_p.h
@@ -0,0 +1,149 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtWaylandClient module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#ifndef QWAYLANDTEXTINPUTV1_H
+#define QWAYLANDTEXTINPUTV1_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include "qwaylandtextinputinterface_p.h"
+#include <QtWaylandClient/private/qwayland-text-input-unstable-v1.h>
+#include <qwaylandinputmethodeventbuilder_p.h>
+
+struct wl_callback;
+struct wl_callback_listener;
+
+QT_BEGIN_NAMESPACE
+
+namespace QtWaylandClient {
+
+class QWaylandDisplay;
+
+class QWaylandTextInputv1 : public QtWayland::zwp_text_input_v1, public QWaylandTextInputInterface
+{
+public:
+ QWaylandTextInputv1(QWaylandDisplay *display, struct ::zwp_text_input_v1 *text_input);
+ ~QWaylandTextInputv1() override;
+
+ void setSeat(struct ::wl_seat *seat) { m_seat = seat; }
+
+ void reset() override;
+ void commit() override;
+ void updateState(Qt::InputMethodQueries queries, uint32_t flags) override;
+
+ void setCursorInsidePreedit(int cursor) override;
+
+ bool isInputPanelVisible() const override;
+ QRectF keyboardRect() const override;
+
+ QLocale locale() const override;
+ Qt::LayoutDirection inputDirection() const override;
+
+ void showInputPanel() override
+ {
+ show_input_panel();
+ }
+ void hideInputPanel() override
+ {
+ hide_input_panel();
+ }
+ void enableSurface(::wl_surface *surface) override
+ {
+ activate(m_seat, surface);
+ }
+ void disableSurface(::wl_surface *surface) override
+ {
+ Q_UNUSED(surface);
+ deactivate(m_seat);
+ }
+
+protected:
+ void zwp_text_input_v1_enter(struct ::wl_surface *surface) override;
+ void zwp_text_input_v1_leave() override;
+ void zwp_text_input_v1_modifiers_map(wl_array *map) override;
+ void zwp_text_input_v1_input_panel_state(uint32_t state) override;
+ void zwp_text_input_v1_preedit_string(uint32_t serial, const QString &text, const QString &commit) override;
+ void zwp_text_input_v1_preedit_styling(uint32_t index, uint32_t length, uint32_t style) override;
+ void zwp_text_input_v1_preedit_cursor(int32_t index) override;
+ void zwp_text_input_v1_commit_string(uint32_t serial, const QString &text) override;
+ void zwp_text_input_v1_cursor_position(int32_t index, int32_t anchor) override;
+ void zwp_text_input_v1_delete_surrounding_text(int32_t before_length, uint32_t after_length) override;
+ void zwp_text_input_v1_keysym(uint32_t serial, uint32_t time, uint32_t sym, uint32_t state, uint32_t modifiers) override;
+ void zwp_text_input_v1_language(uint32_t serial, const QString &language) override;
+ void zwp_text_input_v1_text_direction(uint32_t serial, uint32_t direction) override;
+
+private:
+ Qt::KeyboardModifiers modifiersToQtModifiers(uint32_t modifiers);
+
+ QWaylandDisplay *m_display = nullptr;
+ QWaylandInputMethodEventBuilder m_builder;
+
+ QList<Qt::KeyboardModifier> m_modifiersMap;
+
+ uint32_t m_serial = 0;
+ struct ::wl_surface *m_surface = nullptr;
+ struct ::wl_seat *m_seat = nullptr;
+
+ QString m_preeditCommit;
+
+ bool m_inputPanelVisible = false;
+ QRectF m_keyboardRectangle;
+ QLocale m_locale;
+ Qt::LayoutDirection m_inputDirection = Qt::LayoutDirectionAuto;
+
+ struct ::wl_callback *m_resetCallback = nullptr;
+ static const wl_callback_listener callbackListener;
+ static void resetCallback(void *data, struct wl_callback *wl_callback, uint32_t time);
+};
+
+}
+
+QT_END_NAMESPACE
+#endif // QWAYLANDTEXTINPUTV1_H
+