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