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