summaryrefslogtreecommitdiffstats
path: root/src/compositor
diff options
context:
space:
mode:
authorInho Lee <inho.lee@qt.io>2023-06-30 10:52:08 +0200
committerInho Lee <inho.lee@qt.io>2023-07-06 09:07:27 +0200
commitc0d108b5042752359c279b41cc6f055f4f18ec60 (patch)
tree1186a8de8f5ec51dd205c3701340bdbbe12c6753 /src/compositor
parent820c146f3019429dcaff933afc08c38e8922799a (diff)
WaylandSeat: Add a new api to send a ucs4 unicode
Current APIs to send qtkey event have a restriction to use key codes out of Qt::Key. sendUnicodeKeyEvent will support to send a ucs4 compatible unicode value. Task-number: QTBUG-113387 Task-number: QTBUG-74479 Change-Id: Iee9f0c086e37593af20886b9a2c23edf9743ef0e Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'src/compositor')
-rw-r--r--src/compositor/compositor_api/qwaylandseat.cpp69
-rw-r--r--src/compositor/compositor_api/qwaylandseat.h1
2 files changed, 70 insertions, 0 deletions
diff --git a/src/compositor/compositor_api/qwaylandseat.cpp b/src/compositor/compositor_api/qwaylandseat.cpp
index c99e7ec4f..b580783f0 100644
--- a/src/compositor/compositor_api/qwaylandseat.cpp
+++ b/src/compositor/compositor_api/qwaylandseat.cpp
@@ -542,6 +542,75 @@ void QWaylandSeat::sendKeyEvent(int qtKey, bool pressed)
}
/*!
+ * \qmlmethod void QtWayland.Compositor::WaylandSeat::sendUnicodeKeyEvent(uint unicode, bool pressed)
+ * \since 6.7
+ *
+ * Sends a key press (if \a pressed is \c true) or release (if \a pressed is \c false)
+ * event of a UCS4 unicode through a text-input protocol.
+ *
+ * \note This function will not work properly if the client does not support the
+ * text-input protocol that the compositor supports.
+ */
+
+/*!
+ * Sends a key press (if \a pressed is \c true) or release (if \a pressed is \c false)
+ * event of a UCS4 unicode through a text-input protocol.
+ *
+ * \note This function will not work properly if the client does not support the
+ * text-input protocol that the compositor supports.
+ *
+ * \sa {sendFullKeyEvent} {sendKeyEvent}
+ *
+ * \since 6.7
+ */
+void QWaylandSeat::sendUnicodeKeyEvent(uint unicode, bool pressed)
+{
+ if (!keyboardFocus()) {
+ qWarning("Can't send a unicode key event, no keyboard focus, fix the compositor");
+ return;
+ }
+
+#if QT_CONFIG(im)
+ auto eventType = pressed ? QEvent::KeyPress : QEvent::KeyRelease;
+ // make a keysym value for the UCS4
+ const uint keysym = 0x01000000 | unicode;
+ auto text = QXkbCommon::lookupStringNoKeysymTransformations(keysym);
+ QKeyEvent event(eventType, Qt::Key_unknown, Qt::KeyboardModifiers{}, text);
+ if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) {
+ QWaylandTextInput *textInput = QWaylandTextInput::findIn(this);
+ if (textInput) {
+ textInput->sendKeyEvent(&event);
+ return;
+ }
+ }
+
+ if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) {
+ QWaylandQtTextInputMethod *textInputMethod = QWaylandQtTextInputMethod::findIn(this);
+ if (textInputMethod) {
+ textInputMethod->sendKeyEvent(&event);
+ return;
+ }
+ }
+
+#if QT_WAYLAND_TEXT_INPUT_V4_WIP
+ if (keyboardFocus()->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV4)) {
+ QWaylandTextInputV4 *textInputV4 = QWaylandTextInputV4::findIn(this);
+ if (textInputV4 && !text.isEmpty()) {
+ // it will just commit the text for text-input-unstable-v4-wip when keyPress
+ if (eventType == QEvent::KeyPress)
+ textInputV4->sendKeyEvent(&event);
+ return;
+ }
+ }
+#endif // QT_WAYLAND_TEXT_INPUT_V4_WIP
+#else
+ Q_UNUSED(keysym);
+ Q_UNUSED(pressed);
+ qWarning() << "Can't send a unicode key event: Unable to find a text-input protocol.";
+#endif
+}
+
+/*!
* Returns the keyboard for this input device.
*/
QWaylandKeyboard *QWaylandSeat::keyboard() const
diff --git a/src/compositor/compositor_api/qwaylandseat.h b/src/compositor/compositor_api/qwaylandseat.h
index d789dff30..6522a8d5b 100644
--- a/src/compositor/compositor_api/qwaylandseat.h
+++ b/src/compositor/compositor_api/qwaylandseat.h
@@ -70,6 +70,7 @@ public:
void sendFullKeyEvent(QKeyEvent *event);
Q_INVOKABLE void sendKeyEvent(int qtKey, bool pressed);
+ Q_REVISION(6, 7) Q_INVOKABLE void sendUnicodeKeyEvent(uint unicode, bool pressed);
uint sendTouchPointEvent(QWaylandSurface *surface, int id, const QPointF &point, Qt::TouchPointState state);
Q_INVOKABLE uint sendTouchPointPressed(QWaylandSurface *surface, int id, const QPointF &position);