diff options
Diffstat (limited to 'src/wkb-main.c')
-rw-r--r-- | src/wkb-main.c | 110 |
1 files changed, 76 insertions, 34 deletions
diff --git a/src/wkb-main.c b/src/wkb-main.c index dd10b29..945cac6 100644 --- a/src/wkb-main.c +++ b/src/wkb-main.c @@ -30,6 +30,8 @@ #include <string.h> #include "wkb-log.h" +#include "wkb-ibus.h" + #include "input-method-client-protocol.h" #include "text-client-protocol.h" @@ -55,7 +57,6 @@ struct weekeyboard uint32_t preedit_style; uint32_t content_hint; uint32_t content_purpose; - uint32_t serial; uint32_t surrounding_cursor; Eina_Bool context_changed; @@ -64,7 +65,8 @@ struct weekeyboard static void _cb_wkb_delete_request(Ecore_Evas *ee EINA_UNUSED) { - ecore_main_loop_quit(); + if (!wkb_ibus_shutdown()) + ecore_main_loop_quit(); } static char * @@ -89,7 +91,7 @@ _wkb_commit_preedit_str(struct weekeyboard *wkb) return; wl_input_method_context_cursor_position(wkb->im_ctx, 0, 0); - wl_input_method_context_commit_string(wkb->im_ctx, wkb->serial, wkb->preedit_str); + wl_input_method_context_commit_string(wkb->im_ctx, wkb_ibus_input_context_serial(), wkb->preedit_str); if (wkb->surrounding_text) { @@ -120,7 +122,7 @@ _wkb_send_preedit_str(struct weekeyboard *wkb, int cursor) index = cursor; wl_input_method_context_preedit_cursor(wkb->im_ctx, index); - wl_input_method_context_preedit_string(wkb->im_ctx, wkb->serial, wkb->preedit_str, wkb->preedit_str); + wl_input_method_context_preedit_string(wkb->im_ctx, wkb_ibus_input_context_serial(), wkb->preedit_str, wkb->preedit_str); } static void @@ -175,6 +177,9 @@ _cb_wkb_on_key_down(void *data, Evas_Object *obj, const char *emission EINA_UNUS DBG("Ignoring key: '%s'", key); goto end; } + + wkb_ibus_input_context_process_key_event(key); +#if 0 else if (strcmp(key, "backspace") == 0) { if (strlen(wkb->preedit_str) == 0) @@ -206,7 +211,7 @@ _cb_wkb_on_key_down(void *data, Evas_Object *obj, const char *emission EINA_UNUS DBG("Key pressed: '%s'", key); _wkb_update_preedit_str(wkb, key); - +#endif end: free(src); } @@ -214,26 +219,27 @@ end: static void _wkb_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx, const char *text, uint32_t cursor, uint32_t anchor) { +#if 0 struct weekeyboard *wkb = data; - DBG(""); free(wkb->surrounding_text); wkb->surrounding_text = strdup(text); wkb->surrounding_cursor = cursor; +#endif } static void _wkb_im_ctx_reset(void *data, struct wl_input_method_context *im_ctx) { +#if 0 struct weekeyboard *wkb = data; - DBG(""); - if (strlen(wkb->preedit_str)) { free(wkb->preedit_str); wkb->preedit_str = strdup(""); } +#endif } static void @@ -270,13 +276,14 @@ _wkb_im_ctx_content_type(void *data, struct wl_input_method_context *im_ctx, uin static void _wkb_im_ctx_invoke_action(void *data, struct wl_input_method_context *im_ctx, uint32_t button, uint32_t index) { +#if 0 struct weekeyboard *wkb = data; - DBG(""); if (button != BTN_LEFT) return; _wkb_send_preedit_str(wkb, index); +#endif } static void @@ -284,19 +291,21 @@ _wkb_im_ctx_commit_state(void *data, struct wl_input_method_context *im_ctx, uin { struct weekeyboard *wkb = data; - DBG(""); if (wkb->surrounding_text) INF("Surrounding text updated: %s", wkb->surrounding_text); - wkb->serial = serial; + wkb_ibus_input_context_set_serial(serial); +#if 0 /* FIXME */ - wl_input_method_context_language(im_ctx, wkb->serial, "en");//wkb->language); - wl_input_method_context_text_direction(im_ctx, wkb->serial, WL_TEXT_INPUT_TEXT_DIRECTION_LTR);//wkb->text_direction); + wl_input_method_context_language(im_ctx, wkb_ibus_input_context_serial(), "en");//wkb->language); + wl_input_method_context_text_direction(im_ctx, wkb_ibus_input_context_serial(), WL_TEXT_INPUT_TEXT_DIRECTION_LTR);//wkb->text_direction); +#endif } static void _wkb_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ctx, const char *language) { +#if 0 struct weekeyboard *wkb = data; if (language && wkb->language && !strcmp(language, wkb->language)) @@ -313,6 +322,7 @@ _wkb_im_ctx_preferred_language(void *data, struct wl_input_method_context *im_ct wkb->language = strdup(language); INF("Language changed, new: '%s'", language); } +#endif } static const struct wl_input_method_context_listener wkb_im_context_listener = { @@ -328,7 +338,8 @@ static void _wkb_im_activate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *im_ctx) { struct weekeyboard *wkb = data; - struct wl_array modifiers_map; + + DBG("Activate"); if (wkb->im_ctx) wl_input_method_context_destroy(wkb->im_ctx); @@ -339,16 +350,21 @@ _wkb_im_activate(void *data, struct wl_input_method *input_method, struct wl_inp wkb->preedit_str = strdup(""); wkb->content_hint = WL_TEXT_INPUT_CONTENT_HINT_NONE; wkb->content_purpose = WL_TEXT_INPUT_CONTENT_PURPOSE_NORMAL; + free(wkb->language); wkb->language = NULL; + free(wkb->surrounding_text); wkb->surrounding_text = NULL; - wkb->serial = 0; + + wkb_ibus_input_context_set_serial(0); wkb->im_ctx = im_ctx; wl_input_method_context_add_listener(im_ctx, &wkb_im_context_listener, wkb); + wkb_ibus_input_context_create(im_ctx); - /* +#if 0 + struct wl_array modifiers_map; wl_array_init(&modifiers_map); keysym_modifiers_add(&modifiers_map, "Shift"); @@ -363,9 +379,9 @@ _wkb_im_activate(void *data, struct wl_input_method *input_method, struct wl_inp */ /* FIXME */ - wl_input_method_context_language(im_ctx, wkb->serial, "en");//wkb->language); - wl_input_method_context_text_direction(im_ctx, wkb->serial, WL_TEXT_INPUT_TEXT_DIRECTION_LTR);//wkb->text_direction); - + wl_input_method_context_language(im_ctx, wkb_ibus_input_context_serial(), "en");//wkb->language); + wl_input_method_context_text_direction(im_ctx, wkb_ibus_input_context_serial(), WL_TEXT_INPUT_TEXT_DIRECTION_LTR);//wkb->text_direction); +#endif wkb->context_changed = EINA_TRUE; evas_object_show(wkb->edje_obj); } @@ -375,11 +391,16 @@ _wkb_im_deactivate(void *data, struct wl_input_method *input_method, struct wl_i { struct weekeyboard *wkb = data; - if (!wkb->im_ctx) - return; + DBG("Deactivate"); + + wkb_ibus_input_context_destroy(); + + if (wkb->im_ctx) + { + wl_input_method_context_destroy(wkb->im_ctx); + wkb->im_ctx = NULL; + } - wl_input_method_context_destroy(wkb->im_ctx); - wkb->im_ctx = NULL; evas_object_hide(wkb->edje_obj); } @@ -398,7 +419,7 @@ _wkb_ui_setup(struct weekeyboard *wkb) char *ignore_keys; ecore_evas_alpha_set(wkb->ee, EINA_TRUE); - ecore_evas_title_set(wkb->ee, "EFL virtual keyboard"); + ecore_evas_title_set(wkb->ee, "Weekeyboard"); evas = ecore_evas_get(wkb->ee); wkb->edje_obj = edje_object_add(evas); @@ -417,7 +438,7 @@ _wkb_ui_setup(struct weekeyboard *wkb) if (!edje_object_file_set(wkb->edje_obj, path, "main")) { int err = edje_object_load_error_get(wkb->edje_obj); - ERR("error loading the edje file: '%s'", edje_load_error_str(err)); + ERR("Unable to load the edje file: '%s'", edje_load_error_str(err)); return EINA_FALSE; } @@ -495,6 +516,7 @@ _wkb_setup(struct weekeyboard *wkb) } /* Set input panel surface */ + DBG("Setting up input panel"); wkb->win = ecore_evas_wayland_window_get(wkb->ee); ecore_wl_window_type_set(wkb->win, ECORE_WL_WINDOW_TYPE_NONE); wkb->surface = ecore_wl_window_surface_create(wkb->win); @@ -502,6 +524,7 @@ _wkb_setup(struct weekeyboard *wkb) wl_input_panel_surface_set_toplevel(ips, wkb->output, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM); /* Input method listener */ + DBG("Adding wl_input_method listener"); wl_input_method_add_listener(wkb->im, &wkb_im_listener, wkb); } @@ -511,13 +534,15 @@ _wkb_free(struct weekeyboard *wkb) if (wkb->im_ctx) wl_input_method_context_destroy(wkb->im_ctx); + if (wkb->edje_obj) + evas_object_del(wkb->edje_obj); + if (wkb->ignore_keys) { free(*wkb->ignore_keys); free(wkb->ignore_keys); } - evas_object_del(wkb->edje_obj); free(wkb->preedit_str); free(wkb->surrounding_text); } @@ -553,6 +578,20 @@ err: return ret; } +static Eina_Bool +_wkb_check_ibus_connection(void *data) +{ + static int tries = 0; + + if (tries++ > 5) + { + CRITICAL("Unable to establish connection to IBus."); + return ECORE_CALLBACK_DONE; + } + + return !wkb_ibus_is_connected(); +} + int main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { @@ -563,13 +602,13 @@ main(int argc EINA_UNUSED, char **argv EINA_UNUSED) return ret; if (!ecore_evas_init()) - goto log_err; + goto ee_err; if (!edje_init()) - goto ee_err; + goto edj_err; if (!_wkb_check_evas_engine(&wkb)) - goto edj_err; + goto engine_err; DBG("Selected engine: '%s'", wkb.ee_engine); wkb.ee = ecore_evas_new(wkb.ee_engine, 0, 0, 1, 1, "frame=0"); @@ -582,25 +621,28 @@ main(int argc EINA_UNUSED, char **argv EINA_UNUSED) _wkb_setup(&wkb); + wkb_ibus_init(); + if (!_wkb_ui_setup(&wkb)) goto end; + wkb_ibus_connect(); + ecore_timer_add(1, _wkb_check_ibus_connection, NULL); ecore_main_loop_begin(); ret = EXIT_SUCCESS; - _wkb_free(&wkb); - end: + _wkb_free(&wkb); ecore_evas_free(wkb.ee); -edj_err: +engine_err: edje_shutdown(); -ee_err: +edj_err: ecore_evas_shutdown(); -log_err: +ee_err: wkb_log_shutdown(); return ret; |