42a522cb3ddde1cfe0cae7ee4c97f6322c961aa1
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl / window-base-ecore-wl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // Ecore is littered with C style cast
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wold-style-cast"
21
22 // CLASS HEADER
23 #include <dali/internal/window-system/tizen-wayland/ecore-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 std::string WindowBaseEcoreWl::GetNativeWindowResourceId()
1192 {
1193   return std::string();
1194 }
1195
1196 EGLNativeWindowType WindowBaseEcoreWl::CreateEglWindow(int width, int height)
1197 {
1198   mEglWindow = wl_egl_window_create(mWlSurface, width, height);
1199
1200   return static_cast<EGLNativeWindowType>(mEglWindow);
1201 }
1202
1203 void WindowBaseEcoreWl::DestroyEglWindow()
1204 {
1205   if(mEglWindow != NULL)
1206   {
1207     wl_egl_window_destroy(mEglWindow);
1208     mEglWindow = NULL;
1209   }
1210 }
1211
1212 void WindowBaseEcoreWl::SetEglWindowRotation(int angle)
1213 {
1214   wl_egl_window_rotation rotation;
1215
1216   switch(angle)
1217   {
1218     case 0:
1219     {
1220       rotation = ROTATION_0;
1221       break;
1222     }
1223     case 90:
1224     {
1225       rotation = ROTATION_270;
1226       break;
1227     }
1228     case 180:
1229     {
1230       rotation = ROTATION_180;
1231       break;
1232     }
1233     case 270:
1234     {
1235       rotation = ROTATION_90;
1236       break;
1237     }
1238     default:
1239     {
1240       rotation = ROTATION_0;
1241       break;
1242     }
1243   }
1244
1245   wl_egl_window_set_rotation(mEglWindow, rotation);
1246 }
1247
1248 void WindowBaseEcoreWl::SetEglWindowBufferTransform(int angle)
1249 {
1250   wl_output_transform bufferTransform;
1251
1252   switch(angle)
1253   {
1254     case 0:
1255     {
1256       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1257       break;
1258     }
1259     case 90:
1260     {
1261       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1262       break;
1263     }
1264     case 180:
1265     {
1266       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1267       break;
1268     }
1269     case 270:
1270     {
1271       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1272       break;
1273     }
1274     default:
1275     {
1276       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1277       break;
1278     }
1279   }
1280
1281   wl_egl_window_set_buffer_transform(mEglWindow, bufferTransform);
1282 }
1283
1284 void WindowBaseEcoreWl::SetEglWindowTransform(int angle)
1285 {
1286   wl_output_transform windowTransform;
1287
1288   switch(angle)
1289   {
1290     case 0:
1291     {
1292       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1293       break;
1294     }
1295     case 90:
1296     {
1297       windowTransform = WL_OUTPUT_TRANSFORM_90;
1298       break;
1299     }
1300     case 180:
1301     {
1302       windowTransform = WL_OUTPUT_TRANSFORM_180;
1303       break;
1304     }
1305     case 270:
1306     {
1307       windowTransform = WL_OUTPUT_TRANSFORM_270;
1308       break;
1309     }
1310     default:
1311     {
1312       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1313       break;
1314     }
1315   }
1316
1317   wl_egl_window_set_window_transform(mEglWindow, windowTransform);
1318 }
1319
1320 void WindowBaseEcoreWl::ResizeEglWindow(PositionSize positionSize)
1321 {
1322   wl_egl_window_resize(mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y);
1323 }
1324
1325 bool WindowBaseEcoreWl::IsEglWindowRotationSupported()
1326 {
1327   // Check capability
1328   wl_egl_window_capability capability = static_cast<wl_egl_window_capability>(wl_egl_window_get_capabilities(mEglWindow));
1329   if(capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED)
1330   {
1331     mSupportedPreProtation = true;
1332     return true;
1333   }
1334   mSupportedPreProtation = false;
1335   return false;
1336 }
1337
1338 void WindowBaseEcoreWl::Move(PositionSize positionSize)
1339 {
1340   ecore_wl_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1341 }
1342
1343 void WindowBaseEcoreWl::Resize(PositionSize positionSize)
1344 {
1345   ecore_wl_window_update_size(mEcoreWindow, positionSize.width, positionSize.height);
1346 }
1347
1348 void WindowBaseEcoreWl::MoveResize(PositionSize positionSize)
1349 {
1350   ecore_wl_window_position_set(mEcoreWindow, positionSize.x, positionSize.y);
1351   ecore_wl_window_update_size(mEcoreWindow, positionSize.width, positionSize.height);
1352 }
1353
1354 void WindowBaseEcoreWl::SetClass(const std::string& name, const std::string& className)
1355 {
1356   ecore_wl_window_title_set(mEcoreWindow, name.c_str());
1357   ecore_wl_window_class_name_set(mEcoreWindow, className.c_str());
1358 }
1359
1360 void WindowBaseEcoreWl::Raise()
1361 {
1362   // Use ecore_wl_window_activate to prevent the window shown without rendering
1363   ecore_wl_window_activate(mEcoreWindow);
1364 }
1365
1366 void WindowBaseEcoreWl::Lower()
1367 {
1368   ecore_wl_window_lower(mEcoreWindow);
1369 }
1370
1371 void WindowBaseEcoreWl::Activate()
1372 {
1373   ecore_wl_window_activate(mEcoreWindow);
1374 }
1375
1376 void WindowBaseEcoreWl::Maximize(bool maximize)
1377 {
1378 }
1379
1380 bool WindowBaseEcoreWl::IsMaximized() const
1381 {
1382   return false;
1383 }
1384
1385 void WindowBaseEcoreWl::Minimize(bool minimize)
1386 {
1387 }
1388
1389 bool WindowBaseEcoreWl::IsMinimized() const
1390 {
1391   return false;
1392 }
1393
1394 void WindowBaseEcoreWl::SetAvailableAnlges(const std::vector<int>& angles)
1395 {
1396   int rotations[4] = {0};
1397   DALI_LOG_RELEASE_INFO("WindowBaseEcoreWl::SetAvailableAnlges, angle's count: %d\n", angles.size());
1398   for(std::size_t i = 0; i < angles.size(); ++i)
1399   {
1400     rotations[i] = static_cast<int>(angles[i]);
1401     DALI_LOG_RELEASE_INFO("%d ", rotations[i]);
1402   }
1403   ecore_wl_window_rotation_available_rotations_set(mEcoreWindow, rotations, angles.size());
1404 }
1405
1406 void WindowBaseEcoreWl::SetPreferredAngle(int angle)
1407 {
1408   ecore_wl_window_rotation_preferred_rotation_set(mEcoreWindow, angle);
1409 }
1410
1411 void WindowBaseEcoreWl::SetAcceptFocus(bool accept)
1412 {
1413   ecore_wl_window_focus_skip_set(mEcoreWindow, !accept);
1414 }
1415
1416 void WindowBaseEcoreWl::Show()
1417 {
1418   ecore_wl_window_show(mEcoreWindow);
1419 }
1420
1421 void WindowBaseEcoreWl::Hide()
1422 {
1423   ecore_wl_window_hide(mEcoreWindow);
1424 }
1425
1426 unsigned int WindowBaseEcoreWl::GetSupportedAuxiliaryHintCount() const
1427 {
1428   return mSupportedAuxiliaryHints.size();
1429 }
1430
1431 std::string WindowBaseEcoreWl::GetSupportedAuxiliaryHint(unsigned int index) const
1432 {
1433   if(index >= GetSupportedAuxiliaryHintCount())
1434   {
1435     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index);
1436   }
1437
1438   return mSupportedAuxiliaryHints[index];
1439 }
1440
1441 unsigned int WindowBaseEcoreWl::AddAuxiliaryHint(const std::string& hint, const std::string& value)
1442 {
1443   bool supported = false;
1444
1445   // Check if the hint is suppported
1446   for(std::vector<std::string>::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter)
1447   {
1448     if(*iter == hint)
1449     {
1450       supported = true;
1451       break;
1452     }
1453   }
1454
1455   if(!supported)
1456   {
1457     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str());
1458     return 0;
1459   }
1460
1461   // Check if the hint is already added
1462   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1463   {
1464     if(mAuxiliaryHints[i].first == hint)
1465     {
1466       // Just change the value
1467       mAuxiliaryHints[i].second = value;
1468
1469       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1);
1470
1471       return i + 1; // id is index + 1
1472     }
1473   }
1474
1475   // Add the hint
1476   mAuxiliaryHints.push_back(std::pair<std::string, std::string>(hint, value));
1477
1478   unsigned int id = mAuxiliaryHints.size();
1479
1480   ecore_wl_window_aux_hint_add(mEcoreWindow, static_cast<int>(id), hint.c_str(), value.c_str());
1481
1482   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id);
1483
1484   return id;
1485 }
1486
1487 bool WindowBaseEcoreWl::RemoveAuxiliaryHint(unsigned int id)
1488 {
1489   if(id == 0 || id > mAuxiliaryHints.size())
1490   {
1491     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::RemoveAuxiliaryHint: Invalid id [%d]\n", id);
1492     return false;
1493   }
1494
1495   mAuxiliaryHints[id - 1].second = std::string();
1496
1497   ecore_wl_window_aux_hint_del(mEcoreWindow, static_cast<int>(id));
1498
1499   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str());
1500
1501   return true;
1502 }
1503
1504 bool WindowBaseEcoreWl::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
1505 {
1506   if(id == 0 || id > mAuxiliaryHints.size())
1507   {
1508     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::SetAuxiliaryHintValue: Invalid id [%d]\n", id);
1509     return false;
1510   }
1511
1512   mAuxiliaryHints[id - 1].second = value;
1513
1514   ecore_wl_window_aux_hint_change(mEcoreWindow, static_cast<int>(id), value.c_str());
1515
1516   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());
1517
1518   return true;
1519 }
1520
1521 std::string WindowBaseEcoreWl::GetAuxiliaryHintValue(unsigned int id) const
1522 {
1523   if(id == 0 || id > mAuxiliaryHints.size())
1524   {
1525     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::GetAuxiliaryHintValue: Invalid id [%d]\n", id);
1526     return std::string();
1527   }
1528
1529   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());
1530
1531   return mAuxiliaryHints[id - 1].second;
1532 }
1533
1534 unsigned int WindowBaseEcoreWl::GetAuxiliaryHintId(const std::string& hint) const
1535 {
1536   for(unsigned int i = 0; i < mAuxiliaryHints.size(); i++)
1537   {
1538     if(mAuxiliaryHints[i].first == hint)
1539     {
1540       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1);
1541       return i + 1;
1542     }
1543   }
1544
1545   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str());
1546
1547   return 0;
1548 }
1549
1550 void WindowBaseEcoreWl::SetInputRegion(const Rect<int>& inputRegion)
1551 {
1552   ecore_wl_window_input_region_set(mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1553 }
1554
1555 void WindowBaseEcoreWl::SetType(Dali::WindowType type)
1556 {
1557   Ecore_Wl_Window_Type windowType;
1558
1559   switch(type)
1560   {
1561     case Dali::WindowType::NORMAL:
1562     {
1563       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1564       break;
1565     }
1566     case Dali::WindowType::NOTIFICATION:
1567     {
1568       windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1569       break;
1570     }
1571     case Dali::WindowType::UTILITY:
1572     {
1573       windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1574       break;
1575     }
1576     case Dali::WindowType::DIALOG:
1577     {
1578       windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1579       break;
1580     }
1581     default:
1582     {
1583       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1584       break;
1585     }
1586   }
1587
1588   ecore_wl_window_type_set(mEcoreWindow, windowType);
1589 }
1590
1591 Dali::WindowType WindowBaseEcoreWl::GetType() const
1592 {
1593   return Dali::WindowType::NORMAL;
1594 }
1595
1596 Dali::WindowOperationResult WindowBaseEcoreWl::SetNotificationLevel(Dali::WindowNotificationLevel level)
1597 {
1598   while(!mTizenPolicy)
1599   {
1600     wl_display_dispatch_queue(mDisplay, mEventQueue);
1601   }
1602
1603   int notificationLevel;
1604
1605   switch(level)
1606   {
1607     case Dali::WindowNotificationLevel::NONE:
1608     {
1609       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1610       break;
1611     }
1612     case Dali::WindowNotificationLevel::BASE:
1613     {
1614       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1615       break;
1616     }
1617     case Dali::WindowNotificationLevel::MEDIUM:
1618     {
1619       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1620       break;
1621     }
1622     case Dali::WindowNotificationLevel::HIGH:
1623     {
1624       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1625       break;
1626     }
1627     case Dali::WindowNotificationLevel::TOP:
1628     {
1629       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1630       break;
1631     }
1632     default:
1633     {
1634       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: invalid level [%d]\n", level);
1635       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1636       break;
1637     }
1638   }
1639
1640   mNotificationLevelChangeDone = false;
1641   mNotificationChangeState     = TIZEN_POLICY_ERROR_STATE_NONE;
1642
1643   tizen_policy_set_notification_level(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), notificationLevel);
1644
1645   int count = 0;
1646
1647   while(!mNotificationLevelChangeDone && count < 3)
1648   {
1649     ecore_wl_flush();
1650     wl_display_dispatch_queue(mDisplay, mEventQueue);
1651     count++;
1652   }
1653
1654   if(!mNotificationLevelChangeDone)
1655   {
1656     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState);
1657     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1658   }
1659   else if(mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1660   {
1661     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Permission denied! [%d]\n", level);
1662     return Dali::WindowOperationResult::PERMISSION_DENIED;
1663   }
1664
1665   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel);
1666
1667   return Dali::WindowOperationResult::SUCCEED;
1668 }
1669
1670 Dali::WindowNotificationLevel WindowBaseEcoreWl::GetNotificationLevel() const
1671 {
1672   while(!mTizenPolicy)
1673   {
1674     wl_display_dispatch_queue(mDisplay, mEventQueue);
1675   }
1676
1677   int count = 0;
1678
1679   while(!mNotificationLevelChangeDone && count < 3)
1680   {
1681     ecore_wl_flush();
1682     wl_display_dispatch_queue(mDisplay, mEventQueue);
1683     count++;
1684   }
1685
1686   if(!mNotificationLevelChangeDone)
1687   {
1688     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState);
1689     return Dali::Window::NotificationLevel::NONE;
1690   }
1691
1692   Dali::WindowNotificationLevel level;
1693
1694   switch(mNotificationLevel)
1695   {
1696     case TIZEN_POLICY_LEVEL_NONE:
1697     {
1698       level = Dali::WindowNotificationLevel::NONE;
1699       break;
1700     }
1701     case TIZEN_POLICY_LEVEL_DEFAULT:
1702     {
1703       level = Dali::WindowNotificationLevel::BASE;
1704       break;
1705     }
1706     case TIZEN_POLICY_LEVEL_MEDIUM:
1707     {
1708       level = Dali::WindowNotificationLevel::MEDIUM;
1709       break;
1710     }
1711     case TIZEN_POLICY_LEVEL_HIGH:
1712     {
1713       level = Dali::WindowNotificationLevel::HIGH;
1714       break;
1715     }
1716     case TIZEN_POLICY_LEVEL_TOP:
1717     {
1718       level = Dali::WindowNotificationLevel::TOP;
1719       break;
1720     }
1721     default:
1722     {
1723       DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel);
1724       level = Dali::WindowNotificationLevel::NONE;
1725       break;
1726     }
1727   }
1728
1729   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: level [%d]\n", mNotificationLevel);
1730
1731   return level;
1732 }
1733
1734 void WindowBaseEcoreWl::SetOpaqueState(bool opaque)
1735 {
1736   while(!mTizenPolicy)
1737   {
1738     wl_display_dispatch_queue(mDisplay, mEventQueue);
1739   }
1740
1741   tizen_policy_set_opaque_state(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), (opaque ? 1 : 0));
1742 }
1743
1744 Dali::WindowOperationResult WindowBaseEcoreWl::SetScreenOffMode(WindowScreenOffMode screenOffMode)
1745 {
1746   while(!mTizenPolicy)
1747   {
1748     wl_display_dispatch_queue(mDisplay, mEventQueue);
1749   }
1750
1751   mScreenOffModeChangeDone  = false;
1752   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1753
1754   unsigned int mode = 0;
1755
1756   switch(screenOffMode)
1757   {
1758     case WindowScreenOffMode::TIMEOUT:
1759     {
1760       mode = 0;
1761       break;
1762     }
1763     case WindowScreenOffMode::NEVER:
1764     {
1765       mode = 1;
1766       break;
1767     }
1768   }
1769
1770   tizen_policy_set_window_screen_mode(mTizenPolicy, ecore_wl_window_surface_get(mEcoreWindow), mode);
1771
1772   int count = 0;
1773
1774   while(!mScreenOffModeChangeDone && count < 3)
1775   {
1776     ecore_wl_flush();
1777     wl_display_dispatch_queue(mDisplay, mEventQueue);
1778     count++;
1779   }
1780
1781   if(!mScreenOffModeChangeDone)
1782   {
1783     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState);
1784     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1785   }
1786   else if(mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1787   {
1788     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode);
1789     return Dali::WindowOperationResult::PERMISSION_DENIED;
1790   }
1791
1792   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode);
1793
1794   return Dali::WindowOperationResult::SUCCEED;
1795 }
1796
1797 WindowScreenOffMode WindowBaseEcoreWl::GetScreenOffMode() const
1798 {
1799   while(!mTizenPolicy)
1800   {
1801     wl_display_dispatch_queue(mDisplay, mEventQueue);
1802   }
1803
1804   int count = 0;
1805
1806   while(!mScreenOffModeChangeDone && count < 3)
1807   {
1808     ecore_wl_flush();
1809     wl_display_dispatch_queue(mDisplay, mEventQueue);
1810     count++;
1811   }
1812
1813   if(!mScreenOffModeChangeDone)
1814   {
1815     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState);
1816     return WindowScreenOffMode::TIMEOUT;
1817   }
1818
1819   WindowScreenOffMode screenMode = WindowScreenOffMode::TIMEOUT;
1820
1821   switch(mScreenOffMode)
1822   {
1823     case 0:
1824     {
1825       screenMode = WindowScreenOffMode::TIMEOUT;
1826       break;
1827     }
1828     case 1:
1829     {
1830       screenMode = WindowScreenOffMode::NEVER;
1831       break;
1832     }
1833   }
1834
1835   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode);
1836
1837   return screenMode;
1838 }
1839
1840 Dali::WindowOperationResult WindowBaseEcoreWl::SetBrightness(int brightness)
1841 {
1842   while(!mTizenDisplayPolicy)
1843   {
1844     wl_display_dispatch_queue(mDisplay, mEventQueue);
1845   }
1846
1847   mBrightnessChangeDone  = false;
1848   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1849
1850   tizen_display_policy_set_window_brightness(mTizenDisplayPolicy, ecore_wl_window_surface_get(mEcoreWindow), brightness);
1851
1852   int count = 0;
1853
1854   while(!mBrightnessChangeDone && count < 3)
1855   {
1856     ecore_wl_flush();
1857     wl_display_dispatch_queue(mDisplay, mEventQueue);
1858     count++;
1859   }
1860
1861   if(!mBrightnessChangeDone)
1862   {
1863     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState);
1864     return Dali::WindowOperationResult::UNKNOWN_ERROR;
1865   }
1866   else if(mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED)
1867   {
1868     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Permission denied! [%d]\n", brightness);
1869     return Dali::WindowOperationResult::PERMISSION_DENIED;
1870   }
1871
1872   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness is changed [%d]\n", mBrightness);
1873
1874   return Dali::WindowOperationResult::SUCCEED;
1875 }
1876
1877 int WindowBaseEcoreWl::GetBrightness() const
1878 {
1879   while(!mTizenDisplayPolicy)
1880   {
1881     wl_display_dispatch_queue(mDisplay, mEventQueue);
1882   }
1883
1884   int count = 0;
1885
1886   while(!mBrightnessChangeDone && count < 3)
1887   {
1888     ecore_wl_flush();
1889     wl_display_dispatch_queue(mDisplay, mEventQueue);
1890     count++;
1891   }
1892
1893   if(!mBrightnessChangeDone)
1894   {
1895     DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Error! [%d]\n", mBrightnessChangeState);
1896     return 0;
1897   }
1898
1899   DALI_LOG_INFO(gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Brightness [%d]\n", mBrightness);
1900
1901   return mBrightness;
1902 }
1903
1904 bool WindowBaseEcoreWl::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
1905 {
1906   Ecore_Wl_Window_Keygrab_Mode mode;
1907
1908   switch(grabMode)
1909   {
1910     case KeyGrab::TOPMOST:
1911     {
1912       mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1913       break;
1914     }
1915     case KeyGrab::SHARED:
1916     {
1917       mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1918       break;
1919     }
1920     case KeyGrab::OVERRIDE_EXCLUSIVE:
1921     {
1922       mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1923       break;
1924     }
1925     case KeyGrab::EXCLUSIVE:
1926     {
1927       mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1928       break;
1929     }
1930     default:
1931     {
1932       return false;
1933     }
1934   }
1935
1936   return ecore_wl_window_keygrab_set(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0, 0, mode);
1937 }
1938
1939 bool WindowBaseEcoreWl::UngrabKey(Dali::KEY key)
1940 {
1941   return ecore_wl_window_keygrab_unset(mEcoreWindow, KeyLookup::GetKeyName(key), 0, 0);
1942 }
1943
1944 bool WindowBaseEcoreWl::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
1945 {
1946   int keyCount         = key.Count();
1947   int keyGrabModeCount = grabMode.Count();
1948
1949   if(keyCount != keyGrabModeCount || keyCount == 0)
1950   {
1951     return false;
1952   }
1953
1954   eina_init();
1955
1956   Eina_List*                    keyList = NULL;
1957   Ecore_Wl_Window_Keygrab_Info* info    = new Ecore_Wl_Window_Keygrab_Info[keyCount];
1958
1959   for(int index = 0; index < keyCount; ++index)
1960   {
1961     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
1962
1963     switch(grabMode[index])
1964     {
1965       case KeyGrab::TOPMOST:
1966       {
1967         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1968         break;
1969       }
1970       case KeyGrab::SHARED:
1971       {
1972         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1973         break;
1974       }
1975       case KeyGrab::OVERRIDE_EXCLUSIVE:
1976       {
1977         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1978         break;
1979       }
1980       case KeyGrab::EXCLUSIVE:
1981       {
1982         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1983         break;
1984       }
1985       default:
1986       {
1987         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
1988         break;
1989       }
1990     }
1991
1992     keyList = eina_list_append(keyList, &info);
1993   }
1994
1995   Eina_List* grabList = ecore_wl_window_keygrab_list_set(mEcoreWindow, keyList);
1996
1997   result.Resize(keyCount, true);
1998
1999   Eina_List* l        = NULL;
2000   Eina_List* m        = NULL;
2001   void*      listData = NULL;
2002   void*      data     = NULL;
2003   if(grabList != NULL)
2004   {
2005     EINA_LIST_FOREACH(grabList, m, data)
2006     {
2007       int index = 0;
2008       EINA_LIST_FOREACH(keyList, l, listData)
2009       {
2010         if(static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key == NULL)
2011         {
2012           DALI_LOG_ERROR("input key list has null data!");
2013           break;
2014         }
2015
2016         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key) == 0)
2017         {
2018           result[index] = false;
2019         }
2020         ++index;
2021       }
2022     }
2023   }
2024
2025   delete[] info;
2026
2027   eina_list_free(keyList);
2028   eina_list_free(grabList);
2029   eina_shutdown();
2030
2031   return true;
2032 }
2033
2034 bool WindowBaseEcoreWl::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
2035 {
2036   int keyCount = key.Count();
2037   if(keyCount == 0)
2038   {
2039     return false;
2040   }
2041
2042   eina_init();
2043
2044   Eina_List*                    keyList = NULL;
2045   Ecore_Wl_Window_Keygrab_Info* info    = new Ecore_Wl_Window_Keygrab_Info[keyCount];
2046
2047   for(int index = 0; index < keyCount; ++index)
2048   {
2049     info[index].key = const_cast<char*>(KeyLookup::GetKeyName(key[index]));
2050     keyList         = eina_list_append(keyList, &info);
2051   }
2052
2053   Eina_List* ungrabList = ecore_wl_window_keygrab_list_unset(mEcoreWindow, keyList);
2054
2055   result.Resize(keyCount, true);
2056
2057   Eina_List* l        = NULL;
2058   Eina_List* m        = NULL;
2059   void*      listData = NULL;
2060   void*      data     = NULL;
2061
2062   if(ungrabList != NULL)
2063   {
2064     EINA_LIST_FOREACH(ungrabList, m, data)
2065     {
2066       int index = 0;
2067       EINA_LIST_FOREACH(keyList, l, listData)
2068       {
2069         if(strcmp(static_cast<char*>(data), static_cast<Ecore_Wl_Window_Keygrab_Info*>(listData)->key) == 0)
2070         {
2071           result[index] = false;
2072         }
2073         ++index;
2074       }
2075     }
2076   }
2077
2078   delete[] info;
2079
2080   eina_list_free(keyList);
2081   eina_list_free(ungrabList);
2082   eina_shutdown();
2083
2084   return true;
2085 }
2086
2087 void WindowBaseEcoreWl::GetDpi(unsigned int& dpiHorizontal, unsigned int& dpiVertical)
2088 {
2089   // calculate DPI
2090   float xres, yres;
2091
2092   // 1 inch = 25.4 millimeters
2093   xres = ecore_wl_dpi_get();
2094   yres = ecore_wl_dpi_get();
2095
2096   dpiHorizontal = int(xres + 0.5f); // rounding
2097   dpiVertical   = int(yres + 0.5f);
2098 }
2099
2100 int WindowBaseEcoreWl::GetOrientation() const
2101 {
2102   int orientation = (mScreenRotationAngle + mWindowRotationAngle) % 360;
2103   if(mSupportedPreProtation)
2104   {
2105     orientation = 0;
2106   }
2107   return orientation;
2108 }
2109
2110 int WindowBaseEcoreWl::GetScreenRotationAngle()
2111 {
2112   int transform = 0;
2113
2114   if(ecore_wl_window_ignore_output_transform_get(mEcoreWindow))
2115   {
2116     transform = 0;
2117   }
2118   else
2119   {
2120     transform = ecore_wl_output_transform_get(ecore_wl_window_output_find(mEcoreWindow));
2121   }
2122
2123   mScreenRotationAngle = transform * 90;
2124   return mScreenRotationAngle;
2125 }
2126
2127 void WindowBaseEcoreWl::SetWindowRotationAngle(int degree)
2128 {
2129   mWindowRotationAngle = degree;
2130   ecore_wl_window_rotation_set(mEcoreWindow, degree);
2131 }
2132
2133 void WindowBaseEcoreWl::WindowRotationCompleted(int degree, int width, int height)
2134 {
2135   ecore_wl_window_rotation_change_done_send(mEcoreWindow);
2136 }
2137
2138 void WindowBaseEcoreWl::SetTransparency(bool transparent)
2139 {
2140   ecore_wl_window_alpha_set(mEcoreWindow, transparent);
2141 }
2142
2143 void WindowBaseEcoreWl::InitializeEcoreElDBus()
2144 {
2145 #ifdef DALI_ELDBUS_AVAILABLE
2146   Eldbus_Object* object;
2147   Eldbus_Proxy*  manager;
2148
2149   if(!(mSystemConnection = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM)))
2150   {
2151     DALI_LOG_ERROR("Unable to get system bus\n");
2152   }
2153
2154   object = eldbus_object_get(mSystemConnection, BUS, PATH);
2155   if(!object)
2156   {
2157     DALI_LOG_ERROR("Getting object failed\n");
2158     return;
2159   }
2160
2161   manager = eldbus_proxy_get(object, INTERFACE);
2162   if(!manager)
2163   {
2164     DALI_LOG_ERROR("Getting proxy failed\n");
2165     return;
2166   }
2167
2168   if(!eldbus_proxy_signal_handler_add(manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this))
2169   {
2170     DALI_LOG_ERROR("No signal handler returned\n");
2171   }
2172 #endif
2173 }
2174
2175 void WindowBaseEcoreWl::CreateWindow(PositionSize positionSize)
2176 {
2177   mEcoreWindow = ecore_wl_window_new(0, positionSize.x, positionSize.y, positionSize.width, positionSize.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW);
2178
2179   if(mEcoreWindow == 0)
2180   {
2181     DALI_ASSERT_ALWAYS(0 && "Failed to create Wayland window");
2182   }
2183 }
2184
2185 void WindowBaseEcoreWl::SetParent(WindowBase* parentWinBase, bool belowParent)
2186 {
2187   Ecore_Wl_Window* ecoreParent = NULL;
2188   if(parentWinBase)
2189   {
2190     WindowBaseEcoreWl* winBaseEcore = static_cast<WindowBaseEcoreWl*>(parentWinBase);
2191     ecoreParent                     = winBaseEcore->mEcoreWindow;
2192   }
2193   ecore_wl_window_parent_set(mEcoreWindow, ecoreParent);
2194 }
2195
2196 int WindowBaseEcoreWl::CreateFrameRenderedSyncFence()
2197 {
2198   return -1;
2199 }
2200
2201 int WindowBaseEcoreWl::CreateFramePresentedSyncFence()
2202 {
2203   return -1;
2204 }
2205
2206 void WindowBaseEcoreWl::SetPositionSizeWithAngle(PositionSize positionSize, int angle)
2207 {
2208 }
2209
2210 void WindowBaseEcoreWl::InitializeIme()
2211 {
2212 }
2213
2214 void WindowBaseEcoreWl::ImeWindowReadyToRender()
2215 {
2216 }
2217
2218 void WindowBaseEcoreWl::RequestMoveToServer()
2219 {
2220 }
2221
2222 void WindowBaseEcoreWl::RequestResizeToServer(WindowResizeDirection direction)
2223 {
2224 }
2225
2226 void WindowBaseEcoreWl::EnableFloatingMode(bool enable)
2227 {
2228 }
2229
2230 bool WindowBaseEcoreWl::IsFloatingModeEnabled() const
2231 {
2232   return false;
2233 }
2234
2235 void WindowBaseEcoreWl::IncludeInputRegion(const Rect<int>& inputRegion)
2236 {
2237 }
2238
2239 void WindowBaseEcoreWl::ExcludeInputRegion(const Rect<int>& inputRegion)
2240 {
2241 }
2242
2243 } // namespace Adaptor
2244
2245 } // namespace Internal
2246
2247 } // namespace Dali
2248
2249 #pragma GCC diagnostic pop