From 45491d2959eca125845b9ba4579fcac0590a67fc Mon Sep 17 00:00:00 2001 From: "Eduardo Lima (Etrunko)" Date: Wed, 30 Oct 2013 19:19:01 -0200 Subject: [PATCH] Fix handling of special keys Change-Id: If3e9e2c1b62f8b4f1e72a7473ac62b6e0b59f692 Signed-off-by: Eduardo Lima (Etrunko) --- data/themes/default/ignorekeys.txt | 1 - src/wkb-ibus.c | 65 +++++++++++++++++++++++++++++++++++--- src/wkb-main.c | 32 ------------------- 3 files changed, 61 insertions(+), 37 deletions(-) diff --git a/data/themes/default/ignorekeys.txt b/data/themes/default/ignorekeys.txt index 875ddfa..de27cff 100644 --- a/data/themes/default/ignorekeys.txt +++ b/data/themes/default/ignorekeys.txt @@ -1,4 +1,3 @@ -shift abc ?123 1/2 diff --git a/src/wkb-ibus.c b/src/wkb-ibus.c index a884c22..54a81b1 100644 --- a/src/wkb-ibus.c +++ b/src/wkb-ibus.c @@ -64,6 +64,12 @@ static const unsigned int IBUS_CAP_SURROUNDING_TEXT = 1 << 5; static const unsigned int IBUS_RELEASE_MASK = 1 << 30; +struct wkb_ibus_key +{ + unsigned int code; + unsigned int sym; + unsigned int state; +}; struct wkb_ibus_input_context { @@ -884,7 +890,7 @@ _ibus_input_ctx_key_release(void *data, const Eldbus_Message *msg, Eldbus_Pendin } static unsigned int -_key_sym_to_key_code(unsigned int key_sym) +_key_sym_to_key_code(unsigned int *key_sym) { #define CASE_SYM(_sym, _code) \ case XKB_KEY_ ##_sym: \ @@ -897,7 +903,7 @@ _key_sym_to_key_code(unsigned int key_sym) case XKB_KEY_ ##_low: \ CASE_SYM(_up, _up) - switch(key_sym) + switch(*key_sym) { CASE_NUMBER(0); CASE_NUMBER(1); @@ -946,18 +952,54 @@ _key_sym_to_key_code(unsigned int key_sym) #undef CASE_LETTER } +static unsigned int +_key_to_key_code(const char *key, unsigned int *key_sym) +{ + if (strcmp(key, "shift") == 0) + { + *key_sym = XKB_KEY_Shift_L; + return KEY_LEFTSHIFT; + } + else if (strcmp(key, "backspace") == 0) + { + *key_sym = XKB_KEY_BackSpace; + return KEY_BACKSPACE; + } + else if (strcmp(key, "enter") == 0) + { + *key_sym = XKB_KEY_Return; + return KEY_ENTER; + } + else if (strcmp(key, "space") == 0) + { + *key_sym = XKB_KEY_space; + return KEY_SPACE; + } + + *key_sym = *key; + return _key_sym_to_key_code(*key_sym); +} + void wkb_ibus_input_context_process_key_event(const char *key) { + static Eina_Bool key_shift = 0; static unsigned int key_code = KEY_RESERVED; unsigned int key_sym = XKB_KEY_NoSymbol; if (!wkb_ibus || !wkb_ibus->input_ctx) return; - key_sym = *key; - key_code = _key_sym_to_key_code(key_sym) + 8; + key_code = _key_to_key_code(key, &key_sym); + + if (key_code == KEY_RESERVED) + { + ERR("Unexpected key '%s'", key); + return; + } + + key_code += 8; if (!wkb_ibus->input_ctx->ibus_ctx) { @@ -968,9 +1010,24 @@ wkb_ibus_input_context_process_key_event(const char *key) INF("Process key event with '%s'", key); + /* XXX H4X0R */ + if (key_code-8 == KEY_LEFTSHIFT) + { + key_shift = !key_shift; + if (!key_shift) + goto release; + } + eldbus_proxy_call(wkb_ibus->input_ctx->ibus_ctx, "ProcessKeyEvent", _ibus_input_ctx_key_press, &key_code, -1, "uuu", key_sym, key_code, 0); + + + /* XXX H4X0R */ + if (key_code-8 == KEY_LEFTSHIFT) + return; + +release: eldbus_proxy_call(wkb_ibus->input_ctx->ibus_ctx, "ProcessKeyEvent", _ibus_input_ctx_key_release, &key_code, -1, "uuu", key_sym, key_code, IBUS_RELEASE_MASK); diff --git a/src/wkb-main.c b/src/wkb-main.c index 945cac6..1030631 100644 --- a/src/wkb-main.c +++ b/src/wkb-main.c @@ -179,39 +179,7 @@ _cb_wkb_on_key_down(void *data, Evas_Object *obj, const char *emission EINA_UNUS } wkb_ibus_input_context_process_key_event(key); -#if 0 - else if (strcmp(key, "backspace") == 0) - { - if (strlen(wkb->preedit_str) == 0) - { - wl_input_method_context_delete_surrounding_text(wkb->im_ctx, -1, 1); - wl_input_method_context_commit_string(wkb->im_ctx, wkb->serial, ""); - } - else - { - wkb->preedit_str[strlen(wkb->preedit_str) - 1] = '\0'; - _wkb_send_preedit_str(wkb, -1); - } - goto end; - } - else if (strcmp(key, "enter") == 0) - { - _wkb_commit_preedit_str(wkb); - wl_input_method_context_keysym(wkb->im_ctx, wkb->serial, 0, - XKB_KEY_Return, WL_KEYBOARD_KEY_STATE_PRESSED, - 0); - goto end; - } - else if (strcmp(key, "space") == 0) - { - key = " "; - } - - DBG("Key pressed: '%s'", key); - - _wkb_update_preedit_str(wkb, key); -#endif end: free(src); } -- 2.7.4