2 * Copyright © 2012, 2013 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <Ecore_IMF.h>
25 #define EFL_BETA_API_SUPPORT
26 #include <Ecore_Wl2.h>
30 #include "wayland_imcontext.h"
31 #include <text-client-protocol.h>
36 #define LOG_TAG "IMMODULE"
38 int _ecore_imf_wayland_log_dom = -1;
39 static int ecore_wl2_init_count = 0;
40 static Ecore_Wl2_Display *ewd = NULL;
42 static const Ecore_IMF_Context_Info wayland_im_info =
51 static Ecore_IMF_Context_Class wayland_imf_class =
53 wayland_im_context_add, /* add */
54 wayland_im_context_del, /* del */
55 wayland_im_context_client_window_set, /* client_window_set */
56 wayland_im_context_client_canvas_set, /* client_canvas_set */
57 wayland_im_context_show, /* show */
58 wayland_im_context_hide, /* hide */
59 wayland_im_context_preedit_string_get, /* get_preedit_string */
60 wayland_im_context_focus_in, /* focus_in */
61 wayland_im_context_focus_out, /* focus_out */
62 wayland_im_context_reset, /* reset */
63 wayland_im_context_cursor_position_set, /* cursor_position_set */
64 wayland_im_context_use_preedit_set, /* use_preedit_set */
65 wayland_im_context_input_mode_set, /* input_mode_set */
66 wayland_im_context_filter_event, /* filter_event */
67 wayland_im_context_preedit_string_with_attributes_get, /* preedit_string_with_attribute_get */
68 wayland_im_context_prediction_allow_set, /* prediction_allow_set */
69 wayland_im_context_autocapital_type_set, /* autocapital_type_set */
70 NULL, /* control panel show */
71 NULL, /* control panel hide */
72 wayland_im_context_input_panel_layout_set, /* input_panel_layout_set */
73 wayland_im_context_input_panel_layout_get, /* input_panel_layout_get */
74 wayland_im_context_input_panel_language_set,/* input_panel_language_set, */
75 NULL, /* input_panel_language_get, */
76 wayland_im_context_cursor_location_set, /* cursor_location_set */
77 wayland_im_context_input_panel_imdata_set, /* input_panel_imdata_set */
78 wayland_im_context_input_panel_imdata_get, /* input_panel_imdata_get */
79 wayland_im_context_input_panel_return_key_type_set, /* input_panel_return_key_type_set */
80 wayland_im_context_input_panel_return_key_disabled_set, /* input_panel_return_key_disabled_set */
81 NULL, /* input_panel_caps_lock_mode_set */
82 wayland_im_context_input_panel_geometry_get, /* input_panel_geometry_get */
83 wayland_im_context_input_panel_state_get, /* input_panel_state_get */
84 NULL, /* input_panel_event_callback_add */
85 NULL, /* input_panel_event_callback_del */
86 wayland_im_context_input_panel_language_locale_get, /* input_panel_language_locale_get */
87 NULL, /* candidate_window_geometry_get */
88 wayland_im_context_input_hint_set, /* input_hint_set */
89 wayland_im_context_bidi_direction_set, /* bidi_direction_set */
90 wayland_im_context_input_panel_keyboard_mode_get, /* input_panel_keyboard_mode_get */
91 wayland_im_context_prediction_hint_set, /* prediction_hint_set */
92 wayland_im_context_mime_type_accept_set, /* mime_type_accept_set */
93 wayland_im_context_input_panel_position_set/* input_panel_position_set */
96 static struct wl_text_input_manager *text_input_manager = NULL;
98 static Ecore_IMF_Context *
104 static Ecore_IMF_Context *
107 Ecore_IMF_Context *ctx = NULL;
108 WaylandIMContext *ctxd = NULL;
110 if (!text_input_manager) {
111 Ecore_Wl2_Global *global;
112 struct wl_registry *registry;
113 Eina_Iterator *globals;
115 ecore_wl2_init_count = ecore_wl2_init();
116 if (!ecore_wl2_init_count) {
117 LOGE("Could not initialize ecore_wl2");
121 ewd = ecore_wl2_display_connect(NULL);
123 LOGE("Could not connect to Wayland Display");
127 if (!(registry = ecore_wl2_display_registry_get(ewd)))
130 if (!(globals = ecore_wl2_display_globals_get(ewd)))
133 EINA_ITERATOR_FOREACH(globals, global)
135 if (!strcmp(global->interface, "wl_text_input_manager")) {
137 wl_registry_bind(registry, global->id,
138 &wl_text_input_manager_interface, 1);
139 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom,
140 "bound wl_text_input_manager interface");
144 eina_iterator_free (globals);
146 if (!text_input_manager)
150 ctxd = wayland_im_context_new(text_input_manager);
151 if (!ctxd) return NULL;
153 ctx = ecore_imf_context_new(&wayland_imf_class);
159 ecore_imf_context_data_set(ctx, ctxd);
160 wayland_im_context_pair_set(ctx, ctxd);
165 ecore_wl2_init_count = 0;
167 ecore_wl2_display_disconnect(ewd);
171 ecore_wl2_shutdown();
180 _ecore_imf_wayland_log_dom =
181 eina_log_domain_register("ecore_imf_wayland", EINA_COLOR_YELLOW);
183 if (!getenv("WAYLAND_DISPLAY")) return EINA_FALSE;
184 if ((s = getenv("ELM_DISPLAY"))) {
185 if (strcmp(s, "wl")) return EINA_FALSE;
188 ecore_imf_module_register(&wayland_im_info, im_module_create,
191 // TIZEN_ONLY(20150708): Support back key
192 wayland_im_initialize ();
194 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom, "im module initialized");
200 im_module_shutdown(void)
202 // TIZEN_ONLY(20150708): Support back key
203 wayland_im_uninitialize ();
205 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom, "im module shutdown");
208 ecore_wl2_display_disconnect(ewd);
210 if (ecore_wl2_init_count > 0)
211 ecore_wl2_shutdown();
214 EINA_MODULE_INIT(im_module_init);
215 EINA_MODULE_SHUTDOWN(im_module_shutdown);