Skip to content

Commit f296db8

Browse files
authored
wayland: text input protocol uses UTF-8 encoding (sony#415)
* 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 <[email protected]> * Add Sebastian Urban to AUTHORS --------- Signed-off-by: Sebastian Urban <[email protected]>
1 parent a73994f commit f296db8

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Makoto Sato ([email protected])
1313
Yunhao Tian ([email protected])
1414
Luke Howard <[email protected]>
1515
Stanislav Shmarov <[email protected]>
16+
Sebastian Urban <[email protected]>

src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <algorithm>
1414
#include <cassert>
1515
#include <cmath>
16+
#include <codecvt>
17+
#include <locale>
1618
#include <unordered_map>
1719

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

749751
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
750752
if (self->binding_handler_delegate_ && strlen(text)) {
751-
self->binding_handler_delegate_->OnVirtualKey(text[0]);
753+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
754+
utf8_converter;
755+
std::u16string utf16_text = utf8_converter.from_bytes(text);
756+
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
752757
}
753758
if (self->zwp_text_input_v1_) {
754759
zwp_text_input_v1_reset(self->zwp_text_input_v1_);
@@ -779,7 +784,10 @@ const zwp_text_input_v1_listener ELinuxWindowWayland::kZwpTextInputV1Listener =
779784
// commit_string is notified only when the space key is pressed.
780785
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
781786
if (self->binding_handler_delegate_ && strlen(text)) {
782-
self->binding_handler_delegate_->OnVirtualKey(text[0]);
787+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
788+
utf8_converter;
789+
std::u16string utf16_text = utf8_converter.from_bytes(text);
790+
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
783791
}
784792
// If there is no input data, the backspace key cannot be used,
785793
// so set dummy data.
@@ -895,7 +903,10 @@ const zwp_text_input_v3_listener ELinuxWindowWayland::kZwpTextInputV3Listener =
895903

896904
auto self = reinterpret_cast<ELinuxWindowWayland*>(data);
897905
if (self->binding_handler_delegate_ && strlen(text)) {
898-
self->binding_handler_delegate_->OnVirtualKey(text[0]);
906+
std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>
907+
utf8_converter;
908+
std::u16string utf16_text = utf8_converter.from_bytes(text);
909+
self->binding_handler_delegate_->OnVirtualKey(utf16_text[0]);
899910
}
900911
},
901912
.delete_surrounding_text = [](void* data,

0 commit comments

Comments
 (0)