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