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.
This commit is contained in:
Bhushan Shah 2020-08-31 20:23:44 +05:30 committed by Bhushan Shah
parent 63d2ab4ee6
commit 03f5339302
3 changed files with 92 additions and 3 deletions

View file

@ -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

View file

@ -12,8 +12,10 @@
#include "surfacerole_p.h"
#include <QHash>
#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);
}
}

View file

@ -11,6 +11,8 @@
#include <QVector>
#include <QObject>
#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);