From 03f5339302794b572a2a1adaccd6e89160308200 Mon Sep 17 00:00:00 2001 From: Bhushan Shah Date: Mon, 31 Aug 2020 20:23:44 +0530 Subject: [PATCH] input-method: make sendContentType take the TextInputInterface enums We need to convert the content hint and content purpose to the protocol values before passing it to the input method since text-input v0, v2 and v3 have a different values for some of enums. We need to do manual translation. --- src/wayland/CMakeLists.txt | 6 ++ src/wayland/inputmethod_v1_interface.cpp | 85 +++++++++++++++++++++++- src/wayland/inputmethod_v1_interface.h | 4 +- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/src/wayland/CMakeLists.txt b/src/wayland/CMakeLists.txt index 6f9d4a9fdd..abcad325d1 100644 --- a/src/wayland/CMakeLists.txt +++ b/src/wayland/CMakeLists.txt @@ -162,6 +162,12 @@ ecm_add_wayland_server_protocol(SERVER_LIB_SRCS BASENAME text ) + +ecm_add_qtwayland_server_protocol(SERVER_LIB_SRCS + PROTOCOL ${WaylandProtocols_DATADIR}/unstable/text-input/text-input-unstable-v1.xml + BASENAME text-input-unstable-v1 +) + ecm_add_wayland_server_protocol(SERVER_LIB_SRCS PROTOCOL ${PLASMA_WAYLAND_PROTOCOLS_DIR}/text-input-unstable-v2.xml BASENAME text-input-unstable-v2 diff --git a/src/wayland/inputmethod_v1_interface.cpp b/src/wayland/inputmethod_v1_interface.cpp index 63575d3caa..1154c46b57 100644 --- a/src/wayland/inputmethod_v1_interface.cpp +++ b/src/wayland/inputmethod_v1_interface.cpp @@ -12,8 +12,10 @@ #include "surfacerole_p.h" #include + #include "qwayland-server-input-method-unstable-v1.h" #include "wayland-text-server-protocol.h" +#include "qwayland-server-text-input-unstable-v1.h" namespace KWaylandServer { @@ -154,10 +156,89 @@ void InputMethodContextV1Interface::sendCommitState(uint32_t serial) } } -void InputMethodContextV1Interface::sendContentType(uint32_t hint, uint32_t purpose) +void InputMethodContextV1Interface::sendContentType(TextInputInterface::ContentHints hint, TextInputInterface::ContentPurpose purpose) { + quint32 contentHint = QtWaylandServer::zwp_text_input_v1::content_hint_none; + quint32 contentPurpose; + + if (hint.testFlag(TextInputInterface::ContentHint::AutoCapitalization)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_capitalization; + } + if (hint.testFlag(TextInputInterface::ContentHint::AutoCorrection)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_correction; + } + if (hint.testFlag(TextInputInterface::ContentHint::AutoCapitalization)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_auto_capitalization; + } + if (hint.testFlag(TextInputInterface::ContentHint::LowerCase)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_lowercase; + } + if (hint.testFlag(TextInputInterface::ContentHint::UpperCase)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_uppercase; + } + if (hint.testFlag(TextInputInterface::ContentHint::TitleCase)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_titlecase; + } + if (hint.testFlag(TextInputInterface::ContentHint::HiddenText)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_hidden_text; + } + if (hint.testFlag(TextInputInterface::ContentHint::SensitiveData)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_lowercase; + } + if (hint.testFlag(TextInputInterface::ContentHint::Latin)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_latin; + } + if (hint.testFlag(TextInputInterface::ContentHint::MultiLine)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_multiline; + } + if (hint.testFlag(TextInputInterface::ContentHint::None)) { + contentHint |= QtWaylandServer::zwp_text_input_v1::content_hint_none; + } + + switch (purpose) { + case TextInputInterface::ContentPurpose::Alpha: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_alpha; + break; + case TextInputInterface::ContentPurpose::Digits: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_digits; + break; + case TextInputInterface::ContentPurpose::Number: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_number; + break; + case TextInputInterface::ContentPurpose::Phone: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_phone; + break; + case TextInputInterface::ContentPurpose::Url: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_url; + break; + case TextInputInterface::ContentPurpose::Email: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_email; + break; + case TextInputInterface::ContentPurpose::Name: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_name; + break; + case TextInputInterface::ContentPurpose::Password: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_password; + break; + case TextInputInterface::ContentPurpose::Date: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_date; + break; + case TextInputInterface::ContentPurpose::Time: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_time; + break; + case TextInputInterface::ContentPurpose::DateTime: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_datetime; + break; + case TextInputInterface::ContentPurpose::Terminal: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_terminal; + break; + case TextInputInterface::ContentPurpose::Normal: + default: + contentPurpose = QtWaylandServer::zwp_text_input_v1::content_purpose_alpha; + } + for (auto r : d->resourceMap()) { - d->send_content_type(r->handle, hint, purpose); + d->send_content_type(r->handle, contentHint, contentPurpose); } } diff --git a/src/wayland/inputmethod_v1_interface.h b/src/wayland/inputmethod_v1_interface.h index ffd9469924..9f4ff709fd 100644 --- a/src/wayland/inputmethod_v1_interface.h +++ b/src/wayland/inputmethod_v1_interface.h @@ -11,6 +11,8 @@ #include #include +#include "textinput_interface.h" + namespace KWaylandServer { class OutputInterface; @@ -66,7 +68,7 @@ public: void sendSurroundingText(const QString &text, quint32 cursor, quint32 anchor); void sendReset(); - void sendContentType(quint32 hint, quint32 purpose); + void sendContentType(TextInputInterface::ContentHints hint, TextInputInterface::ContentPurpose purpose); void sendInvokeAction(quint32 button, quint32 index); void sendCommitState(quint32 serial); void sendPreferredLanguage(const QString &language);