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