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