diff --git a/AUTHORS b/AUTHORS index 6a816263..d1ec5bb4 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ Sebastian Urban Athaariq Ardhiansyah Anton Sakhon Bari Rao +Jón Bjarni Bjarnason diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h index d552b499..82e47da7 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h @@ -7,6 +7,7 @@ #include #include +#include namespace flutter { diff --git a/src/flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h b/src/flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h index c84d25f2..c007b1ec 100644 --- a/src/flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h +++ b/src/flutter/shell/platform/common/client_wrapper/include/flutter/message_codec.h @@ -8,6 +8,7 @@ #include #include #include +#include namespace flutter { diff --git a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc index 3cc932c9..8eee76ea 100644 --- a/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc +++ b/src/flutter/shell/platform/linux_embedded/plugins/text_input_plugin.cc @@ -117,9 +117,9 @@ void TextInputPlugin::HandleMethodCall( const std::string& method = method_call.method_name(); if (method.compare(kShowMethod) == 0) { - delegate_->UpdateVirtualKeyboardStatus(true); + delegate_->UpdateVirtualKeyboardStatus(true, input_type_); } else if (method.compare(kHideMethod) == 0) { - delegate_->UpdateVirtualKeyboardStatus(false); + delegate_->UpdateVirtualKeyboardStatus(false, input_type_); } else if (method.compare(kClearClientMethod) == 0) { active_model_ = nullptr; } else if (method.compare(kSetClientMethod) == 0) { diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h index fa1fb9e9..3299b3ba 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_drm.h @@ -249,7 +249,8 @@ class ELinuxWindowDrm : public ELinuxWindow, public WindowBindingHandler { } // |FlutterWindowBindingHandler| - void UpdateVirtualKeyboardStatus(const bool show) override { + void UpdateVirtualKeyboardStatus(const bool show, + const std::string& input_type = "") override { // currently not supported. } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc index 6467bf94..c9fa0400 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.cc @@ -1068,6 +1068,7 @@ ELinuxWindowWayland::ELinuxWindowWayland( wl_data_offer_(nullptr), wl_data_source_(nullptr), serial_(0), + text_input_serial_(0), zwp_text_input_manager_v1_(nullptr), zwp_text_input_manager_v3_(nullptr), zwp_text_input_v1_(nullptr), @@ -1505,12 +1506,15 @@ void ELinuxWindowWayland::DestroyRenderSurface() { } } -void ELinuxWindowWayland::UpdateVirtualKeyboardStatus(const bool show) { +void ELinuxWindowWayland::UpdateVirtualKeyboardStatus( + const bool show, + const std::string& input_type) { // Not supported virtual keyboard. if (!(zwp_text_input_v1_ || zwp_text_input_v3_) || seat_inputs_map_.empty()) { return; } + text_input_type_ = input_type; is_requested_show_virtual_keyboard_ = show; if (is_requested_show_virtual_keyboard_) { ShowVirtualKeyboard(); @@ -1869,16 +1873,52 @@ void ELinuxWindowWayland::ShowVirtualKeyboard() { zwp_text_input_v3_enable(zwp_text_input_v3_); zwp_text_input_v3_commit(zwp_text_input_v3_); - zwp_text_input_v3_set_content_type( - zwp_text_input_v3_, ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE, - ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_TERMINAL); + // Map Flutter input types to Wayland content purposes. + uint32_t hint = ZWP_TEXT_INPUT_V3_CONTENT_HINT_NONE; + uint32_t purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL; + + if (text_input_type_ == "TextInputType.number") { + purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NUMBER; + } else if (text_input_type_ == "TextInputType.phone") { + purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PHONE; + } else if (text_input_type_ == "TextInputType.emailAddress") { + purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_EMAIL; + } else if (text_input_type_ == "TextInputType.url") { + purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_URL; + } else if (text_input_type_ == "TextInputType.visiblePassword") { + purpose = ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_PASSWORD; + } else if (text_input_type_ == "TextInputType.multiline") { + hint |= ZWP_TEXT_INPUT_V3_CONTENT_HINT_MULTILINE; + } + + zwp_text_input_v3_set_content_type(zwp_text_input_v3_, hint, purpose); // Untested code path zwp_text_input_v3_commit(zwp_text_input_v3_); } else { if (native_window_) { - zwp_text_input_v1_show_input_panel(zwp_text_input_v1_); + // Map Flutter input types to Wayland v1 content purposes. + uint32_t hint = ZWP_TEXT_INPUT_V1_CONTENT_HINT_NONE; + uint32_t purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NORMAL; + + if (text_input_type_ == "TextInputType.number") { + purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_NUMBER; + } else if (text_input_type_ == "TextInputType.phone") { + purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PHONE; + } else if (text_input_type_ == "TextInputType.emailAddress") { + purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_EMAIL; + } else if (text_input_type_ == "TextInputType.url") { + purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_URL; + } else if (text_input_type_ == "TextInputType.visiblePassword") { + purpose = ZWP_TEXT_INPUT_V1_CONTENT_PURPOSE_PASSWORD; + } else if (text_input_type_ == "TextInputType.multiline") { + hint |= ZWP_TEXT_INPUT_V1_CONTENT_HINT_MULTILINE; + } + zwp_text_input_v1_activate(zwp_text_input_v1_, seat_inputs_map_.begin()->first, native_window_->Surface()); + zwp_text_input_v1_set_content_type(zwp_text_input_v1_, hint, purpose); + zwp_text_input_v1_commit_state(zwp_text_input_v1_, ++text_input_serial_); + zwp_text_input_v1_show_input_panel(zwp_text_input_v1_); } } } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h index 8ccb84ba..ec8dce63 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_wayland.h @@ -82,7 +82,8 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { void UpdateFlutterCursor(const std::string& cursor_name) override; // |FlutterWindowBindingHandler| - void UpdateVirtualKeyboardStatus(const bool show) override; + void UpdateVirtualKeyboardStatus(const bool show, + const std::string& input_type = "") override; // |FlutterWindowBindingHandler| std::string GetClipboardData() override; @@ -215,6 +216,11 @@ class ELinuxWindowWayland : public ELinuxWindow, public WindowBindingHandler { wl_data_source* wl_data_source_; uint32_t wl_data_device_manager_version_; uint32_t serial_; + + // The current text input type (e.g., "TextInputType.number"). + std::string text_input_type_; + + uint32_t text_input_serial_; }; } // namespace flutter diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc index 862c4d64..bfb32662 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.cc @@ -179,7 +179,9 @@ void ELinuxWindowX11::UpdateFlutterCursor(const std::string& cursor_name) { // TODO: implement here } -void ELinuxWindowX11::UpdateVirtualKeyboardStatus(const bool show) { +void ELinuxWindowX11::UpdateVirtualKeyboardStatus( + const bool show, + const std::string& input_type) { // currently not supported. } diff --git a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h index eb11171e..42ec5ad0 100644 --- a/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h +++ b/src/flutter/shell/platform/linux_embedded/window/elinux_window_x11.h @@ -55,7 +55,8 @@ class ELinuxWindowX11 : public ELinuxWindow, public WindowBindingHandler { void UpdateFlutterCursor(const std::string& cursor_name) override; // |FlutterWindowBindingHandler| - void UpdateVirtualKeyboardStatus(const bool show) override; + void UpdateVirtualKeyboardStatus(const bool show, + const std::string& input_type = "") override; // |FlutterWindowBindingHandler| std::string GetClipboardData() override; diff --git a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h index 34499df8..ae2c7d35 100644 --- a/src/flutter/shell/platform/linux_embedded/window_binding_handler.h +++ b/src/flutter/shell/platform/linux_embedded/window_binding_handler.h @@ -70,7 +70,10 @@ class WindowBindingHandler { // Sets the virtual keyboard status when the virtual keyboard needs to be // shown by Flutter events. - virtual void UpdateVirtualKeyboardStatus(const bool show) = 0; + // @param[in] show Whether to show or hide the virtual keyboard. + // @param[in] input_type The Flutter input type (e.g., "TextInputType.number"). + virtual void UpdateVirtualKeyboardStatus(const bool show, + const std::string& input_type = "") = 0; // Returns the clipboard data. virtual std::string GetClipboardData() = 0;