[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl / window-base-ecore-wl.cpp
1 /*
2  * Copyright (c) 2024 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-wl/window-base-ecore-wl.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
30 // EXTERNAL_HEADERS
31 #include <Ecore_Input.h>
32 #include <dali/integration-api/debug.h>
33 #include <dali/public-api/object/any.h>
34
35 #if defined(VCONF_ENABLED)
36 #include <vconf-keys.h>
37 #include <vconf.h>
38 #endif
39
40 namespace Dali
41 {
42 namespace Internal
43 {
44 namespace Adaptor
45 {
46 namespace
47 {
48 #if defined(DEBUG_ENABLED)
49 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW_BASE");
50 #endif
51
52 const uint32_t     MAX_TIZEN_CLIENT_VERSION = 7;
53 const unsigned int PRIMARY_TOUCH_BUTTON_ID  = 1;
54
55 #if defined(VCONF_ENABLED)
56 const char* DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name"; // It will be update at vconf-key.h and replaced.
57 #endif
58
59 // DBUS accessibility
60 const char* BUS       = "org.enlightenment.wm-screen-reader";
61 const char* INTERFACE = "org.tizen.GestureNavigation";
62 const char* PATH      = "/org/tizen/GestureNavigation";
63
64 /**
65  * Get the device name from the provided ecore key event
66  */
67 void GetDeviceName(Ecore_Event_Key* keyEvent, std::string& result)
68 {
69   const char* ecoreDeviceName = ecore_device_name_get(keyEvent->dev);
70
71   if(ecoreDeviceName)
72   {
73     result = ecoreDeviceName;
74   }
75 }
76
77 /**
78  * Get the device class from the provided ecore event
79  */
80 void GetDeviceClass(Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass)
81 {
82   switch(ecoreDeviceClass)
83   {
84     case ECORE_DEVICE_CLASS_SEAT:
85     {
86       deviceClass = Device::Class::USER;
87       break;
88     }
89     case ECORE_DEVICE_CLASS_KEYBOARD:
90     {
91       deviceClass = Device::Class::KEYBOARD;
92       break;
93     }
94     case ECORE_DEVICE_CLASS_MOUSE:
95     {
96       deviceClass = Device::Class::MOUSE;
97       break;
98     }
99     case ECORE_DEVICE_CLASS_TOUCH:
100     {
101       deviceClass = Device::Class::TOUCH;
102       break;
103     }
104     case ECORE_DEVICE_CLASS_PEN:
105     {
106       deviceClass = Device::Class::PEN;
107       break;
108     }
109     case ECORE_DEVICE_CLASS_POINTER:
110     {
111       deviceClass = Device::Class::POINTER;
112       break;
113     }
114     case ECORE_DEVICE_CLASS_GAMEPAD:
115     {
116       deviceClass = Device::Class::GAMEPAD;
117       break;
118     }
119     default:
120     {
121       deviceClass = Device::Class::NONE;
122       break;
123     }
124   }
125 }
126
127 void GetDeviceSubclass(Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass)
128 {
129   switch(ecoreDeviceSubclass)
130   {
131     case ECORE_DEVICE_SUBCLASS_FINGER:
132     {
133       deviceSubclass = Device::Subclass::FINGER;
134       break;
135     }
136     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
137     {
138       deviceSubclass = Device::Subclass::FINGERNAIL;
139       break;
140     }
141     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
142     {
143       deviceSubclass = Device::Subclass::KNUCKLE;
144       break;
145     }
146     case ECORE_DEVICE_SUBCLASS_PALM:
147     {
148       deviceSubclass = Device::Subclass::PALM;
149       break;
150     }
151     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
152     {
153       deviceSubclass = Device::Subclass::HAND_SIDE;
154       break;
155     }
156     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
157     {
158       deviceSubclass = Device::Subclass::HAND_FLAT;
159       break;
160     }
161     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
162     {
163       deviceSubclass = Device::Subclass::PEN_TIP;
164       break;
165     }
166     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
167     {
168       deviceSubclass = Device::Subclass::TRACKPAD;
169       break;
170     }
171     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
172     {
173       deviceSubclass = Device::Subclass::TRACKPOINT;
174       break;
175     }
176     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
177     {
178       deviceSubclass = Device::Subclass::TRACKBALL;
179       break;
180     }
181     case ECORE_DEVICE_SUBCLASS_REMOCON:
182     {
183       deviceSubclass = Device::Subclass::REMOCON;
184       break;
185     }
186     case ECORE_DEVICE_SUBCLASS_VIRTUAL_KEYBOARD:
187     {
188       deviceSubclass = Device::Subclass::VIRTUAL_KEYBOARD;
189       break;
190     }
191     default:
192     {
193       deviceSubclass = Device::Subclass::NONE;
194       break;
195     }
196   }
197 }
198
199 /////////////////////////////////////////////////////////////////////////////////////////////////
200 // Window Callbacks
201 /////////////////////////////////////////////////////////////////////////////////////////////////
202
203 /// Called when the window iconify state is changed.
204 static Eina_Bool EcoreEventWindowIconifyStateChanged(void* data, int type, void* event)
205 {
206   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
207   if(windowBase)
208   {
209     return windowBase->OnIconifyStateChanged(data, type, event);
210   }
211
212   return ECORE_CALLBACK_PASS_ON;
213 }
214
215 /// Called when the window gains focus
216 static Eina_Bool EcoreEventWindowFocusIn(void* data, int type, void* event)
217 {
218   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
219   if(windowBase)
220   {
221     return windowBase->OnFocusIn(data, type, event);
222   }
223
224   return ECORE_CALLBACK_PASS_ON;
225 }
226
227 /// Called when the window loses focus
228 static Eina_Bool EcoreEventWindowFocusOut(void* data, int type, void* event)
229 {
230   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
231   if(windowBase)
232   {
233     return windowBase->OnFocusOut(data, type, event);
234   }
235
236   return ECORE_CALLBACK_PASS_ON;
237 }
238
239 /// Called when the output is transformed
240 static Eina_Bool EcoreEventOutputTransform(void* data, int type, void* event)
241 {
242   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
243   if(windowBase)
244   {
245     return windowBase->OnOutputTransform(data, type, event);
246   }
247
248   return ECORE_CALLBACK_PASS_ON;
249 }
250
251 /// Called when the output transform should be ignored
252 static Eina_Bool EcoreEventIgnoreOutputTransform(void* data, int type, void* event)
253 {
254   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
255   if(windowBase)
256   {
257     return windowBase->OnIgnoreOutputTransform(data, type, event);
258   }
259
260   return ECORE_CALLBACK_PASS_ON;
261 }
262
263 /**
264  * Called when rotate event is recevied.
265  */
266 static Eina_Bool EcoreEventRotate(void* data, int type, void* event)
267 {
268   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
269   if(windowBase)
270   {
271     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl::EcoreEventRotate\n");
272     windowBase->OnRotation(data, type, event);
273   }
274   return ECORE_CALLBACK_PASS_ON;
275 }
276
277 /////////////////////////////////////////////////////////////////////////////////////////////////
278 // Touch Callbacks
279 /////////////////////////////////////////////////////////////////////////////////////////////////
280
281 /**
282  * Called when a touch down is received.
283  */
284 static Eina_Bool EcoreEventMouseButtonDown(void* data, int type, void* event)
285 {
286   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
287   if(windowBase)
288   {
289     windowBase->OnMouseButtonDown(data, type, event);
290   }
291   return ECORE_CALLBACK_PASS_ON;
292 }
293
294 /**
295  * Called when a touch up is received.
296  */
297 static Eina_Bool EcoreEventMouseButtonUp(void* data, int type, void* event)
298 {
299   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
300   if(windowBase)
301   {
302     windowBase->OnMouseButtonUp(data, type, event);
303   }
304   return ECORE_CALLBACK_PASS_ON;
305 }
306
307 /**
308  * Called when a touch motion is received.
309  */
310 static Eina_Bool EcoreEventMouseButtonMove(void* data, int type, void* event)
311 {
312   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
313   if(windowBase)
314   {
315     windowBase->OnMouseButtonMove(data, type, event);
316   }
317   return ECORE_CALLBACK_PASS_ON;
318 }
319
320 /**
321  * Called when a touch is canceled.
322  */
323 static Eina_Bool EcoreEventMouseButtonCancel(void* data, int type, void* event)
324 {
325   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
326   if(windowBase)
327   {
328     windowBase->OnMouseButtonCancel(data, type, event);
329   }
330   return ECORE_CALLBACK_PASS_ON;
331 }
332
333 /**
334  * Called when a mouse wheel is received.
335  */
336 static Eina_Bool EcoreEventMouseWheel(void* data, int type, void* event)
337 {
338   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
339   if(windowBase)
340   {
341     windowBase->OnMouseWheel(data, type, event);
342   }
343   return ECORE_CALLBACK_PASS_ON;
344 }
345
346 /**
347  * Called when a detent rotation event is recevied.
348  */
349 static Eina_Bool EcoreEventDetentRotation(void* data, int type, void* event)
350 {
351   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
352   if(windowBase)
353   {
354     windowBase->OnDetentRotation(data, type, event);
355   }
356   return ECORE_CALLBACK_PASS_ON;
357 }
358
359 /////////////////////////////////////////////////////////////////////////////////////////////////
360 // Key Callbacks
361 /////////////////////////////////////////////////////////////////////////////////////////////////
362
363 /**
364  * Called when a key down is received.
365  */
366 static Eina_Bool EcoreEventKeyDown(void* data, int type, void* event)
367 {
368   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
369   if(windowBase)
370   {
371     windowBase->OnKeyDown(data, type, event);
372   }
373   return ECORE_CALLBACK_PASS_ON;
374 }
375
376 /**
377  * Called when a key up is received.
378  */
379 static Eina_Bool EcoreEventKeyUp(void* data, int type, void* event)
380 {
381   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
382   if(windowBase)
383   {
384     windowBase->OnKeyUp(data, type, event);
385   }
386   return ECORE_CALLBACK_PASS_ON;
387 }
388
389 /////////////////////////////////////////////////////////////////////////////////////////////////
390 // Selection Callbacks
391 /////////////////////////////////////////////////////////////////////////////////////////////////
392
393 /**
394  * Called when the source window notifies us the content in clipboard is selected.
395  */
396 static Eina_Bool EcoreEventDataSend(void* data, int type, void* event)
397 {
398   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
399   if(windowBase)
400   {
401     windowBase->OnDataSend(data, type, event);
402   }
403   return ECORE_CALLBACK_PASS_ON;
404 }
405
406 /**
407 * Called when the source window sends us about the selected content.
408 * For example, when item is selected in the clipboard.
409 */
410 static Eina_Bool EcoreEventDataReceive(void* data, int type, void* event)
411 {
412   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
413   if(windowBase)
414   {
415     windowBase->OnDataReceive(data, type, event);
416   }
417   return ECORE_CALLBACK_PASS_ON;
418 }
419
420 /////////////////////////////////////////////////////////////////////////////////////////////////
421 // Font Callbacks
422 /////////////////////////////////////////////////////////////////////////////////////////////////
423
424 #if defined(VCONF_ENABLED)
425 /**
426  * Called when a font name is changed.
427  */
428 static void VconfNotifyFontNameChanged(keynode_t* node, void* data)
429 {
430   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
431   if(windowBase)
432   {
433     windowBase->OnFontNameChanged();
434   }
435 }
436
437 /**
438  * Called when a font size is changed.
439  */
440 static void VconfNotifyFontSizeChanged(keynode_t* node, void* data)
441 {
442   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
443   if(windowBase)
444   {
445     windowBase->OnFontSizeChanged();
446   }
447 }
448 #endif
449
450 static void RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
451 {
452   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
453   if(windowBase)
454   {
455     windowBase->RegistryGlobalCallback(data, registry, name, interface, version);
456   }
457 }
458
459 static void RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
460 {
461   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
462   if(windowBase)
463   {
464     windowBase->RegistryGlobalCallbackRemove(data, registry, id);
465   }
466 }
467
468 static void TizenPolicyConformant(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant)
469 {
470 }
471
472 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)
473 {
474 }
475
476 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
477 {
478   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
479   if(windowBase)
480   {
481     windowBase->TizenPolicyNotificationChangeDone(data, tizenPolicy, surface, level, state);
482   }
483 }
484
485 static void TizenPolicyTransientForDone(void* data, struct tizen_policy* tizenPolicy, uint32_t childId)
486 {
487 }
488
489 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
490 {
491   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
492   if(windowBase)
493   {
494     windowBase->TizenPolicyScreenModeChangeDone(data, tizenPolicy, surface, mode, state);
495   }
496 }
497
498 static void TizenPolicyIconifyStateChanged(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force)
499 {
500 }
501
502 static void TizenPolicySupportedAuxiliaryHints(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints)
503 {
504 }
505
506 static void TizenPolicyAllowedAuxiliaryHint(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id)
507 {
508 }
509
510 static void TizenPolicyAuxiliaryMessage(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options)
511 {
512 }
513
514 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)
515 {
516 }
517
518 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
519 {
520   WindowBaseEcoreWl* windowBase = static_cast<WindowBaseEcoreWl*>(data);
521   if(windowBase)
522   {
523     windowBase->DisplayPolicyBrightnessChangeDone(data, displayPolicy, surface, brightness, state);
524   }
525 }
526
527 const struct wl_registry_listener registryListener =
528   {
529     RegistryGlobalCallback,
530     RegistryGlobalCallbackRemove};
531
532 const struct tizen_policy_listener tizenPolicyListener =
533   {
534     TizenPolicyConformant,
535     TizenPolicyConformantArea,
536     TizenPolicyNotificationChangeDone,
537     TizenPolicyTransientForDone,
538     TizenPolicyScreenModeChangeDone,
539     TizenPolicyIconifyStateChanged,
540     TizenPolicySupportedAuxiliaryHints,
541     TizenPolicyAllowedAuxiliaryHint,
542     TizenPolicyAuxiliaryMessage,
543     TizenPolicyConformantRegion};
544
545 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
546   {
547     DisplayPolicyBrightnessChangeDone};
548
549 } // unnamed namespace
550
551 WindowBaseEcoreWl::WindowBaseEcoreWl(Dali::PositionSize positionSize, Any surface, bool isTransparent)
552 : mEcoreEventHandler(),
553   mEcoreWindow(nullptr),
554   mWlSurface(nullptr),
555   mEglWindow(nullptr),
556   mDisplay(nullptr),
557   mEventQueue(nullptr),
558   mTizenPolicy(nullptr),
559   mTizenDisplayPolicy(nullptr),
560   mSupportedAuxiliaryHints(),
561   mAuxiliaryHints(),
562   mNotificationLevel(-1),
563   mNotificationChangeState(0),
564   mNotificationLevelChangeDone(true),
565   mScreenOffMode(0),
566   mScreenOffModeChangeState(0),
567   mScreenOffModeChangeDone(true),
568   mBrightness(0),
569   mBrightnessChangeState(0),
570   mBrightnessChangeDone(true),
571   mOwnSurface(false),
572   mWindowRotationAngle(0),
573   mScreenRotationAngle(0),
574   mSupportedPreProtation(0)
575 {
576   Initialize(positionSize, surface, isTransparent);
577 }
578
579 WindowBaseEcoreWl::~WindowBaseEcoreWl()
580 {
581 #if defined(VCONF_ENABLED)
582   vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged);
583   vconf_ignore_key_changed(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged);
584 #endif
585
586   for(Dali::Vector<Ecore_Event_Handler*>::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter)
587   {
588     ecore_event_handler_del(*iter);
589   }
590   mEcoreEventHandler.Clear();
591
592   if(mEventQueue)
593   {
594     wl_event_queue_destroy(mEventQueue);
595   }
596
597   mSupportedAuxiliaryHints.clear();
598   mAuxiliaryHints.clear();
599
600   if(mEglWindow != NULL)
601   {
602     wl_egl_window_destroy(mEglWindow);
603     mEglWindow = NULL;
604   }
605
606   if(mOwnSurface)
607   {
608     try
609     {
610       ecore_wl_window_free(mEcoreWindow);
611     }
612     catch(std::bad_weak_ptr const& ex)
613     {
614       DALI_LOG_ERROR("WindowBaseEcoreWl::~WindowBaseEcoreWl() - window (%p) std::bad_weak_ptr caught: %s\n", mEcoreWindow, ex.what());
615     }
616   }
617 }
618
619 void WindowBaseEcoreWl::Initialize(PositionSize positionSize, Any surface, bool isTransparent)
620 {
621   if(surface.Empty() == false)
622   {
623     // check we have a valid type
624     DALI_ASSERT_ALWAYS((surface.GetType() == typeid(Ecore_Wl_Window*)) && "Surface type is invalid");
625
626     mEcoreWindow = AnyCast<Ecore_Wl_Window*>(surface);
627   }
628   else
629   {
630     // we own the surface about to created
631     mOwnSurface = true;
632     CreateWindow(positionSize);
633   }
634
635   mWlSurface = ecore_wl_window_surface_create(mEcoreWindow);
636
637   SetTransparency(isTransparent);
638
639   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this));
640   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this));
641   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this));
642   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this));
643   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this));
644
645   // Register Rotate event
646   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_ROTATE, EcoreEventRotate, this));
647
648   // Register Touch events
649   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, EcoreEventMouseButtonDown, this));
650   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, EcoreEventMouseButtonUp, this));
651   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, EcoreEventMouseButtonMove, this));
652   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, EcoreEventMouseButtonCancel, this));
653
654   // Register Mouse wheel events
655   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL, EcoreEventMouseWheel, this));
656
657   // Register Detent event
658   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_DETENT_ROTATE, EcoreEventDetentRotation, this));
659
660   // Register Key events
661   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_DOWN, EcoreEventKeyDown, this));
662   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_EVENT_KEY_UP, EcoreEventKeyUp, this));
663
664   // Register Selection event - clipboard selection
665   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_DATA_SOURCE_SEND, EcoreEventDataSend, this));
666   mEcoreEventHandler.PushBack(ecore_event_handler_add(ECORE_WL_EVENT_SELECTION_DATA_READY, EcoreEventDataReceive, this));
667
668 #if defined(VCONF_ENABLED)
669   // Register Vconf notify - font name and size
670   vconf_notify_key_changed_for_ui_thread(DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this);
671   vconf_notify_key_changed_for_ui_thread(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, this);
672 #endif
673
674   mDisplay = ecore_wl_display_get();
675
676   if(mDisplay)
677   {
678     wl_display* displayWrapper = static_cast<wl_display*>(wl_proxy_create_wrapper(mDisplay));
679     if(displayWrapper)
680     {
681       mEventQueue = wl_display_create_queue(mDisplay);
682       if(mEventQueue)
683       {
684         wl_proxy_set_queue(reinterpret_cast<wl_proxy*>(displayWrapper), mEventQueue);
685
686         wl_registry* registry = wl_display_get_registry(displayWrapper);
687         wl_registry_add_listener(registry, &registryListener, this);
688       }
689
690       wl_proxy_wrapper_destroy(displayWrapper);
691     }
692   }
693
694   // get auxiliary hint
695   Eina_List* hints = ecore_wl_window_aux_hints_supported_get(mEcoreWindow);
696   if(hints)
697   {
698     Eina_List* l    = NULL;
699     char*      hint = NULL;
700
701     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))))
702     {
703       mSupportedAuxiliaryHints.push_back(hint);
704
705       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::Initialize: %s\n", hint);
706     }
707   }
708 }
709
710 Eina_Bool WindowBaseEcoreWl::OnIconifyStateChanged(void* data, int type, void* event)
711 {
712   Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent(static_cast<Ecore_Wl_Event_Window_Iconify_State_Change*>(event));
713   Eina_Bool                                   handled(ECORE_CALLBACK_PASS_ON);
714
715   if(iconifyChangedEvent->win == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
716   {
717     if(iconifyChangedEvent->iconified == EINA_TRUE)
718     {
719       mIconifyChangedSignal.Emit(true);
720     }
721     else
722     {
723       mIconifyChangedSignal.Emit(false);
724     }
725     handled = ECORE_CALLBACK_DONE;
726   }
727
728   return handled;
729 }
730
731 Eina_Bool WindowBaseEcoreWl::OnFocusIn(void* data, int type, void* event)
732 {
733   Ecore_Wl_Event_Focus_In* focusInEvent(static_cast<Ecore_Wl_Event_Focus_In*>(event));
734
735   if(focusInEvent->win == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
736   {
737     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n");
738
739     mFocusChangedSignal.Emit(true);
740   }
741
742   return ECORE_CALLBACK_PASS_ON;
743 }
744
745 Eina_Bool WindowBaseEcoreWl::OnFocusOut(void* data, int type, void* event)
746 {
747   Ecore_Wl_Event_Focus_Out* focusOutEvent(static_cast<Ecore_Wl_Event_Focus_Out*>(event));
748
749   if(focusOutEvent->win == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
750   {
751     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n");
752
753     mFocusChangedSignal.Emit(false);
754   }
755
756   return ECORE_CALLBACK_PASS_ON;
757 }
758
759 Eina_Bool WindowBaseEcoreWl::OnOutputTransform(void* data, int type, void* event)
760 {
761   Ecore_Wl_Event_Output_Transform* transformEvent(static_cast<Ecore_Wl_Event_Output_Transform*>(event));
762
763   if(transformEvent->output == ecore_wl_window_output_find(mEcoreWindow))
764   {
765     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow);
766
767     mOutputTransformedSignal.Emit();
768   }
769
770   return ECORE_CALLBACK_PASS_ON;
771 }
772
773 Eina_Bool WindowBaseEcoreWl::OnIgnoreOutputTransform(void* data, int type, void* event)
774 {
775   Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent(static_cast<Ecore_Wl_Event_Ignore_Output_Transform*>(event));
776
777   if(ignoreTransformEvent->win == mEcoreWindow)
778   {
779     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow);
780
781     mOutputTransformedSignal.Emit();
782   }
783
784   return ECORE_CALLBACK_PASS_ON;
785 }
786
787 void WindowBaseEcoreWl::OnRotation(void* data, int type, void* event)
788 {
789   Ecore_Wl_Event_Window_Rotate* ev(static_cast<Ecore_Wl_Event_Window_Rotate*>(event));
790
791   if(ev->win == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
792   {
793     DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl::OnRotation, angle: %d, width: %d, height: %d\n", ev->angle, ev->w, ev->h);
794
795     RotationEvent rotationEvent;
796     rotationEvent.angle     = ev->angle;
797     rotationEvent.winResize = 0;
798
799     if(ev->angle == 0 || ev->angle == 180)
800     {
801       rotationEvent.width  = ev->w;
802       rotationEvent.height = ev->h;
803     }
804     else
805     {
806       rotationEvent.width  = ev->h;
807       rotationEvent.height = ev->w;
808     }
809
810     mRotationSignal.Emit(rotationEvent);
811   }
812 }
813
814 void WindowBaseEcoreWl::OnMouseButtonDown(void* data, int type, void* event)
815 {
816   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
817
818   if(touchEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
819   {
820     PointState::Type state(PointState::DOWN);
821
822     // Check if the buttons field is set and ensure it's the primary touch button.
823     // If this event was triggered by buttons other than the primary button (used for touch), then
824     // just send an interrupted event to Core.
825     if(touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID))
826     {
827       state = PointState::INTERRUPTED;
828     }
829
830     Device::Class::Type    deviceClass;
831     Device::Subclass::Type deviceSubclass;
832
833     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
834     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
835
836     Integration::Point point;
837     point.SetDeviceId(touchEvent->multi.device);
838     point.SetState(state);
839     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
840     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
841     point.SetPressure(touchEvent->multi.pressure);
842     point.SetAngle(Degree(touchEvent->multi.angle));
843     point.SetDeviceClass(deviceClass);
844     point.SetDeviceSubclass(deviceSubclass);
845
846     mTouchEventSignal.Emit(point, touchEvent->timestamp);
847   }
848 }
849
850 void WindowBaseEcoreWl::OnMouseButtonUp(void* data, int type, void* event)
851 {
852   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
853
854   if(touchEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
855   {
856     Device::Class::Type    deviceClass;
857     Device::Subclass::Type deviceSubclass;
858
859     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
860     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
861
862     Integration::Point point;
863     point.SetDeviceId(touchEvent->multi.device);
864     point.SetState(PointState::UP);
865     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
866     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
867     point.SetPressure(touchEvent->multi.pressure);
868     point.SetAngle(Degree(touchEvent->multi.angle));
869     point.SetDeviceClass(deviceClass);
870     point.SetDeviceSubclass(deviceSubclass);
871
872     mTouchEventSignal.Emit(point, touchEvent->timestamp);
873   }
874 }
875
876 void WindowBaseEcoreWl::OnMouseButtonMove(void* data, int type, void* event)
877 {
878   Ecore_Event_Mouse_Move* touchEvent = static_cast<Ecore_Event_Mouse_Move*>(event);
879
880   if(touchEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
881   {
882     Device::Class::Type    deviceClass;
883     Device::Subclass::Type deviceSubclass;
884
885     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
886     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
887
888     Integration::Point point;
889     point.SetDeviceId(touchEvent->multi.device);
890     point.SetState(PointState::MOTION);
891     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
892     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
893     point.SetPressure(touchEvent->multi.pressure);
894     point.SetAngle(Degree(touchEvent->multi.angle));
895     point.SetDeviceClass(deviceClass);
896     point.SetDeviceSubclass(deviceSubclass);
897
898     mTouchEventSignal.Emit(point, touchEvent->timestamp);
899   }
900 }
901
902 void WindowBaseEcoreWl::OnMouseButtonCancel(void* data, int type, void* event)
903 {
904   Ecore_Event_Mouse_Button* touchEvent = static_cast<Ecore_Event_Mouse_Button*>(event);
905
906   if(touchEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
907   {
908     Device::Class::Type    deviceClass;
909     Device::Subclass::Type deviceSubclass;
910
911     GetDeviceClass(ecore_device_class_get(touchEvent->dev), deviceClass);
912     GetDeviceSubclass(ecore_device_subclass_get(touchEvent->dev), deviceSubclass);
913
914     Integration::Point point;
915     point.SetDeviceId(touchEvent->multi.device);
916     point.SetState(PointState::INTERRUPTED);
917     point.SetScreenPosition(Vector2(touchEvent->x, touchEvent->y));
918     point.SetRadius(touchEvent->multi.radius, Vector2(touchEvent->multi.radius_x, touchEvent->multi.radius_y));
919     point.SetPressure(touchEvent->multi.pressure);
920     point.SetAngle(Degree(touchEvent->multi.angle));
921     point.SetDeviceClass(deviceClass);
922     point.SetDeviceSubclass(deviceSubclass);
923
924     mTouchEventSignal.Emit(point, touchEvent->timestamp);
925
926     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseButtonCancel\n");
927   }
928 }
929
930 void WindowBaseEcoreWl::OnMouseWheel(void* data, int type, void* event)
931 {
932   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast<Ecore_Event_Mouse_Wheel*>(event);
933
934   if(mouseWheelEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
935   {
936     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseWheel: direction: %d, modifiers: %d, x: %d, y: %d, z: %d\n", mouseWheelEvent->direction, mouseWheelEvent->modifiers, mouseWheelEvent->x, mouseWheelEvent->y, mouseWheelEvent->z);
937
938     Integration::WheelEvent wheelEvent(Integration::WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2(mouseWheelEvent->x, mouseWheelEvent->y), mouseWheelEvent->z, mouseWheelEvent->timestamp);
939
940     mWheelEventSignal.Emit(wheelEvent);
941   }
942 }
943
944 void WindowBaseEcoreWl::OnDetentRotation(void* data, int type, void* event)
945 {
946   Ecore_Event_Detent_Rotate* detentEvent = static_cast<Ecore_Event_Detent_Rotate*>(event);
947
948   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnDetentRotation\n");
949
950   int direction = (detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) ? 1 : -1;
951   int timeStamp = detentEvent->timestamp;
952
953   Integration::WheelEvent wheelEvent(Integration::WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2(0.0f, 0.0f), direction, timeStamp);
954
955   mWheelEventSignal.Emit(wheelEvent);
956 }
957
958 void WindowBaseEcoreWl::OnKeyDown(void* data, int type, void* event)
959 {
960   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
961
962   if(keyEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
963   {
964     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyDown\n");
965
966     std::string keyName(keyEvent->keyname);
967     std::string logicalKey("");
968     std::string keyString("");
969     std::string compose("");
970
971     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
972     if(keyEvent->compose)
973     {
974       compose = keyEvent->compose;
975     }
976
977     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
978     if(keyEvent->key)
979     {
980       logicalKey = keyEvent->key;
981     }
982
983     int keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
984     keyCode     = (keyCode == -1) ? 0 : keyCode;
985     int           modifier(keyEvent->modifiers);
986     unsigned long time = keyEvent->timestamp;
987     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
988     {
989       keyCode = atoi(keyEvent->keyname + 8);
990     }
991
992     // Ensure key event string is not NULL as keys like SHIFT have a null string.
993     if(keyEvent->string)
994     {
995       keyString = keyEvent->string;
996     }
997
998     std::string            deviceName;
999     Device::Class::Type    deviceClass;
1000     Device::Subclass::Type deviceSubclass;
1001
1002     GetDeviceName(keyEvent, deviceName);
1003     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1004     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1005
1006     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::DOWN, compose, deviceName, deviceClass, deviceSubclass);
1007     keyEvent.windowId = GetNativeWindowId();
1008
1009     mKeyEventSignal.Emit(keyEvent);
1010   }
1011 }
1012
1013 void WindowBaseEcoreWl::OnKeyUp(void* data, int type, void* event)
1014 {
1015   Ecore_Event_Key* keyEvent = static_cast<Ecore_Event_Key*>(event);
1016
1017   if(keyEvent->window == static_cast<unsigned int>(ecore_wl_window_id_get(mEcoreWindow)))
1018   {
1019     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyUp\n");
1020
1021 #if defined(ECORE_VERSION_MAJOR) && (ECORE_VERSION_MAJOR >= 1) && defined(ECORE_VERSION_MINOR) && (ECORE_VERSION_MINOR >= 23)
1022     // Cancel processing flag is sent because this key event will combine with the previous key. So, the event should not actually perform anything.
1023     if(keyEvent->event_flags & ECORE_EVENT_FLAG_CANCEL)
1024     {
1025       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyUp: This event flag indicates the event is canceled. \n");
1026       return;
1027     }
1028 #endif // Since ecore 1.23 version
1029
1030     std::string keyName(keyEvent->keyname);
1031     std::string logicalKey("");
1032     std::string keyString("");
1033     std::string compose("");
1034
1035     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1036     if(keyEvent->compose)
1037     {
1038       compose = keyEvent->compose;
1039     }
1040
1041     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1042     if(keyEvent->key)
1043     {
1044       logicalKey = keyEvent->key;
1045     }
1046
1047     int keyCode = KeyLookup::GetDaliKeyCode(keyEvent->keyname);
1048     keyCode     = (keyCode == -1) ? 0 : keyCode;
1049     int           modifier(keyEvent->modifiers);
1050     unsigned long time = keyEvent->timestamp;
1051     if(!strncmp(keyEvent->keyname, "Keycode-", 8))
1052     {
1053       keyCode = atoi(keyEvent->keyname + 8);
1054     }
1055
1056     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1057     if(keyEvent->string)
1058     {
1059       keyString = keyEvent->string;
1060     }
1061
1062     std::string            deviceName;
1063     Device::Class::Type    deviceClass;
1064     Device::Subclass::Type deviceSubclass;
1065
1066     GetDeviceName(keyEvent, deviceName);
1067     GetDeviceClass(ecore_device_class_get(keyEvent->dev), deviceClass);
1068     GetDeviceSubclass(ecore_device_subclass_get(keyEvent->dev), deviceSubclass);
1069
1070     Integration::KeyEvent keyEvent(keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::UP, compose, deviceName, deviceClass, deviceSubclass);
1071     keyEvent.windowId = GetNativeWindowId();
1072
1073     mKeyEventSignal.Emit(keyEvent);
1074   }
1075 }
1076
1077 void WindowBaseEcoreWl::OnDataSend(void* data, int type, void* event)
1078 {
1079   mSelectionDataSendSignal.Emit(event);
1080 }
1081
1082 void WindowBaseEcoreWl::OnDataReceive(void* data, int type, void* event)
1083 {
1084   mSelectionDataReceivedSignal.Emit(event);
1085 }
1086
1087 void WindowBaseEcoreWl::OnFontNameChanged()
1088 {
1089   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_CHANGE);
1090 }
1091
1092 void WindowBaseEcoreWl::OnFontSizeChanged()
1093 {
1094   mStyleChangedSignal.Emit(StyleChange::DEFAULT_FONT_SIZE_CHANGE);
1095 }
1096
1097 void WindowBaseEcoreWl::RegistryGlobalCallback(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version)
1098 {
1099   if(strcmp(interface, tizen_policy_interface.name) == 0)
1100   {
1101     uint32_t clientVersion = std::min(version, MAX_TIZEN_CLIENT_VERSION);
1102
1103     mTizenPolicy = static_cast<tizen_policy*>(wl_registry_bind(registry, name, &tizen_policy_interface, clientVersion));
1104     if(!mTizenPolicy)
1105     {
1106       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n");
1107       return;
1108     }
1109
1110     tizen_policy_add_listener(mTizenPolicy, &tizenPolicyListener, data);
1111
1112     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_policy_add_listener is called.\n");
1113   }
1114   else if(strcmp(interface, tizen_display_policy_interface.name) == 0)
1115   {
1116     mTizenDisplayPolicy = static_cast<tizen_display_policy*>(wl_registry_bind(registry, name, &tizen_display_policy_interface, version));
1117     if(!mTizenDisplayPolicy)
1118     {
1119       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n");
1120       return;
1121     }
1122
1123     tizen_display_policy_add_listener(mTizenDisplayPolicy, &tizenDisplayPolicyListener, data);
1124
1125     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n");
1126   }
1127 }
1128
1129 void WindowBaseEcoreWl::RegistryGlobalCallbackRemove(void* data, struct wl_registry* registry, uint32_t id)
1130 {
1131   mTizenPolicy        = NULL;
1132   mTizenDisplayPolicy = NULL;
1133 }
1134
1135 void WindowBaseEcoreWl::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state)
1136 {
1137   mNotificationLevel           = level;
1138   mNotificationChangeState     = state;
1139   mNotificationLevelChangeDone = true;
1140
1141   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state);
1142 }
1143
1144 void WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state)
1145 {
1146   mScreenOffMode            = mode;
1147   mScreenOffModeChangeState = state;
1148   mScreenOffModeChangeDone  = true;
1149
1150   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state);
1151 }
1152
1153 void WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy* displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state)
1154 {
1155   mBrightness            = brightness;
1156   mBrightnessChangeState = state;
1157   mBrightnessChangeDone  = true;
1158
1159   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state);
1160 }
1161
1162 Any WindowBaseEcoreWl::GetNativeWindow()
1163 {
1164   return mEcoreWindow;
1165 }
1166
1167 int WindowBaseEcoreWl::GetNativeWindowId()
1168 {
1169   return ecore_wl_window_id_get(mEcoreWindow);
1170 }
1171
1172 std::string WindowBaseEcoreWl::GetNativeWindowResourceId()
1173 {
1174   return std::string();
1175 }
1176
1177 EGLNativeWindowType WindowBaseEcoreWl::CreateEglWindow(int width, int height)
1178 {
1179   mEglWindow = wl_egl_window_create(mWlSurface, width, height);
1180
1181   return static_cast<EGLNativeWindowType>(mEglWindow);
1182 }
1183
1184 void WindowBaseEcoreWl::DestroyEglWindow()
1185 {
1186   if(mEglWindow != NULL)
1187   {
1188     wl_egl_window_destroy(mEglWindow);
1189     mEglWindow = NULL;
1190   }
1191 }
1192
1193 void WindowBaseEcoreWl::SetEglWindowRotation(int angle)
1194 {
1195   wl_egl_window_rotation rotation;
1196
1197   switch(angle)
1198   {
1199     case 0:
1200     {
1201       rotation = ROTATION_0;
1202       break;
1203     }
1204     case 90:
1205     {
1206       rotation = ROTATION_270;
1207       break;
1208     }
1209     case 180:
1210     {
1211       rotation = ROTATION_180;
1212       break;
1213     }
1214     case 270:
1215     {
1216       rotation = ROTATION_90;
1217       break;
1218     }
1219     default:
1220     {
1221       rotation = ROTATION_0;
1222       break;
1223     }
1224   }
1225
1226   wl_egl_window_set_rotation(mEglWindow, rotation);
1227 }
1228
1229 void WindowBaseEcoreWl::SetEglWindowBufferTransform(int angle)
1230 {
1231   wl_output_transform bufferTransform;
1232
1233   switch(angle)
1234   {
1235     case 0:
1236     {
1237       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1238       break;
1239     }
1240     case 90:
1241     {
1242       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1243       break;
1244     }
1245     case 180:
1246     {
1247       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1248       break;
1249     }
1250     case 270:
1251     {
1252       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1253       break;
1254     }
1255     default:
1256     {
1257       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1258       break;
1259     }
1260   }
1261
1262   wl_egl_window_set_buffer_transform(mEglWindow, bufferTransform);
1263 }
1264
1265 void WindowBaseEcoreWl::SetEglWindowTransform(int angle)
1266 {
1267   wl_output_transform windowTransform;
1268
1269   switch(angle)
1270   {
1271     case 0:
1272     {
1273       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1274       break;
1275     }
1276     case 90:
1277     {
1278       windowTransform = WL_OUTPUT_TRANSFORM_90;
1279       break;
1280     }
1281     case 180:
1282     {
1283       windowTransform = WL_OUTPUT_TRANSFORM_180;
1284       break;
1285     }
1286     case 270:
1287     {
1288       windowTransform = WL_OUTPUT_TRANSFORM_270;
1289       break;
1290     }
1291     default:
1292     {
1293       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1294       break;
1295     }
1296   }
1297
1298   wl_egl_window_set_window_transform(mEglWindow, windowTransform);
1299 }
1300
1301 void WindowBaseEcoreWl::ResizeEglWindow(PositionSize positionSize)
1302 {
1303   wl_egl_window_resize(mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y);
1304 }
1305
1306 bool WindowBaseEcoreWl::IsEglWindowRotationSupported()
1307 {
1308   // Check capability
1309   wl_egl_window_capability capability = static_cast<wl_egl_window_capability>(wl_egl_window_get_capabilities(mEglWindow));
1310   if(capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED)
1311   {
1312     mSupportedPreProtation = true;
1313     return true;
1314   }
1315   mSupportedPreProtation = false;
1316   return false;
1317 }
1318
1319 void WindowBaseEcoreWl::Move(PositionSize positionSize)
1320 {
1321   ecore_wl_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1322 }
1323
1324 void WindowBaseEcoreWl::Resize(PositionSize positionSize)
1325 {
1326   ecore_wl_window_update_size(mEcoreWindow, positionSize.width, positionSize.height);
1327 }
1328
1329 void WindowBaseEcoreWl::MoveResize(PositionSize positionSize)
1330 {
1331   ecore_wl_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1332   ecore_wl_window_update_size(mEcoreWindow, positionSize.width, positionSize.height);
1333 }
1334
1335 void WindowBaseEcoreWl::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
1336 {
1337 }
1338
1339 void WindowBaseEcoreWl::SetClass(const std::string& name, const std::string& className)
1340 {
1341   ecore_wl_window_title_set(mEcoreWindow, name.c_str());
1342   ecore_wl_window_class_name_set(mEcoreWindow, className.c_str());
1343 }
1344
1345 void WindowBaseEcoreWl::Raise()
1346 {
1347   // Use ecore_wl_window_activate to prevent the window shown without rendering
1348   ecore_wl_window_activate(mEcoreWindow);
1349 }
1350
1351 void WindowBaseEcoreWl::Lower()
1352 {
1353   ecore_wl_window_lower(mEcoreWindow);
1354 }
1355
1356 void WindowBaseEcoreWl::Activate()
1357 {
1358   ecore_wl_window_activate(mEcoreWindow);
1359 }
1360
1361 void WindowBaseEcoreWl::Maximize(bool maximize)
1362 {
1363 }
1364
1365 bool WindowBaseEcoreWl::IsMaximized() const
1366 {
1367   return false;
1368 }
1369
1370 void WindowBaseEcoreWl::SetMaximumSize(Dali::Window::WindowSize size)
1371 {
1372 }
1373
1374 void WindowBaseEcoreWl::Minimize(bool minimize)
1375 {
1376 }
1377
1378 bool WindowBaseEcoreWl::IsMinimized() const
1379 {
1380   return false;
1381 }
1382
1383 void WindowBaseEcoreWl::SetMimimumSize(Dali::Window::WindowSize size)
1384 {
1385 }
1386
1387 void WindowBaseEcoreWl::SetAvailableAnlges(const std::vector<int>& angles)
1388 {
1389   int rotations[4] = {0};
1390   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl::SetAvailableAnlges, angle's count: %d\n", angles.size());
1391   for(std::size_t i = 0; i < angles.size(); ++i)
1392   {
1393     rotations[i] = static_cast<int>(angles[i]);
1394     DALI_LOG_RELEASE_INFO("%d ", rotations[i]);
1395   }
1396   ecore_wl_window_rotation_available_rotations_set(mEcoreWindow, rotations, angles.size());
1397 }
1398
1399 void WindowBaseEcoreWl::SetPreferredAngle(int angle)
1400 {
1401   ecore_wl_window_rotation_preferred_rotation_set(mEcoreWindow, angle);
1402 }
1403
1404 void WindowBaseEcoreWl::SetAcceptFocus(bool accept)
1405 {
1406   ecore_wl_window_focus_skip_set(mEcoreWindow, !accept);
1407 }
1408
1409 void WindowBaseEcoreWl::Show()
1410 {
1411   ecore_wl_window_show(mEcoreWindow);
1412 }
1413
1414 void WindowBaseEcoreWl::Hide()
1415 {
1416   ecore_wl_window_hide(mEcoreWindow);
1417 }
1418
1419 unsigned int WindowBaseEcoreWl::GetSupportedAuxiliaryHintCount() const
1420 {
1421   return mSupportedAuxiliaryHints.size();
1422 }
1423
1424 std::string WindowBaseEcoreWl::GetSupportedAuxiliaryHint(unsigned int index) const
1425 {
1426   if(index >= GetSupportedAuxiliaryHintCount())
1427   {
1428     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index);
1429   }
1430
1431   return mSupportedAuxiliaryHints[index];
1432 }
1433
1434 unsigned int WindowBaseEcoreWl::AddAuxiliaryHint(const std::string& hint, const std::string& value)
1435 {
1436   bool supported = false;
1437
1438   // Check if the hint is suppported
1439   for(std::vector<std::string>::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter)
1440   {
1441     if(*iter == hint)
1442     {
1443       supported = true;
1444       break;
1445     }
1446   }
1447
1448   if(!supported)
1449   {
1450     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str());
1451     return 0;
1452   }
1453
1454   // Check if the hint is already added
1455   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1456   {
1457     if(mAuxiliaryHints[i].first == hint)
1458     {
1459       // Just change the value
1460       mAuxiliaryHints[i].second = value;
1461
1462       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1);
1463
1464       return i + 1; // id is index + 1
1465     }
1466   }
1467
1468   // Add the hint
1469   mAuxiliaryHints.push_back(std::pair<std::string, std::string>(hint, value));
1470
1471   unsigned int id = mAuxiliaryHints.size();
1472
1473   ecore_wl_window_aux_hint_add(mEcoreWindow, static_cast<int>(id), hint.c_str(), value.c_str());
1474
1475   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id);
1476
1477   return id;
1478 }
1479
1480 bool WindowBaseEcoreWl::RemoveAuxiliaryHint(unsigned int id)
1481 {
1482   if(id == 0 || id > mAuxiliaryHints.size())
1483   {
1484     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::RemoveAuxiliaryHint: Invalid id [%d]\n", id);
1485     return false;
1486   }
1487
1488   mAuxiliaryHints[id - 1].second = std::string();
1489
1490   ecore_wl_window_aux_hint_del(mEcoreWindow, static_cast<int>(id));
1491
1492   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str());
1493
1494   return true;
1495 }
1496
1497 bool WindowBaseEcoreWl::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
1498 {
1499   if(id == 0 || id > mAuxiliaryHints.size())
1500   {
1501     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::SetAuxiliaryHintValue: Invalid id [%d]\n", id);
1502     return false;
1503   }
1504
1505   mAuxiliaryHints[id - 1].second = value;
1506
1507   ecore_wl_window_aux_hint_change(mEcoreWindow, static_cast<int>(id), value.c_str());
1508
1509   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1510
1511   return true;
1512 }
1513
1514 std::string WindowBaseEcoreWl::GetAuxiliaryHintValue(unsigned int id) const
1515 {
1516   if(id == 0 || id > mAuxiliaryHints.size())
1517   {
1518     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::GetAuxiliaryHintValue: Invalid id [%d]\n", id);
1519     return std::string();
1520   }
1521
1522   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str());
1523
1524   return mAuxiliaryHints[id - 1].second;
1525 }
1526
1527 unsigned int WindowBaseEcoreWl::GetAuxiliaryHintId(const std::string& hint) const
1528 {
1529   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1530   {
1531     if(mAuxiliaryHints[i].first == hint)
1532     {
1533       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1);
1534       return i + 1;
1535     }
1536   }
1537
1538   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str());
1539
1540   return 0;
1541 }
1542
1543 void WindowBaseEcoreWl::SetInputRegion(const Rect<int>& inputRegion)
1544 {
1545   ecore_wl_window_input_region_set(mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1546 }
1547
1548 void WindowBaseEcoreWl::SetType(Dali::WindowType type)
1549 {
1550   Ecore_Wl_Window_Type windowType;
1551
1552   switch(type)
1553   {
1554     case Dali::WindowType::NORMAL:
1555     {
1556       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1557       break;
1558     }
1559     case Dali::WindowType::NOTIFICATION:
1560     {
1561       windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1562       break;
1563     }
1564     case Dali::WindowType::UTILITY:
1565     {
1566       windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1567       break;
1568     }
1569     case Dali::WindowType::DIALOG:
1570     {
1571       windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1572       break;
1573     }
1574     default:
1575     {
1576       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1577       break;
1578     }
1579   }
1580
1581   ecore_wl_window_type_set(mEcoreWindow, windowType);
1582 }
1583
1584 Dali::WindowType WindowBaseEcoreWl::GetType() const
1585 {
1586   return Dali::WindowType::NORMAL;
1587 }
1588
1589 Dali::WindowOperationResult WindowBaseEcoreWl::SetNotificationLevel(Dali::WindowNotificationLevel level)
1590 {
1591   while(!mTizenPolicy)
1592   {
1593     wl_display_dispatch_queue(mDisplay, mEventQueue);
1594   }
1595
1596   int notificationLevel;
1597
1598   switch(level)
1599   {
1600     case Dali::WindowNotificationLevel::NONE:
1601     {
1602       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1603       break;
1604     }
1605     case Dali::WindowNotificationLevel::BASE:
1606     {
1607       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1608       break;
1609     }
1610     case Dali::WindowNotificationLevel::MEDIUM:
1611     {
1612       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1613       break;
1614     }
1615     case Dali::WindowNotificationLevel::HIGH:
1616     {
1617       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1618       break;
1619     }
1620     case Dali::WindowNotificationLevel::TOP:
1621     {
1622       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1623       break;
1624     }
1625     default:
1626     {
1627       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: invalid level [%d]\n", level);
1628       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1629       break;
1630     }
1631   }
1632
1633   mNotificationLevelChangeDone = false;
1634   mNotificationChangeState     = TIZEN_POLICY_ERROR_STATE_NONE;
1635
1636   tizen_policy_set_notification_level(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), notificationLevel);
1637
1638   int count = 0;
1639
1640   while(!mNotificationLevelChangeDone && count < 3)
1641   {
1642     ecore_wl_flush();
1643     wl_display_dispatch_queue(mDisplay, mEventQueue);
1644     count++;
1645   }
1646
1647   if(!mNotificationLevelChangeDone)
1648   {
1649     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
1650     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1651   }
1652   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1653   {
1654     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Permission denied! [%d]\n", level);
1655     return Dali::WindowOperationResult::PERMISSION_DENIED;
1656   }
1657
1658   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
1659
1660   return Dali::WindowOperationResult::SUCCEED;
1661 }
1662
1663 Dali::WindowNotificationLevel WindowBaseEcoreWl::GetNotificationLevel() const
1664 {
1665   while(!mTizenPolicy)
1666   {
1667     wl_display_dispatch_queue(mDisplay, mEventQueue);
1668   }
1669
1670   int count = 0;
1671
1672   while(!mNotificationLevelChangeDone && count < 3)
1673   {
1674     ecore_wl_flush();
1675     wl_display_dispatch_queue(mDisplay, mEventQueue);
1676     count++;
1677   }
1678
1679   if(!mNotificationLevelChangeDone)
1680   {
1681     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState);
1682     return Dali::Window::NotificationLevel::NONE;
1683   }
1684
1685   Dali::WindowNotificationLevel level;
1686
1687   switch(mNotificationLevel)
1688   {
1689     case TIZEN_POLICY_LEVEL_NONE:
1690     {
1691       level = Dali::WindowNotificationLevel::NONE;
1692       break;
1693     }
1694     case TIZEN_POLICY_LEVEL_DEFAULT:
1695     {
1696       level = Dali::WindowNotificationLevel::BASE;
1697       break;
1698     }
1699     case TIZEN_POLICY_LEVEL_MEDIUM:
1700     {
1701       level = Dali::WindowNotificationLevel::MEDIUM;
1702       break;
1703     }
1704     case TIZEN_POLICY_LEVEL_HIGH:
1705     {
1706       level = Dali::WindowNotificationLevel::HIGH;
1707       break;
1708     }
1709     case TIZEN_POLICY_LEVEL_TOP:
1710     {
1711       level = Dali::WindowNotificationLevel::TOP;
1712       break;
1713     }
1714     default:
1715     {
1716       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel);
1717       level = Dali::WindowNotificationLevel::NONE;
1718       break;
1719     }
1720   }
1721
1722   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: level [%d]\n", mNotificationLevel);
1723
1724   return level;
1725 }
1726
1727 void WindowBaseEcoreWl::SetOpaqueState(bool opaque)
1728 {
1729   while(!mTizenPolicy)
1730   {
1731     wl_display_dispatch_queue(mDisplay, mEventQueue);
1732   }
1733
1734   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
1735 }
1736
1737 Dali::WindowOperationResult WindowBaseEcoreWl::SetScreenOffMode(WindowScreenOffMode screenOffMode)
1738 {
1739   while(!mTizenPolicy)
1740   {
1741     wl_display_dispatch_queue(mDisplay, mEventQueue);
1742   }
1743
1744   mScreenOffModeChangeDone  = false;
1745   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1746
1747   unsigned int mode = 0;
1748
1749   switch(screenOffMode)
1750   {
1751     case WindowScreenOffMode::TIMEOUT:
1752     {
1753       mode = 0;
1754       break;
1755     }
1756     case WindowScreenOffMode::NEVER:
1757     {
1758       mode = 1;
1759       break;
1760     }
1761   }
1762
1763   tizen_policy_set_window_screen_mode(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), mode);
1764
1765   int count = 0;
1766
1767   while(!mScreenOffModeChangeDone && count < 3)
1768   {
1769     ecore_wl_flush();
1770     wl_display_dispatch_queue(mDisplay, mEventQueue);
1771     count++;
1772   }
1773
1774   if(!mScreenOffModeChangeDone)
1775   {
1776     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
1777     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1778   }
1779   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1780   {
1781     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
1782     return Dali::WindowOperationResult::PERMISSION_DENIED;
1783   }
1784
1785   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
1786
1787   return Dali::WindowOperationResult::SUCCEED;
1788 }
1789
1790 WindowScreenOffMode WindowBaseEcoreWl::GetScreenOffMode() const
1791 {
1792   while(!mTizenPolicy)
1793   {
1794     wl_display_dispatch_queue(mDisplay, mEventQueue);
1795   }
1796
1797   int count = 0;
1798
1799   while(!mScreenOffModeChangeDone && count < 3)
1800   {
1801     ecore_wl_flush();
1802     wl_display_dispatch_queue(mDisplay, mEventQueue);
1803     count++;
1804   }
1805
1806   if(!mScreenOffModeChangeDone)
1807   {
1808     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState);
1809     return WindowScreenOffMode::TIMEOUT;
1810   }
1811
1812   WindowScreenOffMode screenMode = WindowScreenOffMode::TIMEOUT;
1813
1814   switch(mScreenOffMode)
1815   {
1816     case 0:
1817     {
1818       screenMode = WindowScreenOffMode::TIMEOUT;
1819       break;
1820     }
1821     case 1:
1822     {
1823       screenMode = WindowScreenOffMode::NEVER;
1824       break;
1825     }
1826   }
1827
1828   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode);
1829
1830   return screenMode;
1831 }
1832
1833 Dali::WindowOperationResult WindowBaseEcoreWl::SetBrightness(int brightness)
1834 {
1835   while(!mTizenDisplayPolicy)
1836   {
1837     wl_display_dispatch_queue(mDisplay, mEventQueue);
1838   }
1839
1840   mBrightnessChangeDone  = false;
1841   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1842
1843   tizen_display_policy_set_window_brightness(mTizenDisplayPolicy, ecore_wl_window_surface_get(mEcoreWindow), brightness);
1844
1845   int count = 0;
1846
1847   while(!mBrightnessChangeDone && count < 3)
1848   {
1849     ecore_wl_flush();
1850     wl_display_dispatch_queue(mDisplay, mEventQueue);
1851     count++;
1852   }
1853
1854   if(!mBrightnessChangeDone)
1855   {
1856     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
1857     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1858   }
1859   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1860   {
1861     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Permission denied! [%d]\n", brightness);
1862     return Dali::WindowOperationResult::PERMISSION_DENIED;
1863   }
1864
1865   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness is changed [%d]\n", mBrightness);
1866
1867   return Dali::WindowOperationResult::SUCCEED;
1868 }
1869
1870 int WindowBaseEcoreWl::GetBrightness() const
1871 {
1872   while(!mTizenDisplayPolicy)
1873   {
1874     wl_display_dispatch_queue(mDisplay, mEventQueue);
1875   }
1876
1877   int count = 0;
1878
1879   while(!mBrightnessChangeDone && count < 3)
1880   {
1881     ecore_wl_flush();
1882     wl_display_dispatch_queue(mDisplay, mEventQueue);
1883     count++;
1884   }
1885
1886   if(!mBrightnessChangeDone)
1887   {
1888     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Error! [%d]\n", mBrightnessChangeState);
1889     return 0;
1890   }
1891
1892   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Brightness [%d]\n", mBrightness);
1893
1894   return mBrightness;
1895 }
1896
1897 bool WindowBaseEcoreWl::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
1898 {
1899   Ecore_Wl_Window_Keygrab_Mode mode;
1900
1901   switch(grabMode)
1902   {
1903     case KeyGrab::TOPMOST:
1904     {
1905       mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1906       break;
1907     }
1908     case KeyGrab::SHARED:
1909     {
1910       mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1911       break;
1912     }
1913     case KeyGrab::OVERRIDE_EXCLUSIVE:
1914     {
1915       mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1916       break;
1917     }
1918     case KeyGrab::EXCLUSIVE:
1919     {
1920       mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1921       break;
1922     }
1923     default:
1924     {
1925       return false;
1926     }
1927   }
1928
1929   return ecore_wl_window_keygrab_set(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0, 0, mode);
1930 }
1931
1932 bool WindowBaseEcoreWl::UngrabKey(Dali::KEY key)
1933 {
1934   return ecore_wl_window_keygrab_unset(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0);
1935 }
1936
1937 bool WindowBaseEcoreWl::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
1938 {
1939   int keyCount         = key.Count();
1940   int keyGrabModeCount = grabMode.Count();
1941
1942   if(keyCount != keyGrabModeCount || keyCount == 0)
1943   {
1944     return false;
1945   }
1946
1947   eina_init();
1948
1949   Eina_List*                    keyList = NULL;
1950   Ecore_Wl_Window_Keygrab_Info* info    = new Ecore_Wl_Window_Keygrab_Info[keyCount];
1951
1952   for(int index = 0; index < keyCount; ++index)
1953   {
1954     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
1955
1956     switch(grabMode[index])
1957     {
1958       case KeyGrab::TOPMOST:
1959       {
1960         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1961         break;
1962       }
1963       case KeyGrab::SHARED:
1964       {
1965         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1966         break;
1967       }
1968       case KeyGrab::OVERRIDE_EXCLUSIVE:
1969       {
1970         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1971         break;
1972       }
1973       case KeyGrab::EXCLUSIVE:
1974       {
1975         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1976         break;
1977       }
1978       default:
1979       {
1980         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
1981         break;
1982       }
1983     }
1984
1985     keyList = eina_list_append(keyList, &info);
1986   }
1987
1988   Eina_List* grabList = ecore_wl_window_keygrab_list_set(mEcoreWindow, keyList);
1989
1990   result.Resize(keyCount, true);
1991
1992   Eina_List* l        = NULL;
1993   Eina_List* m        = NULL;
1994   void*      listData = NULL;
1995   void*      data     = NULL;
1996   if(grabList != NULL)
1997   {
1998     EINA_LIST_FOREACH(grabList, m, data)
1999     {
2000       int index = 0;
2001       EINA_LIST_FOREACH(keyList, l, listData)
2002       {
2003         if(static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key == NULL)
2004         {
2005           DALI_LOG_ERROR("input key list has null data!");
2006           break;
2007         }
2008
2009         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key) == 0)
2010         {
2011           result[index] = false;
2012         }
2013         ++index;
2014       }
2015     }
2016   }
2017
2018   delete[] info;
2019
2020   eina_list_free(keyList);
2021   eina_list_free(grabList);
2022   eina_shutdown();
2023
2024   return true;
2025 }
2026
2027 bool WindowBaseEcoreWl::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
2028 {
2029   int keyCount = key.Count();
2030   if(keyCount == 0)
2031   {
2032     return false;
2033   }
2034
2035   eina_init();
2036
2037   Eina_List*                    keyList = NULL;
2038   Ecore_Wl_Window_Keygrab_Info* info    = new Ecore_Wl_Window_Keygrab_Info[keyCount];
2039
2040   for(int index = 0; index < keyCount; ++index)
2041   {
2042     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2043     keyList         = eina_list_append(keyList, &info);
2044   }
2045
2046   Eina_List* ungrabList = ecore_wl_window_keygrab_list_unset(mEcoreWindow, keyList);
2047
2048   result.Resize(keyCount, true);
2049
2050   Eina_List* l        = NULL;
2051   Eina_List* m        = NULL;
2052   void*      listData = NULL;
2053   void*      data     = NULL;
2054
2055   if(ungrabList != NULL)
2056   {
2057     EINA_LIST_FOREACH(ungrabList, m, data)
2058     {
2059       int index = 0;
2060       EINA_LIST_FOREACH(keyList, l, listData)
2061       {
2062         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key) == 0)
2063         {
2064           result[index] = false;
2065         }
2066         ++index;
2067       }
2068     }
2069   }
2070
2071   delete[] info;
2072
2073   eina_list_free(keyList);
2074   eina_list_free(ungrabList);
2075   eina_shutdown();
2076
2077   return true;
2078 }
2079
2080 void WindowBaseEcoreWl::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
2081 {
2082   // calculate DPI
2083   float xres, yres;
2084
2085   // 1 inch = 25.4 millimeters
2086   xres = ecore_wl_dpi_get();
2087   yres = ecore_wl_dpi_get();
2088
2089   dpiHorizontal = int(xres + 0.5f); // rounding
2090   dpiVertical   = int(yres + 0.5f);
2091 }
2092
2093 int WindowBaseEcoreWl::GetWindowRotationAngle() const
2094 {
2095   int orientation = mWindowRotationAngle;
2096   if(mSupportedPreProtation)
2097   {
2098     orientation = 0;
2099   }
2100   return orientation;
2101 }
2102
2103 int WindowBaseEcoreWl::GetScreenRotationAngle()
2104 {
2105   int transform = 0;
2106
2107   if(ecore_wl_window_ignore_output_transform_get(mEcoreWindow))
2108   {
2109     transform = 0;
2110   }
2111   else
2112   {
2113     transform = ecore_wl_output_transform_get(ecore_wl_window_output_find(mEcoreWindow));
2114   }
2115
2116   mScreenRotationAngle = transform * 90;
2117   return mScreenRotationAngle;
2118 }
2119
2120 void WindowBaseEcoreWl::SetWindowRotationAngle(int degree)
2121 {
2122   mWindowRotationAngle = degree;
2123   ecore_wl_window_rotation_set(mEcoreWindow, degree);
2124 }
2125
2126 void WindowBaseEcoreWl::WindowRotationCompleted(int degree, int width, int height)
2127 {
2128   ecore_wl_window_rotation_change_done_send(mEcoreWindow);
2129 }
2130
2131 void WindowBaseEcoreWl::SetTransparency(bool transparent)
2132 {
2133   ecore_wl_window_alpha_set(mEcoreWindow, transparent);
2134 }
2135
2136 void WindowBaseEcoreWl::CreateWindow(PositionSize positionSize)
2137 {
2138   mEcoreWindow = ecore_wl_window_new(0, positionSize.x, positionSize.y, positionSize.width, positionSize.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW);
2139
2140   if(mEcoreWindow == 0)
2141   {
2142     DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
2143   }
2144 }
2145
2146 void WindowBaseEcoreWl::SetParent(WindowBase* parentWinBase, bool belowParent)
2147 {
2148   Ecore_Wl_Window* ecoreParent = NULL;
2149   if(parentWinBase)
2150   {
2151     WindowBaseEcoreWl* winBaseEcore = static_cast<WindowBaseEcoreWl*>(parentWinBase);
2152     ecoreParent                     = winBaseEcore->mEcoreWindow;
2153   }
2154   ecore_wl_window_parent_set(mEcoreWindow, ecoreParent);
2155 }
2156
2157 int WindowBaseEcoreWl::CreateFrameRenderedSyncFence()
2158 {
2159   return -1;
2160 }
2161
2162 int WindowBaseEcoreWl::CreateFramePresentedSyncFence()
2163 {
2164   return -1;
2165 }
2166
2167 void WindowBaseEcoreWl::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
2168 {
2169 }
2170
2171 void WindowBaseEcoreWl::InitializeIme()
2172 {
2173 }
2174
2175 void WindowBaseEcoreWl::ImeWindowReadyToRender()
2176 {
2177 }
2178
2179 void WindowBaseEcoreWl::RequestMoveToServer()
2180 {
2181 }
2182
2183 void WindowBaseEcoreWl::RequestResizeToServer(WindowResizeDirection direction)
2184 {
2185 }
2186
2187 void WindowBaseEcoreWl::EnableFloatingMode(bool enable)
2188 {
2189 }
2190
2191 bool WindowBaseEcoreWl::IsFloatingModeEnabled() const
2192 {
2193   return false;
2194 }
2195
2196 void WindowBaseEcoreWl::IncludeInputRegion(const Rect<int>& inputRegion)
2197 {
2198 }
2199
2200 void WindowBaseEcoreWl::ExcludeInputRegion(const Rect<int>& inputRegion)
2201 {
2202 }
2203
2204 void WindowBaseEcoreWl::SetFrontBufferRendering(bool enable)
2205 {
2206 }
2207
2208 bool WindowBaseEcoreWl::GetFrontBufferRendering()
2209 {
2210   return false;
2211 }
2212
2213 void WindowBaseEcoreWl::SetEglWindowFrontBufferMode(bool enable)
2214 {
2215 }
2216
2217 } // namespace Adaptor
2218
2219 } // namespace Internal
2220
2221 } // namespace Dali
2222
2223 #pragma GCC diagnostic pop