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