hermet pushed a commit to branch master. http://git.enlightenment.org/tools/enventor.git/commit/?id=1b0fc9f4cf6ed590e3b1970625934bb22228562a
commit 1b0fc9f4cf6ed590e3b1970625934bb22228562a Author: ChunEon Park <her...@hermet.pe.kr> Date: Thu Aug 27 00:58:01 2015 +0900 auto completion: fix malfunction of key input on Windows system. re-implement auto completion key input by using key grab mechanism. @fix --- src/lib/auto_comp.c | 116 ++++++++++++++++++++++++++++++++++------------- src/lib/enventor_main.c | 14 ------ src/lib/enventor_smart.c | 38 +++++++++++++++- 3 files changed, 122 insertions(+), 46 deletions(-) diff --git a/src/lib/auto_comp.c b/src/lib/auto_comp.c index 6859496..db8ed4a 100644 --- a/src/lib/auto_comp.c +++ b/src/lib/auto_comp.c @@ -38,6 +38,7 @@ typedef struct autocomp_s Eina_Bool enabled : 1; Ecore_Thread *cntx_lexem_thread; Eina_Bool dot_candidate : 1; + Eina_Bool on_keygrab : 1; } autocomp_data; typedef struct ctx_lexem_thread_data_s @@ -58,6 +59,8 @@ static Eet_Data_Descriptor *lex_desc = NULL; static void candidate_list_show(autocomp_data *ad); static void queue_reset(autocomp_data *ad); static void entry_anchor_off(autocomp_data *ad); +static void anchor_key_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info); + static void eddc_init(void) @@ -363,6 +366,41 @@ init_thread_cancel_cb(void *data, Ecore_Thread *thread EINA_UNUSED) } static void +anchor_keygrab_set(autocomp_data *ad, Eina_Bool grab) +{ + Evas_Object *anchor = ad->anchor; + + if (grab) + { + if (ad->on_keygrab) return; + if (!evas_object_key_grab(anchor, "BackSpace", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - BackSpace"); + if (!evas_object_key_grab(anchor, "Escape", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - Escape"); + if (!evas_object_key_grab(anchor, "Return", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - Return"); + if (!evas_object_key_grab(anchor, "Tab", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - Tab"); + if (!evas_object_key_grab(anchor, "Up", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - Up"); + if (!evas_object_key_grab(anchor, "Down", 0, 0, EINA_TRUE)) + EINA_LOG_ERR("Failed to grab key - Down"); + ad->on_keygrab = EINA_TRUE; + } + else + { + if (!ad->on_keygrab) return; + evas_object_key_ungrab(anchor, "BackSpace", 0, 0); + evas_object_key_ungrab(anchor, "Escape", 0, 0); + evas_object_key_ungrab(anchor, "Return", 0, 0); + evas_object_key_ungrab(anchor, "Tab", 0, 0); + evas_object_key_ungrab(anchor, "Up", 0, 0); + evas_object_key_ungrab(anchor, "Down", 0, 0); + ad->on_keygrab = EINA_FALSE; + } +} + +static void entry_anchor_off(autocomp_data *ad) { if (ad->anchor_visible) @@ -373,9 +411,11 @@ entry_anchor_off(autocomp_data *ad) since tooltip regards the content callback is same with before. */ elm_object_tooltip_content_cb_set(ad->anchor, NULL, NULL, NULL); } + anchor_keygrab_set(ad, EINA_FALSE); ad->anchor_visible = EINA_FALSE; } + static void anchor_unfocused_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED) @@ -613,6 +653,7 @@ candidate_list_show(autocomp_data *ad) entry_tooltip_content_cb, ad, NULL); elm_object_tooltip_orient_set(ad->anchor, tooltip_orient); elm_object_tooltip_show(ad->anchor); + anchor_keygrab_set(ad, EINA_TRUE); ad->anchor_visible = EINA_TRUE; } //Already tooltip is visible, just update the list item @@ -717,6 +758,44 @@ list_item_move(autocomp_data *ad, Eina_Bool up) ad); } +static void +anchor_key_down_cb(void *data, Evas *evas EINA_UNUSED, + Evas_Object *obj EINA_UNUSED, void *event_info) +{ + autocomp_data *ad = data; + if (!ad->anchor_visible) return; + + Evas_Event_Key_Down *ev = event_info; + + //Cancel the auto complete. + if (!strcmp(ev->keyname, "BackSpace") || !strcmp(ev->keyname, "Escape")) + { + queue_reset(ad); + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; + return; + } + if (!strcmp(ev->keyname, "Return") || !strcmp(ev->keyname, "Tab")) + { + insert_completed_text(ad); + queue_reset(ad); + edit_syntax_color_partial_apply(ad->ed, -1); + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; + return; + } + if (!strcmp(ev->keyname, "Up")) + { + list_item_move(ad, EINA_TRUE); + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; + return; + } + if (!strcmp(ev->keyname, "Down")) + { + list_item_move(ad, EINA_FALSE); + ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; + return; + } +} + /*****************************************************************************/ /* Externally accessible calls */ /*****************************************************************************/ @@ -779,6 +858,8 @@ autocomp_target_set(edit_data *ed) evas_object_event_callback_add(entry, EVAS_CALLBACK_MOVE, entry_move_cb, ad); ad->anchor = elm_button_add(edit_obj_get(ed)); + evas_object_event_callback_add(ad->anchor, EVAS_CALLBACK_KEY_DOWN, + anchor_key_down_cb, ad); ad->ed = ed; } @@ -787,39 +868,12 @@ autocomp_event_dispatch(const char *key) { autocomp_data *ad = g_ad; if (!ad) return EINA_FALSE; + if (ad->anchor_visible) return EINA_FALSE; //Reset queue. - if (!ad->anchor_visible) - { - if (!strcmp(key, "Up") || !strcmp(key, "Down") || - !strcmp(key, "Left") || !strcmp(key, "Right")) - queue_reset(ad); - return EINA_FALSE; - } - - //Cancel the auto complete. - if (!strcmp(key, "BackSpace") || !strcmp(key, "Escape")) - { - queue_reset(ad); - return EINA_TRUE; - } - if (!strcmp(key, "Return") || !strcmp(key, "Tab")) - { - insert_completed_text(ad); - queue_reset(ad); - edit_syntax_color_partial_apply(ad->ed, -1); - return EINA_TRUE; - } - if (!strcmp(key, "Up")) - { - list_item_move(ad, EINA_TRUE); - return EINA_TRUE; - } - if (!strcmp(key, "Down")) - { - list_item_move(ad, EINA_FALSE); - return EINA_TRUE; - } + if (!strcmp(key, "Up") || !strcmp(key, "Down") || + !strcmp(key, "Left") || !strcmp(key, "Right")) + queue_reset(ad); return EINA_FALSE; } diff --git a/src/lib/enventor_main.c b/src/lib/enventor_main.c index 3766b92..eb7926c 100644 --- a/src/lib/enventor_main.c +++ b/src/lib/enventor_main.c @@ -24,15 +24,6 @@ const char SIG_FOCUSED[] = "focused"; static int _enventor_init_count = 0; static int _enventor_log_dom = -1; -static Ecore_Event_Handler *_key_down_handler = NULL; - -static Eina_Bool -key_down_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *ev) -{ - Ecore_Event_Key *event = ev; - if (autocomp_event_dispatch(event->key)) return ECORE_CALLBACK_DONE; - return ECORE_CALLBACK_PASS_ON; -} EAPI int enventor_init(int argc, char **argv) @@ -104,8 +95,6 @@ enventor_init(int argc, char **argv) eina_prefix_data_get(PREFIX)); srand(time(NULL)); - _key_down_handler = ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, - key_down_cb, NULL); return _enventor_init_count; } @@ -120,9 +109,6 @@ enventor_shutdown(void) if ((--_enventor_init_count) > 0) return _enventor_init_count; - ecore_event_handler_del(_key_down_handler); - _key_down_handler = NULL; - if ((_enventor_log_dom != -1) && (_enventor_log_dom != EINA_LOG_DOMAIN_GLOBAL)) { diff --git a/src/lib/enventor_smart.c b/src/lib/enventor_smart.c index 702603e..45d264c 100644 --- a/src/lib/enventor_smart.c +++ b/src/lib/enventor_smart.c @@ -27,7 +27,12 @@ typedef struct _Enventor_Object_Data Eina_Stringshare *group_name; Ecore_Timer *file_modified_timer; + Ecore_Event_Handler *key_down_handler; + Ecore_Event_Handler *key_up_handler; + Ecore_Event_Handler *file_modified_handler; + Eina_Bool dummy_swallow : 1; + Eina_Bool key_down : 1; } Enventor_Object_Data; @@ -51,6 +56,29 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = { /*****************************************************************************/ /* Internal method implementation */ /*****************************************************************************/ +static Eina_Bool +key_up_cb(void *data, int type EINA_UNUSED, void *ev) +{ + Enventor_Object_Data *pd = data; + pd->key_down = EINA_FALSE; +} + +static Eina_Bool +key_down_cb(void *data, int type EINA_UNUSED, void *ev) +{ + Enventor_Object_Data *pd = data; + Ecore_Event_Key *event = ev; + Eina_Bool ret; + + eo_do_ret(pd->obj, ret, enventor_obj_focus_get()); + if (!ret) return ECORE_CALLBACK_PASS_ON; + + if (pd->key_down) return; + pd->key_down = EINA_TRUE; + + if (autocomp_event_dispatch(event->key)) return ECORE_CALLBACK_DONE; + return ECORE_CALLBACK_PASS_ON; +} static Eina_Bool file_modified_timer(void *data) @@ -215,7 +243,12 @@ _enventor_object_evas_object_smart_add(Eo *obj, Enventor_Object_Data *pd) elm_widget_can_focus_set(obj, EINA_FALSE); //FIXME: Called twice ?? Why? - ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, file_modified_cb, pd); + pd->file_modified_handler = + ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, file_modified_cb, pd); + pd->key_down_handler = + ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_down_cb, pd); + pd->key_up_handler = + ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, key_up_cb, pd); } EOLIAN static void @@ -228,6 +261,9 @@ _enventor_object_evas_object_smart_del(Evas_Object *obj EINA_UNUSED, eio_monitor_del(pd->edc_monitor); eina_stringshare_del(pd->group_name); edit_term(pd->ed); + ecore_event_handler_del(pd->file_modified_handler); + ecore_event_handler_del(pd->key_down_handler); + ecore_event_handler_del(pd->key_up_handler); edj_mgr_term(); autocomp_term(); build_term(); --