Add GetMouseButton to identify right/left mouse button click
[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_geometry_set( mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
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_geometry_set( mEcoreWindow, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
1362 }
1363
1364 void WindowBaseEcoreWl2::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
1365 {
1366   DALI_LOG_TRACE_METHOD_FMT( gWindowBaseLogFilter, "visible : %d\n", visibleMode );
1367
1368   if( visibleMode == Dali::Window::VISIBLE )
1369   {
1370     // when the indicator is visible, set proper mode for indicator server according to bg mode
1371     if( opacityMode == Dali::Window::OPAQUE )
1372     {
1373       ecore_wl2_window_indicator_opacity_set( mEcoreWindow, ECORE_WL2_INDICATOR_OPAQUE );
1374     }
1375     else if( opacityMode == Dali::Window::TRANSLUCENT )
1376     {
1377       ecore_wl2_window_indicator_opacity_set( mEcoreWindow, ECORE_WL2_INDICATOR_TRANSLUCENT );
1378     }
1379     else if( opacityMode == Dali::Window::TRANSPARENT )
1380     {
1381       ecore_wl2_window_indicator_opacity_set( mEcoreWindow, ECORE_WL2_INDICATOR_OPAQUE );
1382     }
1383   }
1384   else
1385   {
1386     // when the indicator is not visible, set TRANSPARENT mode for indicator server
1387     ecore_wl2_window_indicator_opacity_set( mEcoreWindow, ECORE_WL2_INDICATOR_TRANSPARENT); // it means hidden indicator
1388   }
1389 }
1390
1391 void WindowBaseEcoreWl2::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
1392 {
1393   if( isShow )
1394   {
1395     ecore_wl2_window_indicator_state_set( mEcoreWindow, ECORE_WL2_INDICATOR_STATE_ON );
1396   }
1397   else
1398   {
1399     ecore_wl2_window_indicator_state_set( mEcoreWindow, ECORE_WL2_INDICATOR_STATE_OFF );
1400   }
1401 }
1402
1403 void WindowBaseEcoreWl2::IndicatorTypeChanged( IndicatorInterface::Type type )
1404 {
1405 #if defined(DALI_PROFILE_MOBILE)
1406   switch( type )
1407   {
1408     case IndicatorInterface::INDICATOR_TYPE_1:
1409     {
1410       ecore_wl2_indicator_visible_type_set( mEcoreWindow, ECORE_WL2_INDICATOR_VISIBLE_TYPE_SHOWN );
1411       break;
1412     }
1413     case IndicatorInterface::INDICATOR_TYPE_2:
1414     {
1415       ecore_wl2_indicator_visible_type_set( mEcoreWindow, ECORE_WL2_INDICATOR_VISIBLE_TYPE_HIDDEN );
1416       break;
1417     }
1418     case IndicatorInterface::INDICATOR_TYPE_UNKNOWN:
1419     default:
1420     {
1421       break;
1422     }
1423   }
1424 #endif //MOBILE
1425 }
1426
1427 void WindowBaseEcoreWl2::SetClass( const std::string& name, const std::string& className )
1428 {
1429   ecore_wl2_window_title_set( mEcoreWindow, name.c_str() );
1430   ecore_wl2_window_class_set( mEcoreWindow, className.c_str() );
1431 }
1432
1433 void WindowBaseEcoreWl2::Raise()
1434 {
1435   // Use ecore_wl2_window_activate to prevent the window shown without rendering
1436   ecore_wl2_window_activate( mEcoreWindow );
1437 }
1438
1439 void WindowBaseEcoreWl2::Lower()
1440 {
1441   ecore_wl2_window_lower( mEcoreWindow );
1442 }
1443
1444 void WindowBaseEcoreWl2::Activate()
1445 {
1446   ecore_wl2_window_activate( mEcoreWindow );
1447 }
1448
1449 void WindowBaseEcoreWl2::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
1450 {
1451   int rotations[4] = { 0 };
1452   for( std::size_t i = 0; i < orientations.size(); ++i )
1453   {
1454     rotations[i] = static_cast< int >( orientations[i] );
1455   }
1456   ecore_wl2_window_available_rotations_set( mEcoreWindow, rotations, orientations.size() );
1457 }
1458
1459 void WindowBaseEcoreWl2::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
1460 {
1461   ecore_wl2_window_preferred_rotation_set( mEcoreWindow, orientation );
1462 }
1463
1464 void WindowBaseEcoreWl2::SetAcceptFocus( bool accept )
1465 {
1466   ecore_wl2_window_focus_skip_set( mEcoreWindow, !accept );
1467 }
1468
1469 void WindowBaseEcoreWl2::Show()
1470 {
1471   ecore_wl2_window_show( mEcoreWindow );
1472 }
1473
1474 void WindowBaseEcoreWl2::Hide()
1475 {
1476   ecore_wl2_window_hide( mEcoreWindow );
1477 }
1478
1479 unsigned int WindowBaseEcoreWl2::GetSupportedAuxiliaryHintCount() const
1480 {
1481   return mSupportedAuxiliaryHints.size();
1482 }
1483
1484 std::string WindowBaseEcoreWl2::GetSupportedAuxiliaryHint( unsigned int index ) const
1485 {
1486   if( index >= GetSupportedAuxiliaryHintCount() )
1487   {
1488     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
1489   }
1490
1491   return mSupportedAuxiliaryHints[index];
1492 }
1493
1494 unsigned int WindowBaseEcoreWl2::AddAuxiliaryHint( const std::string& hint, const std::string& value )
1495 {
1496   bool supported = false;
1497
1498   // Check if the hint is suppported
1499   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
1500   {
1501     if( *iter == hint )
1502     {
1503       supported = true;
1504       break;
1505     }
1506   }
1507
1508   if( !supported )
1509   {
1510     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
1511     return 0;
1512   }
1513
1514   // Check if the hint is already added
1515   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1516   {
1517     if( mAuxiliaryHints[i].first == hint )
1518     {
1519       // Just change the value
1520       mAuxiliaryHints[i].second = value;
1521
1522       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
1523
1524       return i + 1;   // id is index + 1
1525     }
1526   }
1527
1528   // Add the hint
1529   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
1530
1531   unsigned int id = mAuxiliaryHints.size();
1532
1533   ecore_wl2_window_aux_hint_add( mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
1534
1535   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
1536
1537   return id;
1538 }
1539
1540 bool WindowBaseEcoreWl2::RemoveAuxiliaryHint( unsigned int id )
1541 {
1542   if( id == 0 || id > mAuxiliaryHints.size() )
1543   {
1544     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
1545     return false;
1546   }
1547
1548   mAuxiliaryHints[id - 1].second = std::string();
1549
1550   ecore_wl2_window_aux_hint_del( mEcoreWindow, static_cast< int >( id ) );
1551
1552   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
1553
1554   return true;
1555 }
1556
1557 bool WindowBaseEcoreWl2::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
1558 {
1559   if( id == 0 || id > mAuxiliaryHints.size() )
1560   {
1561     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1562     return false;
1563   }
1564
1565   mAuxiliaryHints[id - 1].second = value;
1566
1567   ecore_wl2_window_aux_hint_change( mEcoreWindow, static_cast< int >( id ), value.c_str() );
1568
1569   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() );
1570
1571   return true;
1572 }
1573
1574 std::string WindowBaseEcoreWl2::GetAuxiliaryHintValue( unsigned int id ) const
1575 {
1576   if( id == 0 || id > mAuxiliaryHints.size() )
1577   {
1578     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl2::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1579     return std::string();
1580   }
1581
1582   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() );
1583
1584   return mAuxiliaryHints[id - 1].second;
1585 }
1586
1587 unsigned int WindowBaseEcoreWl2::GetAuxiliaryHintId( const std::string& hint ) const
1588 {
1589   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1590   {
1591     if( mAuxiliaryHints[i].first == hint )
1592     {
1593       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1594       return i + 1;
1595     }
1596   }
1597
1598   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1599
1600   return 0;
1601 }
1602
1603 void WindowBaseEcoreWl2::SetInputRegion( const Rect< int >& inputRegion )
1604 {
1605   ecore_wl2_window_input_region_set( mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1606 }
1607
1608 void WindowBaseEcoreWl2::SetType( Dali::Window::Type type )
1609 {
1610   Ecore_Wl2_Window_Type windowType;
1611
1612   switch( type )
1613   {
1614     case Dali::Window::NORMAL:
1615     {
1616       windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1617       break;
1618     }
1619     case Dali::Window::NOTIFICATION:
1620     {
1621       windowType = ECORE_WL2_WINDOW_TYPE_NOTIFICATION;
1622       break;
1623     }
1624     case Dali::Window::UTILITY:
1625     {
1626       windowType = ECORE_WL2_WINDOW_TYPE_UTILITY;
1627       break;
1628     }
1629     case Dali::Window::DIALOG:
1630     {
1631       windowType = ECORE_WL2_WINDOW_TYPE_DIALOG;
1632       break;
1633     }
1634     default:
1635     {
1636       windowType = ECORE_WL2_WINDOW_TYPE_TOPLEVEL;
1637       break;
1638     }
1639   }
1640
1641   ecore_wl2_window_type_set( mEcoreWindow, windowType );
1642 }
1643
1644 bool WindowBaseEcoreWl2::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
1645 {
1646   while( !mTizenPolicy )
1647   {
1648     wl_display_dispatch_queue( mDisplay, mEventQueue );
1649   }
1650
1651   int notificationLevel;
1652
1653   switch( level )
1654   {
1655     case Dali::Window::NotificationLevel::NONE:
1656     {
1657       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1658       break;
1659     }
1660     case Dali::Window::NotificationLevel::BASE:
1661     {
1662       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1663       break;
1664     }
1665     case Dali::Window::NotificationLevel::MEDIUM:
1666     {
1667       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1668       break;
1669     }
1670     case Dali::Window::NotificationLevel::HIGH:
1671     {
1672       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1673       break;
1674     }
1675     case Dali::Window::NotificationLevel::TOP:
1676     {
1677       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1678       break;
1679     }
1680     default:
1681     {
1682       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: invalid level [%d]\n", level );
1683       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1684       break;
1685     }
1686   }
1687
1688   mNotificationLevelChangeDone = false;
1689   mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1690
1691   tizen_policy_set_notification_level( mTizenPolicy, ecore_wl2_window_surface_get( mEcoreWindow ), notificationLevel );
1692
1693   int count = 0;
1694
1695   while( !mNotificationLevelChangeDone && count < 3 )
1696   {
1697     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1698     wl_display_dispatch_queue( mDisplay, mEventQueue );
1699     count++;
1700   }
1701
1702   if( !mNotificationLevelChangeDone )
1703   {
1704     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState );
1705     return false;
1706   }
1707   else if( mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1708   {
1709     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Permission denied! [%d]\n", level );
1710     return false;
1711   }
1712
1713   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel );
1714
1715   return true;
1716 }
1717
1718 Dali::Window::NotificationLevel::Type WindowBaseEcoreWl2::GetNotificationLevel() const
1719 {
1720   while( !mTizenPolicy )
1721   {
1722     wl_display_dispatch_queue( mDisplay, mEventQueue );
1723   }
1724
1725   int count = 0;
1726
1727   while( !mNotificationLevelChangeDone && count < 3 )
1728   {
1729     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1730     wl_display_dispatch_queue( mDisplay, mEventQueue );
1731     count++;
1732   }
1733
1734   if( !mNotificationLevelChangeDone )
1735   {
1736     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState );
1737     return Dali::Window::NotificationLevel::NONE;
1738   }
1739
1740   Dali::Window::NotificationLevel::Type level;
1741
1742   switch( mNotificationLevel )
1743   {
1744     case TIZEN_POLICY_LEVEL_NONE:
1745     {
1746       level = Dali::Window::NotificationLevel::NONE;
1747       break;
1748     }
1749     case TIZEN_POLICY_LEVEL_DEFAULT:
1750     {
1751       level = Dali::Window::NotificationLevel::BASE;
1752       break;
1753     }
1754     case TIZEN_POLICY_LEVEL_MEDIUM:
1755     {
1756       level = Dali::Window::NotificationLevel::MEDIUM;
1757       break;
1758     }
1759     case TIZEN_POLICY_LEVEL_HIGH:
1760     {
1761       level = Dali::Window::NotificationLevel::HIGH;
1762       break;
1763     }
1764     case TIZEN_POLICY_LEVEL_TOP:
1765     {
1766       level = Dali::Window::NotificationLevel::TOP;
1767       break;
1768     }
1769     default:
1770     {
1771       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel );
1772       level = Dali::Window::NotificationLevel::NONE;
1773       break;
1774     }
1775   }
1776
1777   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetNotificationLevel: level [%d]\n", mNotificationLevel );
1778
1779   return level;
1780 }
1781
1782 void WindowBaseEcoreWl2::SetOpaqueState( bool opaque )
1783 {
1784   while( !mTizenPolicy )
1785   {
1786     wl_display_dispatch_queue( mDisplay, mEventQueue );
1787   }
1788
1789   tizen_policy_set_opaque_state( mTizenPolicy, ecore_wl2_window_surface_get( mEcoreWindow ), ( opaque ? 1 : 0 ) );
1790 }
1791
1792 bool WindowBaseEcoreWl2::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
1793 {
1794   while( !mTizenPolicy )
1795   {
1796     wl_display_dispatch_queue( mDisplay, mEventQueue );
1797   }
1798
1799   mScreenOffModeChangeDone = false;
1800   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1801
1802   unsigned int mode = 0;
1803
1804   switch( screenOffMode )
1805   {
1806     case Dali::Window::ScreenOffMode::TIMEOUT:
1807     {
1808       mode = 0;
1809       break;
1810     }
1811     case Dali::Window::ScreenOffMode::NEVER:
1812     {
1813       mode = 1;
1814       break;
1815     }
1816   }
1817
1818   tizen_policy_set_window_screen_mode( mTizenPolicy, ecore_wl2_window_surface_get( mEcoreWindow ), mode );
1819
1820   int count = 0;
1821
1822   while( !mScreenOffModeChangeDone && count < 3 )
1823   {
1824     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1825     wl_display_dispatch_queue( mDisplay, mEventQueue );
1826     count++;
1827   }
1828
1829   if( !mScreenOffModeChangeDone )
1830   {
1831     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState );
1832     return false;
1833   }
1834   else if( mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1835   {
1836     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
1837     return false;
1838   }
1839
1840   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode );
1841
1842   return true;
1843 }
1844
1845 Dali::Window::ScreenOffMode::Type WindowBaseEcoreWl2::GetScreenOffMode() const
1846 {
1847   while( !mTizenPolicy )
1848   {
1849     wl_display_dispatch_queue( mDisplay, mEventQueue );
1850   }
1851
1852   int count = 0;
1853
1854   while( !mScreenOffModeChangeDone && count < 3 )
1855   {
1856     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1857     wl_display_dispatch_queue( mDisplay, mEventQueue );
1858     count++;
1859   }
1860
1861   if( !mScreenOffModeChangeDone )
1862   {
1863     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState );
1864     return Dali::Window::ScreenOffMode::TIMEOUT;
1865   }
1866
1867   Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1868
1869   switch( mScreenOffMode )
1870   {
1871     case 0:
1872     {
1873       screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1874       break;
1875     }
1876     case 1:
1877     {
1878       screenMode = Dali::Window::ScreenOffMode::NEVER;
1879       break;
1880     }
1881   }
1882
1883   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode );
1884
1885   return screenMode;
1886 }
1887
1888 bool WindowBaseEcoreWl2::SetBrightness( int brightness )
1889 {
1890   while( !mTizenDisplayPolicy )
1891   {
1892     wl_display_dispatch_queue( mDisplay, mEventQueue );
1893   }
1894
1895   mBrightnessChangeDone = false;
1896   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1897
1898   tizen_display_policy_set_window_brightness( mTizenDisplayPolicy, ecore_wl2_window_surface_get( mEcoreWindow ), brightness );
1899
1900   int count = 0;
1901
1902   while( !mBrightnessChangeDone && count < 3 )
1903   {
1904     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1905     wl_display_dispatch_queue( mDisplay, mEventQueue );
1906     count++;
1907   }
1908
1909   if( !mBrightnessChangeDone )
1910   {
1911     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState );
1912     return false;
1913   }
1914   else if( mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1915   {
1916     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Permission denied! [%d]\n", brightness );
1917     return false;
1918   }
1919
1920   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::SetBrightness: Brightness is changed [%d]\n", mBrightness );
1921
1922   return true;
1923 }
1924
1925 int WindowBaseEcoreWl2::GetBrightness() const
1926 {
1927   while( !mTizenDisplayPolicy )
1928   {
1929     wl_display_dispatch_queue( mDisplay, mEventQueue );
1930   }
1931
1932   int count = 0;
1933
1934   while( !mBrightnessChangeDone && count < 3 )
1935   {
1936     ecore_wl2_display_flush( ecore_wl2_connected_display_get( NULL ) );
1937     wl_display_dispatch_queue( mDisplay, mEventQueue );
1938     count++;
1939   }
1940
1941   if( !mBrightnessChangeDone )
1942   {
1943     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Error! [%d]\n", mBrightnessChangeState );
1944     return 0;
1945   }
1946
1947   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl2::GetBrightness: Brightness [%d]\n", mBrightness );
1948
1949   return mBrightness;
1950 }
1951
1952 bool WindowBaseEcoreWl2::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
1953 {
1954   Ecore_Wl2_Window_Keygrab_Mode mode;
1955
1956   switch( grabMode )
1957   {
1958     case KeyGrab::TOPMOST:
1959     {
1960       mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
1961       break;
1962     }
1963     case KeyGrab::SHARED:
1964     {
1965       mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
1966       break;
1967     }
1968     case KeyGrab::OVERRIDE_EXCLUSIVE:
1969     {
1970       mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1971       break;
1972     }
1973     case KeyGrab::EXCLUSIVE:
1974     {
1975       mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
1976       break;
1977     }
1978     default:
1979     {
1980       return false;
1981     }
1982   }
1983
1984   return ecore_wl2_window_keygrab_set( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0, 0, mode );
1985 }
1986
1987 bool WindowBaseEcoreWl2::UngrabKey( Dali::KEY key )
1988 {
1989   return ecore_wl2_window_keygrab_unset( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0 );
1990 }
1991
1992 bool WindowBaseEcoreWl2::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
1993 {
1994   int keyCount = key.Count();
1995   int keyGrabModeCount = grabMode.Count();
1996
1997   if( keyCount != keyGrabModeCount || keyCount == 0 )
1998   {
1999     return false;
2000   }
2001
2002   eina_init();
2003
2004   Eina_List* keyList = NULL;
2005   Ecore_Wl2_Window_Keygrab_Info* info = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2006
2007   for( int index = 0; index < keyCount; ++index )
2008   {
2009     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
2010
2011     switch( grabMode[index] )
2012     {
2013       case KeyGrab::TOPMOST:
2014       {
2015         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_TOPMOST;
2016         break;
2017       }
2018       case KeyGrab::SHARED:
2019       {
2020         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_SHARED;
2021         break;
2022       }
2023       case KeyGrab::OVERRIDE_EXCLUSIVE:
2024       {
2025         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2026         break;
2027       }
2028       case KeyGrab::EXCLUSIVE:
2029       {
2030         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_EXCLUSIVE;
2031         break;
2032       }
2033       default:
2034       {
2035         info[index].mode = ECORE_WL2_WINDOW_KEYGRAB_UNKNOWN;
2036         break;
2037       }
2038     }
2039
2040     keyList = eina_list_append( keyList, &info );
2041   }
2042
2043   Eina_List* grabList = ecore_wl2_window_keygrab_list_set( mEcoreWindow, keyList );
2044
2045   result.Resize( keyCount, true );
2046
2047   Eina_List* l = NULL;
2048   Eina_List* m = NULL;
2049   void* listData = NULL;
2050   void* data = NULL;
2051   if( grabList != NULL )
2052   {
2053     EINA_LIST_FOREACH( grabList, m, data )
2054     {
2055       int index = 0;
2056       EINA_LIST_FOREACH( keyList, l, listData )
2057       {
2058         if( static_cast< Ecore_Wl2_Window_Keygrab_Info* >( listData )->key == NULL )
2059         {
2060           DALI_LOG_ERROR( "input key list has null data!" );
2061           break;
2062         }
2063
2064         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl2_Window_Keygrab_Info* >( listData )->key ) == 0 )
2065         {
2066           result[index] = false;
2067         }
2068         ++index;
2069       }
2070     }
2071   }
2072
2073   delete [] info;
2074
2075   eina_list_free( keyList );
2076   eina_list_free( grabList );
2077   eina_shutdown();
2078
2079   return true;
2080 }
2081
2082 bool WindowBaseEcoreWl2::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
2083 {
2084   int keyCount = key.Count();
2085   if( keyCount == 0 )
2086   {
2087     return false;
2088   }
2089
2090   eina_init();
2091
2092   Eina_List* keyList = NULL;
2093   Ecore_Wl2_Window_Keygrab_Info* info = new Ecore_Wl2_Window_Keygrab_Info[keyCount];
2094
2095   for( int index = 0; index < keyCount; ++index )
2096   {
2097     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
2098     keyList = eina_list_append( keyList, &info );
2099   }
2100
2101   Eina_List* ungrabList = ecore_wl2_window_keygrab_list_unset( mEcoreWindow, keyList );
2102
2103   result.Resize( keyCount, true );
2104
2105   Eina_List* l = NULL;
2106   Eina_List* m = NULL;
2107   void *listData = NULL;
2108   void *data = NULL;
2109
2110   if( ungrabList != NULL )
2111   {
2112     EINA_LIST_FOREACH( ungrabList, m, data )
2113     {
2114       int index = 0;
2115       EINA_LIST_FOREACH( keyList, l, listData )
2116       {
2117         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl2_Window_Keygrab_Info* >( listData )->key ) == 0 )
2118         {
2119           result[index] = false;
2120         }
2121         ++index;
2122       }
2123     }
2124   }
2125
2126   delete [] info;
2127
2128   eina_list_free( keyList );
2129   eina_list_free( ungrabList );
2130   eina_shutdown();
2131
2132   return true;
2133 }
2134
2135 void WindowBaseEcoreWl2::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
2136 {
2137   // calculate DPI
2138   float xres, yres;
2139
2140   Ecore_Wl2_Output* output = ecore_wl2_window_output_find( mEcoreWindow );
2141
2142   // 1 inch = 25.4 millimeters
2143   xres = ecore_wl2_output_dpi_get( output );
2144   yres = ecore_wl2_output_dpi_get( output );
2145
2146   dpiHorizontal = int( xres + 0.5f );  // rounding
2147   dpiVertical   = int( yres + 0.5f );
2148 }
2149
2150 void WindowBaseEcoreWl2::SetViewMode( ViewMode viewMode )
2151 {
2152 }
2153
2154 int WindowBaseEcoreWl2::GetScreenRotationAngle()
2155 {
2156   int transform = 0;
2157
2158   if( ecore_wl2_window_ignore_output_transform_get( mEcoreWindow ) )
2159   {
2160     transform = 0;
2161   }
2162   else
2163   {
2164     transform = ecore_wl2_output_transform_get( ecore_wl2_window_output_find( mEcoreWindow ) );
2165   }
2166
2167   return transform * 90;
2168 }
2169
2170 void WindowBaseEcoreWl2::SetWindowRotationAngle( int degree )
2171 {
2172   ecore_wl2_window_rotation_set( mEcoreWindow, degree );
2173 }
2174
2175 void WindowBaseEcoreWl2::WindowRotationCompleted( int degree, int width, int height )
2176 {
2177   ecore_wl2_window_rotation_change_done_send( mEcoreWindow, degree, width, height );
2178 }
2179
2180 void WindowBaseEcoreWl2::SetTransparency( bool transparent )
2181 {
2182   ecore_wl2_window_alpha_set( mEcoreWindow, transparent );
2183 }
2184
2185 void WindowBaseEcoreWl2::InitializeEcoreElDBus()
2186 {
2187 #ifdef DALI_ELDBUS_AVAILABLE
2188   Eldbus_Object* object;
2189   Eldbus_Proxy* manager;
2190
2191   if( !( mSystemConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SYSTEM ) ) )
2192   {
2193     DALI_LOG_ERROR( "Unable to get system bus\n" );
2194   }
2195
2196   object = eldbus_object_get( mSystemConnection, BUS, PATH );
2197   if( !object )
2198   {
2199     DALI_LOG_ERROR( "Getting object failed\n" );
2200     return;
2201   }
2202
2203   manager = eldbus_proxy_get( object, INTERFACE );
2204   if( !manager )
2205   {
2206     DALI_LOG_ERROR( "Getting proxy failed\n" );
2207     return;
2208   }
2209
2210   if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this ) )
2211   {
2212     DALI_LOG_ERROR( "No signal handler returned\n" );
2213   }
2214 #endif
2215 }
2216
2217 void WindowBaseEcoreWl2::CreateWindow( PositionSize positionSize )
2218 {
2219   Ecore_Wl2_Display* display = ecore_wl2_display_connect( NULL );
2220   if( !display )
2221   {
2222     DALI_ASSERT_ALWAYS( 0 && "Failed to get display" );
2223   }
2224
2225   mEcoreWindow = ecore_wl2_window_new( display, NULL, positionSize.x, positionSize.y, positionSize.width, positionSize.height );
2226
2227   if ( mEcoreWindow == 0 )
2228   {
2229     DALI_ASSERT_ALWAYS( 0 && "Failed to create Wayland window" );
2230   }
2231
2232   // Set default type
2233   ecore_wl2_window_type_set( mEcoreWindow, ECORE_WL2_WINDOW_TYPE_TOPLEVEL );
2234 }
2235
2236 } // namespace Adaptor
2237
2238 } // namespace Internal
2239
2240 } // namespace Dali
2241
2242 #pragma GCC diagnostic pop