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