[server] Text input content hint and purpose per protocol version

Summary:
Convert content hint and purpose according to used text-input protocol version.

This way we can use different specifiers, which enables us in the future to use
the default hint of v0 and the pin purpose of v3.

Also code is cleaner when using the correctly versioned specifier names according
to the protocol version.

Test Plan: Compiles, autotest passes.

Reviewers: #kwin, #frameworks, zzag

Reviewed By: #kwin, zzag

Subscribers: zzag, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D16708
This commit is contained in:
Roman Gilg 2018-11-07 14:34:02 +01:00
parent cd53ae5c28
commit 5b4a9eeef3
4 changed files with 167 additions and 85 deletions

View file

@ -59,90 +59,15 @@ void TextInputInterface::Private::setSurroundingTextCallback(wl_client *client,
emit p->q_func()->surroundingTextChanged();
}
namespace {
static TextInputInterface::ContentHints waylandHintsToKWayland(wl_text_input_content_hint wlHints)
{
TextInputInterface::ContentHints hints = TextInputInterface::ContentHint::None;
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION) {
hints |= TextInputInterface::ContentHint::AutoCompletion;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CORRECTION) {
hints |= TextInputInterface::ContentHint::AutoCorrection;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION) {
hints |= TextInputInterface::ContentHint::AutoCapitalization;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_LOWERCASE) {
hints |= TextInputInterface::ContentHint::LowerCase;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE) {
hints |= TextInputInterface::ContentHint::UpperCase;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_TITLECASE) {
hints |= TextInputInterface::ContentHint::TitleCase;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_HIDDEN_TEXT) {
hints |= TextInputInterface::ContentHint::HiddenText;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA) {
hints |= TextInputInterface::ContentHint::SensitiveData;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_LATIN) {
hints |= TextInputInterface::ContentHint::Latin;
}
if (wlHints & WL_TEXT_INPUT_CONTENT_HINT_MULTILINE) {
hints |= TextInputInterface::ContentHint::MultiLine;
}
return hints;
}
static TextInputInterface::ContentPurpose waylandPurposeToKWayland(wl_text_input_content_purpose purpose)
{
switch (purpose) {
case WL_TEXT_INPUT_CONTENT_PURPOSE_ALPHA:
return TextInputInterface::ContentPurpose::Alpha;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
return TextInputInterface::ContentPurpose::Digits;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
return TextInputInterface::ContentPurpose::Number;
case WL_TEXT_INPUT_CONTENT_PURPOSE_PHONE:
return TextInputInterface::ContentPurpose::Phone;
case WL_TEXT_INPUT_CONTENT_PURPOSE_URL:
return TextInputInterface::ContentPurpose::Url;
case WL_TEXT_INPUT_CONTENT_PURPOSE_EMAIL:
return TextInputInterface::ContentPurpose::Email;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NAME:
return TextInputInterface::ContentPurpose::Name;
case WL_TEXT_INPUT_CONTENT_PURPOSE_PASSWORD:
return TextInputInterface::ContentPurpose::Password;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DATE:
return TextInputInterface::ContentPurpose::Date;
case WL_TEXT_INPUT_CONTENT_PURPOSE_TIME:
return TextInputInterface::ContentPurpose::Time;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DATETIME:
return TextInputInterface::ContentPurpose::DateTime;
case WL_TEXT_INPUT_CONTENT_PURPOSE_TERMINAL:
return TextInputInterface::ContentPurpose::Terminal;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NORMAL:
default:
return TextInputInterface::ContentPurpose::Normal;
}
}
}
void TextInputInterface::Private::setContentTypeCallback(wl_client *client, wl_resource *resource, uint32_t hint, uint32_t wlPurpose)
void TextInputInterface::Private::setContentTypeCallback(wl_client *client, wl_resource *resource, uint32_t hint, uint32_t purpose)
{
auto p = cast<Private>(resource);
Q_ASSERT(*p->client == client);
// TODO: pass through Private impl
const auto hints = waylandHintsToKWayland(wl_text_input_content_hint(hint));
const auto purpose = waylandPurposeToKWayland(wl_text_input_content_purpose(wlPurpose));
if (hints != p->contentHints || purpose != p->contentPurpose) {
p->contentHints = hints;
p->contentPurpose = purpose;
const auto contentHints = p->convertContentHint(hint);
const auto contentPurpose = p->convertContentPurpose(purpose);
if (contentHints != p->contentHints || contentPurpose != p->contentPurpose) {
p->contentHints = contentHints;
p->contentPurpose = contentPurpose;
emit p->q_func()->contentTypeChanged();
}
}

View file

@ -66,6 +66,9 @@ public:
virtual void sendInputPanelState() = 0;
virtual void sendLanguage() = 0;
virtual TextInputInterface::ContentHints convertContentHint(uint32_t hint) const = 0;
virtual TextInputInterface::ContentPurpose convertContentPurpose(uint32_t purpose) const = 0;
QByteArray preferredLanguage;
QRect cursorRectangle;
TextInputInterface::ContentHints contentHints = TextInputInterface::ContentHint::None;

View file

@ -68,6 +68,10 @@ private:
static void commitStateCallback(wl_client *client, wl_resource *resource, uint32_t serial);
static void invokeActionCallback(wl_client *client, wl_resource *resource, uint32_t button, uint32_t index);
// helpers
TextInputInterface::ContentHints convertContentHint(uint32_t hint) const override;
TextInputInterface::ContentPurpose convertContentPurpose(uint32_t purpose) const override;
quint32 latestState = 0;
};
@ -268,6 +272,79 @@ void TextInputUnstableV0Interface::Private::invokeActionCallback(wl_client *clie
Q_ASSERT(*p->client == client);
}
TextInputInterface::ContentHints TextInputUnstableV0Interface::Private::convertContentHint(uint32_t hint) const
{
const auto hints = wl_text_input_content_hint(hint);
TextInputInterface::ContentHints ret = TextInputInterface::ContentHint::None;
if (hints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_COMPLETION) {
ret |= TextInputInterface::ContentHint::AutoCompletion;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CORRECTION) {
ret |= TextInputInterface::ContentHint::AutoCorrection;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_AUTO_CAPITALIZATION) {
ret |= TextInputInterface::ContentHint::AutoCapitalization;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_LOWERCASE) {
ret |= TextInputInterface::ContentHint::LowerCase;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_UPPERCASE) {
ret |= TextInputInterface::ContentHint::UpperCase;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_TITLECASE) {
ret |= TextInputInterface::ContentHint::TitleCase;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_HIDDEN_TEXT) {
ret |= TextInputInterface::ContentHint::HiddenText;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_SENSITIVE_DATA) {
ret |= TextInputInterface::ContentHint::SensitiveData;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_LATIN) {
ret |= TextInputInterface::ContentHint::Latin;
}
if (hints & WL_TEXT_INPUT_CONTENT_HINT_MULTILINE) {
ret |= TextInputInterface::ContentHint::MultiLine;
}
return ret;
}
TextInputInterface::ContentPurpose TextInputUnstableV0Interface::Private::convertContentPurpose(uint32_t purpose) const
{
const auto wlPurpose = wl_text_input_content_purpose(purpose);
switch (wlPurpose) {
case WL_TEXT_INPUT_CONTENT_PURPOSE_ALPHA:
return TextInputInterface::ContentPurpose::Alpha;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DIGITS:
return TextInputInterface::ContentPurpose::Digits;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NUMBER:
return TextInputInterface::ContentPurpose::Number;
case WL_TEXT_INPUT_CONTENT_PURPOSE_PHONE:
return TextInputInterface::ContentPurpose::Phone;
case WL_TEXT_INPUT_CONTENT_PURPOSE_URL:
return TextInputInterface::ContentPurpose::Url;
case WL_TEXT_INPUT_CONTENT_PURPOSE_EMAIL:
return TextInputInterface::ContentPurpose::Email;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NAME:
return TextInputInterface::ContentPurpose::Name;
case WL_TEXT_INPUT_CONTENT_PURPOSE_PASSWORD:
return TextInputInterface::ContentPurpose::Password;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DATE:
return TextInputInterface::ContentPurpose::Date;
case WL_TEXT_INPUT_CONTENT_PURPOSE_TIME:
return TextInputInterface::ContentPurpose::Time;
case WL_TEXT_INPUT_CONTENT_PURPOSE_DATETIME:
return TextInputInterface::ContentPurpose::DateTime;
case WL_TEXT_INPUT_CONTENT_PURPOSE_TERMINAL:
return TextInputInterface::ContentPurpose::Terminal;
case WL_TEXT_INPUT_CONTENT_PURPOSE_NORMAL:
default:
return TextInputInterface::ContentPurpose::Normal;
}
}
TextInputUnstableV0Interface::TextInputUnstableV0Interface(TextInputManagerUnstableV0Interface *parent, wl_resource *parentResource)
: TextInputInterface(new Private(this, parent, parentResource))
{

View file

@ -53,15 +53,19 @@ public:
void sendLanguage() override;
private:
static void enableCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
static void disableCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
static void updateStateCallback(wl_client *client, wl_resource *resource, uint32_t serial, uint32_t reason);
static const struct zwp_text_input_v2_interface s_interface;
TextInputUnstableV2Interface *q_func() {
return reinterpret_cast<TextInputUnstableV2Interface *>(q);
}
static void enableCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
static void disableCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
static void updateStateCallback(wl_client *client, wl_resource *resource, uint32_t serial, uint32_t reason);
// helpers
TextInputInterface::ContentHints convertContentHint(uint32_t hint) const override;
TextInputInterface::ContentPurpose convertContentPurpose(uint32_t purpose) const override;
void enable(SurfaceInterface *s);
void disable();
};
@ -243,6 +247,79 @@ void TextInputUnstableV2Interface::Private::updateStateCallback(wl_client *clien
}
}
TextInputInterface::ContentHints TextInputUnstableV2Interface::Private::convertContentHint(uint32_t hint) const
{
const auto hints = zwp_text_input_v2_content_hint(hint);
TextInputInterface::ContentHints ret = TextInputInterface::ContentHint::None;
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_COMPLETION) {
ret |= TextInputInterface::ContentHint::AutoCompletion;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_CORRECTION) {
ret |= TextInputInterface::ContentHint::AutoCorrection;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_AUTO_CAPITALIZATION) {
ret |= TextInputInterface::ContentHint::AutoCapitalization;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_LOWERCASE) {
ret |= TextInputInterface::ContentHint::LowerCase;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_UPPERCASE) {
ret |= TextInputInterface::ContentHint::UpperCase;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_TITLECASE) {
ret |= TextInputInterface::ContentHint::TitleCase;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_HIDDEN_TEXT) {
ret |= TextInputInterface::ContentHint::HiddenText;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_SENSITIVE_DATA) {
ret |= TextInputInterface::ContentHint::SensitiveData;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_LATIN) {
ret |= TextInputInterface::ContentHint::Latin;
}
if (hints & ZWP_TEXT_INPUT_V2_CONTENT_HINT_MULTILINE) {
ret |= TextInputInterface::ContentHint::MultiLine;
}
return ret;
}
TextInputInterface::ContentPurpose TextInputUnstableV2Interface::Private::convertContentPurpose(uint32_t purpose) const
{
const auto wlPurpose = zwp_text_input_v2_content_purpose(purpose);
switch (wlPurpose) {
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_ALPHA:
return TextInputInterface::ContentPurpose::Alpha;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DIGITS:
return TextInputInterface::ContentPurpose::Digits;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_NUMBER:
return TextInputInterface::ContentPurpose::Number;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_PHONE:
return TextInputInterface::ContentPurpose::Phone;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_URL:
return TextInputInterface::ContentPurpose::Url;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_EMAIL:
return TextInputInterface::ContentPurpose::Email;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_NAME:
return TextInputInterface::ContentPurpose::Name;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_PASSWORD:
return TextInputInterface::ContentPurpose::Password;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DATE:
return TextInputInterface::ContentPurpose::Date;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_TIME:
return TextInputInterface::ContentPurpose::Time;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_DATETIME:
return TextInputInterface::ContentPurpose::DateTime;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_TERMINAL:
return TextInputInterface::ContentPurpose::Terminal;
case ZWP_TEXT_INPUT_V2_CONTENT_PURPOSE_NORMAL:
default:
return TextInputInterface::ContentPurpose::Normal;
}
}
TextInputUnstableV2Interface::TextInputUnstableV2Interface(TextInputManagerUnstableV2Interface *parent, wl_resource *parentResource)
: TextInputInterface(new Private(this, parent, parentResource))
{