summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli <ali198724@gmail.com>2020-03-27 06:07:16 +0000
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-04-03 14:39:54 +0200
commitd7d948c23d19cc6c6dc8bc6f014843b2421240a0 (patch)
treefcc83912c152b652e49de3c348dc869183763ae5
parentb7804910a7a6570817cfbde2a3873c1478718128 (diff)
elm_entry: using keycode for main keyboard shortcuts
Previously we use key strings to detect keyboard shortcuts (for example copy/paste/select_all, .. etc) Now we will use key code alongside with these key strings (I do not remove the key string, because I am afraid something depends on them because some methods do not send keycode with keys) This issue can be easily detected when the keyboard layout is not a Latin language, for example Hitting "C" will produce key string depends on related language not letter C, but Keycodes remain the same regardless of keyboard layout. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D11606
-rw-r--r--src/lib/edje/edje_entry.c27
-rw-r--r--src/tests/elementary/elm_test_entry.c23
2 files changed, 40 insertions, 10 deletions
diff --git a/src/lib/edje/edje_entry.c b/src/lib/edje/edje_entry.c
index 5d84b1fbef..81046a3716 100644
--- a/src/lib/edje/edje_entry.c
+++ b/src/lib/edje/edje_entry.c
@@ -1737,6 +1737,13 @@ _compose_seq_reset(Entry *en)
1737 en->composing = EINA_FALSE; 1737 en->composing = EINA_FALSE;
1738} 1738}
1739 1739
1740#define KEYCODE_A 65
1741#define KEYCODE_C 67
1742#define KEYCODE_V 86
1743#define KEYCODE_X 88
1744#define KEYCODE_Y 89
1745#define KEYCODE_Z 90
1746
1740static void 1747static void
1741_edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info) 1748_edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
1742{ 1749{
@@ -2089,9 +2096,9 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2089 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2096 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2090 } 2097 }
2091#if defined(__APPLE__) && defined(__MACH__) 2098#if defined(__APPLE__) && defined(__MACH__)
2092 else if ((super) && (!strcmp(ev->keyname, "a"))) 2099 else if ((super) && (!strcmp(ev->keyname, "a") || ev->keycode == KEYCODE_A))
2093#else 2100#else
2094 else if ((control) && (!strcmp(ev->keyname, "a"))) 2101 else if ((control) && (!strcmp(ev->keyname, "a") || ev->keycode == KEYCODE_A))
2095#endif 2102#endif
2096 { 2103 {
2097 _compose_seq_reset(en); 2104 _compose_seq_reset(en);
@@ -2107,9 +2114,9 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2107 } 2114 }
2108 } 2115 }
2109#if defined(__APPLE__) && defined(__MACH__) 2116#if defined(__APPLE__) && defined(__MACH__)
2110 else if ((super) && (((!shift) && !strcmp(ev->keyname, "c")) || !strcmp(ev->key, "Insert"))) 2117 else if ((super) && (((!shift) && (!strcmp(ev->keyname, "c") || ev->keycode == KEYCODE_C)) || !strcmp(ev->key, "Insert")))
2111#else 2118#else
2112 else if ((control) && (((!shift) && !strcmp(ev->keyname, "c")) || !strcmp(ev->key, "Insert"))) 2119 else if ((control) && (((!shift) && (!strcmp(ev->keyname, "c") || ev->keycode == KEYCODE_C)) || !strcmp(ev->key, "Insert")))
2113#endif 2120#endif
2114 { 2121 {
2115 _compose_seq_reset(en); 2122 _compose_seq_reset(en);
@@ -2117,9 +2124,9 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2117 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2124 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2118 } 2125 }
2119#if defined(__APPLE__) && defined(__MACH__) 2126#if defined(__APPLE__) && defined(__MACH__)
2120 else if ((super) && (!shift) && ((!strcmp(ev->keyname, "x") || (!strcmp(ev->keyname, "m"))))) 2127 else if ((super) && (!shift) && (((!strcmp(ev->keyname, "x") || ev->keycode == KEYCODE_X) || (!strcmp(ev->keyname, "m")))))
2121#else 2128#else
2122 else if ((control) && (!shift) && ((!strcmp(ev->keyname, "x") || (!strcmp(ev->keyname, "m"))))) 2129 else if ((control) && (!shift) && (((!strcmp(ev->keyname, "x") || ev->keycode == KEYCODE_X) || (!strcmp(ev->keyname, "m")))))
2123#endif 2130#endif
2124 { 2131 {
2125 _compose_seq_reset(en); 2132 _compose_seq_reset(en);
@@ -2127,9 +2134,9 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2127 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2134 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2128 } 2135 }
2129#if defined(__APPLE__) && defined(__MACH__) 2136#if defined(__APPLE__) && defined(__MACH__)
2130 else if ((super) && (!strcmp(ev->keyname, "z"))) 2137 else if ((super) && (!strcmp(ev->keyname, "z") || ev->keycode == KEYCODE_Z))
2131#else 2138#else
2132 else if ((control) && (!strcmp(ev->keyname, "z"))) 2139 else if ((control) && (!strcmp(ev->keyname, "z") || ev->keycode == KEYCODE_Z))
2133#endif 2140#endif
2134 { 2141 {
2135 _compose_seq_reset(en); 2142 _compose_seq_reset(en);
@@ -2146,9 +2153,9 @@ _edje_key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
2146 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD; 2153 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
2147 } 2154 }
2148#if defined(__APPLE__) && defined(__MACH__) 2155#if defined(__APPLE__) && defined(__MACH__)
2149 else if ((super) && (!shift) && (!strcmp(ev->keyname, "y"))) 2156 else if ((super) && (!shift) && (!strcmp(ev->keyname, "y") || ev->keycode == KEYCODE_Y))
2150#else 2157#else
2151 else if ((control) && (!shift) && (!strcmp(ev->keyname, "y"))) 2158 else if ((control) && (!shift) && (!strcmp(ev->keyname, "y") || ev->keycode == KEYCODE_Y))
2152#endif 2159#endif
2153 { 2160 {
2154 _compose_seq_reset(en); 2161 _compose_seq_reset(en);
diff --git a/src/tests/elementary/elm_test_entry.c b/src/tests/elementary/elm_test_entry.c
index 4655a688ba..cc68aed0dd 100644
--- a/src/tests/elementary/elm_test_entry.c
+++ b/src/tests/elementary/elm_test_entry.c
@@ -590,6 +590,28 @@ EFL_START_TEST(elm_entry_test_text_class)
590} 590}
591EFL_END_TEST 591EFL_END_TEST
592 592
593EFL_START_TEST(elm_entry_keycode)
594{
595 Evas_Object *win, *entry;
596
597 win = win_add(NULL, "entry", ELM_WIN_BASIC);
598 entry = elm_entry_add(win);
599 evas_object_show(entry);
600
601 elm_entry_entry_set(entry, "Hello World");
602 Evas *e = evas_object_evas_get(entry);
603 elm_object_focus_set(entry, EINA_TRUE);
604 evas_key_modifier_on(e, "Control");
605 evas_event_feed_key_down_with_keycode(e, "", "", "", "", time(NULL), NULL, 65);
606 ecore_main_loop_iterate();
607 evas_event_feed_key_down(e, "BackSpace", "BackSpace", "\b", "\b", time(NULL), NULL);
608 ck_assert_str_eq(elm_object_text_get(entry), "");
609
610 evas_object_del(entry);
611 evas_object_del(win);
612}
613EFL_END_TEST
614
593void elm_test_entry(TCase *tc) 615void elm_test_entry(TCase *tc)
594{ 616{
595 tcase_add_test(tc, elm_entry_legacy_type_check); 617 tcase_add_test(tc, elm_entry_legacy_type_check);
@@ -608,4 +630,5 @@ void elm_test_entry(TCase *tc)
608 tcase_add_test(tc, elm_entry_magnifier); 630 tcase_add_test(tc, elm_entry_magnifier);
609 tcase_add_test(tc, elm_entry_file_get_set); 631 tcase_add_test(tc, elm_entry_file_get_set);
610 tcase_add_test(tc, elm_entry_test_text_class); 632 tcase_add_test(tc, elm_entry_test_text_class);
633 tcase_add_test(tc, elm_entry_keycode);
611} 634}