c2ee17adfe675ea9f1d8f26890d7c99cfc0d274e
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-base-ecore-wl2.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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 // Ecore is littered with C style cast
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wold-style-cast"
21
22 // CLASS HEADER
23 #include <dali/internal/window-system/tizen-wayland/ecore-wl2/window-base-ecore-wl2.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/input/common/key-impl.h>
27 #include <dali/internal/window-system/common/window-impl.h>
28 #include <dali/internal/window-system/common/window-render-surface.h>
29 #include <dali/internal/window-system/common/window-system.h>
30
31 // EXTERNAL_HEADERS
32 #include <Ecore_Input.h>
33 #include <dali/integration-api/debug.h>
34 #include <dali/public-api/adaptor-framework/window-enumerations.h>
35 #include <dali/public-api/events/mouse-button.h>
36 #include <dali/public-api/object/any.h>
37 #include <vconf-keys.h>
38 #include <vconf.h>
39 #include <wayland-egl-tizen.h>
40
41 namespace Dali
42 {
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 namespace
48 {
49 #if defined(DEBUG_ENABLED)
50 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW_BASE");
51 #endif
52
53 const uint32_t     MAX_TIZEN_CLIENT_VERSION = 7;
54 const unsigned int PRIMARY_TOUCH_BUTTON_ID  = 1;
55
56 const char* DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
57
58 #ifdef DALI_ELDBUS_AVAILABLE
59 // DBUS accessibility
60 const char* BUS       = "org.enlightenment.wm-screen-reader";
61 const char* INTERFACE = "org.tizen.GestureNavigation";
62 const char* PATH      = "/org/tizen/GestureNavigation";
63 #endif // DALI_ELDBUS_AVAILABLE
64
65 struct KeyCodeMap
66 {
67   xkb_keysym_t  keySym;
68   xkb_keycode_t keyCode;
69   bool          isKeyCode;
70 };
71
72 /**
73  * Get the device name from the provided ecore key event
74  */
75 void GetDeviceName(Ecore_Event_Key* keyEvent, std::string& result)
76 {
77   const char* ecoreDeviceName = ecore_device_name_get(keyEvent->dev);
78
79   if(ecoreDeviceName)
80   {
81     result = ecoreDeviceName;
82   }
83 }
84
85 /**
86  * Get the device class from the provided ecore event
87  */
88 void GetDeviceClass(Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass)
89 {
90   switch(ecoreDeviceClass)
91   {
92     case ECORE_DEVICE_CLASS_SEAT:
93     {
94       deviceClass = Device::Class::USER;
95       break;
96     }
97     case ECORE_DEVICE_CLASS_KEYBOARD:
98     {
99       deviceClass = Device::Class::KEYBOARD;
100       break;
101     }
102     case ECORE_DEVICE_CLASS_MOUSE:
103     {
104       deviceClass = Device::Class::MOUSE;
105       break;
106     }
107     case ECORE_DEVICE_CLASS_TOUCH:
108     {
109       deviceClass = Device::Class::TOUCH;
110       break;
111     }
112     case ECORE_DEVICE_CLASS_PEN:
113     {
114       deviceClass = Device::Class::PEN;
115       break;
116     }
117     case ECORE_DEVICE_CLASS_POINTER:
118     {
119       deviceClass = Device::Class::POINTER;
120       break;
121     }
122     case ECORE_DEVICE_CLASS_GAMEPAD:
123     {
124       deviceClass = Device::Class::GAMEPAD;
125       break;
126     }
127     default:
128     {
129       deviceClass = Device::Class::NONE;
130       break;
131     }
132   }
133 }
134
135 void GetDeviceSubclass(Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass)
136 {
137   switch(ecoreDeviceSubclass)
138   {
139     case ECORE_DEVICE_SUBCLASS_FINGER:
140     {
141       deviceSubclass = Device::Subclass::FINGER;
142       break;
143     }
144     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
145     {
146       deviceSubclass = Device::Subclass::FINGERNAIL;
147       break;
148     }
149     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
150     {
151       deviceSubclass = Device::Subclass::KNUCKLE;
152       break;
153     }
154     case ECORE_DEVICE_SUBCLASS_PALM:
155     {
156       deviceSubclass = Device::Subclass::PALM;
157       break;
158     }
159     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
160     {
161       deviceSubclass = Device::Subclass::HAND_SIDE;
162       break;
163     }
164     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
165     {
166       deviceSubclass = Device::Subclass::HAND_FLAT;
167       break;
168     }
169     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
170     {
171       deviceSubclass = Device::Subclass::PEN_TIP;
172       break;
173     }
174     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
175     {
176       deviceSubclass = Device::Subclass::TRACKPAD;
177       break;
178     }
179     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
180     {
181       deviceSubclass = Device::Subclass::TRACKPOINT;
182       break;
183     }
184     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
185     {
186       deviceSubclass = Device::Subclass::TRACKBALL;
187       break;
188     }
189     case ECORE_DEVICE_SUBCLASS_REMOCON:
190     {
191       deviceSubclass = Device::Subclass::REMOCON;
192       break;
193     }
194     case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
195     {
196       deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
197       break;
198     }
199     default:
200     {
201       deviceSubclass = Device::Subclass::NONE;
202       break;
203     }
204   }
205 }
206
207 void FindKeyCode(struct xkb_keymap* keyMap, xkb_keycode_t key, void* data)
208 {
209   KeyCodeMap* foundKeyCode = static_cast<KeyCodeMap*>(data);
210   if(foundKeyCode->isKeyCode)
211   {
212     return;
213   }
214
215   xkb_keysym_t        keySym  = foundKeyCode->keySym;
216   int                 nsyms   = 0;
217   const xkb_keysym_t* symsOut = NULL;
218
219   nsyms = xkb_keymap_key_get_syms_by_level(keyMap, key, 0, 0, &symsOut);
220
221   if(nsyms && symsOut)
222   {
223     if(*symsOut == keySym)
224     {
225       foundKeyCode->keyCode   = key;
226       foundKeyCode->isKeyCode = true;
227     }
228   }
229 }
230
231 /////////////////////////////////////////////////////////////////////////////////////////////////
232 // Window Callbacks
233 /////////////////////////////////////////////////////////////////////////////////////////////////
234
235 /// Called when the window iconify state is changed.
236 static Eina_Bool EcoreEventWindowIconifyStateChanged(void* data, int type, void* event)
237 {
238   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
239   if(windowBase)
240   {
241     return windowBase->OnIconifyStateChanged(data, type, event);
242   }
243
244   return ECORE_CALLBACK_PASS_ON;
245 }
246
247 /// Called when the window gains focus
248 static Eina_Bool EcoreEventWindowFocusIn(void* data, int type, void* event)
249 {
250   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
251   if(windowBase)
252   {
253     return windowBase->OnFocusIn(data, type, event);
254   }
255
256   return ECORE_CALLBACK_PASS_ON;
257 }
258
259 /// Called when the window loses focus
260 static Eina_Bool EcoreEventWindowFocusOut(void* data, int type, void* event)
261 {
262   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
263   if(windowBase)
264   {
265     return windowBase->OnFocusOut(data, type, event);
266   }
267
268   return ECORE_CALLBACK_PASS_ON;
269 }
270
271 /// Called when the output is transformed
272 static Eina_Bool EcoreEventOutputTransform(void* data, int type, void* event)
273 {
274   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
275   if(windowBase)
276   {
277     return windowBase->OnOutputTransform(data, type, event);
278   }
279
280   return ECORE_CALLBACK_PASS_ON;
281 }
282
283 /// Called when the output transform should be ignored
284 static Eina_Bool EcoreEventIgnoreOutputTransform(void* data, int type, void* event)
285 {
286   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
287   if(windowBase)
288   {
289     return windowBase->OnIgnoreOutputTransform(data, type, event);
290   }
291
292   return ECORE_CALLBACK_PASS_ON;
293 }
294
295 /**
296  * Called when rotate event is recevied.
297  */
298 static Eina_Bool EcoreEventRotate(void* data, int type, void* event)
299 {
300   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
301   if(windowBase)
302   {
303     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EcoreEventRotate\n");
304     windowBase->OnRotation(data, type, event);
305   }
306   return ECORE_CALLBACK_PASS_ON;
307 }
308
309 /**
310  * Called when configure event is recevied.
311  */
312 static Eina_Bool EcoreEventConfigure(void* data, int type, void* event)
313 {
314   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
315   if(windowBase)
316   {
317     windowBase->OnConfiguration(data, type, event);
318   }
319   return ECORE_CALLBACK_PASS_ON;
320 }
321
322 /////////////////////////////////////////////////////////////////////////////////////////////////
323 // Touch Callbacks
324 /////////////////////////////////////////////////////////////////////////////////////////////////
325
326 /**
327  * Called when a touch down is received.
328  */
329 static Eina_Bool EcoreEventMouseButtonDown(void* data, int type, void* event)
330 {
331   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
332   if(windowBase)
333   {
334     windowBase->OnMouseButtonDown(data, type, event);
335   }
336   return ECORE_CALLBACK_PASS_ON;
337 }
338
339 /**
340  * Called when a touch up is received.
341  */
342 static Eina_Bool EcoreEventMouseButtonUp(void* data, int type, void* event)
343 {
344   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
345   if(windowBase)
346   {
347     windowBase->OnMouseButtonUp(data, type, event);
348   }
349   return ECORE_CALLBACK_PASS_ON;
350 }
351
352 /**
353  * Called when a touch motion is received.
354  */
355 static Eina_Bool EcoreEventMouseButtonMove(void* data, int type, void* event)
356 {
357   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
358   if(windowBase)
359   {
360     windowBase->OnMouseButtonMove(data, type, event);
361   }
362   return ECORE_CALLBACK_PASS_ON;
363 }
364
365 /**
366  * Called when a touch is canceled.
367  */
368 static Eina_Bool EcoreEventMouseButtonCancel(void* data, int type, void* event)
369 {
370   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
371   if(windowBase)
372   {
373     windowBase->OnMouseButtonCancel(data, type, event);
374   }
375   return ECORE_CALLBACK_PASS_ON;
376 }
377
378 /**
379  * Called when a mouse wheel is received.
380  */
381 static Eina_Bool EcoreEventMouseWheel(void* data, int type, void* event)
382 {
383   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
384   if(windowBase)
385   {
386     windowBase->OnMouseWheel(data, type, event);
387   }
388   return ECORE_CALLBACK_PASS_ON;
389 }
390
391 /**
392  * Called when a detent rotation event is recevied.
393  */
394 static Eina_Bool EcoreEventDetentRotation(void* data, int type, void* event)
395 {
396   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
397   if(windowBase)
398   {
399     windowBase->OnDetentRotation(data, type, event);
400   }
401   return ECORE_CALLBACK_PASS_ON;
402 }
403
404 /////////////////////////////////////////////////////////////////////////////////////////////////
405 // Key Callbacks
406 /////////////////////////////////////////////////////////////////////////////////////////////////
407
408 /**
409  * Called when a key down is received.
410  */
411 static Eina_Bool EcoreEventKeyDown(void* data, int type, void* event)
412 {
413   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
414   if(windowBase)
415   {
416     windowBase->OnKeyDown(data, type, event);
417   }
418   return ECORE_CALLBACK_PASS_ON;
419 }
420
421 /**
422  * Called when a key up is received.
423  */
424 static Eina_Bool EcoreEventKeyUp(void* data, int type, void* event)
425 {
426   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
427   if(windowBase)
428   {
429     windowBase->OnKeyUp(data, type, event);
430   }
431   return ECORE_CALLBACK_PASS_ON;
432 }
433
434 /////////////////////////////////////////////////////////////////////////////////////////////////
435 // Selection Callbacks
436 /////////////////////////////////////////////////////////////////////////////////////////////////
437
438 /**
439  * Called when the source window notifies us the content in clipboard is selected.
440  */
441 static Eina_Bool EcoreEventDataSend(void* data, int type, void* event)
442 {
443   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
444   if(windowBase)
445   {
446     windowBase->OnDataSend(data, type, event);
447   }
448   return ECORE_CALLBACK_PASS_ON;
449 }
450
451 /**
452 * Called when the source window sends us about the selected content.
453 * For example, when item is selected in the clipboard.
454 */
455 static Eina_Bool EcoreEventDataReceive(void* data, int type, void* event)
456 {
457   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
458   if(windowBase)
459   {
460     windowBase->OnDataReceive(data, type, event);
461   }
462   return ECORE_CALLBACK_PASS_ON;
463 }
464
465 /////////////////////////////////////////////////////////////////////////////////////////////////
466 // Effect Start/End Callbacks
467 /////////////////////////////////////////////////////////////////////////////////////////////////
468
469 /**
470  * Called when transition animation of the window's shown/hidden is started by window manager.
471  */
472 static Eina_Bool EcoreEventEffectStart(void* data, int type, void* event)
473 {
474   WindowBaseEcoreWl2*           windowBase  = static_cast<WindowBaseEcoreWl2*>(data);
475   Ecore_Wl2_Event_Effect_Start* effectStart = static_cast<Ecore_Wl2_Event_Effect_Start*>(event);
476   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventEffectStart, effect type[ %d ]\n", effectStart->type);
477   if(windowBase)
478   {
479     if(effectStart->type < 3) // only under restack
480     {
481       windowBase->OnTransitionEffectEvent(WindowEffectState::START, static_cast<WindowEffectType>(effectStart->type));
482     }
483   }
484   return ECORE_CALLBACK_PASS_ON;
485 }
486
487 /**
488  * Called when transition animation of the window's shown/hidden is ended by window manager.
489  */
490 static Eina_Bool EcoreEventEffectEnd(void* data, int type, void* event)
491 {
492   Ecore_Wl2_Event_Effect_Start* effectEnd  = static_cast<Ecore_Wl2_Event_Effect_Start*>(event);
493   WindowBaseEcoreWl2*           windowBase = static_cast<WindowBaseEcoreWl2*>(data);
494   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventEffectEnd, effect type[ %d ]\n", effectEnd->type);
495   if(windowBase)
496   {
497     if(effectEnd->type < 3) // only under restack
498     {
499       windowBase->OnTransitionEffectEvent(WindowEffectState::END, static_cast<WindowEffectType>(effectEnd->type));
500     }
501   }
502   return ECORE_CALLBACK_PASS_ON;
503 }
504
505 /////////////////////////////////////////////////////////////////////////////////////////////////
506 // Keyboard Repeat Settings Changed Callbacks
507 /////////////////////////////////////////////////////////////////////////////////////////////////
508
509 static Eina_Bool EcoreEventSeatKeyboardRepeatChanged(void* data, int type, void* event)
510 {
511   Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed* keyboardRepeat = static_cast<Ecore_Wl2_Event_Seat_Keyboard_Repeat_Changed*>(event);
512   WindowBaseEcoreWl2*                           windowBase     = static_cast<WindowBaseEcoreWl2*>(data);
513   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventSeatKeyboardRepeatChanged, id[ %d ]\n", keyboardRepeat->id);
514   if(windowBase)
515   {
516     windowBase->OnKeyboardRepeatSettingsChanged();
517   }
518
519   return ECORE_CALLBACK_RENEW;
520 }
521
522 /////////////////////////////////////////////////////////////////////////////////////////////////
523 // Keymap Changed Callbacks
524 /////////////////////////////////////////////////////////////////////////////////////////////////
525
526 static Eina_Bool EcoreEventSeatKeymapChanged(void* data, int type, void* event)
527 {
528   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
529   if(windowBase)
530   {
531     windowBase->KeymapChanged(data, type, event);
532   }
533
534   return ECORE_CALLBACK_RENEW;
535 }
536
537 /////////////////////////////////////////////////////////////////////////////////////////////////
538 // Font Callbacks
539 /////////////////////////////////////////////////////////////////////////////////////////////////
540
541 /**
542  * Called when a font name is changed.
543  */
544 static void VconfNotifyFontNameChanged(keynode_t* node, void* data)
545 {
546   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
547   if(windowBase)
548   {
549     windowBase->OnFontNameChanged();
550   }
551 }
552
553 /**
554  * Called when a font size is changed.
555  */
556 static void VconfNotifyFontSizeChanged(keynode_t* node, void* data)
557 {
558   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
559   if(windowBase)
560   {
561     windowBase->OnFontSizeChanged();
562   }
563 }
564
565 /////////////////////////////////////////////////////////////////////////////////////////////////
566 // Window Redraw Request Event Callbacks
567 /////////////////////////////////////////////////////////////////////////////////////////////////
568
569 static Eina_Bool EcoreEventWindowRedrawRequest(void* data, int type, void* event)
570 {
571   Ecore_Wl2_Event_Window_Redraw_Request* windowRedrawRequest = static_cast<Ecore_Wl2_Event_Window_Redraw_Request*>(event);
572   WindowBaseEcoreWl2*                    windowBase          = static_cast<WindowBaseEcoreWl2*>(data);
573   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventWindowRedrawRequest, window[ %d ]\n", windowRedrawRequest->win);
574   if(windowBase)
575   {
576     windowBase->OnEcoreEventWindowRedrawRequest();
577   }
578
579   return ECORE_CALLBACK_RENEW;
580 }
581
582 /////////////////////////////////////////////////////////////////////////////////////////////////
583 // Window Auxiliary Message Callbacks
584 /////////////////////////////////////////////////////////////////////////////////////////////////
585 static Eina_Bool EcoreEventWindowAuxiliaryMessage(void *data, int type, void *event)
586 {
587   WindowBaseEcoreWl2*          windowBase             = static_cast<WindowBaseEcoreWl2*>(data);
588   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::EcoreEventWindowAuxiliaryMessage, window[ %d ]\n", windowAuxiliaryMessage->win);
589   if(windowBase)
590   {
591     windowBase->OnEcoreEventWindowAuxiliaryMessage(event);
592   }
593   return ECORE_CALLBACK_RENEW;
594 }
595
596 /////////////////////////////////////////////////////////////////////////////////////////////////
597 // ElDBus Accessibility Callbacks
598 /////////////////////////////////////////////////////////////////////////////////////////////////
599
600 #ifdef DALI_ELDBUS_AVAILABLE
601 // Callback for Ecore ElDBus accessibility events.
602 static void EcoreElDBusAccessibilityNotification(void* context, const Eldbus_Message* message)
603 {
604   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(context);
605   if(windowBase)
606   {
607     windowBase->OnEcoreElDBusAccessibilityNotification(context, message);
608   }
609 }
610 #endif // DALI_ELDBUS_AVAILABLE
611
612 static void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
613 {
614   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
615   if(windowBase)
616   {
617     windowBase->RegistryGlobalCallback(data, registry, name, interface, version);
618   }
619 }
620
621 static void RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
622 {
623   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
624   if(windowBase)
625   {
626     windowBase->RegistryGlobalCallbackRemove(data, registry, id);
627   }
628 }
629
630 static void TizenPolicyConformant(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant)
631 {
632 }
633
634 static void TizenPolicyConformantArea(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h)
635 {
636 }
637
638 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
639 {
640   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
641   if(windowBase)
642   {
643     windowBase->TizenPolicyNotificationChangeDone(data, tizenPolicy, surface, level, state);
644   }
645 }
646
647 static void TizenPolicyTransientForDone(void* data, struct tizen_policy* tizenPolicy, uint32_t childId)
648 {
649 }
650
651 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
652 {
653   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
654   if(windowBase)
655   {
656     windowBase->TizenPolicyScreenModeChangeDone(data, tizenPolicy, surface, mode, state);
657   }
658 }
659
660 static void TizenPolicyIconifyStateChanged(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force)
661 {
662 }
663
664 static void TizenPolicySupportedAuxiliaryHints(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints)
665 {
666 }
667
668 static void TizenPolicyAllowedAuxiliaryHint(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id)
669 {
670 }
671
672 static void TizenPolicyAuxiliaryMessage(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options)
673 {
674 }
675
676 static void TizenPolicyConformantRegion(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial)
677 {
678 }
679
680 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
681 {
682   WindowBaseEcoreWl2* windowBase = static_cast<WindowBaseEcoreWl2*>(data);
683   if(windowBase)
684   {
685     windowBase->DisplayPolicyBrightnessChangeDone(data, displayPolicy, surface, brightness, state);
686   }
687 }
688
689 const struct wl_registry_listener registryListener =
690   {
691     RegistryGlobalCallback,
692     RegistryGlobalCallbackRemove};
693
694 const struct tizen_policy_listener tizenPolicyListener =
695   {
696     TizenPolicyConformant,
697     TizenPolicyConformantArea,
698     TizenPolicyNotificationChangeDone,
699     TizenPolicyTransientForDone,
700     TizenPolicyScreenModeChangeDone,
701     TizenPolicyIconifyStateChanged,
702     TizenPolicySupportedAuxiliaryHints,
703     TizenPolicyAllowedAuxiliaryHint,
704     TizenPolicyAuxiliaryMessage,
705     TizenPolicyConformantRegion};
706
707 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
708   {
709     DisplayPolicyBrightnessChangeDone};
710
711 } // unnamed namespace
712
713 WindowBaseEcoreWl2::WindowBaseEcoreWl2(Dali::PositionSize positionSize, Any surface, bool isTransparent)
714 : mEcoreEventHandler(),
715   mEcoreWindow(nullptr),
716   mWlSurface(nullptr),
717   mWlInputPanel(nullptr),
718   mWlOutput(nullptr),
719   mWlInputPanelSurface(nullptr),
720   mEglWindow(nullptr),
721   mDisplay(nullptr),
722   mEventQueue(nullptr),
723   mTizenPolicy(nullptr),
724   mTizenDisplayPolicy(nullptr),
725   mKeyMap(nullptr),
726   mSupportedAuxiliaryHints(),
727   mWindowPositionSize(positionSize),
728   mAuxiliaryHints(),
729   mType(WindowType::NORMAL),
730   mNotificationLevel(-1),
731   mScreenOffMode(0),
732   mBrightness(0),
733   mWindowRotationAngle(0),
734   mScreenRotationAngle(0),
735   mSupportedPreProtation(0),
736   mNotificationChangeState(0),
737   mScreenOffModeChangeState(0),
738   mBrightnessChangeState(0),
739   mLastSubmittedMoveResizeSerial(0),
740   mMoveResizeSerial(0),
741   mNotificationLevelChangeDone(true),
742   mScreenOffModeChangeDone(true),
743   mVisible(true),
744   mOwnSurface(false),
745   mBrightnessChangeDone(true)
746 #ifdef DALI_ELDBUS_AVAILABLE
747   ,
748   mSystemConnection(NULL)
749 #endif
750 {
751   Initialize(positionSize, surface, isTransparent);
752 }
753
754 WindowBaseEcoreWl2::~WindowBaseEcoreWl2()
755 {
756 #ifdef DALI_ELDBUS_AVAILABLE
757   // Close down ElDBus connections.
758   if(mSystemConnection)
759   {
760     eldbus_connection_unref(mSystemConnection);
761   }
762 #endif // DALI_ELDBUS_AVAILABLE
763
764   vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged);
765   vconf_ignore_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged);
766
767   for(Dali::Vector<Ecore_Event_Handler*>::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter)
768   {
769     ecore_event_handler_del(*iter);
770   }
771   mEcoreEventHandler.Clear();
772
773   if(mEventQueue)
774   {
775     wl_event_queue_destroy(mEventQueue);
776   }
777
778   mSupportedAuxiliaryHints.clear();
779   mAuxiliaryHints.clear();
780
781   if(mEglWindow != NULL)
782   {
783     wl_egl_window_destroy(mEglWindow);
784     mEglWindow = NULL;
785   }
786
787   if(mOwnSurface)
788   {
789     ecore_wl2_window_free(mEcoreWindow);
790
791     WindowSystem::Shutdown();
792   }
793 }
794
795 void WindowBaseEcoreWl2::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
796 {
797   if(surface.Empty() == false)
798   {
799     // check we have a valid type
800     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(Ecore_Wl2_Window*)) && "Surface type is invalid");
801
802     mEcoreWindow = AnyCast<Ecore_Wl2_Window*>(surface);
803   }
804   else
805   {
806     // we own the surface about to created
807     WindowSystem::Initialize();
808
809     mOwnSurface = true;
810     CreateWindow(positionSize);
811   }
812
813   mWlSurface = ecore_wl2_window_surface_get(mEcoreWindow);
814
815   SetTransparency(isTransparent);
816
817   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this));
818   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this));
819   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this));
820   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this));
821   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this));
822
823   // Register Rotate event
824   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_ROTATE, EcoreEventRotate, this));
825
826   // Register Configure event
827   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_CONFIGURE, EcoreEventConfigure, this));
828
829   // Register Touch events
830   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, this));
831   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, this));
832   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, this));
833   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, this));
834
835   // Register Mouse wheel events
836   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, this));
837
838   // Register Detent event
839   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DETENT_ROTATE, EcoreEventDetentRotation, this));
840
841   // Register Key events
842   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this));
843   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this));
844
845   // Register Selection event - clipboard selection
846   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this));
847   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, this));
848
849   // Register Effect Start/End event
850   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_START, EcoreEventEffectStart, this));
851   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_EFFECT_END, EcoreEventEffectEnd, this));
852
853   // Register Keyboard repeat event
854   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYBOARD_REPEAT_CHANGED, EcoreEventSeatKeyboardRepeatChanged, this));
855
856   // Register Window redraw request event
857   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_REDRAW_REQUEST, EcoreEventWindowRedrawRequest, this));
858
859   // Register Window auxiliary event
860   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_AUX_MESSAGE, EcoreEventWindowAuxiliaryMessage, this));
861
862   // Register Vconf notify - font name and size
863   vconf_notify_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this);
864   vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, this);
865
866   InitializeEcoreElDBus();
867
868   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
869   mDisplay                   = ecore_wl2_display_get(display);
870
871   if(mDisplay)
872   {
873     wl_display* displayWrapper = static_cast<wl_display*>(wl_proxy_create_wrapper(mDisplay));
874     if(displayWrapper)
875     {
876       mEventQueue = wl_display_create_queue(mDisplay);
877       if(mEventQueue)
878       {
879         wl_proxy_set_queue(reinterpret_cast<wl_proxy*>(displayWrapper), mEventQueue);
880
881         wl_registry* registry = wl_display_get_registry(displayWrapper);
882         wl_registry_add_listener(registry, &registryListener, this);
883       }
884
885       wl_proxy_wrapper_destroy(displayWrapper);
886     }
887   }
888
889   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(display);
890
891   if(ecoreWlInput)
892   {
893     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
894
895     mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL2_EVENT_SEAT_KEYMAP_CHANGED, EcoreEventSeatKeymapChanged, this));
896   }
897
898   // get auxiliary hint
899   Eina_List* hints = ecore_wl2_window_aux_hints_supported_get(mEcoreWindow);
900   if(hints)
901   {
902     Eina_List* l    = NULL;
903     char*      hint = NULL;
904
905     for(l = hints, (hint = static_cast<char*>(eina_list_data_get(l))); l; l = eina_list_next(l), (hint = static_cast<char*>(eina_list_data_get(l))))
906     {
907       mSupportedAuxiliaryHints.push_back(hint);
908
909       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::Initialize: %s\n", hint);
910     }
911   }
912 }
913
914 Eina_Bool WindowBaseEcoreWl2::OnIconifyStateChanged(void* data, int type, void* event)
915 {
916   Ecore_Wl2_Event_Window_Iconify_State_Change* iconifyChangedEvent(static_cast<Ecore_Wl2_Event_Window_Iconify_State_Change*>(event));
917   Eina_Bool                                    handled(ECORE_CALLBACK_PASS_ON);
918
919   if(iconifyChangedEvent->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
920   {
921     if(iconifyChangedEvent->iconified == EINA_TRUE)
922     {
923       mIconifyChangedSignal.Emit(true);
924     }
925     else
926     {
927       mIconifyChangedSignal.Emit(false);
928     }
929     handled = ECORE_CALLBACK_DONE;
930   }
931
932   return handled;
933 }
934
935 Eina_Bool WindowBaseEcoreWl2::OnFocusIn(void* data, int type, void* event)
936 {
937   Ecore_Wl2_Event_Focus_In* focusInEvent(static_cast<Ecore_Wl2_Event_Focus_In*>(event));
938
939   if(focusInEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
940   {
941     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n");
942
943     mFocusChangedSignal.Emit(true);
944   }
945
946   return ECORE_CALLBACK_PASS_ON;
947 }
948
949 Eina_Bool WindowBaseEcoreWl2::OnFocusOut(void* data, int type, void* event)
950 {
951   Ecore_Wl2_Event_Focus_Out* focusOutEvent(static_cast<Ecore_Wl2_Event_Focus_Out*>(event));
952
953   if(focusOutEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
954   {
955     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n");
956
957     mFocusChangedSignal.Emit(false);
958   }
959
960   return ECORE_CALLBACK_PASS_ON;
961 }
962
963 Eina_Bool WindowBaseEcoreWl2::OnOutputTransform(void* data, int type, void* event)
964 {
965   Ecore_Wl2_Event_Output_Transform* transformEvent(static_cast<Ecore_Wl2_Event_Output_Transform*>(event));
966
967   if(transformEvent->output == ecore_wl2_window_output_find(mEcoreWindow))
968   {
969     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow);
970
971     mScreenRotationAngle = GetScreenRotationAngle();
972
973     mOutputTransformedSignal.Emit();
974   }
975
976   return ECORE_CALLBACK_PASS_ON;
977 }
978
979 Eina_Bool WindowBaseEcoreWl2::OnIgnoreOutputTransform(void* data, int type, void* event)
980 {
981   Ecore_Wl2_Event_Ignore_Output_Transform* ignoreTransformEvent(static_cast<Ecore_Wl2_Event_Ignore_Output_Transform*>(event));
982
983   if(ignoreTransformEvent->win == mEcoreWindow)
984   {
985     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow);
986
987     mScreenRotationAngle = GetScreenRotationAngle();
988
989     mOutputTransformedSignal.Emit();
990   }
991
992   return ECORE_CALLBACK_PASS_ON;
993 }
994
995 void WindowBaseEcoreWl2::OnRotation(void* data, int type, void* event)
996 {
997   Ecore_Wl2_Event_Window_Rotation* ev(static_cast<Ecore_Wl2_Event_Window_Rotation*>(event));
998
999   if(ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1000   {
1001     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h);
1002
1003     RotationEvent rotationEvent;
1004     rotationEvent.angle     = ev->angle;
1005     rotationEvent.winResize = 0;
1006
1007     if(ev->w == 0 || ev->h == 0)
1008     {
1009       // Use previous client side window's size.
1010       if(mWindowRotationAngle == 90 || mWindowRotationAngle == 270)
1011       {
1012         ev->w = mWindowPositionSize.height;
1013         ev->h = mWindowPositionSize.width;
1014       }
1015       else
1016       {
1017         ev->w = mWindowPositionSize.width;
1018         ev->h = mWindowPositionSize.height;
1019       }
1020     }
1021
1022     mWindowRotationAngle = ev->angle;
1023
1024     if(ev->angle == 0 || ev->angle == 180)
1025     {
1026       rotationEvent.width  = ev->w;
1027       rotationEvent.height = ev->h;
1028     }
1029     else
1030     {
1031       rotationEvent.width  = ev->h;
1032       rotationEvent.height = ev->w;
1033     }
1034
1035     mWindowPositionSize.width  = rotationEvent.width;
1036     mWindowPositionSize.height = rotationEvent.height;
1037
1038     mRotationSignal.Emit(rotationEvent);
1039   }
1040 }
1041
1042 void WindowBaseEcoreWl2::OnConfiguration(void* data, int type, void* event)
1043 {
1044   Ecore_Wl2_Event_Window_Configure* ev(static_cast<Ecore_Wl2_Event_Window_Configure*>(event));
1045
1046   if(ev && ev->win == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1047   {
1048     // Note: To comply with the wayland protocol, Dali should make an ack_configure
1049     // by calling ecore_wl2_window_commit
1050
1051     int tempWidth  = static_cast<int>(ev->w);
1052     int tempHeight = static_cast<int>(ev->h);
1053
1054     // Initialize with previous size for skip resize when new size is 0.
1055     // When window is just moved or window is resized by client application,
1056     // The configure notification event's size will be 0.
1057     // If new size is 0, the resized work should be skip.
1058     int  newWidth    = mWindowPositionSize.width;
1059     int  newHeight   = mWindowPositionSize.height;
1060     bool windowMoved = false, windowResized = false;
1061
1062     if(ev->x != mWindowPositionSize.x || ev->y != mWindowPositionSize.y)
1063     {
1064       windowMoved = true;
1065     }
1066
1067     if(tempWidth != 0 && tempHeight != 0 && (tempWidth != mWindowPositionSize.width || tempHeight != mWindowPositionSize.height))
1068     {
1069       windowResized = true;
1070       newWidth      = tempWidth;
1071       newHeight     = tempHeight;
1072     }
1073
1074     if(windowMoved || windowResized)
1075     {
1076       Dali::PositionSize newPositionSize(ev->x, ev->y, newWidth, newHeight);
1077       mUpdatePositionSizeSignal.Emit(newPositionSize);
1078     }
1079
1080     ecore_wl2_window_commit(mEcoreWindow, EINA_FALSE);
1081   }
1082 }
1083
1084 void WindowBaseEcoreWl2::OnMouseButtonDown(void* data, int type, void* event)
1085 {
1086   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1087
1088   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1089   {
1090     Device::Class::Type    deviceClass;
1091     Device::Subclass::Type deviceSubclass;
1092
1093     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1094     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1095
1096     PointState::Type state(PointState::DOWN);
1097
1098     if(deviceClass != Device::Class::Type::MOUSE)
1099     {
1100       // Check if the buttons field is set and ensure it's the primary touch button.
1101       // If this event was triggered by buttons other than the primary button (used for touch), then
1102       // just send an interrupted event to Core.
1103       if(touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID))
1104       {
1105         state = PointState::INTERRUPTED;
1106       }
1107     }
1108
1109     Integration::Point point;
1110     point.SetDeviceId(touchEvent->multi.device);
1111     point.SetState(state);
1112     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1113     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1114     point.SetPressure(touchEvent->multi.pressure);
1115     point.SetAngle(Degree(touchEvent->multi.angle));
1116     point.SetDeviceClass(deviceClass);
1117     point.SetDeviceSubclass(deviceSubclass);
1118     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1119
1120     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1121   }
1122 }
1123
1124 void WindowBaseEcoreWl2::OnMouseButtonUp(void* data, int type, void* event)
1125 {
1126   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1127
1128   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1129   {
1130     Device::Class::Type    deviceClass;
1131     Device::Subclass::Type deviceSubclass;
1132
1133     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1134     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1135
1136     Integration::Point point;
1137     point.SetDeviceId(touchEvent->multi.device);
1138     point.SetState(PointState::UP);
1139     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1140     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1141     point.SetPressure(touchEvent->multi.pressure);
1142     point.SetAngle(Degree(touchEvent->multi.angle));
1143     point.SetDeviceClass(deviceClass);
1144     point.SetDeviceSubclass(deviceSubclass);
1145     point.SetMouseButton(static_cast<MouseButton::Type>(touchEvent->buttons));
1146
1147     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1148   }
1149 }
1150
1151 void WindowBaseEcoreWl2::OnMouseButtonMove(void* data, int type, void* event)
1152 {
1153   Ecore_Event_Mouse_Move* touchEvent = static_cast<Ecore_Event_Mouse_Move*>(event);
1154
1155   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1156   {
1157     Device::Class::Type    deviceClass;
1158     Device::Subclass::Type deviceSubclass;
1159
1160     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
1161     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
1162
1163     Integration::Point point;
1164     point.SetDeviceId(touchEvent->multi.device);
1165     point.SetState(PointState::MOTION);
1166     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
1167     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
1168     point.SetPressure(touchEvent->multi.pressure);
1169     point.SetAngle(Degree(touchEvent->multi.angle));
1170     point.SetDeviceClass(deviceClass);
1171     point.SetDeviceSubclass(deviceSubclass);
1172
1173     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1174   }
1175 }
1176
1177 void WindowBaseEcoreWl2::OnMouseButtonCancel(void* data, int type, void* event)
1178 {
1179   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
1180
1181   if(touchEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1182   {
1183     Integration::Point point;
1184     point.SetDeviceId(touchEvent->multi.device);
1185     point.SetState(PointState::INTERRUPTED);
1186     point.SetScreenPosition(Vector2(0.0f, 0.0f));
1187
1188     mTouchEventSignal.Emit(point, touchEvent->timestamp);
1189
1190     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseButtonCancel\n");
1191   }
1192 }
1193
1194 void WindowBaseEcoreWl2::OnMouseWheel(void* data, int type, void* event)
1195 {
1196   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast<Ecore_Event_Mouse_Wheel*>(event);
1197
1198   if(mouseWheelEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1199   {
1200     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
1201
1202     Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
1203
1204     mWheelEventSignal.Emit(wheelEvent);
1205   }
1206 }
1207
1208 void WindowBaseEcoreWl2::OnDetentRotation(void* data, int type, void* event)
1209 {
1210   Ecore_Event_Detent_Rotate* detentEvent = static_cast<Ecore_Event_Detent_Rotate*>(event);
1211
1212   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::OnDetentRotation\n");
1213
1214   int direction = (detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
1215   int timeStamp = detentEvent->timestamp;
1216
1217   Integration::WheelEvent wheelEvent(Integration::WheelEvent::CUSTOM_WHEEL, direction, 0, Vector2(0.0f, 0.0f), 0, timeStamp);
1218
1219   mWheelEventSignal.Emit(wheelEvent);
1220 }
1221
1222 void WindowBaseEcoreWl2::OnKeyDown(void* data, int type, void* event)
1223 {
1224   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1225
1226   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1227   {
1228     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyDown\n");
1229
1230     std::string keyName(keyEvent->keyname);
1231     std::string logicalKey("");
1232     std::string keyString("");
1233     std::string compose("");
1234
1235     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1236     if(keyEvent->compose)
1237     {
1238       compose = keyEvent->compose;
1239     }
1240
1241     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1242     if(keyEvent->key)
1243     {
1244       logicalKey = keyEvent->key;
1245     }
1246
1247     int keyCode = 0;
1248     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1249
1250     if(keyCode == 0)
1251     {
1252       // Get a specific key code from dali key look up table.
1253       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1254     }
1255
1256     keyCode = (keyCode == -1) ? 0 : keyCode;
1257     int           modifier(keyEvent->modifiers);
1258     unsigned long time = keyEvent->timestamp;
1259     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1260     {
1261       keyCode = atoi(keyEvent->keyname + 8);
1262     }
1263
1264     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1265     if(keyEvent->string)
1266     {
1267       keyString = keyEvent->string;
1268     }
1269
1270     std::string            deviceName;
1271     Device::Class::Type    deviceClass;
1272     Device::Subclass::Type deviceSubclass;
1273
1274     GetDeviceName(keyEvent, deviceName);
1275     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1276     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1277
1278     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::DOWN, compose, deviceName, deviceClass, deviceSubclass);
1279
1280     mKeyEventSignal.Emit(keyEvent);
1281   }
1282 }
1283
1284 void WindowBaseEcoreWl2::OnKeyUp(void* data, int type, void* event)
1285 {
1286   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1287
1288   if(keyEvent->window == static_cast<unsigned int>(ecore_wl2_window_id_get(mEcoreWindow)))
1289   {
1290     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp\n");
1291
1292 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
1293     // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
1294     if(keyEvent->event_flags & ECORE_EVENT_FLAG_CANCEL)
1295     {
1296       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::OnKeyUp: This event flag indicates the event is canceled. \n");
1297       return;
1298     }
1299 #endif // Since ecore 1.23 version
1300
1301     std::string keyName(keyEvent->keyname);
1302     std::string logicalKey("");
1303     std::string keyString("");
1304     std::string compose("");
1305
1306     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1307     if(keyEvent->compose)
1308     {
1309       compose = keyEvent->compose;
1310     }
1311
1312     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1313     if(keyEvent->key)
1314     {
1315       logicalKey = keyEvent->key;
1316     }
1317
1318     int keyCode = 0;
1319     GetKeyCode(keyName, keyCode); // Get key code dynamically.
1320
1321     if(keyCode == 0)
1322     {
1323       // Get a specific key code from dali key look up table.
1324       keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1325     }
1326
1327     keyCode = (keyCode == -1) ? 0 : keyCode;
1328     int           modifier(keyEvent->modifiers);
1329     unsigned long time = keyEvent->timestamp;
1330     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1331     {
1332       keyCode = atoi(keyEvent->keyname + 8);
1333     }
1334
1335     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1336     if(keyEvent->string)
1337     {
1338       keyString = keyEvent->string;
1339     }
1340
1341     std::string            deviceName;
1342     Device::Class::Type    deviceClass;
1343     Device::Subclass::Type deviceSubclass;
1344
1345     GetDeviceName(keyEvent, deviceName);
1346     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1347     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1348
1349     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, compose, deviceName, deviceClass, deviceSubclass);
1350
1351     mKeyEventSignal.Emit(keyEvent);
1352   }
1353 }
1354
1355 void WindowBaseEcoreWl2::OnDataSend(void* data, int type, void* event)
1356 {
1357   mSelectionDataSendSignal.Emit(event);
1358 }
1359
1360 void WindowBaseEcoreWl2::OnDataReceive(void* data, int type, void* event)
1361 {
1362   mSelectionDataReceivedSignal.Emit(event);
1363 }
1364
1365 void WindowBaseEcoreWl2::OnFontNameChanged()
1366 {
1367   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_CHANGE);
1368 }
1369
1370 void WindowBaseEcoreWl2::OnFontSizeChanged()
1371 {
1372   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1373 }
1374
1375 #ifdef DALI_ELDBUS_AVAILABLE
1376 void WindowBaseEcoreWl2::OnEcoreElDBusAccessibilityNotification(void* context, const Eldbus_Message* message)
1377 {
1378   AccessibilityInfo info;
1379
1380   // The string defines the arg-list's respective types.
1381   if(!eldbus_message_arguments_get(message, "iiiiiiu", &info.gestureValue, &info.startX, &info.startY, &info.endX, &info.endY, &info.state, &info.eventTime))
1382   {
1383     DALI_LOG_ERROR("OnEcoreElDBusAccessibilityNotification: Error getting arguments\n");
1384   }
1385
1386   mAccessibilitySignal.Emit(info);
1387 }
1388 #endif // DALI_ELDBUS_AVAILABLE
1389
1390 void WindowBaseEcoreWl2::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
1391 {
1392   mTransitionEffectEventSignal.Emit(state, type);
1393 }
1394
1395 void WindowBaseEcoreWl2::OnKeyboardRepeatSettingsChanged()
1396 {
1397   mKeyboardRepeatSettingsChangedSignal.Emit();
1398 }
1399
1400 void WindowBaseEcoreWl2::OnEcoreEventWindowRedrawRequest()
1401 {
1402   mWindowRedrawRequestSignal.Emit();
1403 }
1404
1405 void WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage(void* event)
1406 {
1407  Ecore_Wl2_Event_Aux_Message *message = static_cast<Ecore_Wl2_Event_Aux_Message*>(event);
1408  if(message)
1409  {
1410    DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, key:%s, value:%s \n",message->key, message->val);
1411    std::string key(message->key);
1412    std::string value(message->val);
1413    Dali::Property::Array options;
1414
1415    if(message->options)
1416    {
1417      Eina_List *l;
1418      void* data;
1419      EINA_LIST_FOREACH(message->options, l, data)
1420      {
1421        DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::OnEcoreEventWindowAuxiliaryMessage, option: %s\n",(char*)data);
1422        std::string option(static_cast<char*>(data));
1423        options.Add(option);
1424      }
1425    }
1426
1427    mAuxiliaryMessageSignal.Emit(key, value, options);
1428  }
1429 }
1430
1431
1432 void WindowBaseEcoreWl2::KeymapChanged(void* data, int type, void* event)
1433 {
1434   Ecore_Wl2_Event_Seat_Keymap_Changed* changed = static_cast<Ecore_Wl2_Event_Seat_Keymap_Changed*>(event);
1435   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::KeymapChanged, keymap id[ %d ]\n", changed->id);
1436   Ecore_Wl2_Input* ecoreWlInput = ecore_wl2_input_default_input_get(changed->display);
1437   if(ecoreWlInput)
1438   {
1439     mKeyMap = ecore_wl2_input_keymap_get(ecoreWlInput);
1440   }
1441 }
1442
1443 void WindowBaseEcoreWl2::RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
1444 {
1445   if(strcmp(interface, tizen_policy_interface.name) == 0)
1446   {
1447     uint32_t clientVersion = std::min(version, MAX_TIZEN_CLIENT_VERSION);
1448
1449     mTizenPolicy = static_cast<tizen_policy*>(wl_registry_bind(registry, name, &tizen_policy_interface, clientVersion));
1450     if(!mTizenPolicy)
1451     {
1452       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n");
1453       return;
1454     }
1455
1456     tizen_policy_add_listener(mTizenPolicy, &tizenPolicyListener, data);
1457
1458     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_policy_add_listener is called.\n");
1459   }
1460   else if(strcmp(interface, tizen_display_policy_interface.name) == 0)
1461   {
1462     mTizenDisplayPolicy = static_cast<tizen_display_policy*>(wl_registry_bind(registry, name, &tizen_display_policy_interface, version));
1463     if(!mTizenDisplayPolicy)
1464     {
1465       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n");
1466       return;
1467     }
1468
1469     tizen_display_policy_add_listener(mTizenDisplayPolicy, &tizenDisplayPolicyListener, data);
1470
1471     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n");
1472   }
1473 }
1474
1475 void WindowBaseEcoreWl2::RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
1476 {
1477   mTizenPolicy        = NULL;
1478   mTizenDisplayPolicy = NULL;
1479 }
1480
1481 void WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
1482 {
1483   mNotificationLevel           = level;
1484   mNotificationChangeState     = state;
1485   mNotificationLevelChangeDone = true;
1486
1487   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state);
1488 }
1489
1490 void WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
1491 {
1492   mScreenOffMode            = mode;
1493   mScreenOffModeChangeState = state;
1494   mScreenOffModeChangeDone  = true;
1495
1496   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state);
1497 }
1498
1499 void WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
1500 {
1501   mBrightness            = brightness;
1502   mBrightnessChangeState = state;
1503   mBrightnessChangeDone  = true;
1504
1505   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl2::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state);
1506 }
1507
1508 void WindowBaseEcoreWl2::GetKeyCode(std::string keyName, int32_t& keyCode)
1509 {
1510   xkb_keysym_t sym = XKB_KEY_NoSymbol;
1511   KeyCodeMap   foundKeyCode;
1512
1513   sym = xkb_keysym_from_name(keyName.c_str(), XKB_KEYSYM_NO_FLAGS);
1514   if(sym == XKB_KEY_NoSymbol)
1515   {
1516     DALI_LOG_ERROR("Failed to get keysym in WindowBaseEcoreWl2\n");
1517     return;
1518   }
1519
1520   foundKeyCode.keySym    = sym;
1521   foundKeyCode.isKeyCode = false;
1522   xkb_keymap_key_for_each(mKeyMap, FindKeyCode, &foundKeyCode);
1523   keyCode = static_cast<int32_t>(foundKeyCode.keyCode);
1524 }
1525
1526 Any WindowBaseEcoreWl2::GetNativeWindow()
1527 {
1528   return mEcoreWindow;
1529 }
1530
1531 int WindowBaseEcoreWl2::GetNativeWindowId()
1532 {
1533   return ecore_wl2_window_id_get(mEcoreWindow);
1534 }
1535
1536 EGLNativeWindowType WindowBaseEcoreWl2::CreateEglWindow(int width, int height)
1537 {
1538   int totalAngle = (mWindowRotationAngle + mScreenRotationAngle) % 360;
1539   if(totalAngle == 90 || totalAngle == 270)
1540   {
1541     mEglWindow = wl_egl_window_create(mWlSurface, height, width);
1542   }
1543   else
1544   {
1545     mEglWindow = wl_egl_window_create(mWlSurface, width, height);
1546   }
1547
1548   return static_cast<EGLNativeWindowType>(mEglWindow);
1549 }
1550
1551 void WindowBaseEcoreWl2::DestroyEglWindow()
1552 {
1553   if(mEglWindow != NULL)
1554   {
1555     wl_egl_window_destroy(mEglWindow);
1556     mEglWindow = NULL;
1557   }
1558 }
1559
1560 void WindowBaseEcoreWl2::SetEglWindowRotation(int angle)
1561 {
1562   wl_egl_window_tizen_rotation rotation;
1563
1564   switch(angle)
1565   {
1566     case 0:
1567     {
1568       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1569       break;
1570     }
1571     case 90:
1572     {
1573       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_270;
1574       break;
1575     }
1576     case 180:
1577     {
1578       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_180;
1579       break;
1580     }
1581     case 270:
1582     {
1583       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_90;
1584       break;
1585     }
1586     default:
1587     {
1588       rotation = WL_EGL_WINDOW_TIZEN_ROTATION_0;
1589       break;
1590     }
1591   }
1592
1593   wl_egl_window_tizen_set_rotation(mEglWindow, rotation);
1594 }
1595
1596 void WindowBaseEcoreWl2::SetEglWindowBufferTransform(int angle)
1597 {
1598   wl_output_transform bufferTransform;
1599
1600   switch(angle)
1601   {
1602     case 0:
1603     {
1604       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1605       break;
1606     }
1607     case 90:
1608     {
1609       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1610       break;
1611     }
1612     case 180:
1613     {
1614       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1615       break;
1616     }
1617     case 270:
1618     {
1619       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1620       break;
1621     }
1622     default:
1623     {
1624       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1625       break;
1626     }
1627   }
1628
1629   wl_egl_window_tizen_set_buffer_transform(mEglWindow, bufferTransform);
1630 }
1631
1632 void WindowBaseEcoreWl2::SetEglWindowTransform(int angle)
1633 {
1634   wl_output_transform windowTransform;
1635
1636   switch(angle)
1637   {
1638     case 0:
1639     {
1640       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1641       break;
1642     }
1643     case 90:
1644     {
1645       windowTransform = WL_OUTPUT_TRANSFORM_90;
1646       break;
1647     }
1648     case 180:
1649     {
1650       windowTransform = WL_OUTPUT_TRANSFORM_180;
1651       break;
1652     }
1653     case 270:
1654     {
1655       windowTransform = WL_OUTPUT_TRANSFORM_270;
1656       break;
1657     }
1658     default:
1659     {
1660       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1661       break;
1662     }
1663   }
1664
1665   wl_egl_window_tizen_set_window_transform(mEglWindow, windowTransform);
1666 }
1667
1668 void WindowBaseEcoreWl2::ResizeEglWindow(PositionSize positionSize)
1669 {
1670   wl_egl_window_resize(mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y);
1671
1672   // Note: Both "Resize" and "MoveResize" cases can reach here, but only "MoveResize" needs to submit serial number
1673   if(mMoveResizeSerial != mLastSubmittedMoveResizeSerial)
1674   {
1675     wl_egl_window_tizen_set_window_serial(mEglWindow, mMoveResizeSerial);
1676     mLastSubmittedMoveResizeSerial = mMoveResizeSerial;
1677   }
1678 }
1679
1680 bool WindowBaseEcoreWl2::IsEglWindowRotationSupported()
1681 {
1682   // Check capability
1683   wl_egl_window_tizen_capability capability = static_cast<wl_egl_window_tizen_capability>(wl_egl_window_tizen_get_capabilities(mEglWindow));
1684   if(capability == WL_EGL_WINDOW_TIZEN_CAPABILITY_ROTATION_SUPPORTED)
1685   {
1686     mSupportedPreProtation = true;
1687     return true;
1688   }
1689   mSupportedPreProtation = false;
1690   return false;
1691 }
1692
1693 void WindowBaseEcoreWl2::Move(PositionSize positionSize)
1694 {
1695   mWindowPositionSize = positionSize;
1696   ecore_wl2_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1697 }
1698
1699 void WindowBaseEcoreWl2::Resize(PositionSize positionSize)
1700 {
1701   mWindowPositionSize = positionSize;
1702   ecore_wl2_window_geometry_set(mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
1703 }
1704
1705 void WindowBaseEcoreWl2::MoveResize(PositionSize positionSize)
1706 {
1707   mWindowPositionSize = positionSize;
1708   ecore_wl2_window_sync_geometry_set(mEcoreWindow, ++mMoveResizeSerial, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
1709 }
1710
1711 void WindowBaseEcoreWl2::SetClass(const std::string& name, const std::string& className)
1712 {
1713   ecore_wl2_window_title_set(mEcoreWindow, name.c_str());
1714   ecore_wl2_window_class_set(mEcoreWindow, className.c_str());
1715 }
1716
1717 void WindowBaseEcoreWl2::Raise()
1718 {
1719   // Use ecore_wl2_window_activate to prevent the window shown without rendering
1720   ecore_wl2_window_activate(mEcoreWindow);
1721 }
1722
1723 void WindowBaseEcoreWl2::Lower()
1724 {
1725   ecore_wl2_window_lower(mEcoreWindow);
1726 }
1727
1728 void WindowBaseEcoreWl2::Activate()
1729 {
1730   ecore_wl2_window_activate(mEcoreWindow);
1731 }
1732
1733 void WindowBaseEcoreWl2::SetAvailableAnlges(const std::vector<int>& angles)
1734 {
1735   int rotations[4] = {0};
1736   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetAvailableAnlges, angle's count: %d, angles\n", angles.size());
1737   for(std::size_t i = 0; i < angles.size(); ++i)
1738   {
1739     rotations[i] = static_cast<int>(angles[i]);
1740     DALI_LOG_RELEASE_INFO("%d ", rotations[i]);
1741   }
1742   ecore_wl2_window_available_rotations_set(mEcoreWindow, rotations, angles.size());
1743 }
1744
1745 void WindowBaseEcoreWl2::SetPreferredAngle(int angle)
1746 {
1747   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPreferredAngle, angle: %d\n", angle);
1748   ecore_wl2_window_preferred_rotation_set(mEcoreWindow, angle);
1749 }
1750
1751 void WindowBaseEcoreWl2::SetAcceptFocus(bool accept)
1752 {
1753   ecore_wl2_window_focus_skip_set(mEcoreWindow, !accept);
1754 }
1755
1756 void WindowBaseEcoreWl2::Show()
1757 {
1758   if(!mVisible)
1759   {
1760     // Ecore-wl2 has the original window size
1761     // and he always sends the window rotation event with the swapped size.
1762     // So, to restore, dali should set the reswapped size(original window size) to ecore-wl2 for restoring.
1763     if(mWindowRotationAngle == 0 || mWindowRotationAngle == 180)
1764     {
1765       ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.width, mWindowPositionSize.height);
1766     }
1767     else
1768     {
1769       ecore_wl2_window_geometry_set(mEcoreWindow, mWindowPositionSize.x, mWindowPositionSize.y, mWindowPositionSize.height, mWindowPositionSize.width);
1770     }
1771   }
1772   mVisible = true;
1773
1774   ecore_wl2_window_show(mEcoreWindow);
1775 }
1776
1777 void WindowBaseEcoreWl2::Hide()
1778 {
1779   mVisible = false;
1780   ecore_wl2_window_hide(mEcoreWindow);
1781 }
1782
1783 unsigned int WindowBaseEcoreWl2::GetSupportedAuxiliaryHintCount() const
1784 {
1785   return mSupportedAuxiliaryHints.size();
1786 }
1787
1788 std::string WindowBaseEcoreWl2::GetSupportedAuxiliaryHint(unsigned int index) const
1789 {
1790   if(index >= GetSupportedAuxiliaryHintCount())
1791   {
1792     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index);
1793   }
1794
1795   return mSupportedAuxiliaryHints[index];
1796 }
1797
1798 unsigned int WindowBaseEcoreWl2::AddAuxiliaryHint(const std::string& hint, const std::string& value)
1799 {
1800   bool supported = false;
1801
1802   // Check if the hint is suppported
1803   for(std::vector<std::string>::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter)
1804   {
1805     if(*iter == hint)
1806     {
1807       supported = true;
1808       break;
1809     }
1810   }
1811
1812   if(!supported)
1813   {
1814     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str());
1815     return 0;
1816   }
1817
1818   // Check if the hint is already added
1819   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1820   {
1821     if(mAuxiliaryHints[i].first == hint)
1822     {
1823       // Just change the value
1824       mAuxiliaryHints[i].second = value;
1825
1826       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1);
1827
1828       return i + 1; // id is index + 1
1829     }
1830   }
1831
1832   // Add the hint
1833   mAuxiliaryHints.push_back(std::pair<std::string, std::string>(hint, value));
1834
1835   unsigned int id = mAuxiliaryHints.size();
1836
1837   ecore_wl2_window_aux_hint_add(mEcoreWindow, static_cast<int>(id), hint.c_str(), value.c_str());
1838
1839   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id);
1840
1841   return id;
1842 }
1843
1844 bool WindowBaseEcoreWl2::RemoveAuxiliaryHint(unsigned int id)
1845 {
1846   if(id == 0 || id > mAuxiliaryHints.size())
1847   {
1848     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: Invalid id [%d]\n", id);
1849     return false;
1850   }
1851
1852   mAuxiliaryHints[id - 1].second = std::string();
1853
1854   ecore_wl2_window_aux_hint_del(mEcoreWindow, static_cast<int>(id));
1855
1856   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str());
1857
1858   return true;
1859 }
1860
1861 bool WindowBaseEcoreWl2::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
1862 {
1863   if(id == 0 || id > mAuxiliaryHints.size())
1864   {
1865     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: Invalid id [%d]\n", id);
1866     return false;
1867   }
1868
1869   mAuxiliaryHints[id - 1].second = value;
1870
1871   ecore_wl2_window_aux_hint_change(mEcoreWindow, static_cast<int>(id), value.c_str());
1872
1873   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1874
1875   return true;
1876 }
1877
1878 std::string WindowBaseEcoreWl2::GetAuxiliaryHintValue(unsigned int id) const
1879 {
1880   if(id == 0 || id > mAuxiliaryHints.size())
1881   {
1882     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: Invalid id [%d]\n", id);
1883     return std::string();
1884   }
1885
1886   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1887
1888   return mAuxiliaryHints[id - 1].second;
1889 }
1890
1891 unsigned int WindowBaseEcoreWl2::GetAuxiliaryHintId(const std::string& hint) const
1892 {
1893   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1894   {
1895     if(mAuxiliaryHints[i].first == hint)
1896     {
1897       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1);
1898       return i + 1;
1899     }
1900   }
1901
1902   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str());
1903
1904   return 0;
1905 }
1906
1907 void WindowBaseEcoreWl2::SetInputRegion(const Rect<int>& inputRegion)
1908 {
1909   ecore_wl2_window_input_region_set(mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1910 }
1911
1912 void WindowBaseEcoreWl2::SetType(Dali::WindowType type)
1913 {
1914   if(mType != type)
1915   {
1916     mType = type;
1917     Ecore_Wl2_Window_Type windowType;
1918
1919     switch(type)
1920     {
1921       case Dali::WindowType::NORMAL:
1922       {
1923         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1924         break;
1925       }
1926       case Dali::WindowType::NOTIFICATION:
1927       {
1928         windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
1929         break;
1930       }
1931       case Dali::WindowType::UTILITY:
1932       {
1933         windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
1934         break;
1935       }
1936       case Dali::WindowType::DIALOG:
1937       {
1938         windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
1939         break;
1940       }
1941       case Dali::WindowType::IME:
1942       {
1943         windowType = ECORE_WL2_WINDOW_TYPE_NONE;
1944         break;
1945       }
1946       default:
1947       {
1948         windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1949         break;
1950       }
1951     }
1952     ecore_wl2_window_type_set(mEcoreWindow, windowType);
1953   }
1954 }
1955
1956 Dali::WindowType WindowBaseEcoreWl2::GetType() const
1957 {
1958   return mType;
1959 }
1960
1961 Dali::WindowOperationResult WindowBaseEcoreWl2::SetNotificationLevel(Dali::WindowNotificationLevel level)
1962 {
1963   while(!mTizenPolicy)
1964   {
1965     wl_display_dispatch_queue(mDisplay, mEventQueue);
1966   }
1967
1968   int notificationLevel;
1969
1970   switch(level)
1971   {
1972     case Dali::WindowNotificationLevel::NONE:
1973     {
1974       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1975       break;
1976     }
1977     case Dali::WindowNotificationLevel::BASE:
1978     {
1979       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1980       break;
1981     }
1982     case Dali::WindowNotificationLevel::MEDIUM:
1983     {
1984       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1985       break;
1986     }
1987     case Dali::WindowNotificationLevel::HIGH:
1988     {
1989       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1990       break;
1991     }
1992     case Dali::WindowNotificationLevel::TOP:
1993     {
1994       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1995       break;
1996     }
1997     default:
1998     {
1999       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: invalid level [%d]\n", level);
2000       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
2001       break;
2002     }
2003   }
2004
2005   mNotificationLevelChangeDone = false;
2006   mNotificationChangeState     = TIZEN_POLICY_ERROR_STATE_NONE;
2007
2008   tizen_policy_set_notification_level(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), notificationLevel);
2009
2010   int count = 0;
2011
2012   while(!mNotificationLevelChangeDone && count < 3)
2013   {
2014     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2015     wl_display_dispatch_queue(mDisplay, mEventQueue);
2016     count++;
2017   }
2018
2019   if(!mNotificationLevelChangeDone)
2020   {
2021     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
2022     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2023   }
2024   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2025   {
2026     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Permission denied! [%d]\n", level);
2027     return Dali::WindowOperationResult::PERMISSION_DENIED;
2028   }
2029
2030   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
2031
2032   return Dali::WindowOperationResult::SUCCEED;
2033 }
2034
2035 Dali::WindowNotificationLevel WindowBaseEcoreWl2::GetNotificationLevel() const
2036 {
2037   while(!mTizenPolicy)
2038   {
2039     wl_display_dispatch_queue(mDisplay, mEventQueue);
2040   }
2041
2042   int count = 0;
2043
2044   while(!mNotificationLevelChangeDone && count < 3)
2045   {
2046     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2047     wl_display_dispatch_queue(mDisplay, mEventQueue);
2048     count++;
2049   }
2050
2051   if(!mNotificationLevelChangeDone)
2052   {
2053     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState);
2054     return Dali::WindowNotificationLevel::NONE;
2055   }
2056
2057   Dali::WindowNotificationLevel level;
2058
2059   switch(mNotificationLevel)
2060   {
2061     case TIZEN_POLICY_LEVEL_NONE:
2062     {
2063       level = Dali::WindowNotificationLevel::NONE;
2064       break;
2065     }
2066     case TIZEN_POLICY_LEVEL_DEFAULT:
2067     {
2068       level = Dali::WindowNotificationLevel::BASE;
2069       break;
2070     }
2071     case TIZEN_POLICY_LEVEL_MEDIUM:
2072     {
2073       level = Dali::WindowNotificationLevel::MEDIUM;
2074       break;
2075     }
2076     case TIZEN_POLICY_LEVEL_HIGH:
2077     {
2078       level = Dali::WindowNotificationLevel::HIGH;
2079       break;
2080     }
2081     case TIZEN_POLICY_LEVEL_TOP:
2082     {
2083       level = Dali::WindowNotificationLevel::TOP;
2084       break;
2085     }
2086     default:
2087     {
2088       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel);
2089       level = Dali::WindowNotificationLevel::NONE;
2090       break;
2091     }
2092   }
2093
2094   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: level [%d]\n", mNotificationLevel);
2095
2096   return level;
2097 }
2098
2099 void WindowBaseEcoreWl2::SetOpaqueState(bool opaque)
2100 {
2101   while(!mTizenPolicy)
2102   {
2103     wl_display_dispatch_queue(mDisplay, mEventQueue);
2104   }
2105
2106   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
2107 }
2108
2109 Dali::WindowOperationResult WindowBaseEcoreWl2::SetScreenOffMode(WindowScreenOffMode screenOffMode)
2110 {
2111   while(!mTizenPolicy)
2112   {
2113     wl_display_dispatch_queue(mDisplay, mEventQueue);
2114   }
2115
2116   mScreenOffModeChangeDone  = false;
2117   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2118
2119   unsigned int mode = 0;
2120
2121   switch(screenOffMode)
2122   {
2123     case WindowScreenOffMode::TIMEOUT:
2124     {
2125       mode = 0;
2126       break;
2127     }
2128     case WindowScreenOffMode::NEVER:
2129     {
2130       mode = 1;
2131       break;
2132     }
2133   }
2134
2135   tizen_policy_set_window_screen_mode(mTizenPolicy, ecore_wl2_window_surface_get(mEcoreWindow), mode);
2136
2137   int count = 0;
2138
2139   while(!mScreenOffModeChangeDone && count < 3)
2140   {
2141     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2142     wl_display_dispatch_queue(mDisplay, mEventQueue);
2143     count++;
2144   }
2145
2146   if(!mScreenOffModeChangeDone)
2147   {
2148     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
2149     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2150   }
2151   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2152   {
2153     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
2154     return Dali::WindowOperationResult::PERMISSION_DENIED;
2155   }
2156
2157   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
2158
2159   return Dali::WindowOperationResult::SUCCEED;
2160 }
2161
2162 WindowScreenOffMode WindowBaseEcoreWl2::GetScreenOffMode() const
2163 {
2164   while(!mTizenPolicy)
2165   {
2166     wl_display_dispatch_queue(mDisplay, mEventQueue);
2167   }
2168
2169   int count = 0;
2170
2171   while(!mScreenOffModeChangeDone && count < 3)
2172   {
2173     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2174     wl_display_dispatch_queue(mDisplay, mEventQueue);
2175     count++;
2176   }
2177
2178   if(!mScreenOffModeChangeDone)
2179   {
2180     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState);
2181     return WindowScreenOffMode::TIMEOUT;
2182   }
2183
2184   WindowScreenOffMode screenMode = WindowScreenOffMode::TIMEOUT;
2185
2186   switch(mScreenOffMode)
2187   {
2188     case 0:
2189     {
2190       screenMode = WindowScreenOffMode::TIMEOUT;
2191       break;
2192     }
2193     case 1:
2194     {
2195       screenMode = WindowScreenOffMode::NEVER;
2196       break;
2197     }
2198   }
2199
2200   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode);
2201
2202   return screenMode;
2203 }
2204
2205 Dali::WindowOperationResult WindowBaseEcoreWl2::SetBrightness(int brightness)
2206 {
2207   while(!mTizenDisplayPolicy)
2208   {
2209     wl_display_dispatch_queue(mDisplay, mEventQueue);
2210   }
2211
2212   mBrightnessChangeDone  = false;
2213   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
2214
2215   tizen_display_policy_set_window_brightness(mTizenDisplayPolicy, ecore_wl2_window_surface_get(mEcoreWindow), brightness);
2216
2217   int count = 0;
2218
2219   while(!mBrightnessChangeDone && count < 3)
2220   {
2221     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2222     wl_display_dispatch_queue(mDisplay, mEventQueue);
2223     count++;
2224   }
2225
2226   if(!mBrightnessChangeDone)
2227   {
2228     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
2229     return Dali::WindowOperationResult::UNKNOWN_ERROR;
2230   }
2231   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
2232   {
2233     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Permission denied! [%d]\n", brightness);
2234     return Dali::WindowOperationResult::PERMISSION_DENIED;
2235   }
2236
2237   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness is changed [%d]\n", mBrightness);
2238
2239   return Dali::WindowOperationResult::SUCCEED;
2240 }
2241
2242 int WindowBaseEcoreWl2::GetBrightness() const
2243 {
2244   while(!mTizenDisplayPolicy)
2245   {
2246     wl_display_dispatch_queue(mDisplay, mEventQueue);
2247   }
2248
2249   int count = 0;
2250
2251   while(!mBrightnessChangeDone && count < 3)
2252   {
2253     ecore_wl2_display_flush(ecore_wl2_connected_display_get(NULL));
2254     wl_display_dispatch_queue(mDisplay, mEventQueue);
2255     count++;
2256   }
2257
2258   if(!mBrightnessChangeDone)
2259   {
2260     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Error! [%d]\n", mBrightnessChangeState);
2261     return 0;
2262   }
2263
2264   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Brightness [%d]\n", mBrightness);
2265
2266   return mBrightness;
2267 }
2268
2269 bool WindowBaseEcoreWl2::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
2270 {
2271   Ecore_Wl2_Window_Keygrab_Mode mode;
2272
2273   switch(grabMode)
2274   {
2275     case KeyGrab::TOPMOST:
2276     {
2277       mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2278       break;
2279     }
2280     case KeyGrab::SHARED:
2281     {
2282       mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2283       break;
2284     }
2285     case KeyGrab::OVERRIDE_EXCLUSIVE:
2286     {
2287       mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2288       break;
2289     }
2290     case KeyGrab::EXCLUSIVE:
2291     {
2292       mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2293       break;
2294     }
2295     default:
2296     {
2297       return false;
2298     }
2299   }
2300
2301   return ecore_wl2_window_keygrab_set(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0, 0, mode);
2302 }
2303
2304 bool WindowBaseEcoreWl2::UngrabKey(Dali::KEY key)
2305 {
2306   return ecore_wl2_window_keygrab_unset(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0);
2307 }
2308
2309 bool WindowBaseEcoreWl2::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
2310 {
2311   int keyCount         = key.Count();
2312   int keyGrabModeCount = grabMode.Count();
2313
2314   if(keyCount != keyGrabModeCount || keyCount == 0)
2315   {
2316     return false;
2317   }
2318
2319   eina_init();
2320
2321   Eina_List*                     keyList = NULL;
2322   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2323
2324   for(int index = 0; index < keyCount; ++index)
2325   {
2326     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2327
2328     switch(grabMode[index])
2329     {
2330       case KeyGrab::TOPMOST:
2331       {
2332         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2333         break;
2334       }
2335       case KeyGrab::SHARED:
2336       {
2337         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2338         break;
2339       }
2340       case KeyGrab::OVERRIDE_EXCLUSIVE:
2341       {
2342         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2343         break;
2344       }
2345       case KeyGrab::EXCLUSIVE:
2346       {
2347         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2348         break;
2349       }
2350       default:
2351       {
2352         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_UNKNOWN;
2353         break;
2354       }
2355     }
2356
2357     keyList = eina_list_append(keyList, &info);
2358   }
2359
2360   Eina_List* grabList = ecore_wl2_window_keygrab_list_set(mEcoreWindow, keyList);
2361
2362   result.Resize(keyCount, true);
2363
2364   Eina_List* l        = NULL;
2365   Eina_List* m        = NULL;
2366   void*      listData = NULL;
2367   void*      data     = NULL;
2368   if(grabList != NULL)
2369   {
2370     EINA_LIST_FOREACH(grabList, m, data)
2371     {
2372       int index = 0;
2373       EINA_LIST_FOREACH(keyList, l, listData)
2374       {
2375         if(static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key == NULL)
2376         {
2377           DALI_LOG_ERROR("input key list has null data!");
2378           break;
2379         }
2380
2381         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2382         {
2383           result[index] = false;
2384         }
2385         ++index;
2386       }
2387     }
2388   }
2389
2390   delete[] info;
2391
2392   eina_list_free(keyList);
2393   eina_list_free(grabList);
2394   eina_shutdown();
2395
2396   return true;
2397 }
2398
2399 bool WindowBaseEcoreWl2::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
2400 {
2401   int keyCount = key.Count();
2402   if(keyCount == 0)
2403   {
2404     return false;
2405   }
2406
2407   eina_init();
2408
2409   Eina_List*                     keyList = NULL;
2410   Ecore_Wl2_Window_Keygrab_Info* info    = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2411
2412   for(int index = 0; index < keyCount; ++index)
2413   {
2414     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2415     keyList         = eina_list_append(keyList, &info);
2416   }
2417
2418   Eina_List* ungrabList = ecore_wl2_window_keygrab_list_unset(mEcoreWindow, keyList);
2419
2420   result.Resize(keyCount, true);
2421
2422   Eina_List* l        = NULL;
2423   Eina_List* m        = NULL;
2424   void*      listData = NULL;
2425   void*      data     = NULL;
2426
2427   if(ungrabList != NULL)
2428   {
2429     EINA_LIST_FOREACH(ungrabList, m, data)
2430     {
2431       int index = 0;
2432       EINA_LIST_FOREACH(keyList, l, listData)
2433       {
2434         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl2_Window_Keygrab_Info*>(listData)->key) == 0)
2435         {
2436           result[index] = false;
2437         }
2438         ++index;
2439       }
2440     }
2441   }
2442
2443   delete[] info;
2444
2445   eina_list_free(keyList);
2446   eina_list_free(ungrabList);
2447   eina_shutdown();
2448
2449   return true;
2450 }
2451
2452 void WindowBaseEcoreWl2::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
2453 {
2454   // calculate DPI
2455   float xres, yres;
2456
2457   Ecore_Wl2_Output* output = ecore_wl2_window_output_find(mEcoreWindow);
2458
2459   // 1 inch = 25.4 millimeters
2460   xres = ecore_wl2_output_dpi_get(output);
2461   yres = ecore_wl2_output_dpi_get(output);
2462
2463   dpiHorizontal = int(xres + 0.5f); // rounding
2464   dpiVertical   = int(yres + 0.5f);
2465 }
2466
2467 int WindowBaseEcoreWl2::GetOrientation() const
2468 {
2469   int orientation = (mScreenRotationAngle + mWindowRotationAngle) % 360;
2470   if(mSupportedPreProtation)
2471   {
2472     orientation = 0;
2473   }
2474   return orientation;
2475 }
2476
2477 int WindowBaseEcoreWl2::GetScreenRotationAngle()
2478 {
2479   int transform = 0;
2480
2481   if(ecore_wl2_window_ignore_output_transform_get(mEcoreWindow))
2482   {
2483     transform = 0;
2484   }
2485   else
2486   {
2487     transform = ecore_wl2_output_transform_get(ecore_wl2_window_output_find(mEcoreWindow));
2488   }
2489   mScreenRotationAngle = transform * 90;
2490   return mScreenRotationAngle;
2491 }
2492
2493 void WindowBaseEcoreWl2::SetWindowRotationAngle(int degree)
2494 {
2495   mWindowRotationAngle = degree;
2496   ecore_wl2_window_rotation_set(mEcoreWindow, degree);
2497 }
2498
2499 void WindowBaseEcoreWl2::WindowRotationCompleted(int degree, int width, int height)
2500 {
2501   ecore_wl2_window_rotation_change_done_send(mEcoreWindow, degree, width, height);
2502 }
2503
2504 void WindowBaseEcoreWl2::SetTransparency(bool transparent)
2505 {
2506   ecore_wl2_window_alpha_set(mEcoreWindow, transparent);
2507 }
2508
2509 void WindowBaseEcoreWl2::InitializeEcoreElDBus()
2510 {
2511 #ifdef DALI_ELDBUS_AVAILABLE
2512   Eldbus_Object* object;
2513   Eldbus_Proxy*  manager;
2514
2515   if(!(mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM)))
2516   {
2517     DALI_LOG_ERROR("Unable to get system bus\n");
2518   }
2519
2520   object = eldbus_object_get(mSystemConnection, BUS, PATH);
2521   if(!object)
2522   {
2523     DALI_LOG_ERROR("Getting object failed\n");
2524     return;
2525   }
2526
2527   manager = eldbus_proxy_get(object, INTERFACE);
2528   if(!manager)
2529   {
2530     DALI_LOG_ERROR("Getting proxy failed\n");
2531     return;
2532   }
2533
2534   if(!eldbus_proxy_signal_handler_add(manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this))
2535   {
2536     DALI_LOG_ERROR("No signal handler returned\n");
2537   }
2538 #endif
2539 }
2540
2541 void WindowBaseEcoreWl2::CreateWindow(PositionSize positionSize)
2542 {
2543   Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
2544   if(!display)
2545   {
2546     DALI_ASSERT_ALWAYS(0 && "Failed to get display");
2547   }
2548
2549   ecore_wl2_display_sync(display);
2550
2551   mEcoreWindow = ecore_wl2_window_new(display, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2552
2553   if(mEcoreWindow == 0)
2554   {
2555     DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
2556   }
2557
2558   // Set default type
2559   ecore_wl2_window_type_set(mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
2560 }
2561
2562 void WindowBaseEcoreWl2::SetParent(WindowBase* parentWinBase, bool belowParent)
2563 {
2564   Ecore_Wl2_Window* ecoreParent = NULL;
2565   if(parentWinBase)
2566   {
2567     WindowBaseEcoreWl2* winBaseEcore2 = static_cast<WindowBaseEcoreWl2*>(parentWinBase);
2568     ecoreParent                       = winBaseEcore2->mEcoreWindow;
2569   }
2570   ecore_wl2_window_transient_parent_set(mEcoreWindow, ecoreParent, belowParent);
2571 }
2572
2573 int WindowBaseEcoreWl2::CreateFrameRenderedSyncFence()
2574 {
2575   return wl_egl_window_tizen_create_commit_sync_fd(mEglWindow);
2576 }
2577
2578 int WindowBaseEcoreWl2::CreateFramePresentedSyncFence()
2579 {
2580   return wl_egl_window_tizen_create_presentation_sync_fd(mEglWindow);
2581 }
2582
2583 void WindowBaseEcoreWl2::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
2584 {
2585   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::SetPositionSizeWithAngle, angle: %d, x: %d, y: %d, w: %d, h: %d\n", angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2586   ecore_wl2_window_rotation_geometry_set(mEcoreWindow, angle, positionSize.x, positionSize.y, positionSize.width, positionSize.height);
2587 }
2588
2589 void WindowBaseEcoreWl2::InitializeIme()
2590 {
2591   Eina_Iterator*      globals;
2592   struct wl_registry* registry;
2593   Ecore_Wl2_Global*   global;
2594   Ecore_Wl2_Display*  ecoreWl2Display;
2595
2596   if(!(ecoreWl2Display = ecore_wl2_connected_display_get(NULL)))
2597   {
2598     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 connected display\n");
2599     return;
2600   }
2601
2602   DALI_LOG_RELEASE_INFO("InitializeIme:  Ecore_Wl2_Display: %p, ecore wl window: %p\n", ecoreWl2Display, mEcoreWindow);
2603
2604   if(!(registry = ecore_wl2_display_registry_get(ecoreWl2Display)))
2605   {
2606     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 display registry\n");
2607     return;
2608   }
2609
2610   if(!(globals = ecore_wl2_display_globals_get(ecoreWl2Display)))
2611   {
2612     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get ecore_wl2 globals\n");
2613     return;
2614   }
2615
2616   EINA_ITERATOR_FOREACH(globals, global)
2617   {
2618     if(strcmp(global->interface, "wl_input_panel") == 0)
2619     {
2620       mWlInputPanel = (wl_input_panel*)wl_registry_bind(registry, global->id, &wl_input_panel_interface, 1);
2621     }
2622     else if(strcmp(global->interface, "wl_output") == 0)
2623     {
2624       mWlOutput = (wl_output*)wl_registry_bind(registry, global->id, &wl_output_interface, 1);
2625     }
2626   }
2627
2628   if(!mWlInputPanel)
2629   {
2630     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel interface\n");
2631     return;
2632   }
2633
2634   if(!mWlOutput)
2635   {
2636     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland output panel interface\n");
2637     return;
2638   }
2639
2640   mWlInputPanelSurface = wl_input_panel_get_input_panel_surface(mWlInputPanel, mWlSurface);
2641   if(!mWlInputPanelSurface)
2642   {
2643     DALI_LOG_ERROR("WindowBaseEcoreWl2::InitializeIme(), fail to get wayland input panel surface\n");
2644     return;
2645   }
2646
2647   wl_input_panel_surface_set_toplevel(mWlInputPanelSurface, mWlOutput, WL_INPUT_PANEL_SURFACE_POSITION_CENTER_BOTTOM);
2648 }
2649
2650 void WindowBaseEcoreWl2::ImeWindowReadyToRender()
2651 {
2652   if(!mWlInputPanelSurface)
2653   {
2654     DALI_LOG_ERROR("WindowBaseEcoreWl2::ImeWindowReadyToRender(), wayland input panel surface is null\n");
2655     return;
2656   }
2657
2658   wl_input_panel_surface_set_ready(mWlInputPanelSurface, 1);
2659 }
2660
2661 void WindowBaseEcoreWl2::RequestMoveToServer()
2662 {
2663   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
2664   if(!display)
2665   {
2666     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get ecore_wl2_display\n");
2667     return;
2668   }
2669
2670   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
2671   if(!input)
2672   {
2673     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestMoveToServer, Fail to get default Ecore_Wl2_Input\n");
2674     return;
2675   }
2676
2677   ecore_wl2_window_move(mEcoreWindow, input);
2678   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestMoveToServer, starts the window[%p] is moved by server\n", mEcoreWindow);
2679 }
2680
2681 void WindowBaseEcoreWl2::RequestResizeToServer(WindowResizeDirection direction)
2682 {
2683   Ecore_Wl2_Display* display = ecore_wl2_connected_display_get(NULL);
2684   if(!display)
2685   {
2686     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get ecore_wl2_display\n");
2687     return;
2688   }
2689
2690   Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(display);
2691   if(!input)
2692   {
2693     DALI_LOG_ERROR("WindowBaseEcoreWl2::RequestResizeToServer, Fail to get default Ecore_Wl2_Input\n");
2694     return;
2695   }
2696
2697   int location = 0;
2698   switch(direction)
2699   {
2700     case WindowResizeDirection::TOP_LEFT:
2701     {
2702       location = 5;
2703       break;
2704     }
2705     case WindowResizeDirection::TOP:
2706     {
2707       location = 1;
2708       break;
2709     }
2710     case WindowResizeDirection::TOP_RIGHT:
2711     {
2712       location = 9;
2713       break;
2714     }
2715     case WindowResizeDirection::LEFT:
2716     {
2717       location = 4;
2718       break;
2719     }
2720     case WindowResizeDirection::RIGHT:
2721     {
2722       location = 8;
2723       break;
2724     }
2725     case WindowResizeDirection::BOTTOM_LEFT:
2726     {
2727       location = 6;
2728       break;
2729     }
2730     case WindowResizeDirection::BOTTOM:
2731     {
2732       location = 2;
2733       break;
2734     }
2735     case WindowResizeDirection::BOTTOM_RIGHT:
2736     {
2737       location = 10;
2738       break;
2739     }
2740     default:
2741     {
2742       location = 0;
2743       break;
2744     }
2745   }
2746
2747   ecore_wl2_window_resize(mEcoreWindow, input, location);
2748   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::RequestResizeToServer, starts the window[%p] is resized by server, mode:%d\n", mEcoreWindow, location);
2749 }
2750
2751 void WindowBaseEcoreWl2::EnableFloatingMode(bool enable)
2752 {
2753   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl2::EnableFloatingMode, floating mode flag: [%p], enable [%d]\n", mEcoreWindow, enable);
2754   if(enable == true)
2755   {
2756     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_TRUE);
2757   }
2758   else
2759   {
2760     ecore_wl2_window_floating_mode_set(mEcoreWindow, EINA_FALSE);
2761   }
2762 }
2763
2764 bool WindowBaseEcoreWl2::IsFloatingModeEnabled() const
2765 {
2766   return ecore_wl2_window_floating_mode_get(mEcoreWindow);
2767 }
2768
2769 void WindowBaseEcoreWl2::IncludeInputRegion(const Rect<int>& inputRegion)
2770 {
2771   Eina_Rectangle rect;
2772   rect.x = inputRegion.x;
2773   rect.y = inputRegion.y;
2774   rect.w = inputRegion.width;
2775   rect.h = inputRegion.height;
2776
2777   ecore_wl2_window_input_rect_add(mEcoreWindow, &rect);
2778   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2779 }
2780
2781 void WindowBaseEcoreWl2::ExcludeInputRegion(const Rect<int>& inputRegion)
2782 {
2783   Eina_Rectangle rect;
2784   rect.x = inputRegion.x;
2785   rect.y = inputRegion.y;
2786   rect.w = inputRegion.width;
2787   rect.h = inputRegion.height;
2788
2789   ecore_wl2_window_input_rect_subtract(mEcoreWindow, &rect);
2790   ecore_wl2_window_commit(mEcoreWindow, EINA_TRUE);
2791 }
2792
2793 } // namespace Adaptor
2794
2795 } // namespace Internal
2796
2797 } // namespace Dali
2798
2799 #pragma GCC diagnostic pop