Allow previous input context to hide input panel
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 7 Mar 2017 02:14:26 +0000 (11:14 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 7 Mar 2017 13:05:17 +0000 (22:05 +0900)
Since there are cases an application that manually
calls input_panel_show() / hide() without considering
system's input panel policy, sometimes they are
requesting to hide input panel on input context that
did not explicitly requested to show in the past.
For now this patch will fix the issues above, but
will be reverted in the future since this patch will
break the policy that "ONLY the context that requested
to show input panel, can hide input panel".

Change-Id: I903213eebe78d0211113173651412fa15c7e62f7

src/e_mod_main.c

index 0e6d507..7466203 100644 (file)
@@ -147,6 +147,7 @@ static Ecore_Timer *g_timer_will_hide  = NULL;
 static enum _E_Input_Panel_State g_input_panel_state = E_INPUT_PANEL_STATE_DID_HIDE;
 static E_Client *client_surface_ec = NULL;
 static E_Text_Input *g_show_text_input = NULL;
+static E_Text_Input *g_old_text_input = NULL;
 
 static Eina_List *hooks_ec = NULL;
 
@@ -1166,7 +1167,13 @@ _e_text_input_cb_activate(struct wl_client *client, struct wl_resource *resource
      return;
 
    if (old)
-     _e_text_input_deactivate(old, input_method, EINA_TRUE);
+     {
+        _e_text_input_deactivate(old, input_method, EINA_TRUE);
+        if (g_input_panel_state == E_INPUT_PANEL_STATE_DID_SHOW || g_input_panel_state == E_INPUT_PANEL_STATE_WILL_SHOW)
+          {
+             g_old_text_input = old;
+          }
+     }
 
    if (!_e_text_input_method_create_context(client, input_method, text_input, EINA_TRUE))
      return;
@@ -1218,6 +1225,11 @@ _e_text_input_cb_deactivate(struct wl_client *client EINA_UNUSED, struct wl_reso
         g_client = NULL;
      }
 
+   if (text_input == g_old_text_input)
+     {
+        g_old_text_input = NULL;
+     }
+
    /* FIXME: should get input_method object from seat. */
    if (g_input_method && g_input_method->resource)
      input_method = wl_resource_get_user_data(g_input_method->resource);
@@ -1346,11 +1358,20 @@ static void
 _e_text_input_cb_input_panel_hide(struct wl_client *client, struct wl_resource *resource)
 {
    E_Text_Input *text_input = wl_resource_get_user_data(resource);
+   Eina_Bool hide_allowed = EINA_FALSE;
+
+   if (!g_text_input || (text_input && g_show_text_input == text_input))
+     hide_allowed = EINA_TRUE;
+
+   if (g_old_text_input && text_input == g_old_text_input && g_client == client)
+     hide_allowed = EINA_TRUE;
 
-   if (!g_text_input || (text_input && g_show_text_input == text_input)) {
-      _input_panel_hide(client, resource, EINA_FALSE);
-      g_show_text_input = NULL;
-   }
+   if (hide_allowed)
+     {
+        _input_panel_hide(client, resource, EINA_FALSE);
+        g_show_text_input = NULL;
+        g_old_text_input = NULL;
+     }
 }
 
 static void