Skip to content

Commit 49fed08

Browse files
committed
Linux: add support for TextInputType.none
flutter/flutter#76072
1 parent e120494 commit 49fed08

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

shell/platform/linux/fl_text_input_plugin.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static constexpr char kTransform[] = "transform";
4141

4242
static constexpr char kTextAffinityDownstream[] = "TextAffinity.downstream";
4343
static constexpr char kMultilineInputType[] = "TextInputType.multiline";
44+
static constexpr char kNoneInputType[] = "TextInputType.none";
4445

4546
static constexpr int64_t kClientIdUnset = -1;
4647

@@ -58,6 +59,9 @@ struct FlTextInputPluginPrivate {
5859
// Send newline when multi-line and enter is pressed.
5960
gboolean input_multiline;
6061

62+
// Whether to show the on-screen keyboard.
63+
gboolean show_osk;
64+
6165
// Input method.
6266
GtkIMContext* im_context;
6367

@@ -265,17 +269,22 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
265269
priv->input_action = g_strdup(fl_value_get_string(input_action_value));
266270
}
267271

268-
// Clear the multiline flag, then set it only if the field is multiline.
272+
// Reset the input type flags, then set them only if appropriate.
269273
priv->input_multiline = FALSE;
274+
priv->show_osk = TRUE;
270275
FlValue* input_type_value =
271276
fl_value_lookup_string(config_value, kTextInputTypeKey);
272277
if (fl_value_get_type(input_type_value) == FL_VALUE_TYPE_MAP) {
273278
FlValue* input_type_name =
274279
fl_value_lookup_string(input_type_value, kTextInputTypeNameKey);
275-
if (fl_value_get_type(input_type_name) == FL_VALUE_TYPE_STRING &&
276-
g_strcmp0(fl_value_get_string(input_type_name), kMultilineInputType) ==
277-
0) {
278-
priv->input_multiline = TRUE;
280+
if (fl_value_get_type(input_type_name) == FL_VALUE_TYPE_STRING) {
281+
if (g_strcmp0(fl_value_get_string(input_type_name),
282+
kMultilineInputType) == 0) {
283+
priv->input_multiline = TRUE;
284+
} else if (g_strcmp0(fl_value_get_string(input_type_name),
285+
kNoneInputType) == 0) {
286+
priv->show_osk = FALSE;
287+
}
279288
}
280289
}
281290

@@ -286,12 +295,14 @@ static FlMethodResponse* set_client(FlTextInputPlugin* self, FlValue* args) {
286295
static FlMethodResponse* show(FlTextInputPlugin* self) {
287296
FlTextInputPluginPrivate* priv = static_cast<FlTextInputPluginPrivate*>(
288297
fl_text_input_plugin_get_instance_private(self));
289-
// Set the top-level window used for system input method windows.
290-
GdkWindow* window =
291-
gtk_widget_get_window(gtk_widget_get_toplevel(GTK_WIDGET(priv->view)));
292-
gtk_im_context_set_client_window(priv->im_context, window);
298+
if (priv->show_osk == TRUE) {
299+
// Set the top-level window used for system input method windows.
300+
GdkWindow* window =
301+
gtk_widget_get_window(gtk_widget_get_toplevel(GTK_WIDGET(priv->view)));
302+
gtk_im_context_set_client_window(priv->im_context, window);
293303

294-
gtk_im_context_focus_in(priv->im_context);
304+
gtk_im_context_focus_in(priv->im_context);
305+
}
295306

296307
return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
297308
}

0 commit comments

Comments
 (0)