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