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