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