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 LOGD("text_input_manager = %p", text_input_manager);
140 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom,
141 "bound wl_text_input_manager interface");
145 eina_iterator_free (globals);
147 if (!text_input_manager)
151 ctxd = wayland_im_context_new(text_input_manager);
152 if (!ctxd) return NULL;
154 ctx = ecore_imf_context_new(&wayland_imf_class);
160 ecore_imf_context_data_set(ctx, ctxd);
161 wayland_im_context_pair_set(ctx, ctxd);
166 ecore_wl2_init_count = 0;
168 ecore_wl2_display_disconnect(ewd);
172 ecore_wl2_shutdown();
181 _ecore_imf_wayland_log_dom =
182 eina_log_domain_register("ecore_imf_wayland", EINA_COLOR_YELLOW);
184 if (!getenv("WAYLAND_DISPLAY")) return EINA_FALSE;
185 if ((s = getenv("ELM_DISPLAY"))) {
186 if (strcmp(s, "wl")) return EINA_FALSE;
189 ecore_imf_module_register(&wayland_im_info, im_module_create,
192 // TIZEN_ONLY(20150708): Support back key
193 wayland_im_initialize ();
195 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom, "im module initialized");
201 im_module_shutdown(void)
203 // TIZEN_ONLY(20150708): Support back key
204 wayland_im_uninitialize ();
206 EINA_LOG_DOM_INFO(_ecore_imf_wayland_log_dom, "im module shutdown");
209 ecore_wl2_display_disconnect(ewd);
211 if (ecore_wl2_init_count > 0)
212 ecore_wl2_shutdown();
215 EINA_MODULE_INIT(im_module_init);
216 EINA_MODULE_SHUTDOWN(im_module_shutdown);