From d07b5ed0d618813bebc21588bc11de9bee132aaa Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Tue, 20 Oct 2020 10:19:33 +0000 Subject: [PATCH] UI: Delay hiding only when leaving a text field --- src/imservice.rs | 6 +++--- src/server-context-service.c | 38 ++++++++++++++++++++++++------------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/imservice.rs b/src/imservice.rs index a4546d94..4db7fc86 100644 --- a/src/imservice.rs +++ b/src/imservice.rs @@ -42,7 +42,7 @@ pub mod c { pub fn eek_input_method_commit(im: *mut InputMethod, serial: u32); fn eekboard_context_service_set_hint_purpose(state: *const StateManager, hint: u32, purpose: u32); fn server_context_service_show_keyboard(imservice: *const UIManager); - fn server_context_service_hide_keyboard(imservice: *const UIManager); + fn server_context_service_keyboard_release_visibility(imservice: *const UIManager); } // The following defined in Rust. TODO: wrap naked pointers to Rust data inside RefCells to prevent multiple writers @@ -165,7 +165,7 @@ pub mod c { } } else { if let Some(ui) = imservice.ui_manager { - unsafe { server_context_service_hide_keyboard(ui); } + unsafe { server_context_service_keyboard_release_visibility(ui); } } } } @@ -185,7 +185,7 @@ pub mod c { imservice.current.active = false; if let Some(ui) = imservice.ui_manager { - unsafe { server_context_service_hide_keyboard(ui); } + unsafe { server_context_service_keyboard_release_visibility(ui); } } } diff --git a/src/server-context-service.c b/src/server-context-service.c index 3a365c33..33f1101f 100644 --- a/src/server-context-service.c +++ b/src/server-context-service.c @@ -226,15 +226,6 @@ make_widget (ServerContextService *self) gtk_widget_show_all(self->widget); } -static gboolean -on_hide (ServerContextService *self) -{ - gtk_widget_hide (GTK_WIDGET(self->window)); - self->hiding = 0; - - return G_SOURCE_REMOVE; -} - static void server_context_service_real_show_keyboard (ServerContextService *self) { @@ -260,12 +251,19 @@ server_context_service_real_show_keyboard (ServerContextService *self) static void server_context_service_real_hide_keyboard (ServerContextService *self) { - if (!self->hiding) { - self->hiding = g_timeout_add (200, (GSourceFunc) on_hide, self); - } + gtk_widget_hide (GTK_WIDGET(self->window)); self->visible = FALSE; } +static gboolean +on_hide (ServerContextService *self) +{ + server_context_service_real_hide_keyboard(self); + self->hiding = 0; + + return G_SOURCE_REMOVE; +} + void server_context_service_show_keyboard (ServerContextService *self) { @@ -286,6 +284,22 @@ server_context_service_hide_keyboard (ServerContextService *self) } } +/// Meant for use by the input-method handler: +/// the visible keyboard is no longer needed. +/// The implementation will delay it slightly, +/// because the release may be due to switching from one text field to another. +/// In this case, the user doesn't really need the keyboard surface +/// to disappear completely. +void +server_context_service_keyboard_release_visibility (ServerContextService *self) +{ + g_return_if_fail (SERVER_IS_CONTEXT_SERVICE(self)); + + if (!self->hiding && self->visible) { + self->hiding = g_timeout_add (200, (GSourceFunc) on_hide, self); + } +} + static void server_context_service_set_property (GObject *object, guint prop_id,