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