b055d4035f21578291a39e3c4f504092fbc08e33
[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 // Font Callbacks
423 /////////////////////////////////////////////////////////////////////////////////////////////////
424
425 /**
426  * Called when a font name is changed.
427  */
428 static void VconfNotifyFontNameChanged( keynode_t* node, void* data )
429 {
430   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
431   if( windowBase )
432   {
433     windowBase->OnFontNameChanged();
434   }
435 }
436
437 /**
438  * Called when a font size is changed.
439  */
440 static void VconfNotifyFontSizeChanged( keynode_t* node, void* data )
441 {
442   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
443   if( windowBase )
444   {
445     windowBase->OnFontSizeChanged();
446   }
447 }
448
449 /////////////////////////////////////////////////////////////////////////////////////////////////
450 // ElDBus Accessibility Callbacks
451 /////////////////////////////////////////////////////////////////////////////////////////////////
452
453 #ifdef DALI_ELDBUS_AVAILABLE
454 // Callback for Ecore ElDBus accessibility events.
455 static void EcoreElDBusAccessibilityNotification( void* context, const Eldbus_Message* message )
456 {
457   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( context );
458   if( windowBase )
459   {
460     windowBase->OnEcoreElDBusAccessibilityNotification( context, message );
461   }
462 }
463 #endif // DALI_ELDBUS_AVAILABLE
464
465 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
466 {
467   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
468   if( windowBase )
469   {
470     windowBase->RegistryGlobalCallback( data, registry, name, interface, version );
471   }
472 }
473
474 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
475 {
476   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
477   if( windowBase )
478   {
479     windowBase->RegistryGlobalCallbackRemove( data, registry, id );
480   }
481 }
482
483 static void TizenPolicyConformant( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant )
484 {
485 }
486
487 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 )
488 {
489 }
490
491 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
492 {
493   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
494   if( windowBase )
495   {
496     windowBase->TizenPolicyNotificationChangeDone( data, tizenPolicy, surface, level, state );
497   }
498 }
499
500 static void TizenPolicyTransientForDone( void* data, struct tizen_policy* tizenPolicy, uint32_t childId )
501 {
502 }
503
504 static void TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
505 {
506   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
507   if( windowBase )
508   {
509     windowBase->TizenPolicyScreenModeChangeDone( data, tizenPolicy, surface, mode, state );
510   }
511 }
512
513 static void TizenPolicyIconifyStateChanged( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force )
514 {
515 }
516
517 static void TizenPolicySupportedAuxiliaryHints( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints )
518 {
519 }
520
521 static void TizenPolicyAllowedAuxiliaryHint( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id )
522 {
523 }
524
525 static void TizenPolicyAuxiliaryMessage( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options )
526 {
527 }
528
529 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 )
530 {
531 }
532
533 static void DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
534 {
535   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
536   if( windowBase )
537   {
538     windowBase->DisplayPolicyBrightnessChangeDone( data, displayPolicy, surface, brightness, state );
539   }
540 }
541
542 const struct wl_registry_listener registryListener =
543 {
544    RegistryGlobalCallback,
545    RegistryGlobalCallbackRemove
546 };
547
548 const struct tizen_policy_listener tizenPolicyListener =
549 {
550    TizenPolicyConformant,
551    TizenPolicyConformantArea,
552    TizenPolicyNotificationChangeDone,
553    TizenPolicyTransientForDone,
554    TizenPolicyScreenModeChangeDone,
555    TizenPolicyIconifyStateChanged,
556    TizenPolicySupportedAuxiliaryHints,
557    TizenPolicyAllowedAuxiliaryHint,
558    TizenPolicyAuxiliaryMessage,
559    TizenPolicyConformantRegion
560 };
561
562 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
563 {
564   DisplayPolicyBrightnessChangeDone
565 };
566
567 } // unnamed namespace
568
569 WindowBaseEcoreWl::WindowBaseEcoreWl( Dali::PositionSize positionSize, Any surface, bool isTransparent )
570 : mEcoreEventHandler(),
571   mEcoreWindow( NULL ),
572   mWlSurface( NULL ),
573   mEglWindow( NULL ),
574   mDisplay( NULL ),
575   mEventQueue( NULL ),
576   mTizenPolicy( NULL ),
577   mTizenDisplayPolicy( NULL ),
578   mSupportedAuxiliaryHints(),
579   mAuxiliaryHints(),
580   mNotificationLevel( -1 ),
581   mNotificationChangeState( 0 ),
582   mNotificationLevelChangeDone( true ),
583   mScreenOffMode( 0 ),
584   mScreenOffModeChangeState( 0 ),
585   mScreenOffModeChangeDone( true ),
586   mBrightness( 0 ),
587   mBrightnessChangeState( 0 ),
588   mBrightnessChangeDone( true ),
589   mOwnSurface( false )
590 #ifdef DALI_ELDBUS_AVAILABLE
591   , mSystemConnection( NULL )
592 #endif
593 {
594   Initialize( positionSize, surface, isTransparent );
595 }
596
597 WindowBaseEcoreWl::~WindowBaseEcoreWl()
598 {
599 #ifdef DALI_ELDBUS_AVAILABLE
600     // Close down ElDBus connections.
601     if( mSystemConnection )
602     {
603       eldbus_connection_unref( mSystemConnection );
604     }
605 #endif // DALI_ELDBUS_AVAILABLE
606
607   vconf_ignore_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged );
608   vconf_ignore_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged );
609
610   for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
611   {
612     ecore_event_handler_del( *iter );
613   }
614   mEcoreEventHandler.Clear();
615
616   if( mEventQueue )
617   {
618     wl_event_queue_destroy( mEventQueue );
619   }
620
621   mSupportedAuxiliaryHints.clear();
622   mAuxiliaryHints.clear();
623
624   if( mEglWindow != NULL )
625   {
626     wl_egl_window_destroy( mEglWindow );
627     mEglWindow = NULL;
628   }
629
630   if( mOwnSurface )
631   {
632     ecore_wl_window_free( mEcoreWindow );
633
634     WindowSystem::Shutdown();
635   }
636 }
637
638 void WindowBaseEcoreWl::Initialize( PositionSize positionSize, Any surface, bool isTransparent )
639 {
640   if( surface.Empty() == false )
641   {
642     // check we have a valid type
643     DALI_ASSERT_ALWAYS( ( surface.GetType() == typeid (Ecore_Wl_Window *) ) && "Surface type is invalid" );
644
645     mEcoreWindow = AnyCast< Ecore_Wl_Window* >( surface );
646   }
647   else
648   {
649     // we own the surface about to created
650     WindowSystem::Initialize();
651
652     mOwnSurface = true;
653     CreateWindow( positionSize );
654   }
655
656   mWlSurface = ecore_wl_window_surface_create( mEcoreWindow );
657
658   SetTransparency( isTransparent );
659
660   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
661   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN,                    EcoreEventWindowFocusIn,             this ) );
662   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT,                   EcoreEventWindowFocusOut,            this ) );
663   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_OUTPUT_TRANSFORM,            EcoreEventOutputTransform,           this ) );
664   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM,     EcoreEventIgnoreOutputTransform,     this ) );
665
666   // Register Rotate event
667   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ROTATE,               EcoreEventRotate,                    this ) );
668
669   // Register Touch events
670   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN,              EcoreEventMouseButtonDown,           this ) );
671   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_UP,                EcoreEventMouseButtonUp,             this ) );
672   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_MOVE,                     EcoreEventMouseButtonMove,           this ) );
673   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_CANCEL,            EcoreEventMouseButtonCancel,         this ) );
674
675   // Register Mouse wheel events
676   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_MOUSE_WHEEL,                    EcoreEventMouseWheel,                this ) );
677
678   // Register Detent event
679   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_DETENT_ROTATE,                  EcoreEventDetentRotation,            this ) );
680
681   // Register Key events
682   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_DOWN,                       EcoreEventKeyDown,                   this ) );
683   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_EVENT_KEY_UP,                         EcoreEventKeyUp,                     this ) );
684
685   // Register Selection event - clipboard selection
686   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_DATA_SOURCE_SEND,            EcoreEventDataSend,                  this ) );
687   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_SELECTION_DATA_READY,        EcoreEventDataReceive,               this ) );
688
689   // Register Vconf notify - font name and size
690   vconf_notify_key_changed( DALI_VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_NAME, VconfNotifyFontNameChanged, this );
691   vconf_notify_key_changed( VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, VconfNotifyFontSizeChanged, this );
692
693   InitializeEcoreElDBus();
694
695   mDisplay = ecore_wl_display_get();
696
697   if( mDisplay )
698   {
699     wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
700     if( displayWrapper )
701     {
702       mEventQueue = wl_display_create_queue( mDisplay );
703       if( mEventQueue )
704       {
705         wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
706
707         wl_registry* registry = wl_display_get_registry( displayWrapper );
708         wl_registry_add_listener( registry, &registryListener, this );
709       }
710
711       wl_proxy_wrapper_destroy( displayWrapper );
712     }
713   }
714
715   // get auxiliary hint
716   Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEcoreWindow );
717   if( hints )
718   {
719     Eina_List* l = NULL;
720     char* hint = NULL;
721
722     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) ) ) )
723     {
724       mSupportedAuxiliaryHints.push_back( hint );
725
726       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::Initialize: %s\n", hint );
727     }
728   }
729 }
730
731 Eina_Bool WindowBaseEcoreWl::OnIconifyStateChanged( void* data, int type, void* event )
732 {
733   Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
734   Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
735
736   if( iconifyChangedEvent->win == static_cast< unsigned int>( ecore_wl_window_id_get( mEcoreWindow ) ) )
737   {
738     if( iconifyChangedEvent->iconified == EINA_TRUE )
739     {
740       mIconifyChangedSignal.Emit( true );
741     }
742     else
743     {
744       mIconifyChangedSignal.Emit( false );
745     }
746     handled = ECORE_CALLBACK_DONE;
747   }
748
749   return handled;
750 }
751
752 Eina_Bool WindowBaseEcoreWl::OnFocusIn( void* data, int type, void* event )
753 {
754   Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
755
756   if( focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
757   {
758     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
759
760     mFocusChangedSignal.Emit( true );
761   }
762
763   return ECORE_CALLBACK_PASS_ON;
764 }
765
766 Eina_Bool WindowBaseEcoreWl::OnFocusOut( void* data, int type, void* event )
767 {
768   Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
769
770   if( focusOutEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
771   {
772     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
773
774     mFocusChangedSignal.Emit( false );
775   }
776
777   return ECORE_CALLBACK_PASS_ON;
778 }
779
780 Eina_Bool WindowBaseEcoreWl::OnOutputTransform( void* data, int type, void* event )
781 {
782   Ecore_Wl_Event_Output_Transform* transformEvent( static_cast< Ecore_Wl_Event_Output_Transform* >( event ) );
783
784   if( transformEvent->output == ecore_wl_window_output_find( mEcoreWindow ) )
785   {
786     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow );
787
788     mOutputTransformedSignal.Emit();
789   }
790
791   return ECORE_CALLBACK_PASS_ON;
792 }
793
794 Eina_Bool WindowBaseEcoreWl::OnIgnoreOutputTransform( void* data, int type, void* event )
795 {
796   Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
797
798   if( ignoreTransformEvent->win == mEcoreWindow )
799   {
800     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow );
801
802     mOutputTransformedSignal.Emit();
803   }
804
805   return ECORE_CALLBACK_PASS_ON;
806 }
807
808 void WindowBaseEcoreWl::OnRotation( void* data, int type, void* event )
809 {
810   Ecore_Wl_Event_Window_Rotate* ev( static_cast< Ecore_Wl_Event_Window_Rotate* >( event ) );
811
812   if( ev->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
813   {
814     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnRotation\n" );
815
816     RotationEvent rotationEvent;
817     rotationEvent.angle = ev->angle;
818     rotationEvent.winResize = 0;
819
820     if( ev->angle == 0 || ev->angle == 180 )
821     {
822       rotationEvent.width = ev->w;
823       rotationEvent.height = ev->h;
824     }
825     else
826     {
827       rotationEvent.width = ev->h;
828       rotationEvent.height = ev->w;
829     }
830
831     mRotationSignal.Emit( rotationEvent );
832   }
833 }
834
835 void WindowBaseEcoreWl::OnMouseButtonDown( void* data, int type, void* event )
836 {
837   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
838
839   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
840   {
841     PointState::Type state ( PointState::DOWN );
842
843     // Check if the buttons field is set and ensure it's the primary touch button.
844     // If this event was triggered by buttons other than the primary button (used for touch), then
845     // just send an interrupted event to Core.
846     if( touchEvent->buttons && (touchEvent->buttons != PRIMARY_TOUCH_BUTTON_ID ) )
847     {
848       state = PointState::INTERRUPTED;
849     }
850
851     Device::Class::Type deviceClass;
852     Device::Subclass::Type deviceSubclass;
853
854     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
855     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
856
857     Integration::Point point;
858     point.SetDeviceId( touchEvent->multi.device );
859     point.SetState( state );
860     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
861     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
862     point.SetPressure( touchEvent->multi.pressure );
863     point.SetAngle( Degree( touchEvent->multi.angle ) );
864     point.SetDeviceClass( deviceClass );
865     point.SetDeviceSubclass( deviceSubclass );
866
867     mTouchEventSignal.Emit( point, touchEvent->timestamp );
868   }
869 }
870
871 void WindowBaseEcoreWl::OnMouseButtonUp( void* data, int type, void* event )
872 {
873   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
874
875   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
876   {
877     Device::Class::Type deviceClass;
878     Device::Subclass::Type deviceSubclass;
879
880     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
881     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
882
883     Integration::Point point;
884     point.SetDeviceId( touchEvent->multi.device );
885     point.SetState( PointState::UP );
886     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
887     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
888     point.SetPressure( touchEvent->multi.pressure );
889     point.SetAngle( Degree( touchEvent->multi.angle ) );
890     point.SetDeviceClass( deviceClass );
891     point.SetDeviceSubclass( deviceSubclass );
892
893     mTouchEventSignal.Emit( point, touchEvent->timestamp );
894   }
895 }
896
897 void WindowBaseEcoreWl::OnMouseButtonMove( void* data, int type, void* event )
898 {
899   Ecore_Event_Mouse_Move* touchEvent = static_cast< Ecore_Event_Mouse_Move* >( event );
900
901   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
902   {
903     Device::Class::Type deviceClass;
904     Device::Subclass::Type deviceSubclass;
905
906     GetDeviceClass( ecore_device_class_get( touchEvent->dev ), deviceClass );
907     GetDeviceSubclass( ecore_device_subclass_get( touchEvent->dev ), deviceSubclass );
908
909     Integration::Point point;
910     point.SetDeviceId( touchEvent->multi.device );
911     point.SetState( PointState::MOTION );
912     point.SetScreenPosition( Vector2( touchEvent->x, touchEvent->y ) );
913     point.SetRadius( touchEvent->multi.radius, Vector2( touchEvent->multi.radius_x, touchEvent->multi.radius_y ) );
914     point.SetPressure( touchEvent->multi.pressure );
915     point.SetAngle( Degree( touchEvent->multi.angle ) );
916     point.SetDeviceClass( deviceClass );
917     point.SetDeviceSubclass( deviceSubclass );
918
919     mTouchEventSignal.Emit( point, touchEvent->timestamp );
920   }
921 }
922
923 void WindowBaseEcoreWl::OnMouseButtonCancel( void* data, int type, void* event )
924 {
925   Ecore_Event_Mouse_Button* touchEvent = static_cast< Ecore_Event_Mouse_Button* >( event );
926
927   if( touchEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
928   {
929     Integration::Point point;
930     point.SetDeviceId( touchEvent->multi.device );
931     point.SetState( PointState::INTERRUPTED );
932     point.SetScreenPosition( Vector2( 0.0f, 0.0f ) );
933
934     mTouchEventSignal.Emit( point, touchEvent->timestamp );
935
936     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnMouseButtonCancel\n" );
937   }
938 }
939
940 void WindowBaseEcoreWl::OnMouseWheel( void* data, int type, void* event )
941 {
942   Ecore_Event_Mouse_Wheel* mouseWheelEvent = static_cast< Ecore_Event_Mouse_Wheel* >( event );
943
944   if( mouseWheelEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
945   {
946     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 );
947
948     WheelEvent wheelEvent( WheelEvent::MOUSE_WHEEL, mouseWheelEvent->direction, mouseWheelEvent->modifiers, Vector2( mouseWheelEvent->x, mouseWheelEvent->y ), mouseWheelEvent->z, mouseWheelEvent->timestamp );
949
950     mWheelEventSignal.Emit( wheelEvent );
951   }
952 }
953
954 void WindowBaseEcoreWl::OnDetentRotation( void* data, int type, void* event )
955 {
956   Ecore_Event_Detent_Rotate* detentEvent = static_cast< Ecore_Event_Detent_Rotate* >( event );
957
958   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::OnDetentRotation\n" );
959
960   int direction = ( detentEvent->direction == ECORE_DETENT_DIRECTION_CLOCKWISE ) ? 1 : -1;
961   int timeStamp = detentEvent->timestamp;
962
963   WheelEvent wheelEvent( WheelEvent::CUSTOM_WHEEL, 0, 0, Vector2( 0.0f, 0.0f ), direction, timeStamp );
964
965   mWheelEventSignal.Emit( wheelEvent );
966 }
967
968 void WindowBaseEcoreWl::OnKeyDown( void* data, int type, void* event )
969 {
970   Ecore_Event_Key* keyEvent = static_cast< Ecore_Event_Key* >( event );
971
972   if( keyEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
973   {
974     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyDown\n" );
975
976     std::string keyName( keyEvent->keyname );
977     std::string logicalKey( "" );
978     std::string keyString( "" );
979     std::string compose( "" );
980
981     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
982     if( keyEvent->compose )
983     {
984       compose = keyEvent->compose;
985     }
986
987     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
988     if( keyEvent->key )
989     {
990       logicalKey = keyEvent->key;
991     }
992
993     int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
994     keyCode = ( keyCode == -1 ) ? 0 : keyCode;
995     int modifier( keyEvent->modifiers );
996     unsigned long time = keyEvent->timestamp;
997     if( !strncmp( keyEvent->keyname, "Keycode-", 8 ) )
998     {
999       keyCode = atoi( keyEvent->keyname + 8 );
1000     }
1001
1002     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1003     if( keyEvent->string )
1004     {
1005       keyString = keyEvent->string;
1006     }
1007
1008     std::string deviceName;
1009     Device::Class::Type deviceClass;
1010     Device::Subclass::Type deviceSubclass;
1011
1012     GetDeviceName( keyEvent, deviceName );
1013     GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
1014     GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
1015
1016     Integration::KeyEvent keyEvent( keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::Down, compose, deviceName, deviceClass, deviceSubclass );
1017
1018      mKeyEventSignal.Emit( keyEvent );
1019   }
1020 }
1021
1022 void WindowBaseEcoreWl::OnKeyUp( void* data, int type, void* event )
1023 {
1024   Ecore_Event_Key* keyEvent = static_cast< Ecore_Event_Key* >( event );
1025
1026   if( keyEvent->window == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
1027   {
1028     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::OnKeyUp\n" );
1029
1030     std::string keyName( keyEvent->keyname );
1031     std::string logicalKey( "" );
1032     std::string keyString( "" );
1033     std::string compose( "" );
1034
1035     // Ensure key compose string is not NULL as keys like SHIFT or arrow have a null string.
1036     if( keyEvent->compose )
1037     {
1038       compose = keyEvent->compose;
1039     }
1040
1041     // Ensure key symbol is not NULL as keys like SHIFT have a null string.
1042     if( keyEvent->key )
1043     {
1044       logicalKey = keyEvent->key;
1045     }
1046
1047     int keyCode = KeyLookup::GetDaliKeyCode( keyEvent->keyname );
1048     keyCode = ( keyCode == -1 ) ? 0 : keyCode;
1049     int modifier( keyEvent->modifiers );
1050     unsigned long time = keyEvent->timestamp;
1051     if( !strncmp( keyEvent->keyname, "Keycode-", 8 ) )
1052     {
1053       keyCode = atoi( keyEvent->keyname + 8 );
1054     }
1055
1056     // Ensure key event string is not NULL as keys like SHIFT have a null string.
1057     if( keyEvent->string )
1058     {
1059       keyString = keyEvent->string;
1060     }
1061
1062     std::string deviceName;
1063     Device::Class::Type deviceClass;
1064     Device::Subclass::Type deviceSubclass;
1065
1066     GetDeviceName( keyEvent, deviceName );
1067     GetDeviceClass( ecore_device_class_get( keyEvent->dev ), deviceClass );
1068     GetDeviceSubclass( ecore_device_subclass_get( keyEvent->dev ), deviceSubclass );
1069
1070     Integration::KeyEvent keyEvent( keyName, logicalKey, keyString, keyCode, modifier, time, Integration::KeyEvent::Up, compose, deviceName, deviceClass, deviceSubclass );
1071
1072      mKeyEventSignal.Emit( keyEvent );
1073   }
1074 }
1075
1076 void WindowBaseEcoreWl::OnDataSend( void* data, int type, void* event )
1077 {
1078   mSelectionDataSendSignal.Emit( event );
1079 }
1080
1081 void WindowBaseEcoreWl::OnDataReceive( void* data, int type, void* event )
1082 {
1083   mSelectionDataReceivedSignal.Emit( event  );
1084 }
1085
1086 void WindowBaseEcoreWl::OnFontNameChanged()
1087 {
1088   mStyleChangedSignal.Emit( StyleChange::DEFAULT_FONT_CHANGE );
1089 }
1090
1091 void WindowBaseEcoreWl::OnFontSizeChanged()
1092 {
1093   mStyleChangedSignal.Emit( StyleChange::DEFAULT_FONT_SIZE_CHANGE );
1094 }
1095
1096 void WindowBaseEcoreWl::OnEcoreElDBusAccessibilityNotification( void* context, const Eldbus_Message* message )
1097 {
1098 #ifdef DALI_ELDBUS_AVAILABLE
1099   AccessibilityInfo info;
1100
1101   // The string defines the arg-list's respective types.
1102   if( !eldbus_message_arguments_get( message, "iiiiiiu", &info.gestureValue, &info.startX, &info.startY, &info.endX, &info.endY, &info.state, &info.eventTime ) )
1103   {
1104     DALI_LOG_ERROR( "OnEcoreElDBusAccessibilityNotification: Error getting arguments\n" );
1105   }
1106
1107   mAccessibilitySignal.Emit( info );
1108 #endif
1109 }
1110
1111 void WindowBaseEcoreWl::RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
1112 {
1113   if( strcmp( interface, tizen_policy_interface.name ) == 0 )
1114   {
1115     uint32_t clientVersion = std::min( version, MAX_TIZEN_CLIENT_VERSION );
1116
1117     mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, clientVersion ) );
1118     if( !mTizenPolicy )
1119     {
1120       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
1121       return;
1122     }
1123
1124     tizen_policy_add_listener( mTizenPolicy, &tizenPolicyListener, data );
1125
1126     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
1127   }
1128   else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
1129   {
1130     mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
1131     if( !mTizenDisplayPolicy )
1132     {
1133       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
1134       return;
1135     }
1136
1137     tizen_display_policy_add_listener( mTizenDisplayPolicy, &tizenDisplayPolicyListener, data );
1138
1139     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
1140   }
1141 }
1142
1143 void WindowBaseEcoreWl::RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
1144 {
1145   mTizenPolicy = NULL;
1146   mTizenDisplayPolicy = NULL;
1147 }
1148
1149 void WindowBaseEcoreWl::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
1150 {
1151   mNotificationLevel = level;
1152   mNotificationChangeState = state;
1153   mNotificationLevelChangeDone = true;
1154
1155   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
1156 }
1157
1158 void WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
1159 {
1160   mScreenOffMode = mode;
1161   mScreenOffModeChangeState = state;
1162   mScreenOffModeChangeDone = true;
1163
1164   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
1165 }
1166
1167 void WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
1168 {
1169   mBrightness = brightness;
1170   mBrightnessChangeState = state;
1171   mBrightnessChangeDone = true;
1172
1173   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
1174 }
1175
1176 Any WindowBaseEcoreWl::GetNativeWindow()
1177 {
1178   return mEcoreWindow;
1179 }
1180
1181 int WindowBaseEcoreWl::GetNativeWindowId()
1182 {
1183   return ecore_wl_window_id_get( mEcoreWindow );
1184 }
1185
1186 EGLNativeWindowType WindowBaseEcoreWl::CreateEglWindow( int width, int height )
1187 {
1188   mEglWindow = wl_egl_window_create( mWlSurface, width, height );
1189
1190   return static_cast< EGLNativeWindowType >( mEglWindow );
1191 }
1192
1193 void WindowBaseEcoreWl::DestroyEglWindow()
1194 {
1195   if( mEglWindow != NULL )
1196   {
1197     wl_egl_window_destroy( mEglWindow );
1198     mEglWindow = NULL;
1199   }
1200 }
1201
1202 void WindowBaseEcoreWl::SetEglWindowRotation( int angle )
1203 {
1204   wl_egl_window_rotation rotation;
1205
1206   switch( angle )
1207   {
1208     case 0:
1209     {
1210       rotation = ROTATION_0;
1211       break;
1212     }
1213     case 90:
1214     {
1215       rotation = ROTATION_270;
1216       break;
1217     }
1218     case 180:
1219     {
1220       rotation = ROTATION_180;
1221       break;
1222     }
1223     case 270:
1224     {
1225       rotation = ROTATION_90;
1226       break;
1227     }
1228     default:
1229     {
1230       rotation = ROTATION_0;
1231       break;
1232     }
1233   }
1234
1235   wl_egl_window_set_rotation( mEglWindow, rotation );
1236 }
1237
1238 void WindowBaseEcoreWl::SetEglWindowBufferTransform( int angle )
1239 {
1240   wl_output_transform bufferTransform;
1241
1242   switch( angle )
1243   {
1244     case 0:
1245     {
1246       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1247       break;
1248     }
1249     case 90:
1250     {
1251       bufferTransform = WL_OUTPUT_TRANSFORM_90;
1252       break;
1253     }
1254     case 180:
1255     {
1256       bufferTransform = WL_OUTPUT_TRANSFORM_180;
1257       break;
1258     }
1259     case 270:
1260     {
1261       bufferTransform = WL_OUTPUT_TRANSFORM_270;
1262       break;
1263     }
1264     default:
1265     {
1266       bufferTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1267       break;
1268     }
1269   }
1270
1271   wl_egl_window_set_buffer_transform( mEglWindow, bufferTransform );
1272 }
1273
1274 void WindowBaseEcoreWl::SetEglWindowTransform( int angle )
1275 {
1276   wl_output_transform windowTransform;
1277
1278   switch( angle )
1279   {
1280     case 0:
1281     {
1282       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1283       break;
1284     }
1285     case 90:
1286     {
1287       windowTransform = WL_OUTPUT_TRANSFORM_90;
1288       break;
1289     }
1290     case 180:
1291     {
1292       windowTransform = WL_OUTPUT_TRANSFORM_180;
1293       break;
1294     }
1295     case 270:
1296     {
1297       windowTransform = WL_OUTPUT_TRANSFORM_270;
1298       break;
1299     }
1300     default:
1301     {
1302       windowTransform = WL_OUTPUT_TRANSFORM_NORMAL;
1303       break;
1304     }
1305   }
1306
1307   wl_egl_window_set_window_transform( mEglWindow, windowTransform );
1308 }
1309
1310 void WindowBaseEcoreWl::ResizeEglWindow( PositionSize positionSize )
1311 {
1312   wl_egl_window_resize( mEglWindow, positionSize.width, positionSize.height, positionSize.x, positionSize.y );
1313 }
1314
1315 bool WindowBaseEcoreWl::IsEglWindowRotationSupported()
1316 {
1317   // Check capability
1318   wl_egl_window_capability capability = static_cast< wl_egl_window_capability >( wl_egl_window_get_capabilities( mEglWindow ) );
1319   if( capability == WL_EGL_WINDOW_CAPABILITY_ROTATION_SUPPORTED )
1320   {
1321     return true;
1322   }
1323
1324   return false;
1325 }
1326
1327 void WindowBaseEcoreWl::Move( PositionSize positionSize )
1328 {
1329   ecore_wl_window_position_set( mEcoreWindow, positionSize.x, positionSize.y );
1330 }
1331
1332 void WindowBaseEcoreWl::Resize( PositionSize positionSize )
1333 {
1334   ecore_wl_window_update_size( mEcoreWindow, positionSize.width, positionSize.height );
1335 }
1336
1337 void WindowBaseEcoreWl::MoveResize( PositionSize positionSize )
1338 {
1339   ecore_wl_window_position_set( mEcoreWindow, positionSize.x, positionSize.y );
1340   ecore_wl_window_update_size( mEcoreWindow, positionSize.width, positionSize.height );
1341 }
1342
1343 void WindowBaseEcoreWl::SetClass( const std::string& name, const std::string& className )
1344 {
1345   ecore_wl_window_title_set( mEcoreWindow, name.c_str() );
1346   ecore_wl_window_class_name_set( mEcoreWindow, className.c_str() );
1347 }
1348
1349 void WindowBaseEcoreWl::Raise()
1350 {
1351   // Use ecore_wl_window_activate to prevent the window shown without rendering
1352   ecore_wl_window_activate( mEcoreWindow );
1353 }
1354
1355 void WindowBaseEcoreWl::Lower()
1356 {
1357   ecore_wl_window_lower( mEcoreWindow );
1358 }
1359
1360 void WindowBaseEcoreWl::Activate()
1361 {
1362   ecore_wl_window_activate( mEcoreWindow );
1363 }
1364
1365 void WindowBaseEcoreWl::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
1366 {
1367   int rotations[4] = { 0 };
1368   for( std::size_t i = 0; i < orientations.size(); ++i )
1369   {
1370     rotations[i] = static_cast< int >( orientations[i] );
1371   }
1372   ecore_wl_window_rotation_available_rotations_set( mEcoreWindow, rotations, orientations.size() );
1373 }
1374
1375 void WindowBaseEcoreWl::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
1376 {
1377   ecore_wl_window_rotation_preferred_rotation_set( mEcoreWindow, orientation );
1378 }
1379
1380 void WindowBaseEcoreWl::SetAcceptFocus( bool accept )
1381 {
1382   ecore_wl_window_focus_skip_set( mEcoreWindow, !accept );
1383 }
1384
1385 void WindowBaseEcoreWl::Show()
1386 {
1387   ecore_wl_window_show( mEcoreWindow );
1388 }
1389
1390 void WindowBaseEcoreWl::Hide()
1391 {
1392   ecore_wl_window_hide( mEcoreWindow );
1393 }
1394
1395 unsigned int WindowBaseEcoreWl::GetSupportedAuxiliaryHintCount() const
1396 {
1397   return mSupportedAuxiliaryHints.size();
1398 }
1399
1400 std::string WindowBaseEcoreWl::GetSupportedAuxiliaryHint( unsigned int index ) const
1401 {
1402   if( index >= GetSupportedAuxiliaryHintCount() )
1403   {
1404     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
1405   }
1406
1407   return mSupportedAuxiliaryHints[index];
1408 }
1409
1410 unsigned int WindowBaseEcoreWl::AddAuxiliaryHint( const std::string& hint, const std::string& value )
1411 {
1412   bool supported = false;
1413
1414   // Check if the hint is suppported
1415   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
1416   {
1417     if( *iter == hint )
1418     {
1419       supported = true;
1420       break;
1421     }
1422   }
1423
1424   if( !supported )
1425   {
1426     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
1427     return 0;
1428   }
1429
1430   // Check if the hint is already added
1431   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1432   {
1433     if( mAuxiliaryHints[i].first == hint )
1434     {
1435       // Just change the value
1436       mAuxiliaryHints[i].second = value;
1437
1438       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
1439
1440       return i + 1;   // id is index + 1
1441     }
1442   }
1443
1444   // Add the hint
1445   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
1446
1447   unsigned int id = mAuxiliaryHints.size();
1448
1449   ecore_wl_window_aux_hint_add( mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
1450
1451   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
1452
1453   return id;
1454 }
1455
1456 bool WindowBaseEcoreWl::RemoveAuxiliaryHint( unsigned int id )
1457 {
1458   if( id == 0 || id > mAuxiliaryHints.size() )
1459   {
1460     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
1461     return false;
1462   }
1463
1464   mAuxiliaryHints[id - 1].second = std::string();
1465
1466   ecore_wl_window_aux_hint_del( mEcoreWindow, static_cast< int >( id ) );
1467
1468   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
1469
1470   return true;
1471 }
1472
1473 bool WindowBaseEcoreWl::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
1474 {
1475   if( id == 0 || id > mAuxiliaryHints.size() )
1476   {
1477     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1478     return false;
1479   }
1480
1481   mAuxiliaryHints[id - 1].second = value;
1482
1483   ecore_wl_window_aux_hint_change( mEcoreWindow, static_cast< int >( id ), value.c_str() );
1484
1485   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() );
1486
1487   return true;
1488 }
1489
1490 std::string WindowBaseEcoreWl::GetAuxiliaryHintValue( unsigned int id ) const
1491 {
1492   if( id == 0 || id > mAuxiliaryHints.size() )
1493   {
1494     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1495     return std::string();
1496   }
1497
1498   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() );
1499
1500   return mAuxiliaryHints[id - 1].second;
1501 }
1502
1503 unsigned int WindowBaseEcoreWl::GetAuxiliaryHintId( const std::string& hint ) const
1504 {
1505   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1506   {
1507     if( mAuxiliaryHints[i].first == hint )
1508     {
1509       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1510       return i + 1;
1511     }
1512   }
1513
1514   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1515
1516   return 0;
1517 }
1518
1519 void WindowBaseEcoreWl::SetInputRegion( const Rect< int >& inputRegion )
1520 {
1521   ecore_wl_window_input_region_set( mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1522 }
1523
1524 void WindowBaseEcoreWl::SetType( Dali::Window::Type type )
1525 {
1526   Ecore_Wl_Window_Type windowType;
1527
1528   switch( type )
1529   {
1530     case Dali::Window::NORMAL:
1531     {
1532       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1533       break;
1534     }
1535     case Dali::Window::NOTIFICATION:
1536     {
1537       windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1538       break;
1539     }
1540     case Dali::Window::UTILITY:
1541     {
1542       windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1543       break;
1544     }
1545     case Dali::Window::DIALOG:
1546     {
1547       windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1548       break;
1549     }
1550     default:
1551     {
1552       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1553       break;
1554     }
1555   }
1556
1557   ecore_wl_window_type_set( mEcoreWindow, windowType );
1558 }
1559
1560 bool WindowBaseEcoreWl::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
1561 {
1562   while( !mTizenPolicy )
1563   {
1564     wl_display_dispatch_queue( mDisplay, mEventQueue );
1565   }
1566
1567   int notificationLevel;
1568
1569   switch( level )
1570   {
1571     case Dali::Window::NotificationLevel::NONE:
1572     {
1573       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1574       break;
1575     }
1576     case Dali::Window::NotificationLevel::BASE:
1577     {
1578       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1579       break;
1580     }
1581     case Dali::Window::NotificationLevel::MEDIUM:
1582     {
1583       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1584       break;
1585     }
1586     case Dali::Window::NotificationLevel::HIGH:
1587     {
1588       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1589       break;
1590     }
1591     case Dali::Window::NotificationLevel::TOP:
1592     {
1593       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1594       break;
1595     }
1596     default:
1597     {
1598       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: invalid level [%d]\n", level );
1599       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1600       break;
1601     }
1602   }
1603
1604   mNotificationLevelChangeDone = false;
1605   mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1606
1607   tizen_policy_set_notification_level( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), notificationLevel );
1608
1609   int count = 0;
1610
1611   while( !mNotificationLevelChangeDone && count < 3 )
1612   {
1613     ecore_wl_flush();
1614     wl_display_dispatch_queue( mDisplay, mEventQueue );
1615     count++;
1616   }
1617
1618   if( !mNotificationLevelChangeDone )
1619   {
1620     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState );
1621     return false;
1622   }
1623   else if( mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1624   {
1625     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Permission denied! [%d]\n", level );
1626     return false;
1627   }
1628
1629   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel );
1630
1631   return true;
1632 }
1633
1634 Dali::Window::NotificationLevel::Type WindowBaseEcoreWl::GetNotificationLevel() const
1635 {
1636   while( !mTizenPolicy )
1637   {
1638     wl_display_dispatch_queue( mDisplay, mEventQueue );
1639   }
1640
1641   int count = 0;
1642
1643   while( !mNotificationLevelChangeDone && count < 3 )
1644   {
1645     ecore_wl_flush();
1646     wl_display_dispatch_queue( mDisplay, mEventQueue );
1647     count++;
1648   }
1649
1650   if( !mNotificationLevelChangeDone )
1651   {
1652     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState );
1653     return Dali::Window::NotificationLevel::NONE;
1654   }
1655
1656   Dali::Window::NotificationLevel::Type level;
1657
1658   switch( mNotificationLevel )
1659   {
1660     case TIZEN_POLICY_LEVEL_NONE:
1661     {
1662       level = Dali::Window::NotificationLevel::NONE;
1663       break;
1664     }
1665     case TIZEN_POLICY_LEVEL_DEFAULT:
1666     {
1667       level = Dali::Window::NotificationLevel::BASE;
1668       break;
1669     }
1670     case TIZEN_POLICY_LEVEL_MEDIUM:
1671     {
1672       level = Dali::Window::NotificationLevel::MEDIUM;
1673       break;
1674     }
1675     case TIZEN_POLICY_LEVEL_HIGH:
1676     {
1677       level = Dali::Window::NotificationLevel::HIGH;
1678       break;
1679     }
1680     case TIZEN_POLICY_LEVEL_TOP:
1681     {
1682       level = Dali::Window::NotificationLevel::TOP;
1683       break;
1684     }
1685     default:
1686     {
1687       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel );
1688       level = Dali::Window::NotificationLevel::NONE;
1689       break;
1690     }
1691   }
1692
1693   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: level [%d]\n", mNotificationLevel );
1694
1695   return level;
1696 }
1697
1698 void WindowBaseEcoreWl::SetOpaqueState( bool opaque )
1699 {
1700   while( !mTizenPolicy )
1701   {
1702     wl_display_dispatch_queue( mDisplay, mEventQueue );
1703   }
1704
1705   tizen_policy_set_opaque_state( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), ( opaque ? 1 : 0 ) );
1706 }
1707
1708 bool WindowBaseEcoreWl::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
1709 {
1710   while( !mTizenPolicy )
1711   {
1712     wl_display_dispatch_queue( mDisplay, mEventQueue );
1713   }
1714
1715   mScreenOffModeChangeDone = false;
1716   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1717
1718   unsigned int mode = 0;
1719
1720   switch( screenOffMode )
1721   {
1722     case Dali::Window::ScreenOffMode::TIMEOUT:
1723     {
1724       mode = 0;
1725       break;
1726     }
1727     case Dali::Window::ScreenOffMode::NEVER:
1728     {
1729       mode = 1;
1730       break;
1731     }
1732   }
1733
1734   tizen_policy_set_window_screen_mode( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), mode );
1735
1736   int count = 0;
1737
1738   while( !mScreenOffModeChangeDone && count < 3 )
1739   {
1740     ecore_wl_flush();
1741     wl_display_dispatch_queue( mDisplay, mEventQueue );
1742     count++;
1743   }
1744
1745   if( !mScreenOffModeChangeDone )
1746   {
1747     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState );
1748     return false;
1749   }
1750   else if( mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1751   {
1752     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
1753     return false;
1754   }
1755
1756   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode );
1757
1758   return true;
1759 }
1760
1761 Dali::Window::ScreenOffMode::Type WindowBaseEcoreWl::GetScreenOffMode() const
1762 {
1763   while( !mTizenPolicy )
1764   {
1765     wl_display_dispatch_queue( mDisplay, mEventQueue );
1766   }
1767
1768   int count = 0;
1769
1770   while( !mScreenOffModeChangeDone && count < 3 )
1771   {
1772     ecore_wl_flush();
1773     wl_display_dispatch_queue( mDisplay, mEventQueue );
1774     count++;
1775   }
1776
1777   if( !mScreenOffModeChangeDone )
1778   {
1779     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState );
1780     return Dali::Window::ScreenOffMode::TIMEOUT;
1781   }
1782
1783   Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1784
1785   switch( mScreenOffMode )
1786   {
1787     case 0:
1788     {
1789       screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1790       break;
1791     }
1792     case 1:
1793     {
1794       screenMode = Dali::Window::ScreenOffMode::NEVER;
1795       break;
1796     }
1797   }
1798
1799   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode );
1800
1801   return screenMode;
1802 }
1803
1804 bool WindowBaseEcoreWl::SetBrightness( int brightness )
1805 {
1806   while( !mTizenDisplayPolicy )
1807   {
1808     wl_display_dispatch_queue( mDisplay, mEventQueue );
1809   }
1810
1811   mBrightnessChangeDone = false;
1812   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1813
1814   tizen_display_policy_set_window_brightness( mTizenDisplayPolicy, ecore_wl_window_surface_get( mEcoreWindow ), brightness );
1815
1816   int count = 0;
1817
1818   while( !mBrightnessChangeDone && count < 3 )
1819   {
1820     ecore_wl_flush();
1821     wl_display_dispatch_queue( mDisplay, mEventQueue );
1822     count++;
1823   }
1824
1825   if( !mBrightnessChangeDone )
1826   {
1827     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState );
1828     return false;
1829   }
1830   else if( mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1831   {
1832     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Permission denied! [%d]\n", brightness );
1833     return false;
1834   }
1835
1836   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness is changed [%d]\n", mBrightness );
1837
1838   return true;
1839 }
1840
1841 int WindowBaseEcoreWl::GetBrightness() const
1842 {
1843   while( !mTizenDisplayPolicy )
1844   {
1845     wl_display_dispatch_queue( mDisplay, mEventQueue );
1846   }
1847
1848   int count = 0;
1849
1850   while( !mBrightnessChangeDone && count < 3 )
1851   {
1852     ecore_wl_flush();
1853     wl_display_dispatch_queue( mDisplay, mEventQueue );
1854     count++;
1855   }
1856
1857   if( !mBrightnessChangeDone )
1858   {
1859     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Error! [%d]\n", mBrightnessChangeState );
1860     return 0;
1861   }
1862
1863   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Brightness [%d]\n", mBrightness );
1864
1865   return mBrightness;
1866 }
1867
1868 bool WindowBaseEcoreWl::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
1869 {
1870   Ecore_Wl_Window_Keygrab_Mode mode;
1871
1872   switch( grabMode )
1873   {
1874     case KeyGrab::TOPMOST:
1875     {
1876       mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1877       break;
1878     }
1879     case KeyGrab::SHARED:
1880     {
1881       mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1882       break;
1883     }
1884     case KeyGrab::OVERRIDE_EXCLUSIVE:
1885     {
1886       mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1887       break;
1888     }
1889     case KeyGrab::EXCLUSIVE:
1890     {
1891       mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1892       break;
1893     }
1894     default:
1895     {
1896       return false;
1897     }
1898   }
1899
1900   return ecore_wl_window_keygrab_set( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0, 0, mode );
1901 }
1902
1903 bool WindowBaseEcoreWl::UngrabKey( Dali::KEY key )
1904 {
1905   return ecore_wl_window_keygrab_unset( mEcoreWindow, KeyLookup::GetKeyName( key ), 0, 0 );
1906 }
1907
1908 bool WindowBaseEcoreWl::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
1909 {
1910   int keyCount = key.Count();
1911   int keyGrabModeCount = grabMode.Count();
1912
1913   if( keyCount != keyGrabModeCount || keyCount == 0 )
1914   {
1915     return false;
1916   }
1917
1918   eina_init();
1919
1920   Eina_List* keyList = NULL;
1921   Ecore_Wl_Window_Keygrab_Info* info = new Ecore_Wl_Window_Keygrab_Info[keyCount];
1922
1923   for( int index = 0; index < keyCount; ++index )
1924   {
1925     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
1926
1927     switch( grabMode[index] )
1928     {
1929       case KeyGrab::TOPMOST:
1930       {
1931         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_TOPMOST;
1932         break;
1933       }
1934       case KeyGrab::SHARED:
1935       {
1936         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_SHARED;
1937         break;
1938       }
1939       case KeyGrab::OVERRIDE_EXCLUSIVE:
1940       {
1941         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_OVERRIDE_EXCLUSIVE;
1942         break;
1943       }
1944       case KeyGrab::EXCLUSIVE:
1945       {
1946         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_EXCLUSIVE;
1947         break;
1948       }
1949       default:
1950       {
1951         info[index].mode = ECORE_WL_WINDOW_KEYGRAB_UNKNOWN;
1952         break;
1953       }
1954     }
1955
1956     keyList = eina_list_append( keyList, &info );
1957   }
1958
1959   Eina_List* grabList = ecore_wl_window_keygrab_list_set( mEcoreWindow, keyList );
1960
1961   result.Resize( keyCount, true );
1962
1963   Eina_List* l = NULL;
1964   Eina_List* m = NULL;
1965   void* listData = NULL;
1966   void* data = NULL;
1967   if( grabList != NULL )
1968   {
1969     EINA_LIST_FOREACH( grabList, m, data )
1970     {
1971       int index = 0;
1972       EINA_LIST_FOREACH( keyList, l, listData )
1973       {
1974         if( static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key == NULL )
1975         {
1976           DALI_LOG_ERROR( "input key list has null data!" );
1977           break;
1978         }
1979
1980         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key ) == 0 )
1981         {
1982           result[index] = false;
1983         }
1984         ++index;
1985       }
1986     }
1987   }
1988
1989   delete [] info;
1990
1991   eina_list_free( keyList );
1992   eina_list_free( grabList );
1993   eina_shutdown();
1994
1995   return true;
1996 }
1997
1998 bool WindowBaseEcoreWl::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
1999 {
2000   int keyCount = key.Count();
2001   if( keyCount == 0 )
2002   {
2003     return false;
2004   }
2005
2006   eina_init();
2007
2008   Eina_List* keyList = NULL;
2009   Ecore_Wl_Window_Keygrab_Info* info = new Ecore_Wl_Window_Keygrab_Info[keyCount];
2010
2011   for( int index = 0; index < keyCount; ++index )
2012   {
2013     info[index].key = const_cast< char* >( KeyLookup::GetKeyName( key[index] ) );
2014     keyList = eina_list_append( keyList, &info );
2015   }
2016
2017   Eina_List* ungrabList = ecore_wl_window_keygrab_list_unset( mEcoreWindow, keyList );
2018
2019   result.Resize( keyCount, true );
2020
2021   Eina_List* l = NULL;
2022   Eina_List* m = NULL;
2023   void *listData = NULL;
2024   void *data = NULL;
2025
2026   if( ungrabList != NULL )
2027   {
2028     EINA_LIST_FOREACH( ungrabList, m, data )
2029     {
2030       int index = 0;
2031       EINA_LIST_FOREACH( keyList, l, listData )
2032       {
2033         if( strcmp( static_cast< char* >( data ), static_cast< Ecore_Wl_Window_Keygrab_Info* >( listData )->key ) == 0 )
2034         {
2035           result[index] = false;
2036         }
2037         ++index;
2038       }
2039     }
2040   }
2041
2042   delete [] info;
2043
2044   eina_list_free( keyList );
2045   eina_list_free( ungrabList );
2046   eina_shutdown();
2047
2048   return true;
2049 }
2050
2051 void WindowBaseEcoreWl::GetDpi( unsigned int& dpiHorizontal, unsigned int& dpiVertical )
2052 {
2053   // calculate DPI
2054   float xres, yres;
2055
2056   // 1 inch = 25.4 millimeters
2057   xres = ecore_wl_dpi_get();
2058   yres = ecore_wl_dpi_get();
2059
2060   dpiHorizontal = int( xres + 0.5f );  // rounding
2061   dpiVertical   = int( yres + 0.5f );
2062 }
2063
2064 int WindowBaseEcoreWl::GetScreenRotationAngle()
2065 {
2066   int transform = 0;
2067
2068   if( ecore_wl_window_ignore_output_transform_get( mEcoreWindow ) )
2069   {
2070     transform = 0;
2071   }
2072   else
2073   {
2074     transform = ecore_wl_output_transform_get( ecore_wl_window_output_find( mEcoreWindow ) );
2075   }
2076
2077   return transform * 90;
2078 }
2079
2080 void WindowBaseEcoreWl::SetWindowRotationAngle( int degree )
2081 {
2082   ecore_wl_window_rotation_set( mEcoreWindow, degree );
2083 }
2084
2085 void WindowBaseEcoreWl::WindowRotationCompleted( int degree, int width, int height )
2086 {
2087   ecore_wl_window_rotation_change_done_send( mEcoreWindow );
2088 }
2089
2090 void WindowBaseEcoreWl::SetTransparency( bool transparent )
2091 {
2092   ecore_wl_window_alpha_set( mEcoreWindow, transparent );
2093 }
2094
2095 void WindowBaseEcoreWl::InitializeEcoreElDBus()
2096 {
2097 #ifdef DALI_ELDBUS_AVAILABLE
2098   Eldbus_Object* object;
2099   Eldbus_Proxy* manager;
2100
2101   if( !( mSystemConnection = eldbus_connection_get( ELDBUS_CONNECTION_TYPE_SYSTEM ) ) )
2102   {
2103     DALI_LOG_ERROR( "Unable to get system bus\n" );
2104   }
2105
2106   object = eldbus_object_get( mSystemConnection, BUS, PATH );
2107   if( !object )
2108   {
2109     DALI_LOG_ERROR( "Getting object failed\n" );
2110     return;
2111   }
2112
2113   manager = eldbus_proxy_get( object, INTERFACE );
2114   if( !manager )
2115   {
2116     DALI_LOG_ERROR( "Getting proxy failed\n" );
2117     return;
2118   }
2119
2120   if( !eldbus_proxy_signal_handler_add( manager, "GestureDetected", EcoreElDBusAccessibilityNotification, this ) )
2121   {
2122     DALI_LOG_ERROR( "No signal handler returned\n" );
2123   }
2124 #endif
2125 }
2126
2127 void WindowBaseEcoreWl::CreateWindow( PositionSize positionSize )
2128 {
2129   mEcoreWindow = ecore_wl_window_new( 0, positionSize.x, positionSize.y, positionSize.width, positionSize.height, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW );
2130
2131   if ( mEcoreWindow == 0 )
2132   {
2133     DALI_ASSERT_ALWAYS( 0 && "Failed to create Wayland window" );
2134   }
2135 }
2136
2137 } // namespace Adaptor
2138
2139 } // namespace Internal
2140
2141 } // namespace Dali
2142
2143 #pragma GCC diagnostic pop