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