Merge "To support openssl new feature" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl / window-base-ecore-wl.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-wl/window-base-ecore-wl.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/window-system/common/window-impl.h>
27 #include <dali/internal/window-system/common/window-system.h>
28 #include <dali/internal/window-system/common/window-render-surface.h>
29 #include <dali/internal/input/common/key-impl.h>
30
31 // EXTERNAL_HEADERS
32 #include <dali/public-api/object/any.h>
33 #include <dali/integration-api/debug.h>
34 #include <Ecore_Input.h>
35 #include <vconf.h>
36 #include <vconf-keys.h>
37
38 namespace Dali
39 {
40
41 namespace Internal
42 {
43
44 namespace Adaptor
45 {
46
47 namespace
48 {
49
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
52 #endif
53
54 const uint32_t MAX_TIZEN_CLIENT_VERSION = 7;
55 const unsigned int PRIMARY_TOUCH_BUTTON_ID = 1;
56
57 const char* DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME = "db/setting/accessibility/font_name";  // It will be update at vconf-key.h and replaced.
58
59 // DBUS accessibility
60 const char* BUS = "org.enlightenment.wm-screen-reader";
61 const char* INTERFACE = "org.tizen.GestureNavigation";
62 const char* PATH = "/org/tizen/GestureNavigation";
63
64 /**
65  * Get the device name from the provided ecore key event
66  */
67 void GetDeviceName( Ecore_Event_Key* keyEvent, std::string& result )
68 {
69   const char* ecoreDeviceName = ecore_device_name_get( keyEvent->dev );
70
71   if( ecoreDeviceName )
72   {
73     result = ecoreDeviceName;
74   }
75 }
76
77 /**
78  * Get the device class from the provided ecore event
79  */
80 void GetDeviceClass( Ecore_Device_Class ecoreDeviceClass, Device::Class::Type& deviceClass )
81 {
82   switch( ecoreDeviceClass )
83   {
84     case ECORE_DEVICE_CLASS_SEAT:
85     {
86       deviceClass = Device::Class::USER;
87       break;
88     }
89     case ECORE_DEVICE_CLASS_KEYBOARD:
90     {
91       deviceClass = Device::Class::KEYBOARD;
92       break;
93     }
94     case ECORE_DEVICE_CLASS_MOUSE:
95     {
96       deviceClass = Device::Class::MOUSE;
97       break;
98     }
99     case ECORE_DEVICE_CLASS_TOUCH:
100     {
101       deviceClass = Device::Class::TOUCH;
102       break;
103     }
104     case ECORE_DEVICE_CLASS_PEN:
105     {
106       deviceClass = Device::Class::PEN;
107       break;
108     }
109     case ECORE_DEVICE_CLASS_POINTER:
110     {
111       deviceClass = Device::Class::POINTER;
112       break;
113     }
114     case ECORE_DEVICE_CLASS_GAMEPAD:
115     {
116       deviceClass = Device::Class::GAMEPAD;
117       break;
118     }
119     default:
120     {
121       deviceClass = Device::Class::NONE;
122       break;
123     }
124   }
125 }
126
127 void GetDeviceSubclass( Ecore_Device_Subclass ecoreDeviceSubclass, Device::Subclass::Type& deviceSubclass )
128 {
129   switch( ecoreDeviceSubclass )
130   {
131     case ECORE_DEVICE_SUBCLASS_FINGER:
132     {
133       deviceSubclass = Device::Subclass::FINGER;
134       break;
135     }
136     case ECORE_DEVICE_SUBCLASS_FINGERNAIL:
137     {
138       deviceSubclass = Device::Subclass::FINGERNAIL;
139       break;
140     }
141     case ECORE_DEVICE_SUBCLASS_KNUCKLE:
142     {
143       deviceSubclass = Device::Subclass::KNUCKLE;
144       break;
145     }
146     case ECORE_DEVICE_SUBCLASS_PALM:
147     {
148       deviceSubclass = Device::Subclass::PALM;
149       break;
150     }
151     case ECORE_DEVICE_SUBCLASS_HAND_SIZE:
152     {
153       deviceSubclass = Device::Subclass::HAND_SIDE;
154       break;
155     }
156     case ECORE_DEVICE_SUBCLASS_HAND_FLAT:
157     {
158       deviceSubclass = Device::Subclass::HAND_FLAT;
159       break;
160     }
161     case ECORE_DEVICE_SUBCLASS_PEN_TIP:
162     {
163       deviceSubclass = Device::Subclass::PEN_TIP;
164       break;
165     }
166     case ECORE_DEVICE_SUBCLASS_TRACKPAD:
167     {
168       deviceSubclass = Device::Subclass::TRACKPAD;
169       break;
170     }
171     case ECORE_DEVICE_SUBCLASS_TRACKPOINT:
172     {
173       deviceSubclass = Device::Subclass::TRACKPOINT;
174       break;
175     }
176     case ECORE_DEVICE_SUBCLASS_TRACKBALL:
177     {
178       deviceSubclass = Device::Subclass::TRACKBALL;
179       break;
180     }
181 #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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
288   if( windowBase )
289   {
290     windowBase->OnMouseButtonDown( data, type, event );
291   }
292   return ECORE_CALLBACK_PASS_ON;
293 }
294
295 /**
296  * Called when a touch up is received.
297  */
298 static Eina_Bool EcoreEventMouseButtonUp( void* data, int type, void* event )
299 {
300   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
301   if( windowBase )
302   {
303     windowBase->OnMouseButtonUp( data, type, event );
304   }
305   return ECORE_CALLBACK_PASS_ON;
306 }
307
308 /**
309  * Called when a touch motion is received.
310  */
311 static Eina_Bool EcoreEventMouseButtonMove( void* data, int type, void* event )
312 {
313   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
314   if( windowBase )
315   {
316     windowBase->OnMouseButtonMove( data, type, event );
317   }
318   return ECORE_CALLBACK_PASS_ON;
319 }
320
321 /**
322  * Called when a touch is canceled.
323  */
324 static Eina_Bool EcoreEventMouseButtonCancel( void* data, int type, void* event )
325 {
326   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
327   if( windowBase )
328   {
329     windowBase->OnMouseButtonCancel( data, type, event );
330   }
331   return ECORE_CALLBACK_PASS_ON;
332 }
333
334 /**
335  * Called when a mouse wheel is received.
336  */
337 static Eina_Bool EcoreEventMouseWheel( void* data, int type, void* event )
338 {
339   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
340   if( windowBase )
341   {
342     windowBase->OnMouseWheel( data, type, event );
343   }
344   return ECORE_CALLBACK_PASS_ON;
345 }
346
347 /**
348  * Called when a detent rotation event is recevied.
349  */
350 static Eina_Bool EcoreEventDetentRotation( void* data, int type, void* event )
351 {
352   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
353   if( windowBase )
354   {
355     windowBase->OnDetentRotation( data, type, event );
356   }
357   return ECORE_CALLBACK_PASS_ON;
358 }
359
360 /////////////////////////////////////////////////////////////////////////////////////////////////
361 // Key Callbacks
362 /////////////////////////////////////////////////////////////////////////////////////////////////
363
364 /**
365  * Called when a key down is received.
366  */
367 static Eina_Bool EcoreEventKeyDown( void* data, int type, void* event )
368 {
369   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
370   if( windowBase )
371   {
372     windowBase->OnKeyDown( data, type, event );
373   }
374   return ECORE_CALLBACK_PASS_ON;
375 }
376
377 /**
378  * Called when a key up is received.
379  */
380 static Eina_Bool EcoreEventKeyUp( void* data, int type, void* event )
381 {
382   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
383   if( windowBase )
384   {
385     windowBase->OnKeyUp( data, type, event );
386   }
387   return ECORE_CALLBACK_PASS_ON;
388 }
389
390 /////////////////////////////////////////////////////////////////////////////////////////////////
391 // Selection Callbacks
392 /////////////////////////////////////////////////////////////////////////////////////////////////
393
394 /**
395  * Called when the source window notifies us the content in clipboard is selected.
396  */
397 static Eina_Bool EcoreEventDataSend( void* data, int type, void* event )
398 {
399   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
400   if( windowBase )
401   {
402     windowBase->OnDataSend( data, type, event );
403   }
404   return ECORE_CALLBACK_PASS_ON;
405 }
406
407 /**
408 * Called when the source window sends us about the selected content.
409 * For example, when item is selected in the clipboard.
410 */
411 static Eina_Bool EcoreEventDataReceive( void* data, int type, void* event )
412 {
413   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
414   if( windowBase )
415   {
416     windowBase->OnDataReceive( data, type, event );
417   }
418   return ECORE_CALLBACK_PASS_ON;
419 }
420
421 /////////////////////////////////////////////////////////////////////////////////////////////////
422 // 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     WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( 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 WindowBaseEcoreWl::WindowBaseEcoreWl( 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 WindowBaseEcoreWl::~WindowBaseEcoreWl()
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_wl_window_free( mEcoreWindow );
652
653     WindowSystem::Shutdown();
654   }
655 }
656
657 void WindowBaseEcoreWl::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_Wl_Window *) ) && "Surface type is invalid" );
663
664     mEcoreWindow = AnyCast< Ecore_Wl_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_wl_window_surface_create( mEcoreWindow );
676
677   SetTransparency( isTransparent );
678
679   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
680   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,                    EcoreEventWindowFocusIn,             this ) );
681   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT,                   EcoreEventWindowFocusOut,            this ) );
682   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_OUTPUT_TRANSFORM,            EcoreEventOutputTransform,           this ) );
683   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM,     EcoreEventIgnoreOutputTransform,     this ) );
684
685   // Register Rotate event
686   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_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_WL_EVENT_DATA_SOURCE_SEND,            EcoreEventDataSend,                  this ) );
706   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_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_WL_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   mDisplay = ecore_wl_display_get();
720
721   if( mDisplay )
722   {
723     wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
724     if( displayWrapper )
725     {
726       mEventQueue = wl_display_create_queue( mDisplay );
727       if( mEventQueue )
728       {
729         wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
730
731         wl_registry* registry = wl_display_get_registry( displayWrapper );
732         wl_registry_add_listener( registry, &registryListener, this );
733       }
734
735       wl_proxy_wrapper_destroy( displayWrapper );
736     }
737   }
738
739   // get auxiliary hint
740   Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEcoreWindow );
741   if( hints )
742   {
743     Eina_List* l = NULL;
744     char* hint = NULL;
745
746     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) ) ) )
747     {
748       mSupportedAuxiliaryHints.push_back( hint );
749
750       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::Initialize: %s\n", hint );
751     }
752   }
753 }
754
755 Eina_Bool WindowBaseEcoreWl::OnIconifyStateChanged( void* data, int type, void* event )
756 {
757   Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
758   Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
759
760   if( iconifyChangedEvent->win == static_cast< unsigned int>( ecore_wl_window_id_get( mEcoreWindow ) ) )
761   {
762     if( iconifyChangedEvent->iconified == EINA_TRUE )
763     {
764       mIconifyChangedSignal.Emit( true );
765     }
766     else
767     {
768       mIconifyChangedSignal.Emit( false );
769     }
770     handled = ECORE_CALLBACK_DONE;
771   }
772
773   return handled;
774 }
775
776 Eina_Bool WindowBaseEcoreWl::OnFocusIn( void* data, int type, void* event )
777 {
778   Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
779
780   if( focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
781   {
782     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
783
784     mFocusChangedSignal.Emit( true );
785   }
786
787   return ECORE_CALLBACK_PASS_ON;
788 }
789
790 Eina_Bool WindowBaseEcoreWl::OnFocusOut( void* data, int type, void* event )
791 {
792   Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
793
794   if( focusOutEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
795   {
796     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
797
798     mFocusChangedSignal.Emit( false );
799   }
800
801   return ECORE_CALLBACK_PASS_ON;
802 }
803
804 Eina_Bool WindowBaseEcoreWl::OnOutputTransform( void* data, int type, void* event )
805 {
806   Ecore_Wl_Event_Output_Transform* transformEvent( static_cast< Ecore_Wl_Event_Output_Transform* >( event ) );
807
808   if( transformEvent->output == ecore_wl_window_output_find( mEcoreWindow ) )
809   {
810     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow );
811
812     mOutputTransformedSignal.Emit();
813   }
814
815   return ECORE_CALLBACK_PASS_ON;
816 }
817
818 Eina_Bool WindowBaseEcoreWl::OnIgnoreOutputTransform( void* data, int type, void* event )
819 {
820   Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
821
822   if( ignoreTransformEvent->win == mEcoreWindow )
823   {
824     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow );
825
826     mOutputTransformedSignal.Emit();
827   }
828
829   return ECORE_CALLBACK_PASS_ON;
830 }
831
832 void WindowBaseEcoreWl::OnRotation( void* data, int type, void* event )
833 {
834   Ecore_Wl_Event_Window_Rotate* ev( static_cast< Ecore_Wl_Event_Window_Rotate* >( event ) );
835
836   if( ev->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
837   {
838     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnRotation\n" );
839
840     RotationEvent rotationEvent;
841     rotationEvent.angle = ev->angle;
842     rotationEvent.winResize = 0;
843
844     if( ev->angle == 0 || ev->angle == 180 )
845     {
846       rotationEvent.width = ev->w;
847       rotationEvent.height = ev->h;
848     }
849     else
850     {
851       rotationEvent.width = ev->h;
852       rotationEvent.height = ev->w;
853     }
854
855     mRotationSignal.Emit( rotationEvent );
856   }
857 }
858
859 void WindowBaseEcoreWl::OnMouseButtonDown( void* data, int type, void* event )
860 {
861   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
862
863   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
864   {
865     PointState::Type state ( PointState::DOWN );
866
867     // Check if the buttons field is set and ensure it's the primary touch button.
868     // If this event was triggered by buttons other than the primary button (used for touch), then
869     // just send an interrupted event to Core.
870     if( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
871     {
872       state = PointState::INTERRUPTED;
873     }
874
875     Device::Class::Type deviceClass;
876     Device::Subclass::Type deviceSubclass;
877
878     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
879     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
880
881     Integration::Point point;
882     point.SetDeviceId( touchEvent->multi.device );
883     point.SetState( state );
884     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
885     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
886     point.SetPressure( touchEvent->multi.pressure );
887     point.SetAngle( Degree( touchEvent->multi.angle ) );
888     point.SetDeviceClass( deviceClass );
889     point.SetDeviceSubclass( deviceSubclass );
890
891     mTouchEventSignal.Emit( point, touchEvent->timestamp );
892   }
893 }
894
895 void WindowBaseEcoreWl::OnMouseButtonUp( void* data, int type, void* event )
896 {
897   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
898
899   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
900   {
901     Device::Class::Type deviceClass;
902     Device::Subclass::Type deviceSubclass;
903
904     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
905     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
906
907     Integration::Point point;
908     point.SetDeviceId( touchEvent->multi.device );
909     point.SetState( PointState::UP );
910     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
911     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
912     point.SetPressure( touchEvent->multi.pressure );
913     point.SetAngle( Degree( touchEvent->multi.angle ) );
914     point.SetDeviceClass( deviceClass );
915     point.SetDeviceSubclass( deviceSubclass );
916
917     mTouchEventSignal.Emit( point, touchEvent->timestamp );
918   }
919 }
920
921 void WindowBaseEcoreWl::OnMouseButtonMove( void* data, int type, void* event )
922 {
923   Ecore_Event_Mouse_Move* touchEvent = static_cast< Ecore_Event_Mouse_Move* >( event );
924
925   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
926   {
927     Device::Class::Type deviceClass;
928     Device::Subclass::Type deviceSubclass;
929
930     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
931     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
932
933     Integration::Point point;
934     point.SetDeviceId( touchEvent->multi.device );
935     point.SetState( PointState::MOTION );
936     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
937     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
938     point.SetPressure( touchEvent->multi.pressure );
939     point.SetAngle( Degree( touchEvent->multi.angle ) );
940     point.SetDeviceClass( deviceClass );
941     point.SetDeviceSubclass( deviceSubclass );
942
943     mTouchEventSignal.Emit( point, touchEvent->timestamp );
944   }
945 }
946
947 void WindowBaseEcoreWl::OnMouseButtonCancel( void* data, int type, void* event )
948 {
949   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
950
951   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
952   {
953     Integration::Point point;
954     point.SetDeviceId( touchEvent->multi.device );
955     point.SetState( PointState::INTERRUPTED );
956     point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
957
958     mTouchEventSignal.Emit( point, touchEvent->timestamp );
959
960     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseButtonCancel\n" );
961   }
962 }
963
964 void WindowBaseEcoreWl::OnMouseWheel( void* data, int type, void* event )
965 {
966   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast< Ecore_Event_Mouse_Wheel* >( event );
967
968   if( mouseWheelEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
969   {
970     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 );
971
972     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2( mouseWheelEvent->x, mouseWheelEvent->y ), mouseWheelEvent->z, mouseWheelEvent->timestamp );
973
974     mWheelEventSignal.Emit( wheelEvent );
975   }
976 }
977
978 void WindowBaseEcoreWl::OnDetentRotation( void* data, int type, void* event )
979 {
980   Ecore_Event_Detent_Rotate* detentEvent = static_cast< Ecore_Event_Detent_Rotate* >( event );
981
982   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnDetentRotation\n" );
983
984   int direction = ( detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE ) ? 1 : -1;
985   int timeStamp = detentEvent->timestamp;
986
987   WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2( 0.0f, 0.0f ), direction, timeStamp );
988
989   mWheelEventSignal.Emit( wheelEvent );
990 }
991
992 void WindowBaseEcoreWl::OnKeyDown( void* data, int type, void* event )
993 {
994   Ecore_Event_Key* keyEvent = static_cast< Ecore_Event_Key* >( event );
995
996   if( keyEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
997   {
998     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyDown\n" );
999
1000     std::string keyName( keyEvent->keyname );
1001     std::string logicalKey( "" );
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     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1012     if( keyEvent->key )
1013     {
1014       logicalKey = keyEvent->key;
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, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, deviceName, deviceClass, deviceSubclass );
1041
1042      mKeyEventSignal.Emit( keyEvent );
1043   }
1044 }
1045
1046 void WindowBaseEcoreWl::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_wl_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 logicalKey( "" );
1056     std::string keyString( "" );
1057     std::string compose( "" );
1058
1059     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1060     if( keyEvent->compose )
1061     {
1062       compose = keyEvent->compose;
1063     }
1064
1065     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1066     if( keyEvent->key )
1067     {
1068       logicalKey = keyEvent->key;
1069     }
1070
1071     int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
1072     keyCode = ( keyCode == -1 ) ? 0 : keyCode;
1073     int modifier( keyEvent->modifiers );
1074     unsigned long time = keyEvent->timestamp;
1075     if( !strncmp( keyEvent->keyname, "Keycode-", 8 ) )
1076     {
1077       keyCode = atoi( keyEvent->keyname + 8 );
1078     }
1079
1080     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1081     if( keyEvent->string )
1082     {
1083       keyString = keyEvent->string;
1084     }
1085
1086     std::string deviceName;
1087     Device::Class::Type deviceClass;
1088     Device::Subclass::Type deviceSubclass;
1089
1090     GetDeviceName( keyEvent, deviceName );
1091     GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
1092     GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
1093
1094     Integration::KeyEvent keyEvent( keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, deviceName, deviceClass, deviceSubclass );
1095
1096      mKeyEventSignal.Emit( keyEvent );
1097   }
1098 }
1099
1100 void WindowBaseEcoreWl::OnDataSend( void* data, int type, void* event )
1101 {
1102   mSelectionDataSendSignal.Emit( event );
1103 }
1104
1105 void WindowBaseEcoreWl::OnDataReceive( void* data, int type, void* event )
1106 {
1107   mSelectionDataReceivedSignal.Emit( event  );
1108 }
1109
1110 void WindowBaseEcoreWl::OnIndicatorFlicked( void* data, int type, void* event )
1111 {
1112   mIndicatorFlickedSignal.Emit();
1113 }
1114
1115 void WindowBaseEcoreWl::OnFontNameChanged()
1116 {
1117   mStyleChangedSignal.Emit( StyleChange::DEFAULT_FONT_CHANGE );
1118 }
1119
1120 void WindowBaseEcoreWl::OnFontSizeChanged()
1121 {
1122   mStyleChangedSignal.Emit( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1123 }
1124
1125 void WindowBaseEcoreWl::OnEcoreElDBusAccessibilityNotification( void* context, const Eldbus_Message* message )
1126 {
1127 #ifdef DALI_ELDBUS_AVAILABLE
1128   AccessibilityInfo info;
1129
1130   // The string defines the arg-list's respective types.
1131   if( !eldbus_message_arguments_get( message, "iiiiiiu", &info.gestureValue, &info.startX, &info.startY, &info.endX, &info.endY, &info.state, &info.eventTime ) )
1132   {
1133     DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1134   }
1135
1136   mAccessibilitySignal.Emit( info );
1137 #endif
1138 }
1139
1140 void WindowBaseEcoreWl::RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
1141 {
1142   if( strcmp( interface, tizen_policy_interface.name ) == 0 )
1143   {
1144     uint32_t clientVersion = std::min( version, MAX_TIZEN_CLIENT_VERSION );
1145
1146     mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, clientVersion ) );
1147     if( !mTizenPolicy )
1148     {
1149       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
1150       return;
1151     }
1152
1153     tizen_policy_add_listener( mTizenPolicy, &tizenPolicyListener, data );
1154
1155     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
1156   }
1157   else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
1158   {
1159     mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
1160     if( !mTizenDisplayPolicy )
1161     {
1162       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
1163       return;
1164     }
1165
1166     tizen_display_policy_add_listener( mTizenDisplayPolicy, &tizenDisplayPolicyListener, data );
1167
1168     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
1169   }
1170 }
1171
1172 void WindowBaseEcoreWl::RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
1173 {
1174   mTizenPolicy = NULL;
1175   mTizenDisplayPolicy = NULL;
1176 }
1177
1178 void WindowBaseEcoreWl::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
1179 {
1180   mNotificationLevel = level;
1181   mNotificationChangeState = state;
1182   mNotificationLevelChangeDone = true;
1183
1184   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
1185 }
1186
1187 void WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
1188 {
1189   mScreenOffMode = mode;
1190   mScreenOffModeChangeState = state;
1191   mScreenOffModeChangeDone = true;
1192
1193   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
1194 }
1195
1196 void WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
1197 {
1198   mBrightness = brightness;
1199   mBrightnessChangeState = state;
1200   mBrightnessChangeDone = true;
1201
1202   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
1203 }
1204
1205 Any WindowBaseEcoreWl::GetNativeWindow()
1206 {
1207   return mEcoreWindow;
1208 }
1209
1210 int WindowBaseEcoreWl::GetNativeWindowId()
1211 {
1212   return ecore_wl_window_id_get( mEcoreWindow );
1213 }
1214
1215 EGLNativeWindowType WindowBaseEcoreWl::CreateEglWindow( int width, int height )
1216 {
1217   mEglWindow = wl_egl_window_create( mWlSurface, width, height );
1218
1219   return static_cast< EGLNativeWindowType >( mEglWindow );
1220 }
1221
1222 void WindowBaseEcoreWl::DestroyEglWindow()
1223 {
1224   if( mEglWindow != NULL )
1225   {
1226     wl_egl_window_destroy( mEglWindow );
1227     mEglWindow = NULL;
1228   }
1229 }
1230
1231 void WindowBaseEcoreWl::SetEglWindowRotation( int angle )
1232 {
1233   wl_egl_window_rotation rotation;
1234
1235   switch( angle )
1236   {
1237     case 0:
1238     {
1239       rotation = ROTATION_0;
1240       break;
1241     }
1242     case 90:
1243     {
1244       rotation = ROTATION_270;
1245       break;
1246     }
1247     case 180:
1248     {
1249       rotation = ROTATION_180;
1250       break;
1251     }
1252     case 270:
1253     {
1254       rotation = ROTATION_90;
1255       break;
1256     }
1257     default:
1258     {
1259       rotation = ROTATION_0;
1260       break;
1261     }
1262   }
1263
1264   wl_egl_window_set_rotation( mEglWindow, rotation );
1265 }
1266
1267 void WindowBaseEcoreWl::SetEglWindowBufferTransform( int angle )
1268 {
1269   wl_output_transform bufferTransform;
1270
1271   switch( angle )
1272   {
1273     case 0:
1274     {
1275       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1276       break;
1277     }
1278     case 90:
1279     {
1280       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1281       break;
1282     }
1283     case 180:
1284     {
1285       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1286       break;
1287     }
1288     case 270:
1289     {
1290       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1291       break;
1292     }
1293     default:
1294     {
1295       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1296       break;
1297     }
1298   }
1299
1300   wl_egl_window_set_buffer_transform( mEglWindow, bufferTransform );
1301 }
1302
1303 void WindowBaseEcoreWl::SetEglWindowTransform( int angle )
1304 {
1305   wl_output_transform windowTransform;
1306
1307   switch( angle )
1308   {
1309     case 0:
1310     {
1311       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1312       break;
1313     }
1314     case 90:
1315     {
1316       windowTransform = WL_OUTPUT_TRANSFORM_90;
1317       break;
1318     }
1319     case 180:
1320     {
1321       windowTransform = WL_OUTPUT_TRANSFORM_180;
1322       break;
1323     }
1324     case 270:
1325     {
1326       windowTransform = WL_OUTPUT_TRANSFORM_270;
1327       break;
1328     }
1329     default:
1330     {
1331       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1332       break;
1333     }
1334   }
1335
1336   wl_egl_window_set_window_transform( mEglWindow, windowTransform );
1337 }
1338
1339 void WindowBaseEcoreWl::ResizeEglWindow( PositionSize positionSize )
1340 {
1341   wl_egl_window_resize( mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y );
1342 }
1343
1344 bool WindowBaseEcoreWl::IsEglWindowRotationSupported()
1345 {
1346   // Check capability
1347   wl_egl_window_capability capability = static_cast< wl_egl_window_capability >( wl_egl_window_get_capabilities( mEglWindow ) );
1348   if( capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED )
1349   {
1350     return true;
1351   }
1352
1353   return false;
1354 }
1355
1356 void WindowBaseEcoreWl::Move( PositionSize positionSize )
1357 {
1358   ecore_wl_window_position_set( mEcoreWindow, positionSize.x, positionSize.y );
1359 }
1360
1361 void WindowBaseEcoreWl::Resize( PositionSize positionSize )
1362 {
1363   ecore_wl_window_update_size( mEcoreWindow, positionSize.width, positionSize.height );
1364 }
1365
1366 void WindowBaseEcoreWl::MoveResize( PositionSize positionSize )
1367 {
1368   ecore_wl_window_position_set( mEcoreWindow, positionSize.x, positionSize.y );
1369   ecore_wl_window_update_size( mEcoreWindow, positionSize.width, positionSize.height );
1370 }
1371
1372 void WindowBaseEcoreWl::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
1373 {
1374   DALI_LOG_TRACE_METHOD_FMT( gWindowBaseLogFilter, "visible : %d\n", visibleMode );
1375
1376   if( visibleMode == Dali::Window::VISIBLE )
1377   {
1378     // when the indicator is visible, set proper mode for indicator server according to bg mode
1379     if( opacityMode == Dali::Window::OPAQUE )
1380     {
1381       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_OPAQUE );
1382     }
1383     else if( opacityMode == Dali::Window::TRANSLUCENT )
1384     {
1385       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_TRANSLUCENT );
1386     }
1387     else if( opacityMode == Dali::Window::TRANSPARENT )
1388     {
1389       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_OPAQUE );
1390     }
1391   }
1392   else
1393   {
1394     // when the indicator is not visible, set TRANSPARENT mode for indicator server
1395     ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
1396   }
1397 }
1398
1399 void WindowBaseEcoreWl::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
1400 {
1401   if( isShow )
1402   {
1403     ecore_wl_window_indicator_state_set( mEcoreWindow, ECORE_WL_INDICATOR_STATE_ON );
1404   }
1405   else
1406   {
1407     ecore_wl_window_indicator_state_set( mEcoreWindow, ECORE_WL_INDICATOR_STATE_OFF );
1408   }
1409 }
1410
1411 void WindowBaseEcoreWl::IndicatorTypeChanged( IndicatorInterface::Type type )
1412 {
1413 #if defined(DALI_PROFILE_MOBILE)
1414   switch( type )
1415   {
1416     case IndicatorInterface::INDICATOR_TYPE_1:
1417     {
1418       ecore_wl_indicator_visible_type_set( mEcoreWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN );
1419       break;
1420     }
1421     case IndicatorInterface::INDICATOR_TYPE_2:
1422     {
1423       ecore_wl_indicator_visible_type_set( mEcoreWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN );
1424       break;
1425     }
1426     case IndicatorInterface::INDICATOR_TYPE_UNKNOWN:
1427     default:
1428     {
1429       break;
1430     }
1431   }
1432 #endif //MOBILE
1433 }
1434
1435 void WindowBaseEcoreWl::SetClass( const std::string& name, const std::string& className )
1436 {
1437   ecore_wl_window_title_set( mEcoreWindow, name.c_str() );
1438   ecore_wl_window_class_name_set( mEcoreWindow, className.c_str() );
1439 }
1440
1441 void WindowBaseEcoreWl::Raise()
1442 {
1443   // Use ecore_wl_window_activate to prevent the window shown without rendering
1444   ecore_wl_window_activate( mEcoreWindow );
1445 }
1446
1447 void WindowBaseEcoreWl::Lower()
1448 {
1449   ecore_wl_window_lower( mEcoreWindow );
1450 }
1451
1452 void WindowBaseEcoreWl::Activate()
1453 {
1454   ecore_wl_window_activate( mEcoreWindow );
1455 }
1456
1457 void WindowBaseEcoreWl::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
1458 {
1459   int rotations[4] = { 0 };
1460   for( std::size_t i = 0; i < orientations.size(); ++i )
1461   {
1462     rotations[i] = static_cast< int >( orientations[i] );
1463   }
1464   ecore_wl_window_rotation_available_rotations_set( mEcoreWindow, rotations, orientations.size() );
1465 }
1466
1467 void WindowBaseEcoreWl::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
1468 {
1469   ecore_wl_window_rotation_preferred_rotation_set( mEcoreWindow, orientation );
1470 }
1471
1472 void WindowBaseEcoreWl::SetAcceptFocus( bool accept )
1473 {
1474   ecore_wl_window_focus_skip_set( mEcoreWindow, !accept );
1475 }
1476
1477 void WindowBaseEcoreWl::Show()
1478 {
1479   ecore_wl_window_show( mEcoreWindow );
1480 }
1481
1482 void WindowBaseEcoreWl::Hide()
1483 {
1484   ecore_wl_window_hide( mEcoreWindow );
1485 }
1486
1487 unsigned int WindowBaseEcoreWl::GetSupportedAuxiliaryHintCount() const
1488 {
1489   return mSupportedAuxiliaryHints.size();
1490 }
1491
1492 std::string WindowBaseEcoreWl::GetSupportedAuxiliaryHint( unsigned int index ) const
1493 {
1494   if( index >= GetSupportedAuxiliaryHintCount() )
1495   {
1496     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
1497   }
1498
1499   return mSupportedAuxiliaryHints[index];
1500 }
1501
1502 unsigned int WindowBaseEcoreWl::AddAuxiliaryHint( const std::string& hint, const std::string& value )
1503 {
1504   bool supported = false;
1505
1506   // Check if the hint is suppported
1507   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
1508   {
1509     if( *iter == hint )
1510     {
1511       supported = true;
1512       break;
1513     }
1514   }
1515
1516   if( !supported )
1517   {
1518     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
1519     return 0;
1520   }
1521
1522   // Check if the hint is already added
1523   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1524   {
1525     if( mAuxiliaryHints[i].first == hint )
1526     {
1527       // Just change the value
1528       mAuxiliaryHints[i].second = value;
1529
1530       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
1531
1532       return i + 1;   // id is index + 1
1533     }
1534   }
1535
1536   // Add the hint
1537   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
1538
1539   unsigned int id = mAuxiliaryHints.size();
1540
1541   ecore_wl_window_aux_hint_add( mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
1542
1543   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
1544
1545   return id;
1546 }
1547
1548 bool WindowBaseEcoreWl::RemoveAuxiliaryHint( unsigned int id )
1549 {
1550   if( id == 0 || id > mAuxiliaryHints.size() )
1551   {
1552     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
1553     return false;
1554   }
1555
1556   mAuxiliaryHints[id - 1].second = std::string();
1557
1558   ecore_wl_window_aux_hint_del( mEcoreWindow, static_cast< int >( id ) );
1559
1560   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
1561
1562   return true;
1563 }
1564
1565 bool WindowBaseEcoreWl::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
1566 {
1567   if( id == 0 || id > mAuxiliaryHints.size() )
1568   {
1569     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1570     return false;
1571   }
1572
1573   mAuxiliaryHints[id - 1].second = value;
1574
1575   ecore_wl_window_aux_hint_change( mEcoreWindow, static_cast< int >( id ), value.c_str() );
1576
1577   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
1578
1579   return true;
1580 }
1581
1582 std::string WindowBaseEcoreWl::GetAuxiliaryHintValue( unsigned int id ) const
1583 {
1584   if( id == 0 || id > mAuxiliaryHints.size() )
1585   {
1586     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1587     return std::string();
1588   }
1589
1590   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
1591
1592   return mAuxiliaryHints[id - 1].second;
1593 }
1594
1595 unsigned int WindowBaseEcoreWl::GetAuxiliaryHintId( const std::string& hint ) const
1596 {
1597   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1598   {
1599     if( mAuxiliaryHints[i].first == hint )
1600     {
1601       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1602       return i + 1;
1603     }
1604   }
1605
1606   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1607
1608   return 0;
1609 }
1610
1611 void WindowBaseEcoreWl::SetInputRegion( const Rect< int >& inputRegion )
1612 {
1613   ecore_wl_window_input_region_set( mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1614 }
1615
1616 void WindowBaseEcoreWl::SetType( Dali::Window::Type type )
1617 {
1618   Ecore_Wl_Window_Type windowType;
1619
1620   switch( type )
1621   {
1622     case Dali::Window::NORMAL:
1623     {
1624       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1625       break;
1626     }
1627     case Dali::Window::NOTIFICATION:
1628     {
1629       windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1630       break;
1631     }
1632     case Dali::Window::UTILITY:
1633     {
1634       windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1635       break;
1636     }
1637     case Dali::Window::DIALOG:
1638     {
1639       windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1640       break;
1641     }
1642     default:
1643     {
1644       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1645       break;
1646     }
1647   }
1648
1649   ecore_wl_window_type_set( mEcoreWindow, windowType );
1650 }
1651
1652 bool WindowBaseEcoreWl::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
1653 {
1654   while( !mTizenPolicy )
1655   {
1656     wl_display_dispatch_queue( mDisplay, mEventQueue );
1657   }
1658
1659   int notificationLevel;
1660
1661   switch( level )
1662   {
1663     case Dali::Window::NotificationLevel::NONE:
1664     {
1665       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1666       break;
1667     }
1668     case Dali::Window::NotificationLevel::BASE:
1669     {
1670       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1671       break;
1672     }
1673     case Dali::Window::NotificationLevel::MEDIUM:
1674     {
1675       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1676       break;
1677     }
1678     case Dali::Window::NotificationLevel::HIGH:
1679     {
1680       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1681       break;
1682     }
1683     case Dali::Window::NotificationLevel::TOP:
1684     {
1685       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1686       break;
1687     }
1688     default:
1689     {
1690       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: invalid level [%d]\n", level );
1691       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1692       break;
1693     }
1694   }
1695
1696   mNotificationLevelChangeDone = false;
1697   mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1698
1699   tizen_policy_set_notification_level( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), notificationLevel );
1700
1701   int count = 0;
1702
1703   while( !mNotificationLevelChangeDone && count < 3 )
1704   {
1705     ecore_wl_flush();
1706     wl_display_dispatch_queue( mDisplay, mEventQueue );
1707     count++;
1708   }
1709
1710   if( !mNotificationLevelChangeDone )
1711   {
1712     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState );
1713     return false;
1714   }
1715   else if( mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1716   {
1717     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Permission denied! [%d]\n", level );
1718     return false;
1719   }
1720
1721   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel );
1722
1723   return true;
1724 }
1725
1726 Dali::Window::NotificationLevel::Type WindowBaseEcoreWl::GetNotificationLevel() const
1727 {
1728   while( !mTizenPolicy )
1729   {
1730     wl_display_dispatch_queue( mDisplay, mEventQueue );
1731   }
1732
1733   int count = 0;
1734
1735   while( !mNotificationLevelChangeDone && count < 3 )
1736   {
1737     ecore_wl_flush();
1738     wl_display_dispatch_queue( mDisplay, mEventQueue );
1739     count++;
1740   }
1741
1742   if( !mNotificationLevelChangeDone )
1743   {
1744     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState );
1745     return Dali::Window::NotificationLevel::NONE;
1746   }
1747
1748   Dali::Window::NotificationLevel::Type level;
1749
1750   switch( mNotificationLevel )
1751   {
1752     case TIZEN_POLICY_LEVEL_NONE:
1753     {
1754       level = Dali::Window::NotificationLevel::NONE;
1755       break;
1756     }
1757     case TIZEN_POLICY_LEVEL_DEFAULT:
1758     {
1759       level = Dali::Window::NotificationLevel::BASE;
1760       break;
1761     }
1762     case TIZEN_POLICY_LEVEL_MEDIUM:
1763     {
1764       level = Dali::Window::NotificationLevel::MEDIUM;
1765       break;
1766     }
1767     case TIZEN_POLICY_LEVEL_HIGH:
1768     {
1769       level = Dali::Window::NotificationLevel::HIGH;
1770       break;
1771     }
1772     case TIZEN_POLICY_LEVEL_TOP:
1773     {
1774       level = Dali::Window::NotificationLevel::TOP;
1775       break;
1776     }
1777     default:
1778     {
1779       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel );
1780       level = Dali::Window::NotificationLevel::NONE;
1781       break;
1782     }
1783   }
1784
1785   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: level [%d]\n", mNotificationLevel );
1786
1787   return level;
1788 }
1789
1790 void WindowBaseEcoreWl::SetOpaqueState( bool opaque )
1791 {
1792   while( !mTizenPolicy )
1793   {
1794     wl_display_dispatch_queue( mDisplay, mEventQueue );
1795   }
1796
1797   tizen_policy_set_opaque_state( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), ( opaque ? 1 : 0 ) );
1798 }
1799
1800 bool WindowBaseEcoreWl::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
1801 {
1802   while( !mTizenPolicy )
1803   {
1804     wl_display_dispatch_queue( mDisplay, mEventQueue );
1805   }
1806
1807   mScreenOffModeChangeDone = false;
1808   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1809
1810   unsigned int mode = 0;
1811
1812   switch( screenOffMode )
1813   {
1814     case Dali::Window::ScreenOffMode::TIMEOUT:
1815     {
1816       mode = 0;
1817       break;
1818     }
1819     case Dali::Window::ScreenOffMode::NEVER:
1820     {
1821       mode = 1;
1822       break;
1823     }
1824   }
1825
1826   tizen_policy_set_window_screen_mode( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), mode );
1827
1828   int count = 0;
1829
1830   while( !mScreenOffModeChangeDone && count < 3 )
1831   {
1832     ecore_wl_flush();
1833     wl_display_dispatch_queue( mDisplay, mEventQueue );
1834     count++;
1835   }
1836
1837   if( !mScreenOffModeChangeDone )
1838   {
1839     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState );
1840     return false;
1841   }
1842   else if( mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1843   {
1844     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
1845     return false;
1846   }
1847
1848   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode );
1849
1850   return true;
1851 }
1852
1853 Dali::Window::ScreenOffMode::Type WindowBaseEcoreWl::GetScreenOffMode() const
1854 {
1855   while( !mTizenPolicy )
1856   {
1857     wl_display_dispatch_queue( mDisplay, mEventQueue );
1858   }
1859
1860   int count = 0;
1861
1862   while( !mScreenOffModeChangeDone && count < 3 )
1863   {
1864     ecore_wl_flush();
1865     wl_display_dispatch_queue( mDisplay, mEventQueue );
1866     count++;
1867   }
1868
1869   if( !mScreenOffModeChangeDone )
1870   {
1871     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState );
1872     return Dali::Window::ScreenOffMode::TIMEOUT;
1873   }
1874
1875   Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1876
1877   switch( mScreenOffMode )
1878   {
1879     case 0:
1880     {
1881       screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1882       break;
1883     }
1884     case 1:
1885     {
1886       screenMode = Dali::Window::ScreenOffMode::NEVER;
1887       break;
1888     }
1889   }
1890
1891   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode );
1892
1893   return screenMode;
1894 }
1895
1896 bool WindowBaseEcoreWl::SetBrightness( int brightness )
1897 {
1898   while( !mTizenDisplayPolicy )
1899   {
1900     wl_display_dispatch_queue( mDisplay, mEventQueue );
1901   }
1902
1903   mBrightnessChangeDone = false;
1904   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1905
1906   tizen_display_policy_set_window_brightness( mTizenDisplayPolicy, ecore_wl_window_surface_get( mEcoreWindow ), brightness );
1907
1908   int count = 0;
1909
1910   while( !mBrightnessChangeDone && count < 3 )
1911   {
1912     ecore_wl_flush();
1913     wl_display_dispatch_queue( mDisplay, mEventQueue );
1914     count++;
1915   }
1916
1917   if( !mBrightnessChangeDone )
1918   {
1919     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState );
1920     return false;
1921   }
1922   else if( mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1923   {
1924     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Permission denied! [%d]\n", brightness );
1925     return false;
1926   }
1927
1928   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness is changed [%d]\n", mBrightness );
1929
1930   return true;
1931 }
1932
1933 int WindowBaseEcoreWl::GetBrightness() const
1934 {
1935   while( !mTizenDisplayPolicy )
1936   {
1937     wl_display_dispatch_queue( mDisplay, mEventQueue );
1938   }
1939
1940   int count = 0;
1941
1942   while( !mBrightnessChangeDone && count < 3 )
1943   {
1944     ecore_wl_flush();
1945     wl_display_dispatch_queue( mDisplay, mEventQueue );
1946     count++;
1947   }
1948
1949   if( !mBrightnessChangeDone )
1950   {
1951     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Error! [%d]\n", mBrightnessChangeState );
1952     return 0;
1953   }
1954
1955   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Brightness [%d]\n", mBrightness );
1956
1957   return mBrightness;
1958 }
1959
1960 bool WindowBaseEcoreWl::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
1961 {
1962   Ecore_Wl_Window_Keygrab_Mode mode;
1963
1964   switch( grabMode )
1965   {
1966     case KeyGrab::TOPMOST:
1967     {
1968       mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1969       break;
1970     }
1971     case KeyGrab::SHARED:
1972     {
1973       mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1974       break;
1975     }
1976     case KeyGrab::OVERRIDE_EXCLUSIVE:
1977     {
1978       mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1979       break;
1980     }
1981     case KeyGrab::EXCLUSIVE:
1982     {
1983       mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1984       break;
1985     }
1986     default:
1987     {
1988       return false;
1989     }
1990   }
1991
1992   return ecore_wl_window_keygrab_set( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0, 0, mode );
1993 }
1994
1995 bool WindowBaseEcoreWl::UngrabKey( Dali::KEY key )
1996 {
1997   return ecore_wl_window_keygrab_unset( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0 );
1998 }
1999
2000 bool WindowBaseEcoreWl::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
2001 {
2002   int keyCount = key.Count();
2003   int keyGrabModeCount = grabMode.Count();
2004
2005   if( keyCount != keyGrabModeCount || keyCount == 0 )
2006   {
2007     return false;
2008   }
2009
2010   eina_init();
2011
2012   Eina_List* keyList = NULL;
2013   Ecore_Wl_Window_Keygrab_Info* info = new Ecore_Wl_Window_Keygrab_Info[keyCount];
2014
2015   for( int index = 0; index < keyCount; ++index )
2016   {
2017     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
2018
2019     switch( grabMode[index] )
2020     {
2021       case KeyGrab::TOPMOST:
2022       {
2023         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
2024         break;
2025       }
2026       case KeyGrab::SHARED:
2027       {
2028         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
2029         break;
2030       }
2031       case KeyGrab::OVERRIDE_EXCLUSIVE:
2032       {
2033         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
2034         break;
2035       }
2036       case KeyGrab::EXCLUSIVE:
2037       {
2038         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
2039         break;
2040       }
2041       default:
2042       {
2043         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
2044         break;
2045       }
2046     }
2047
2048     keyList = eina_list_append( keyList, &info );
2049   }
2050
2051   Eina_List* grabList = ecore_wl_window_keygrab_list_set( mEcoreWindow, keyList );
2052
2053   result.Resize( keyCount, true );
2054
2055   Eina_List* l = NULL;
2056   Eina_List* m = NULL;
2057   void* listData = NULL;
2058   void* data = NULL;
2059   if( grabList != NULL )
2060   {
2061     EINA_LIST_FOREACH( grabList, m, data )
2062     {
2063       int index = 0;
2064       EINA_LIST_FOREACH( keyList, l, listData )
2065       {
2066         if( static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key == NULL )
2067         {
2068           DALI_LOG_ERROR( "input key list has null data!" );
2069           break;
2070         }
2071
2072         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key ) == 0 )
2073         {
2074           result[index] = false;
2075         }
2076         ++index;
2077       }
2078     }
2079   }
2080
2081   delete [] info;
2082
2083   eina_list_free( keyList );
2084   eina_list_free( grabList );
2085   eina_shutdown();
2086
2087   return true;
2088 }
2089
2090 bool WindowBaseEcoreWl::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
2091 {
2092   int keyCount = key.Count();
2093   if( keyCount == 0 )
2094   {
2095     return false;
2096   }
2097
2098   eina_init();
2099
2100   Eina_List* keyList = NULL;
2101   Ecore_Wl_Window_Keygrab_Info* info = new Ecore_Wl_Window_Keygrab_Info[keyCount];
2102
2103   for( int index = 0; index < keyCount; ++index )
2104   {
2105     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
2106     keyList = eina_list_append( keyList, &info );
2107   }
2108
2109   Eina_List* ungrabList = ecore_wl_window_keygrab_list_unset( mEcoreWindow, keyList );
2110
2111   result.Resize( keyCount, true );
2112
2113   Eina_List* l = NULL;
2114   Eina_List* m = NULL;
2115   void *listData = NULL;
2116   void *data = NULL;
2117
2118   if( ungrabList != NULL )
2119   {
2120     EINA_LIST_FOREACH( ungrabList, m, data )
2121     {
2122       int index = 0;
2123       EINA_LIST_FOREACH( keyList, l, listData )
2124       {
2125         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key ) == 0 )
2126         {
2127           result[index] = false;
2128         }
2129         ++index;
2130       }
2131     }
2132   }
2133
2134   delete [] info;
2135
2136   eina_list_free( keyList );
2137   eina_list_free( ungrabList );
2138   eina_shutdown();
2139
2140   return true;
2141 }
2142
2143 void WindowBaseEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
2144 {
2145   // calculate DPI
2146   float xres, yres;
2147
2148   // 1 inch = 25.4 millimeters
2149   xres = ecore_wl_dpi_get();
2150   yres = ecore_wl_dpi_get();
2151
2152   dpiHorizontal = int( xres + 0.5f );  // rounding
2153   dpiVertical   = int( yres + 0.5f );
2154 }
2155
2156 int WindowBaseEcoreWl::GetScreenRotationAngle()
2157 {
2158   int transform = 0;
2159
2160   if( ecore_wl_window_ignore_output_transform_get( mEcoreWindow ) )
2161   {
2162     transform = 0;
2163   }
2164   else
2165   {
2166     transform = ecore_wl_output_transform_get( ecore_wl_window_output_find( mEcoreWindow ) );
2167   }
2168
2169   return transform * 90;
2170 }
2171
2172 void WindowBaseEcoreWl::SetWindowRotationAngle( int degree )
2173 {
2174   ecore_wl_window_rotation_set( mEcoreWindow, degree );
2175 }
2176
2177 void WindowBaseEcoreWl::WindowRotationCompleted( int degree, int width, int height )
2178 {
2179   ecore_wl_window_rotation_change_done_send( mEcoreWindow );
2180 }
2181
2182 void WindowBaseEcoreWl::SetTransparency( bool transparent )
2183 {
2184   ecore_wl_window_alpha_set( mEcoreWindow, transparent );
2185 }
2186
2187 void WindowBaseEcoreWl::InitializeEcoreElDBus()
2188 {
2189 #ifdef DALI_ELDBUS_AVAILABLE
2190   Eldbus_Object* object;
2191   Eldbus_Proxy* manager;
2192
2193   if( !( mSystemConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SYSTEM ) ) )
2194   {
2195     DALI_LOG_ERROR( "Unable to get system bus\n" );
2196   }
2197
2198   object = eldbus_object_get( mSystemConnection, BUS, PATH );
2199   if( !object )
2200   {
2201     DALI_LOG_ERROR( "Getting object failed\n" );
2202     return;
2203   }
2204
2205   manager = eldbus_proxy_get( object, INTERFACE );
2206   if( !manager )
2207   {
2208     DALI_LOG_ERROR( "Getting proxy failed\n" );
2209     return;
2210   }
2211
2212   if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this ) )
2213   {
2214     DALI_LOG_ERROR( "No signal handler returned\n" );
2215   }
2216 #endif
2217 }
2218
2219 void WindowBaseEcoreWl::CreateWindow( PositionSize positionSize )
2220 {
2221   mEcoreWindow = ecore_wl_window_new( 0, positionSize.x, positionSize.y, positionSize.width, positionSize.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
2222
2223   if ( mEcoreWindow == 0 )
2224   {
2225     DALI_ASSERT_ALWAYS( 0 && "Failed to create Wayland window" );
2226   }
2227 }
2228
2229 } // namespace Adaptor
2230
2231 } // namespace Internal
2232
2233 } // namespace Dali
2234
2235 #pragma GCC diagnostic pop