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