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