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 71aa2165b2..3d77b0ea3e 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 @@ -45,6 +45,14 @@ static constexpr char kNoneInputType[] = "TextInputType.none"; static constexpr int64_t kClientIdUnset = -1; +typedef enum { + FL_TEXT_INPUT_TYPE_TEXT, + // Send newline when multi-line and enter is pressed. + FL_TEXT_INPUT_TYPE_MULTILINE, + // The input method is not shown at all. + FL_TEXT_INPUT_TYPE_NONE, +} FlTextInputType; + struct FlTextInputPluginPrivate { GObject parent_instance; @@ -56,11 +64,8 @@ struct FlTextInputPluginPrivate { // Input action to perform when enter pressed. gchar* input_action; - // 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; + // The type of the input method. + FlTextInputType input_type; // Input method. GtkIMContext* im_context; @@ -269,9 +274,8 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) { priv->input_action = g_strdup(fl_value_get_string(input_action_value)); } - // Reset the input type flags, then set them only if appropriate. - priv->input_multiline = FALSE; - priv->input_none = FALSE; + // Reset the input type, then set only if appropriate. + priv->input_type = FL_TEXT_INPUT_TYPE_TEXT; FlValue* input_type_value = fl_value_lookup_string(config_value, kTextInputTypeKey); if (fl_value_get_type(input_type_value) == FL_VALUE_TYPE_MAP) { @@ -280,9 +284,9 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) { 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; + priv->input_type = FL_TEXT_INPUT_TYPE_MULTILINE; } else if (g_strcmp0(input_type, kNoneInputType) == 0) { - priv->input_none = TRUE; + priv->input_type = FL_TEXT_INPUT_TYPE_NONE; } } } @@ -303,7 +307,7 @@ static FlMethodResponse* hide(FlTextInputPlugin* self) { static FlMethodResponse* show(FlTextInputPlugin* self) { FlTextInputPluginPrivate* priv = static_cast( fl_text_input_plugin_get_instance_private(self)); - if (priv->input_none == TRUE) { + if (priv->input_type == FL_TEXT_INPUT_TYPE_NONE) { return hide(self); } @@ -534,7 +538,7 @@ static gboolean fl_text_input_plugin_filter_keypress_default( case GDK_KEY_Return: case GDK_KEY_KP_Enter: case GDK_KEY_ISO_Enter: - if (priv->input_multiline == TRUE) { + if (priv->input_type == FL_TEXT_INPUT_TYPE_MULTILINE) { priv->text_model->AddCodePoint('\n'); changed = TRUE; } @@ -584,8 +588,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; + priv->input_type = FL_TEXT_INPUT_TYPE_TEXT; g_signal_connect_object(priv->im_context, "preedit-start", G_CALLBACK(im_preedit_start_cb), self, G_CONNECT_SWAPPED);