Skip to content

Commit

Permalink
wayland: text input protocol uses UTF-8 encoding (#415)
Browse files Browse the repository at this point in the history
* wayland: text input protocol uses UTF-8 encoding

The Wayland text input protocol sends text in
UTF-8 encoding, but the Flutter TextInputModel
expects UTF-16.

This adds the missing conversion from UTF-8 to
UTF-16.

Signed-off-by: Sebastian Urban <surban@surban.net>

* Add Sebastian Urban to AUTHORS

---------

Signed-off-by: Sebastian Urban <surban@surban.net>
  • Loading branch information
surban authored May 8, 2024
1 parent a73994f commit f296db8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Makoto Sato (makoto.sato@atmark-techno.com)
Yunhao Tian (t123yh@outlook.com)
Luke Howard <lukeh@padl.com>
Stanislav Shmarov <github@snarpix.com>
Sebastian Urban <surban@surban.net>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <codecvt>
#include <locale>
#include <unordered_map>

#include "flutter/shell/platform/linux_embedded/logger.h"
Expand Down Expand Up @@ -748,7 +750,10 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener =

auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
if (self->binding_handler_delegate_ && strlen(text)) {
self->binding_handler_delegate_->OnVirtualKey(text[0]);
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
utf8_converter;
std::u16string utf16_text = utf8_converter.from_bytes(text);
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
}
if (self->zwp_text_input_v1_) {
zwp_text_input_v1_reset(self->zwp_text_input_v1_);
Expand Down Expand Up @@ -779,7 +784,10 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener =
// commit_string is notified only when the space key is pressed.
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
if (self->binding_handler_delegate_ && strlen(text)) {
self->binding_handler_delegate_->OnVirtualKey(text[0]);
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
utf8_converter;
std::u16string utf16_text = utf8_converter.from_bytes(text);
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
}
// If there is no input data, the backspace key cannot be used,
// so set dummy data.
Expand Down Expand Up @@ -895,7 +903,10 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener =

auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
if (self->binding_handler_delegate_ && strlen(text)) {
self->binding_handler_delegate_->OnVirtualKey(text[0]);
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
utf8_converter;
std::u16string utf16_text = utf8_converter.from_bytes(text);
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
}
},
.delete_surrounding_text = [](void* data,
Expand Down

0 comments on commit f296db8

Please sign in to comment.