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