Remove unused variable
[platform/core/uifw/libscl-core.git] / src / sclcoreui-efl.cpp
1 /*
2  * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "sclcoreui-efl.h"
19 #include "sclcoreimpl.h"
20 #include <Elementary.h>
21 #include <dlog.h>
22 #include <appcore-efl.h>
23
24 #include <vconf.h>
25 #include <vconf-keys.h>
26
27 #include <glib.h>
28 #ifdef WAYLAND
29 #include <Ecore_Wayland.h>
30 #include <input-method-client-protocol.h>
31 #else
32 #include <Ecore_X.h>
33 #include <X11/Xlib.h>
34 #include <X11/Xatom.h>
35 #endif
36
37 #ifdef WEBSOCKET
38  /* This websocket agent is for supporting Tizen 2.X legacy web IMEs that uses websocket */
39 CWebHelperAgentWebSocket g_websocket;
40 #endif
41
42 static struct appcore_ops ops;
43
44 #ifdef WAYLAND
45 struct WaylandKeyboard
46 {
47     Ecore_Evas *ee;
48     Ecore_Wl_Window *wl_win;
49     const char *ee_engine;
50
51     struct wl_surface *surface;
52     struct wl_input_panel *ip;
53     struct wl_output *output;
54     struct wl_input_panel_surface *ips;
55 };
56
57 struct WaylandKeyboard wlkb = {0};
58
59 #define RENDER_PRE_TIMEOUT 1.0f
60 static Ecore_Timer *_render_pre_timer = NULL;
61 static void delete_render_pre_timer()
62 {
63     if (_render_pre_timer) {
64         ecore_timer_del(_render_pre_timer);
65         _render_pre_timer = NULL;
66     }
67 }
68 #endif
69
70 using namespace scl;
71
72 CSCLCoreUIEFL::CSCLCoreUIEFL()
73 {
74     m_initialized = FALSE;
75
76     m_backend_identifier = "EFL";
77
78     m_rotation_degree = 0;
79     m_main_window = SCLWINDOW_INVALID;
80     m_uuid = NULL;
81     m_display = NULL;
82 }
83
84 CSCLCoreUIEFL::~CSCLCoreUIEFL()
85 {
86 }
87
88 sclboolean CSCLCoreUIEFL::init()
89 {
90     m_initialized = TRUE;
91     m_rotation_degree = -1;
92
93     for (int loop = 0;loop < OPTION_WINDOW_TYPE_MAX;loop++) {
94         m_option_window_info[loop].window = SCLWINDOW_INVALID;
95     }
96
97 #ifdef WEBSOCKET
98     g_websocket.init();
99 #endif
100
101     return TRUE;
102 }
103
104 void CSCLCoreUIEFL::fini()
105 {
106     m_initialized = FALSE;
107
108 #ifdef WEBSOCKET
109     g_websocket.exit();
110 #endif
111 }
112
113 sclwindow CSCLCoreUIEFL::get_main_window()
114 {
115     if (m_initialized) {
116         return m_main_window;
117     } else {
118         return NULL;
119     }
120 }
121
122 void CSCLCoreUIEFL::set_keyboard_size_hints(SclSize portrait, SclSize landscape)
123 {
124     Evas_Object *main_window = NATIVE_WINDOW_CAST(m_main_window);
125
126 #ifdef WAYLAND
127     ecore_wl_window_rotation_geometry_set(elm_win_wl_window_get(main_window),   0, 0, 0, portrait.width, portrait.height);
128     ecore_wl_window_rotation_geometry_set(elm_win_wl_window_get(main_window),  90, 0, 0, landscape.height, landscape.width);
129     ecore_wl_window_rotation_geometry_set(elm_win_wl_window_get(main_window), 180, 0, 0, portrait.width, portrait.height);
130     ecore_wl_window_rotation_geometry_set(elm_win_wl_window_get(main_window), 270, 0, 0, landscape.height, landscape.width);
131 #else
132     /*
133     ecore_x_e_window_rotation_geometry_set(elm_win_xwindow_get(main_window),   0, 0, 0, portrait.width, portrait.height);
134     ecore_x_e_window_rotation_geometry_set(elm_win_xwindow_get(main_window),  90, 0, 0, landscape.height, landscape.width);
135     ecore_x_e_window_rotation_geometry_set(elm_win_xwindow_get(main_window), 180, 0, 0, portrait.width, portrait.height);
136     ecore_x_e_window_rotation_geometry_set(elm_win_xwindow_get(main_window), 270, 0, 0, landscape.height, landscape.width);
137     */
138 #endif
139 }
140
141 static void language_changed_cb(keynode_t *key, void* data)
142 {
143     char clang[_POSIX_PATH_MAX] = {0};
144     char *vconf_str = vconf_get_str(VCONFKEY_LANGSET);
145     if (vconf_str) {
146         snprintf(clang, sizeof(clang), "%s", vconf_str);
147         free(vconf_str);
148     }
149     LOGD("current language is %s\n", clang);
150
151     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
152     if (impl) {
153         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
154         if (callback) {
155             callback->on_set_display_language(clang);
156         }
157     }
158 }
159
160 static void accessibility_changed_cb(keynode_t *key, void* data)
161 {
162     int vconf_value = 0;
163     if (vconf_get_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, &vconf_value) == 0) {
164         LOGD("accessibility state : %d\n", vconf_value);
165
166         CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
167         if (impl) {
168             ISCLCoreEventCallback *callback = impl->get_core_event_callback();
169             if (callback) {
170                 callback->on_set_accessibility_state(vconf_value);
171             }
172         }
173     }
174 }
175
176 #ifdef WAYLAND
177 static void win_rotation_changed_cb(void *data, Evas_Object *obj, void *event)
178 {
179     int degree = elm_win_rotation_get(obj);
180     LOGD("rotation angle : %d\n", degree);
181
182     ISCLCoreEventCallback *callback = NULL;
183     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
184     if (impl) {
185         callback = impl->get_core_event_callback();
186     }
187
188     CSCLCoreUIEFL *coreui = static_cast<CSCLCoreUIEFL*>(data);
189     if (coreui) {
190         coreui->set_screen_rotation_degree(degree);
191     }
192     if (callback) {
193         callback->on_set_rotation_degree(degree);
194     }
195 }
196 #else
197 static Eina_Bool _client_message_cb(void *data, int type, void *event)
198 {
199     Ecore_X_Event_Client_Message *ev = (Ecore_X_Event_Client_Message *)event;
200
201     ISCLCoreEventCallback *callback = NULL;
202     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
203     Evas_Object *main_window = NULL;
204     if (impl) {
205         callback = impl->get_core_event_callback();
206         main_window = NATIVE_WINDOW_CAST(impl->get_main_window());
207     }
208
209 #ifndef APPLY_WINDOW_MANAGER_CHANGE
210 #else
211     if (ev->message_type == ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE) {
212         LOGD("ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE , %d %d\n", ev->data.l[0], gFHiddenState);
213         angle = ev->data.l[0];
214         ise_set_screen_direction(angle);
215         if (!gFHiddenState) {
216             ise_show(gLastIC);
217         }
218     } else if (ev->message_type == ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE) {
219         LOGD("ECORE_X_ATOM_E_VIRTUAL_KEYBOARD_STATE , %d\n", ev->data.l[0]);
220         elm_win_keyboard_mode_set(main_window, (Elm_Win_Keyboard_Mode)(ev->data.l[0]));
221         gFHiddenState = !(ev->data.l[0]);
222     }
223 #endif
224
225     if (ev->message_type == ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST) {
226         if (ev->win == elm_win_xwindow_get(main_window)) {
227             int degree = ev->data.l[1];
228             CSCLCoreUIEFL *coreui = static_cast<CSCLCoreUIEFL*>(data);
229             if (coreui) {
230                 coreui->set_screen_rotation_degree(degree);
231             }
232             LOGD("_ECORE_X_ATOM_E_WINDOW_ROTATION_REQUEST, %d\n", degree);
233             if (callback) {
234                 callback->on_set_rotation_degree(degree);
235             }
236             Ecore_X_Window control_window = 0;
237             Ecore_X_Atom atom = ecore_x_atom_get("_ISF_CONTROL_WINDOW");
238             Ecore_X_Window root = ecore_x_window_root_first_get();
239             if (ecore_x_window_prop_xid_get(root, atom, ECORE_X_ATOM_WINDOW, &control_window, 1) == 1) {
240                 ecore_x_client_message32_send(control_window, ECORE_X_ATOM_E_WINDOW_ROTATION_CHANGE_REQUEST,
241                     ECORE_X_EVENT_MASK_WINDOW_CONFIGURE,
242                     ev->data.l[0], ev->data.l[1], ev->data.l[2], ev->data.l[3], ev->data.l[4]);
243             }
244         }
245     }
246
247     return ECORE_CALLBACK_RENEW;
248 }
249 #endif
250
251 int CSCLCoreUIEFL::get_screen_rotation_degree()
252 {
253     int angle = 0;
254
255 #ifdef WAYLAND
256     angle = elm_win_rotation_get(NATIVE_WINDOW_CAST(m_main_window));
257 #else
258     if (m_rotation_degree == -1) {
259         int  ret = 0;
260         Atom type_return;
261         int  format_return;
262         unsigned long    nitems_return;
263         unsigned long    bytes_after_return;
264         unsigned char   *data_window = NULL;
265         unsigned char   *data_angle = NULL;
266
267         Ecore_X_Window app_window = 0;
268
269         Evas_Object *keypad_win = NATIVE_WINDOW_CAST(m_main_window);
270
271         LOGD("Trying to get app window degree for %p\n", keypad_win);
272         Ecore_X_Window win = elm_win_xwindow_get(NATIVE_WINDOW_CAST(keypad_win));
273         ret = XGetWindowProperty((Display *)ecore_x_display_get(),
274             ecore_x_window_root_get(win),
275             ecore_x_atom_get("_ISF_ACTIVE_WINDOW"),
276             0, G_MAXLONG, False, XA_WINDOW, &type_return,
277             &format_return, &nitems_return, &bytes_after_return,
278             &data_window);
279
280         if (ret == Success) {
281             if ((type_return == XA_WINDOW) && (format_return == 32) && (data_window)) {
282                 app_window = *(Window *)data_window;
283
284                 ret = XGetWindowProperty((Display *)ecore_x_display_get(), app_window,
285                     ecore_x_atom_get("_E_ILLUME_ROTATE_WINDOW_ANGLE"),
286                     0, G_MAXLONG, False, XA_CARDINAL, &type_return,
287                     &format_return, &nitems_return, &bytes_after_return,
288                     &data_angle);
289
290                 LOGD("app_window : %p, ret %d, %d, %p\n", app_window, ret, type_return, data_angle);
291                 if (ret == Success) {
292                     if (data_angle) {
293                         if (type_return == XA_CARDINAL) {
294                             angle = *(unsigned int*)data_angle;
295                             LOGD("current rotation angle is %p %d\n", app_window, angle);
296                         }
297                         XFree(data_angle);
298                     }
299                 }
300             }
301             if (data_window)
302                 XFree(data_window);
303         }
304     } else {
305         angle = m_rotation_degree;
306     }
307 #endif
308
309     return angle;
310 }
311
312 static void signal_handler(int sig) {
313     elm_exit();
314 }
315
316 #ifdef WAYLAND
317 static bool
318 _wayland_setup(struct WaylandKeyboard *wlkb, Evas_Object *main_window)
319 {
320     Eina_Inlist *globals;
321     struct wl_registry *registry;
322     Ecore_Wl_Global *global;
323
324     if (!(registry = ecore_wl_registry_get()))
325         return false;
326
327     if (!(globals = ecore_wl_globals_get()))
328         return false;
329
330     EINA_INLIST_FOREACH(globals, global)
331     {
332         if (strcmp(global->interface, "wl_input_panel") == 0)
333             wlkb->ip = (wl_input_panel *)wl_registry_bind(registry, global->id, &wl_input_panel_interface, 1);
334         else if (strcmp(global->interface, "wl_output") == 0)
335             wlkb->output = (wl_output *)wl_registry_bind(registry, global->id, &wl_output_interface, 1);
336     }
337
338     if (!wlkb->ip) {
339         LOGW("Can't get wayland input panel interface\n");
340         return false;
341     }
342
343     if (!wlkb->output) {
344         LOGW("Can't get wayland output interface\n");
345         return false;
346     }
347
348     wlkb->ee = ecore_evas_ecore_evas_get(evas_object_evas_get(main_window));
349     if (!wlkb->ee) {
350         LOGW("ERROR: Unable to create Ecore_Evas object\n");
351         return false;
352     }
353
354     /* Set input panel surface */
355     LOGD("Setting up input panel\n");
356     wlkb->wl_win = ecore_evas_wayland_window_get(wlkb->ee);
357     if (!wlkb->wl_win) {
358         LOGW("Couldn't get wayland window\n");
359         return false;
360     }
361
362     ecore_wl_window_type_set(wlkb->wl_win, ECORE_WL_WINDOW_TYPE_NONE);
363     wlkb->surface = ecore_wl_window_surface_create(wlkb->wl_win);
364     if (!wlkb->surface) {
365         LOGW("Couldn't create surface\n");
366         return false;
367     }
368
369     wlkb->ips = wl_input_panel_get_input_panel_surface(wlkb->ip, wlkb->surface);
370     if (!wlkb->ips) {
371         LOGW("Couldn't get input panel surface\n");
372         return false;
373     }
374
375     wl_input_panel_surface_set_toplevel(wlkb->ips, wlkb->output, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM);
376
377     return true;
378 }
379
380 static Eina_Bool
381 check_evas_engine(struct WaylandKeyboard *wlkb)
382 {
383     Eina_Bool ret = EINA_FALSE;
384     const char *env = getenv("ECORE_EVAS_ENGINE");
385
386     if (!env) {
387         if (ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_SHM)) {
388             env = "wayland_shm";
389         } else if (ecore_evas_engine_type_supported_get(ECORE_EVAS_ENGINE_WAYLAND_EGL)) {
390             env = "wayland_egl";
391         } else {
392             LOGW("ERROR: Ecore_Evas does must be compiled with support for Wayland engines\n");
393             goto err;
394         }
395     } else if (strcmp(env, "wayland_shm") != 0 && strcmp(env, "wayland_egl") != 0) {
396         LOGW("ERROR: ECORE_EVAS_ENGINE must be set to either 'wayland_shm' or 'wayland_egl'\n");
397         goto err;
398     }
399
400     wlkb->ee_engine = env;
401     ret = EINA_TRUE;
402
403 err:
404     return ret;
405 }
406 #endif
407
408 int CSCLCoreUIEFL::create(void *data)
409 {
410 #ifdef WAYLAND
411     if (!check_evas_engine(&wlkb)) {
412         LOGW("_wlkb_check_evas_engine error!\n");
413         elm_shutdown();
414         return -1;
415     }
416     LOGD("Selected engine: '%s'\n", wlkb.ee_engine);
417 #endif
418
419     elm_config_accel_preference_set("3d");
420     elm_policy_set(ELM_POLICY_THROTTLE, ELM_POLICY_THROTTLE_NEVER);
421
422     Evas_Object *main_window = elm_win_add(NULL, m_uuid, ELM_WIN_UTILITY);
423     if (!main_window) {
424         LOGE("Failed to create main window\n");
425         return -1;
426     }
427
428     m_main_window = SCL_WINDOW_CAST(main_window);
429
430 #ifdef WAYLAND
431     if (!_wayland_setup(&wlkb, main_window)) {
432         LOGW("ERROR: Unable to setup input panel.\n");
433         appcore_efl_fini();
434         return -1;
435     }
436 #endif
437
438     elm_win_borderless_set(main_window, EINA_TRUE);
439     elm_win_keyboard_win_set(main_window, EINA_TRUE);
440     elm_win_autodel_set(main_window, EINA_TRUE);
441     elm_win_title_set(main_window, m_uuid);
442     elm_win_prop_focus_skip_set(main_window, EINA_TRUE);
443     int rots[] = { 0, 90, 180, 270 };
444     elm_win_wm_rotation_available_rotations_set(main_window, rots, (sizeof(rots) / sizeof(int)));
445
446 #ifndef WAYLAND
447     unsigned int set = 1;
448     ecore_x_window_prop_card32_set(elm_win_xwindow_get(main_window),
449         ECORE_X_ATOM_E_WINDOW_ROTATION_SUPPORTED,
450         &set, 1);
451
452     ecore_x_icccm_name_class_set(elm_win_xwindow_get(main_window), "Virtual Keyboard", "ISF");
453 #endif
454
455     vconf_notify_key_changed(VCONFKEY_LANGSET, language_changed_cb, NULL);
456     vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, accessibility_changed_cb, NULL);
457
458     /* Should we call these callback functions here? */
459     language_changed_cb(NULL, NULL);
460     accessibility_changed_cb(NULL, NULL);
461
462     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
463     if (impl)
464         impl->init(m_display);
465
466 #ifdef WAYLAND
467     evas_object_smart_callback_add(main_window, "wm,rotation,changed", win_rotation_changed_cb, NULL);
468 #else
469     Ecore_Event_Handler *XClientMsgHandler =
470         ecore_event_handler_add(ECORE_X_EVENT_CLIENT_MESSAGE, _client_message_cb, this);
471 #endif
472
473     signal(SIGQUIT, signal_handler);
474     signal(SIGTERM, signal_handler);
475     signal(SIGINT,  signal_handler);
476     signal(SIGHUP,  signal_handler);
477
478 #ifdef WAYLAND
479     evas_object_show(main_window);
480 #endif
481
482     return 0;
483 }
484
485 int CSCLCoreUIEFL::terminate(void *data)
486 {
487     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
488     if (impl)
489         impl->fini();
490
491     vconf_ignore_key_changed(VCONFKEY_LANGSET, language_changed_cb);
492     vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, accessibility_changed_cb);
493
494 #ifndef WAYLAND
495     if (XClientMsgHandler) {
496         ecore_event_handler_del(XClientMsgHandler);
497         XClientMsgHandler = NULL;
498     }
499 #endif
500
501     return 0;
502 }
503
504 static int app_create_cb(void *data)
505 {
506     CSCLCoreUIEFL *sclui = static_cast<CSCLCoreUIEFL *>(data);
507     if (sclui)
508         return sclui->create(data);
509
510     return -1;
511 }
512
513 static int app_terminate_cb(void *data)
514 {
515     CSCLCoreUIEFL *sclui = static_cast<CSCLCoreUIEFL *>(data);
516     if (sclui)
517         return sclui->terminate(data);
518
519     return -1;
520 }
521
522 void CSCLCoreUIEFL::run(const sclchar *display)
523 {
524     char **argv = new char*[4];
525     int argc = 3;
526     const sclchar *uuid = NULL;
527
528     ops.create = app_create_cb;
529     ops.terminate = app_terminate_cb;
530     ops.resume = NULL;
531     ops.pause = NULL;
532     ops.reset = NULL;
533     ops.data = this;
534
535     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
536     if (impl) {
537         uuid = impl->get_uuid();
538     }
539
540     if (!uuid)
541         uuid = "";
542
543     m_uuid = uuid;
544     m_display = display;
545
546     argv[0] = const_cast<char *> (uuid);
547     argv[1] = (char *)"--display";
548     argv[2] = const_cast<char *> (display);
549     argv[3] = 0;
550
551     LOGD("name : %s\n", uuid);
552
553     appcore_efl_main(uuid, &argc, (char ***)&argv, &ops);
554
555     delete [] argv;
556 }
557
558 static void focus_out_cb(void *data, Evas *e, void *event)
559 {
560     OptionWindowInfo *info = static_cast<OptionWindowInfo*>(data);
561     if (info) {
562         if (info->window) {
563             CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
564             if (impl) {
565                 ISCLCoreEventCallback *callback = impl->get_core_event_callback();
566                 if (callback) {
567                     callback->on_destroy_option_window(info->window);
568                 }
569             }
570
571             evas_object_hide(NATIVE_WINDOW_CAST(info->window));
572             evas_object_del(NATIVE_WINDOW_CAST(info->window));
573             info->window = NULL;
574         }
575     }
576 }
577
578 static void
579 set_transient_for_app_window(Evas_Object *window)
580 {
581     /* Set a transient window for window stack */
582     /* Gets the current XID of the active window into the root window property  */
583 #ifndef WAYLAND
584     Atom type_return;
585     unsigned long nitems_return;
586     unsigned long bytes_after_return;
587     int format_return;
588     unsigned char *data = NULL;
589     Ecore_X_Window xAppWindow;
590     Ecore_X_Window xWindow = elm_win_xwindow_get(window);
591     gint ret = 0;
592
593     ret = XGetWindowProperty((Display *)ecore_x_display_get(), ecore_x_window_root_get(xWindow),
594         ecore_x_atom_get("_ISF_ACTIVE_WINDOW"),
595         0, G_MAXLONG, False, XA_WINDOW, &type_return,
596         &format_return, &nitems_return, &bytes_after_return,
597         &data);
598
599     if (ret == Success) {
600         if (data) {
601             if (type_return == XA_WINDOW) {
602                 xAppWindow = *(Window *)data;
603                 LOGD("TRANSIENT_FOR SET : %x , %x\n", xAppWindow, xWindow);
604                 ecore_x_icccm_transient_for_set(xWindow, xAppWindow);
605             }
606             XFree(data);
607         }
608     }
609 #endif
610 }
611
612 static void
613 set_transient_for_isf_setting_window(Evas_Object *window)
614 {
615     /* Set a transient window for window stack */
616     /* Gets the current XID of the active window into the root window property  */
617 #ifndef WAYLAND
618     Atom type_return;
619     unsigned long nitems_return;
620     unsigned long bytes_after_return;
621     int format_return;
622     unsigned char *data = NULL;
623     Ecore_X_Window xControlWindow, xSettingWindow;
624     Ecore_X_Window xWindow = elm_win_xwindow_get(window);
625     gint ret = 0;
626
627     ret = XGetWindowProperty((Display *)ecore_x_display_get(), ecore_x_window_root_get(xWindow),
628         ecore_x_atom_get("_ISF_CONTROL_WINDOW"),
629         0, G_MAXLONG, False, XA_WINDOW, &type_return,
630         &format_return, &nitems_return, &bytes_after_return,
631         &data);
632
633     if (ret == Success) {
634         if (data) {
635             if (type_return == XA_WINDOW) {
636                 xControlWindow = *(Window *)data;
637
638                 ecore_x_window_prop_xid_get(xControlWindow, ecore_x_atom_get("ISF Setting window"),
639                     ECORE_X_ATOM_WINDOW, &xSettingWindow, 1);
640
641                 LOGD("TRANSIENT_FOR SET : %x , %x\n", xSettingWindow, xWindow);
642                 ecore_x_icccm_transient_for_set(xWindow, xSettingWindow);
643             }
644             XFree(data);
645         }
646     }
647 #endif
648 }
649
650 sclwindow CSCLCoreUIEFL::create_option_window(SCLOptionWindowType type)
651 {
652     if (type < 0 || type >= OPTION_WINDOW_TYPE_MAX) {
653         return SCLWINDOW_INVALID;
654     }
655
656     ISCLCoreEventCallback *callback = NULL;
657     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
658     if (impl) {
659         callback = impl->get_core_event_callback();
660         if (callback) {
661             sclboolean ret = false;
662             callback->on_check_option_window_availability(&ret);
663             if (ret == false) {
664                 LOGW("option_window not available\n");
665                 return SCLWINDOW_INVALID;
666             }
667         } else {
668             return SCLWINDOW_INVALID;
669         }
670     }
671
672     /* Just in case the previous option window for setting application exists */
673     if (type == OPTION_WINDOW_TYPE_SETTING_APPLICATION) {
674         if (m_option_window_info[type].window != SCLWINDOW_INVALID) {
675             destroy_option_window(m_option_window_info[type].window);
676         }
677     }
678
679     Evas_Object *window = elm_win_util_standard_add("Option window", "Option window");
680
681 #ifndef WAYLAND
682     Evas_Coord win_w = 0, win_h = 0;
683     elm_win_screen_size_get(window, NULL, NULL, &win_w, &win_h);
684     int degree = get_screen_rotation_degree();
685     if (degree == 90 || degree == 270) {
686         evas_object_resize(window, win_h, win_w);
687     } else {
688         evas_object_resize(window, win_w, win_h);
689     }
690 #endif
691
692     int rots[] = { 0, 90, 180, 270 };
693     elm_win_wm_rotation_available_rotations_set(window, rots, (sizeof(rots) / sizeof(int)));
694
695     elm_win_indicator_mode_set(window, ELM_WIN_INDICATOR_SHOW);
696
697     if (callback) {
698         callback->on_create_option_window(window, type);
699     }
700
701     if (type == OPTION_WINDOW_TYPE_NORMAL) {
702         Evas *evas = evas_object_evas_get(window);
703         evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, focus_out_cb, &m_option_window_info[type]);
704         set_transient_for_app_window(window);
705     } else if (type == OPTION_WINDOW_TYPE_SETTING_APPLICATION) {
706         set_transient_for_isf_setting_window(window);
707     }
708
709     m_option_window_info[type].window = window;
710
711     return window;
712 }
713
714 bool CSCLCoreUIEFL::show_option_window(SCLOptionWindowType type)
715 {
716     if (type < 0 || type >= OPTION_WINDOW_TYPE_MAX) {
717         return SCLWINDOW_INVALID;
718     }
719
720     ISCLCoreEventCallback *callback = NULL;
721     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
722     if (impl) {
723         callback = impl->get_core_event_callback();
724         if (callback) {
725             sclboolean ret = false;
726             callback->on_check_option_window_availability(&ret);
727             if (ret == false) {
728                 LOGW("option_window not available\n");
729                 return false;
730             }
731         } else {
732             return false;
733         }
734     }
735
736     if (m_option_window_info[type].window != SCLWINDOW_INVALID) {
737         evas_object_show(static_cast<Evas_Object*>(m_option_window_info[type].window));
738         elm_win_raise(static_cast<Evas_Object*>(m_option_window_info[type].window));
739         return true;
740     }
741
742     return false;
743 }
744
745 void CSCLCoreUIEFL::destroy_option_window(sclwindow window)
746 {
747     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
748     if (impl) {
749         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
750         if (callback) {
751             callback->on_destroy_option_window(window);
752         }
753     }
754
755     for (int loop = 0;loop < OPTION_WINDOW_TYPE_MAX;loop++) {
756         if (m_option_window_info[loop].window == window) {
757             evas_object_del(NATIVE_WINDOW_CAST(window));
758             m_option_window_info[loop].window = SCLWINDOW_INVALID;
759         }
760     }
761 }
762
763 void CSCLCoreUIEFL::set_screen_rotation_degree(int degree)
764 {
765     m_rotation_degree = degree;
766 }
767
768 #ifdef WAYLAND
769 static void _render_pre_cb(void *data, Evas *e, void *event_info)
770 {
771     LOGD("_render_pre_cb() called, now invoking wl_input_panel_surface_set_ready()");
772
773     wl_input_panel_surface_set_ready(wlkb.ips, 1);
774
775     Evas_Object *main_window = NATIVE_WINDOW_CAST(data);
776     evas_event_callback_del_full(evas_object_evas_get(main_window),
777         EVAS_CALLBACK_RENDER_PRE, _render_pre_cb, main_window);
778
779     delete_render_pre_timer();
780 }
781
782 static Eina_Bool _render_pre_timeout(void *data)
783 {
784     LOGD("_render_pre_timer expired, forcing to call _render_pre_cb() callback");
785
786     _render_pre_cb(data, NULL, NULL);
787
788     return ECORE_CALLBACK_CANCEL;
789 }
790 #endif
791
792 void CSCLCoreUIEFL::process_keyboard_ui_state_change(KEYBOARD_UI_STATE state)
793 {
794 #ifdef WAYLAND
795     static Evas_Object *force_update_helper_obj = NULL;
796     static int force_update_num = 0;
797
798     if (state == KEYBOARD_UI_STATE_WILL_SHOW) {
799         evas_event_callback_add(evas_object_evas_get(NATIVE_WINDOW_CAST(m_main_window)),
800             EVAS_CALLBACK_RENDER_PRE, _render_pre_cb, (void*)m_main_window);
801         _render_pre_timer = ecore_timer_add(RENDER_PRE_TIMEOUT, _render_pre_timeout, (void*)m_main_window);
802         LOGD("Registered RENDER_PRE callback, _render_pre_cb() and a timer callback");
803     } else if (state == KEYBOARD_UI_STATE_DID_SHOW) {
804         LOGD("Forcing keyboard window to render : %d", force_update_num);
805
806         /* Since the ISE is waiting for RENDER_PRE event, we need to make sure the render event is
807          * occured on our ISE window. Since right now there is no proper way to trigger render event
808          * manually, we are creating a half transparent box above the keyboard window. Need to find
809          * more appropriate way to generate render event */
810         if (force_update_helper_obj) evas_object_del(force_update_helper_obj);
811         force_update_helper_obj = elm_bg_add(NATIVE_WINDOW_CAST(m_main_window));
812         evas_object_color_set(force_update_helper_obj, 255, 255, 255, 1);
813         evas_object_resize(force_update_helper_obj, 1, 1);
814         evas_object_move(force_update_helper_obj, force_update_num % 100, 0);
815         evas_object_layer_set(force_update_helper_obj, EVAS_LAYER_MAX);
816         evas_object_show(force_update_helper_obj);
817         force_update_num++;
818     } else if (state == KEYBOARD_UI_STATE_WILL_HIDE) {
819         if (force_update_helper_obj) evas_object_del(force_update_helper_obj);
820         force_update_helper_obj = NULL;
821     }
822 #endif
823 }