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