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