From 765ce541926832a367ca84a0f573e7c218a3a229 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Thu, 27 May 2021 11:06:44 +0200 Subject: [PATCH] Linux: add support for TextInputType.none TextInputType.none makes it possible to disable the virtual keyboard for certain TextFields, and lays the foundations for custom in-app virtual keyboards (flutter/flutter#76072). Ref: flutter/flutter#83567 --- .../platform/linux/fl_text_input_plugin.cc | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc b/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc index dbf318e5bb..71aa2165b2 100644 --- a/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc +++ b/engine/src/flutter/shell/platform/linux/fl_text_input_plugin.cc @@ -41,6 +41,7 @@ static constexpr char kTransform[] = "transform"; static constexpr char kTextAffinityDownstream[] = "TextAffinity.downstream"; static constexpr char kMultilineInputType[] = "TextInputType.multiline"; +static constexpr char kNoneInputType[] = "TextInputType.none"; static constexpr int64_t kClientIdUnset = -1; @@ -58,6 +59,9 @@ struct FlTextInputPluginPrivate { // Send newline when multi-line and enter is pressed. gboolean input_multiline; + // The input method is not shown when the input type is "none". + gboolean input_none; + // Input method. GtkIMContext* im_context; @@ -265,27 +269,44 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) { priv->input_action = g_strdup(fl_value_get_string(input_action_value)); } - // Clear the multiline flag, then set it only if the field is multiline. + // Reset the input type flags, then set them only if appropriate. priv->input_multiline = FALSE; + priv->input_none = FALSE; FlValue* input_type_value = fl_value_lookup_string(config_value, kTextInputTypeKey); if (fl_value_get_type(input_type_value) == FL_VALUE_TYPE_MAP) { FlValue* input_type_name = fl_value_lookup_string(input_type_value, kTextInputTypeNameKey); - if (fl_value_get_type(input_type_name) == FL_VALUE_TYPE_STRING && - g_strcmp0(fl_value_get_string(input_type_name), kMultilineInputType) == - 0) { - priv->input_multiline = TRUE; + if (fl_value_get_type(input_type_name) == FL_VALUE_TYPE_STRING) { + const gchar* input_type = fl_value_get_string(input_type_name); + if (g_strcmp0(input_type, kMultilineInputType) == 0) { + priv->input_multiline = TRUE; + } else if (g_strcmp0(input_type, kNoneInputType) == 0) { + priv->input_none = TRUE; + } } } return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); } +// Hides the input method. +static FlMethodResponse* hide(FlTextInputPlugin* self) { + FlTextInputPluginPrivate* priv = static_cast( + fl_text_input_plugin_get_instance_private(self)); + gtk_im_context_focus_out(priv->im_context); + + return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); +} + // Shows the input method. static FlMethodResponse* show(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); + if (priv->input_none == TRUE) { + return hide(self); + } + // Set the top-level window used for system input method windows. GdkWindow* window = gtk_widget_get_window(gtk_widget_get_toplevel(GTK_WIDGET(priv->view))); @@ -343,15 +364,6 @@ static FlMethodResponse* clear_client(FlTextInputPlugin* self) { return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); } -// Hides the input method. -static FlMethodResponse* hide(FlTextInputPlugin* self) { - FlTextInputPluginPrivate* priv = static_cast( - fl_text_input_plugin_get_instance_private(self)); - gtk_im_context_focus_out(priv->im_context); - - return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); -} - // Update the IM cursor position. // // As text is input by the user, the framework sends two streams of updates @@ -573,6 +585,7 @@ static void fl_text_input_plugin_init(FlTextInputPlugin* self) { priv->client_id = kClientIdUnset; priv->im_context = gtk_im_multicontext_new(); priv->input_multiline = FALSE; + priv->input_none = FALSE; g_signal_connect_object(priv->im_context, "preedit-start", G_CALLBACK(im_preedit_start_cb), self, G_CONNECT_SWAPPED);