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