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