From: duna.oh Date: Wed, 24 Aug 2022 02:32:57 +0000 (+0900) Subject: ime: refactoring. delete new_input_method_context event/listener X-Git-Tag: accepted/tizen/unified/20220829.062550~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=928ee8905b7248112a372b3de94d0d6058b2d8c9;hp=c6b878a8afb44527c778f518c2da7349dfa33078;p=platform%2Fcore%2Fuifw%2Flibds-tizen.git ime: refactoring. delete new_input_method_context event/listener Change-Id: Iaf93b435f8178b8b8bf2a13d477d9a2364d20503 --- diff --git a/examples/tinyds-tdm.c b/examples/tinyds-tdm.c index 56d9412..8ffaec5 100644 --- a/examples/tinyds-tdm.c +++ b/examples/tinyds-tdm.c @@ -217,8 +217,6 @@ struct tinyds_input_method { struct wl_listener destroy; struct wl_listener mgr_destroy; - - struct wl_listener new_im_context; }; struct tinyds_input_method_context { @@ -285,6 +283,9 @@ server_view_at(struct tinyds_server *server, double lx, double ly, static bool add_new_text_input(struct tinyds_server *server); static bool add_new_input_method(struct tinyds_server *server); +static bool add_new_input_method_context( + struct tinyds_input_method *input_method, + struct tinyds_text_input *text_input); static void text_input_mgr_handle_destroy(struct wl_listener *listener, void *data TINYDS_UNUSED); @@ -296,8 +297,6 @@ static void input_method_mgr_handle_destroy(struct wl_listener *listener, static void input_method_handle_destroy(struct wl_listener *listener, void *data TINYDS_UNUSED); -static void input_method_handle_new_im_context(struct wl_listener *listener, - void *data TINYDS_UNUSED); int main(void) @@ -1827,82 +1826,6 @@ output_schedule_commit(struct tinyds_output *output) wl_event_loop_add_idle(ev, output_schedule_commit_handle_idle_timer, output); } -static bool -add_new_text_input(struct tinyds_server *server) -{ - struct tinyds_text_input *text_input; - - text_input = calloc(1, sizeof *text_input); - if (!text_input) - return false; - - text_input->text_input_mgr = ds_tizen_text_input_manager_create(server->display); - if (!text_input->text_input_mgr) { - free(text_input); - ds_err("Could not create ds_tizen_text_input_manager"); - return false; - } - - wl_list_init(&text_input->input_methods); - - text_input->destroy.notify = text_input_mgr_handle_destroy; - ds_tizen_text_input_manager_add_destroy_listener(text_input->text_input_mgr, - &text_input->destroy); - - text_input->new_text_input.notify = text_input_mgr_handle_new_text_input; - ds_tizen_text_input_manager_add_new_text_input_listener(text_input->text_input_mgr, - &text_input->new_text_input); - - text_input->server = server; - server->text_input = text_input; - - ds_inf("Text_Input (%p) added", text_input); - - return true; -} - -static bool -add_new_input_method(struct tinyds_server *server) -{ - struct tinyds_input_method *input_method; - - input_method = calloc(1, sizeof *input_method); - if (!input_method) - return false; - - input_method->input_method = ds_tizen_input_method_create(server->display); - if (!input_method->input_method) { - free(input_method); - ds_err("Could not create ds_tizen_input_method"); - return false; - } - input_method->destroy.notify = input_method_handle_destroy; - ds_tizen_input_method_add_destroy_listener(input_method->input_method, - &input_method->destroy); - - input_method->input_method_mgr = ds_tizen_input_method_manager_create(server->display); - if (!input_method->input_method_mgr) { - free(input_method); - ds_err("Could not create ds_tizen_input_method_manager"); - return false; - } - - input_method->mgr_destroy.notify = input_method_mgr_handle_destroy; - ds_tizen_input_method_manager_add_destroy_listener(input_method->input_method_mgr, - &input_method->mgr_destroy); - - input_method->new_im_context.notify = input_method_handle_new_im_context; - ds_tizen_input_method_add_new_input_method_context_listener(input_method->input_method, - &input_method->new_im_context); - - input_method->server = server; - server->input_method = input_method; - - ds_inf("Input_Method (%p) added", input_method); - - return true; -} - static void text_input_mgr_handle_destroy(struct wl_listener *listener, void *data) { @@ -1935,7 +1858,7 @@ static void text_input_handle_destroy(struct wl_listener *listener, void *data) { struct tinyds_text_input *text_input; - + ds_inf("text_input_handle_destroy"); text_input = wl_container_of(listener, text_input, destroy); @@ -1948,7 +1871,6 @@ text_input_handle_activate(struct wl_listener *listener, void *data) { struct tinyds_text_input *text_input; struct tinyds_input_method *input_method; - struct tinyds_input_method_context *context; struct ds_tizen_text_input_event_activate *event = data; text_input = wl_container_of(listener, text_input, text_input_activate); @@ -1967,17 +1889,8 @@ text_input_handle_activate(struct wl_listener *listener, void *data) text_input->surface = event->surface; - context = calloc(1, sizeof *context); - if (context == NULL) - { - ds_err("calloc is failed. tinyds_input_method_context"); + if (!add_new_input_method_context(input_method, text_input)) return; - } - input_method->context = context; - context->server = text_input->server; - context->context = ds_tizen_input_method_create_context(input_method->input_method); - context->input = text_input; - context->input_method = input_method; // ds_tizen_input_method_send_set_text_input_id(); } @@ -2165,7 +2078,6 @@ input_method_handle_destroy(struct wl_listener *listener, void *data) input_method = wl_container_of(listener, input_method, destroy); wl_list_remove(&input_method->destroy.link); - wl_list_remove(&input_method->new_im_context.link); server = input_method->server; server->input_method = NULL; @@ -2410,71 +2322,152 @@ context_handle_text_direction(struct wl_listener *listener, void *data) ds_tizen_text_input_send_text_direction(text_input->input, event->serial, event->direction); } -static void -input_method_handle_new_im_context(struct wl_listener *listener, void *data) +static bool +add_new_text_input(struct tinyds_server *server) +{ + struct tinyds_text_input *text_input; + + text_input = calloc(1, sizeof *text_input); + if (!text_input) + return false; + + text_input->text_input_mgr = ds_tizen_text_input_manager_create(server->display); + if (!text_input->text_input_mgr) { + free(text_input); + ds_err("Could not create ds_tizen_text_input_manager"); + return false; + } + + wl_list_init(&text_input->input_methods); + + text_input->destroy.notify = text_input_mgr_handle_destroy; + ds_tizen_text_input_manager_add_destroy_listener(text_input->text_input_mgr, + &text_input->destroy); + + text_input->new_text_input.notify = text_input_mgr_handle_new_text_input; + ds_tizen_text_input_manager_add_new_text_input_listener(text_input->text_input_mgr, + &text_input->new_text_input); + + text_input->server = server; + server->text_input = text_input; + + ds_inf("Text_Input (%p) added", text_input); + + return true; +} + +static bool +add_new_input_method(struct tinyds_server *server) { - struct ds_tizen_input_method_context *context = data; struct tinyds_input_method *input_method; - struct tinyds_input_method_context *ctx; - ds_inf("input_method_handle_new_im_context"); + input_method = calloc(1, sizeof *input_method); + if (!input_method) + return false; + + input_method->input_method = ds_tizen_input_method_create(server->display); + if (!input_method->input_method) { + free(input_method); + ds_err("Could not create ds_tizen_input_method"); + return false; + } + input_method->destroy.notify = input_method_handle_destroy; + ds_tizen_input_method_add_destroy_listener(input_method->input_method, + &input_method->destroy); + + input_method->input_method_mgr = ds_tizen_input_method_manager_create(server->display); + if (!input_method->input_method_mgr) { + free(input_method); + ds_err("Could not create ds_tizen_input_method_manager"); + return false; + } - input_method = wl_container_of(listener, input_method, new_im_context); - ctx = input_method->context; + input_method->mgr_destroy.notify = input_method_mgr_handle_destroy; + ds_tizen_input_method_manager_add_destroy_listener(input_method->input_method_mgr, + &input_method->mgr_destroy); - ctx->destroy.notify = context_handle_destroy; - ds_tizen_input_method_context_add_destroy_listener(context, - &ctx->destroy); + input_method->server = server; + server->input_method = input_method; - ctx->im_context_commit_string.notify = context_handle_commit_string; - ds_tizen_input_method_context_add_commit_string_listener(context, - &ctx->im_context_commit_string); + ds_inf("Input_Method (%p) added", input_method); - ctx->im_context_preedit_string.notify = context_handle_preedit_string; - ds_tizen_input_method_context_add_preedit_string_listener(context, - &ctx->im_context_preedit_string); + return true; +} - ctx->im_context_preedit_styling.notify = context_handle_preedit_styling; - ds_tizen_input_method_context_add_preedit_styling_listener(context, - &ctx->im_context_preedit_styling); +static bool +add_new_input_method_context(struct tinyds_input_method *input_method, + struct tinyds_text_input *text_input) +{ + struct tinyds_input_method_context *context; - ctx->im_context_preedit_cursor.notify = context_handle_preedit_cursor; - ds_tizen_input_method_context_add_preedit_cursor_listener(context, - &ctx->im_context_preedit_cursor); + context = calloc(1, sizeof *context); + if (context == NULL) + { + ds_err("calloc is failed. tinyds_input_method_context"); + return false; + } + input_method->context = context; + context->input_method = input_method; + context->server = input_method->server; + context->input = text_input; + + context->context = ds_tizen_input_method_create_context(input_method->input_method); + + context->destroy.notify = context_handle_destroy; + ds_tizen_input_method_context_add_destroy_listener(context->context, + &context->destroy); + + context->im_context_commit_string.notify = context_handle_commit_string; + ds_tizen_input_method_context_add_commit_string_listener(context->context, + &context->im_context_commit_string); - ctx->im_context_delete_surrounding_text.notify = context_handle_delete_surrounding_text; - ds_tizen_input_method_context_add_delete_surrounding_text_listener(context, - &ctx->im_context_delete_surrounding_text); + context->im_context_preedit_string.notify = context_handle_preedit_string; + ds_tizen_input_method_context_add_preedit_string_listener(context->context, + &context->im_context_preedit_string); - ctx->im_context_cursor_position.notify = context_handle_cursor_position; - ds_tizen_input_method_context_add_cursor_position_listener(context, - &ctx->im_context_cursor_position); + context->im_context_preedit_styling.notify = context_handle_preedit_styling; + ds_tizen_input_method_context_add_preedit_styling_listener(context->context, + &context->im_context_preedit_styling); - ctx->im_context_modifiers_map.notify = context_handle_modifiers_map; - ds_tizen_input_method_context_add_modifiers_map_listener(context, - &ctx->im_context_modifiers_map); + context->im_context_preedit_cursor.notify = context_handle_preedit_cursor; + ds_tizen_input_method_context_add_preedit_cursor_listener(context->context, + &context->im_context_preedit_cursor); - ctx->im_context_keysym.notify = context_handle_keysym; - ds_tizen_input_method_context_add_keysym_listener(context, - &ctx->im_context_keysym); + context->im_context_delete_surrounding_text.notify = context_handle_delete_surrounding_text; + ds_tizen_input_method_context_add_delete_surrounding_text_listener(context->context, + &context->im_context_delete_surrounding_text); - ctx->im_context_grab_keyboard.notify = context_handle_grab_keyboard; - ds_tizen_input_method_context_add_grab_keyboard_listener(context, - &ctx->im_context_grab_keyboard); + context->im_context_cursor_position.notify = context_handle_cursor_position; + ds_tizen_input_method_context_add_cursor_position_listener(context->context, + &context->im_context_cursor_position); - ctx->im_context_key.notify = context_handle_key; - ds_tizen_input_method_context_add_key_listener(context, - &ctx->im_context_key); + context->im_context_modifiers_map.notify = context_handle_modifiers_map; + ds_tizen_input_method_context_add_modifiers_map_listener(context->context, + &context->im_context_modifiers_map); - ctx->im_context_modifiers.notify = context_handle_modifiers; - ds_tizen_input_method_context_add_modifiers_listener(context, - &ctx->im_context_modifiers); + context->im_context_keysym.notify = context_handle_keysym; + ds_tizen_input_method_context_add_keysym_listener(context->context, + &context->im_context_keysym); - ctx->im_context_language.notify = context_handle_language; - ds_tizen_input_method_context_add_language_listener(context, - &ctx->im_context_language); + context->im_context_grab_keyboard.notify = context_handle_grab_keyboard; + ds_tizen_input_method_context_add_grab_keyboard_listener(context->context, + &context->im_context_grab_keyboard); - ctx->im_context_text_direction.notify = context_handle_text_direction; - ds_tizen_input_method_context_add_text_direction_listener(context, - &ctx->im_context_text_direction); + context->im_context_key.notify = context_handle_key; + ds_tizen_input_method_context_add_key_listener(context->context, + &context->im_context_key); + + context->im_context_modifiers.notify = context_handle_modifiers; + ds_tizen_input_method_context_add_modifiers_listener(context->context, + &context->im_context_modifiers); + + context->im_context_language.notify = context_handle_language; + ds_tizen_input_method_context_add_language_listener(context->context, + &context->im_context_language); + + context->im_context_text_direction.notify = context_handle_text_direction; + ds_tizen_input_method_context_add_text_direction_listener(context->context, + &context->im_context_text_direction); + + return true; } diff --git a/include/libds-tizen/input_method.h b/include/libds-tizen/input_method.h index 2209026..c6a40c2 100644 --- a/include/libds-tizen/input_method.h +++ b/include/libds-tizen/input_method.h @@ -103,9 +103,6 @@ ds_tizen_input_method_create_context(struct ds_tizen_input_method *input_method) void ds_tizen_input_method_add_destroy_listener( struct ds_tizen_input_method *im, struct wl_listener *listener); -void -ds_tizen_input_method_add_new_input_method_context_listener( - struct ds_tizen_input_method *im, struct wl_listener *listener); // events void ds_tizen_input_method_send_activate(struct ds_tizen_input_method *im, diff --git a/src/input_method/input_method.c b/src/input_method/input_method.c index eb6232b..8eed2f2 100644 --- a/src/input_method/input_method.c +++ b/src/input_method/input_method.c @@ -42,7 +42,6 @@ struct ds_tizen_input_method { struct { struct wl_signal destroy; - struct wl_signal new_input_method_context; } events; }; @@ -115,30 +114,23 @@ static const struct zwp_input_method_manager_v1_interface input_method_mgr_impl }; static void -input_method_mgr_client_handle_destroy(struct wl_resource *resource) -{ - ds_inf("input_method_mgr_client_handle_destroy"); -} - -static void input_method_mgr_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { struct ds_tizen_input_method_manager *input_method_mgr = data; - struct wl_resource *resource; ds_inf("input_method_mgr. client binds. (client:%p)", wl_client); - resource = wl_resource_create(wl_client, + input_method_mgr->resource = wl_resource_create(wl_client, &zwp_input_method_manager_v1_interface, version, id); - if (resource == NULL) { + if (input_method_mgr->resource == NULL) { ds_err("input_method_mgr. wl_resource_create() failed."); wl_client_post_no_memory(wl_client); return; } - wl_resource_set_implementation(resource, &input_method_mgr_impl, - input_method_mgr, input_method_mgr_client_handle_destroy); + wl_resource_set_implementation(input_method_mgr->resource, &input_method_mgr_impl, + input_method_mgr, NULL); } WL_EXPORT struct ds_tizen_input_method_manager * @@ -178,13 +170,6 @@ ds_tizen_input_method_add_destroy_listener( } WL_EXPORT void -ds_tizen_input_method_add_new_input_method_context_listener( - struct ds_tizen_input_method *im, struct wl_listener *listener) -{ - wl_signal_add(&im->events.new_input_method_context, listener); -} - -WL_EXPORT void ds_tizen_input_method_send_activate(struct ds_tizen_input_method *im, struct ds_tizen_input_method_context *context) { @@ -243,6 +228,10 @@ ds_tizen_input_method_create_context(struct ds_tizen_input_method *input_method) if (!binding) return NULL; context->resource = wl_resource_create(wl_resource_get_client(binding), &zwp_input_method_context_v1_interface, INPUT_METHOD_VERSION, 0); + if (context->resource == NULL) { + ds_err("context. wl_resource_create() failed."); + return NULL; + } wl_resource_set_implementation(context->resource, &context_impl, context, input_method_context_client_handle_destroy); @@ -261,8 +250,6 @@ ds_tizen_input_method_create_context(struct ds_tizen_input_method *input_method) wl_signal_init(&context->events.language); wl_signal_init(&context->events.text_direction); - wl_signal_emit(&input_method->events.new_input_method_context, context); - ds_tizen_input_method_send_activate(input_method, context); input_method->context = context; @@ -675,12 +662,6 @@ input_method_handle_display_destroy(struct wl_listener *listener, void *data) } static void -input_method_client_handle_destroy(struct wl_resource *resource) -{ - ds_inf("input_method_client_handle_destroy"); -} - -static void input_method_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { @@ -697,7 +678,7 @@ input_method_bind(struct wl_client *wl_client, void *data, return; } wl_resource_set_implementation(input_method->resource, NULL, - input_method, input_method_client_handle_destroy); + input_method, NULL); } WL_EXPORT struct ds_tizen_input_method * @@ -719,7 +700,6 @@ ds_tizen_input_method_create(struct wl_display *display) } wl_signal_init(&input_method->events.destroy); - wl_signal_init(&input_method->events.new_input_method_context); input_method->destroy.notify = input_method_handle_display_destroy; wl_display_add_destroy_listener(display, &input_method->destroy); diff --git a/src/text_input/text_input.c b/src/text_input/text_input.c index 7a9c4f2..05adda7 100644 --- a/src/text_input/text_input.c +++ b/src/text_input/text_input.c @@ -472,12 +472,6 @@ static const struct wl_text_input_manager_interface text_input_mgr_impl = }; static void -text_input_mgr_client_handle_destroy(struct wl_resource *resource) -{ - ds_inf("text_input_mgr_client_handle_destroy"); -} - -static void text_input_mgr_bind(struct wl_client *wl_client, void *data, uint32_t version, uint32_t id) { @@ -495,7 +489,7 @@ text_input_mgr_bind(struct wl_client *wl_client, void *data, return; } wl_resource_set_implementation(resource, &text_input_mgr_impl, - text_input_mgr, text_input_mgr_client_handle_destroy); + text_input_mgr, NULL); } WL_EXPORT struct ds_tizen_text_input_manager * diff --git a/tests/tc_input_method.cpp b/tests/tc_input_method.cpp index 1bbc1be..a9b1ecf 100644 --- a/tests/tc_input_method.cpp +++ b/tests/tc_input_method.cpp @@ -41,13 +41,6 @@ public: mockComp->mDestroyListener.parent = mockComp; ds_tizen_input_method_add_destroy_listener(mockComp->mInputMethod, &mockComp->mDestroyListener); - - // new input method context listener - mockComp->mNewInputMethodContextListener.notify = - MockInputMethodCompositor::NewInputMethodContextCallback; - mockComp->mNewInputMethodContextListener.parent = mockComp; - ds_tizen_input_method_add_new_input_method_context_listener(mockComp->mInputMethod, - &mockComp->mNewInputMethodContextListener); } static void DestroyCallback(struct wl_listener *listener, void *data) @@ -60,26 +53,13 @@ public: mockComp->bDestroyed = true; } - static void NewInputMethodContextCallback(struct wl_listener *listener, void *data) - { - ds_inf("%s", __func__); - - MockInputMethodCompositor *mockComp = - reinterpret_cast(listener)->parent; - struct ds_tizen_input_method_context *context = - static_cast(data); - - ds_inf("%s: mockComp(%p), input_method_context(%p)", __func__, mockComp, context); - - mockComp->mInputMethodContext = context; - mockComp->bNewInputMethodContext = true; - } - void CreateInputMethodContext() { ds_inf("%s", __func__); - ds_tizen_input_method_create_context(mInputMethod); + mInputMethodContext = ds_tizen_input_method_create_context(mInputMethod); + if (mInputMethodContext) + bNewInputMethodContext = true; } void SendActivate() @@ -109,11 +89,6 @@ private: MockInputMethodCompositor *parent; }; DestroyListener mDestroyListener; - - struct NewInputMethodContextListener: ::wl_listener { - MockInputMethodCompositor *parent; - }; - NewInputMethodContextListener mNewInputMethodContextListener; }; class MockInputMethodClient : public MockClient