Refactoring window system
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / window-base-ecore-wl.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/window-base-ecore-wl.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/window-system/common/window-impl.h>
27 #include <dali/internal/window-system/tizen-wayland/window-render-surface-ecore-wl.h>
28
29 // EXTERNAL_HEADERS
30 #include <dali/public-api/object/any.h>
31 #include <dali/integration-api/debug.h>
32
33 namespace Dali
34 {
35
36 namespace Internal
37 {
38
39 namespace Adaptor
40 {
41
42 namespace
43 {
44
45 #if defined(DEBUG_ENABLED)
46 Debug::Filter* gWindowBaseLogFilter = Debug::Filter::New( Debug::NoLogging, false, "LOG_WINDOW_BASE" );
47 #endif
48
49 const uint32_t MAX_TIZEN_CLIENT_VERSION = 7;
50
51 /// Called when the window iconify state is changed.
52 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
53 {
54   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
55   if( windowBase )
56   {
57     return windowBase->OnIconifyStateChanged( data, type, event );
58   }
59
60   return ECORE_CALLBACK_PASS_ON;
61 }
62
63 /// Called when the window gains focus
64 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
65 {
66   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
67   if( windowBase )
68   {
69     return windowBase->OnFocusIn( data, type, event );
70   }
71
72   return ECORE_CALLBACK_PASS_ON;
73 }
74
75 /// Called when the window loses focus
76 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
77 {
78   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
79   if( windowBase )
80   {
81     return windowBase->OnFocusOut( data, type, event );
82   }
83
84   return ECORE_CALLBACK_PASS_ON;
85 }
86
87 /// Called when the output is transformed
88 static Eina_Bool EcoreEventOutputTransform( void* data, int type, void* event )
89 {
90   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
91   if( windowBase )
92   {
93     return windowBase->OnOutputTransform( data, type, event );
94   }
95
96   return ECORE_CALLBACK_PASS_ON;
97 }
98
99 /// Called when the output transform should be ignored
100 static Eina_Bool EcoreEventIgnoreOutputTransform( void* data, int type, void* event )
101 {
102   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
103   if( windowBase )
104   {
105     return windowBase->OnIgnoreOutputTransform( data, type, event );
106   }
107
108   return ECORE_CALLBACK_PASS_ON;
109 }
110
111 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
112 {
113   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
114   if( windowBase )
115   {
116     windowBase->RegistryGlobalCallback( data, registry, name, interface, version );
117   }
118 }
119
120 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
121 {
122   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
123   if( windowBase )
124   {
125     windowBase->RegistryGlobalCallbackRemove( data, registry, id );
126   }
127 }
128
129 static void TizenPolicyConformant( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t isConformant )
130 {
131 }
132
133 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 )
134 {
135 }
136
137 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
138 {
139   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
140   if( windowBase )
141   {
142     windowBase->TizenPolicyNotificationChangeDone( data, tizenPolicy, surface, level, state );
143   }
144 }
145
146 static void TizenPolicyTransientForDone( void* data, struct tizen_policy* tizenPolicy, uint32_t childId )
147 {
148 }
149
150 static void TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
151 {
152   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
153   if( windowBase )
154   {
155     windowBase->TizenPolicyScreenModeChangeDone( data, tizenPolicy, surface, mode, state );
156   }
157 }
158
159 static void TizenPolicyIconifyStateChanged( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force )
160 {
161 }
162
163 static void TizenPolicySupportedAuxiliaryHints( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints )
164 {
165 }
166
167 static void TizenPolicyAllowedAuxiliaryHint( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id )
168 {
169 }
170
171 static void TizenPolicyAuxiliaryMessage( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options )
172 {
173 }
174
175 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 )
176 {
177 }
178
179 static void DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
180 {
181   WindowBaseEcoreWl* windowBase = static_cast< WindowBaseEcoreWl* >( data );
182   if( windowBase )
183   {
184     windowBase->DisplayPolicyBrightnessChangeDone( data, displayPolicy, surface, brightness, state );
185   }
186 }
187
188 const struct wl_registry_listener registryListener =
189 {
190    RegistryGlobalCallback,
191    RegistryGlobalCallbackRemove
192 };
193
194 const struct tizen_policy_listener tizenPolicyListener =
195 {
196    TizenPolicyConformant,
197    TizenPolicyConformantArea,
198    TizenPolicyNotificationChangeDone,
199    TizenPolicyTransientForDone,
200    TizenPolicyScreenModeChangeDone,
201    TizenPolicyIconifyStateChanged,
202    TizenPolicySupportedAuxiliaryHints,
203    TizenPolicyAllowedAuxiliaryHint,
204    TizenPolicyAuxiliaryMessage,
205    TizenPolicyConformantRegion
206 };
207
208 const struct tizen_display_policy_listener tizenDisplayPolicyListener =
209 {
210   DisplayPolicyBrightnessChangeDone
211 };
212
213 } // unnamed namespace
214
215 WindowBaseEcoreWl::WindowBaseEcoreWl( Window* window, WindowRenderSurface* windowRenderSurface )
216 : mEcoreEventHandler(),
217   mWindow( window ),
218   mWindowSurface( NULL ),
219   mEcoreWindow( NULL ),
220   mDisplay( NULL ),
221   mEventQueue( NULL ),
222   mTizenPolicy( NULL ),
223   mTizenDisplayPolicy( NULL ),
224   mSupportedAuxiliaryHints(),
225   mAuxiliaryHints(),
226   mNotificationLevel( -1 ),
227   mNotificationChangeState( 0 ),
228   mNotificationLevelChangeDone( true ),
229   mScreenOffMode( 0 ),
230   mScreenOffModeChangeState( 0 ),
231   mScreenOffModeChangeDone( true ),
232   mBrightness( 0 ),
233   mBrightnessChangeState( 0 ),
234   mBrightnessChangeDone( true )
235 {
236   mWindowSurface = dynamic_cast< WindowRenderSurfaceEcoreWl* >( windowRenderSurface );
237 }
238
239 WindowBaseEcoreWl::~WindowBaseEcoreWl()
240 {
241   for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
242   {
243     ecore_event_handler_del( *iter );
244   }
245   mEcoreEventHandler.Clear();
246
247   if( mEventQueue )
248   {
249     wl_event_queue_destroy( mEventQueue );
250   }
251
252   mSupportedAuxiliaryHints.clear();
253   mAuxiliaryHints.clear();
254 }
255
256 void WindowBaseEcoreWl::Initialize()
257 {
258   if( !mWindowSurface )
259   {
260     DALI_ASSERT_ALWAYS( "Invalid window surface" );
261   }
262
263   mEcoreWindow = mWindowSurface->GetWlWindow();
264   DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no EcoreWl window" );
265
266   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
267   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this ) );
268   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this ) );
269   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this) );
270   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this) );
271
272   mDisplay = ecore_wl_display_get();
273
274   if( mDisplay )
275   {
276     wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
277     if( displayWrapper )
278     {
279       mEventQueue = wl_display_create_queue( mDisplay );
280       if( mEventQueue )
281       {
282         wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
283
284         wl_registry* registry = wl_display_get_registry( displayWrapper );
285         wl_registry_add_listener( registry, &registryListener, this );
286       }
287
288       wl_proxy_wrapper_destroy( displayWrapper );
289     }
290   }
291
292   // get auxiliary hint
293   Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEcoreWindow );
294   if( hints )
295   {
296     Eina_List* l = NULL;
297     char* hint = NULL;
298
299     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) ) ) )
300     {
301       mSupportedAuxiliaryHints.push_back( hint );
302
303       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::Initialize: %s\n", hint );
304     }
305   }
306 }
307
308 Eina_Bool WindowBaseEcoreWl::OnIconifyStateChanged( void* data, int type, void* event )
309 {
310   Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
311   Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
312
313   if( iconifyChangedEvent->win == static_cast< unsigned int>( ecore_wl_window_id_get( mEcoreWindow ) ) )
314   {
315     if( iconifyChangedEvent->iconified == EINA_TRUE )
316     {
317       mWindow->OnIconifyChanged( true );
318     }
319     else
320     {
321       mWindow->OnIconifyChanged( false );
322     }
323     handled = ECORE_CALLBACK_DONE;
324   }
325
326   return handled;
327 }
328
329 Eina_Bool WindowBaseEcoreWl::OnFocusIn( void* data, int type, void* event )
330 {
331   Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
332
333   if( focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
334   {
335     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
336
337     mWindow->OnFocusChanged( true );
338   }
339
340   return ECORE_CALLBACK_PASS_ON;
341 }
342
343 Eina_Bool WindowBaseEcoreWl::OnFocusOut( void* data, int type, void* event )
344 {
345   Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
346
347   if( focusOutEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( mEcoreWindow ) ) )
348   {
349     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
350
351     mWindow->OnFocusChanged( false );
352   }
353
354   return ECORE_CALLBACK_PASS_ON;
355 }
356
357 Eina_Bool WindowBaseEcoreWl::OnOutputTransform( void* data, int type, void* event )
358 {
359   Ecore_Wl_Event_Output_Transform* transformEvent( static_cast< Ecore_Wl_Event_Output_Transform* >( event ) );
360
361   if( transformEvent->output == ecore_wl_window_output_find( mEcoreWindow ) )
362   {
363     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", mEcoreWindow );
364
365     mWindowSurface->OutputTransformed();
366
367     mWindow->OnOutputTransformed();
368   }
369
370   return ECORE_CALLBACK_PASS_ON;
371 }
372
373 Eina_Bool WindowBaseEcoreWl::OnIgnoreOutputTransform( void* data, int type, void* event )
374 {
375   Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
376
377   if( ignoreTransformEvent->win == mEcoreWindow )
378   {
379     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", mEcoreWindow );
380
381     mWindowSurface->OutputTransformed();
382
383     mWindow->OnOutputTransformed();
384   }
385
386   return ECORE_CALLBACK_PASS_ON;
387 }
388
389 void WindowBaseEcoreWl::RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
390 {
391   if( strcmp( interface, tizen_policy_interface.name ) == 0 )
392   {
393     uint32_t clientVersion = std::min( version, MAX_TIZEN_CLIENT_VERSION );
394
395     mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, clientVersion ) );
396     if( !mTizenPolicy )
397     {
398       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
399       return;
400     }
401
402     tizen_policy_add_listener( mTizenPolicy, &tizenPolicyListener, data );
403
404     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
405   }
406   else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
407   {
408     mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
409     if( !mTizenDisplayPolicy )
410     {
411       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
412       return;
413     }
414
415     tizen_display_policy_add_listener( mTizenDisplayPolicy, &tizenDisplayPolicyListener, data );
416
417     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
418   }
419 }
420
421 void WindowBaseEcoreWl::RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
422 {
423   mTizenPolicy = NULL;
424   mTizenDisplayPolicy = NULL;
425 }
426
427 void WindowBaseEcoreWl::TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
428 {
429   mNotificationLevel = level;
430   mNotificationChangeState = state;
431   mNotificationLevelChangeDone = true;
432
433   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
434 }
435
436 void WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
437 {
438   mScreenOffMode = mode;
439   mScreenOffModeChangeState = state;
440   mScreenOffModeChangeDone = true;
441
442   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
443 }
444
445 void WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone( void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
446 {
447   mBrightness = brightness;
448   mBrightnessChangeState = state;
449   mBrightnessChangeDone = true;
450
451   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "WindowBaseEcoreWl::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
452 }
453
454 void WindowBaseEcoreWl::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
455 {
456   DALI_LOG_TRACE_METHOD_FMT( gWindowBaseLogFilter, "visible : %d\n", visibleMode );
457
458   if( visibleMode == Dali::Window::VISIBLE )
459   {
460     // when the indicator is visible, set proper mode for indicator server according to bg mode
461     if( opacityMode == Dali::Window::OPAQUE )
462     {
463       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_OPAQUE );
464     }
465     else if( opacityMode == Dali::Window::TRANSLUCENT )
466     {
467       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_TRANSLUCENT );
468     }
469     else if( opacityMode == Dali::Window::TRANSPARENT )
470     {
471       ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_OPAQUE );
472     }
473   }
474   else
475   {
476     // when the indicator is not visible, set TRANSPARENT mode for indicator server
477     ecore_wl_window_indicator_opacity_set( mEcoreWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
478   }
479 }
480
481 void WindowBaseEcoreWl::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
482 {
483   if( isShow )
484   {
485     ecore_wl_window_indicator_state_set( mEcoreWindow, ECORE_WL_INDICATOR_STATE_ON );
486   }
487   else
488   {
489     ecore_wl_window_indicator_state_set( mEcoreWindow, ECORE_WL_INDICATOR_STATE_OFF );
490   }
491 }
492
493 void WindowBaseEcoreWl::IndicatorTypeChanged( IndicatorInterface::Type type )
494 {
495 #if defined(DALI_PROFILE_MOBILE)
496   switch( type )
497   {
498     case IndicatorInterface::INDICATOR_TYPE_1:
499     {
500       ecore_wl_indicator_visible_type_set( mEcoreWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN );
501       break;
502     }
503     case IndicatorInterface::INDICATOR_TYPE_2:
504     {
505       ecore_wl_indicator_visible_type_set( mEcoreWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN );
506       break;
507     }
508     case IndicatorInterface::INDICATOR_TYPE_UNKNOWN:
509     default:
510     {
511       break;
512     }
513   }
514 #endif //MOBILE
515 }
516
517 void WindowBaseEcoreWl::SetClass( std::string name, std::string className )
518 {
519   ecore_wl_window_title_set( mEcoreWindow, name.c_str() );
520   ecore_wl_window_class_name_set( mEcoreWindow, className.c_str() );
521 }
522
523 void WindowBaseEcoreWl::Raise()
524 {
525   // Use ecore_wl_window_activate to prevent the window shown without rendering
526   ecore_wl_window_activate( mEcoreWindow );
527 }
528
529 void WindowBaseEcoreWl::Lower()
530 {
531   ecore_wl_window_lower( mEcoreWindow );
532 }
533
534 void WindowBaseEcoreWl::Activate()
535 {
536   ecore_wl_window_activate( mEcoreWindow );
537 }
538
539 void WindowBaseEcoreWl::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
540 {
541   int rotations[4] = { 0 };
542   for( std::size_t i = 0; i < orientations.size(); ++i )
543   {
544     rotations[i] = static_cast< int >( orientations[i] );
545   }
546   ecore_wl_window_rotation_available_rotations_set( mEcoreWindow, rotations, orientations.size() );
547 }
548
549 void WindowBaseEcoreWl::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
550 {
551   ecore_wl_window_rotation_preferred_rotation_set( mEcoreWindow, orientation );
552 }
553
554 void WindowBaseEcoreWl::SetAcceptFocus( bool accept )
555 {
556   ecore_wl_window_focus_skip_set( mEcoreWindow, !accept );
557 }
558
559 void WindowBaseEcoreWl::Show()
560 {
561   ecore_wl_window_show( mEcoreWindow );
562 }
563
564 void WindowBaseEcoreWl::Hide()
565 {
566   ecore_wl_window_hide( mEcoreWindow );
567 }
568
569 unsigned int WindowBaseEcoreWl::GetSupportedAuxiliaryHintCount() const
570 {
571   return mSupportedAuxiliaryHints.size();
572 }
573
574 std::string WindowBaseEcoreWl::GetSupportedAuxiliaryHint( unsigned int index ) const
575 {
576   if( index >= GetSupportedAuxiliaryHintCount() )
577   {
578     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
579   }
580
581   return mSupportedAuxiliaryHints[index];
582 }
583
584 unsigned int WindowBaseEcoreWl::AddAuxiliaryHint( const std::string& hint, const std::string& value )
585 {
586   bool supported = false;
587
588   // Check if the hint is suppported
589   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
590   {
591     if( *iter == hint )
592     {
593       supported = true;
594       break;
595     }
596   }
597
598   if( !supported )
599   {
600     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
601     return 0;
602   }
603
604   // Check if the hint is already added
605   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
606   {
607     if( mAuxiliaryHints[i].first == hint )
608     {
609       // Just change the value
610       mAuxiliaryHints[i].second = value;
611
612       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
613
614       return i + 1;   // id is index + 1
615     }
616   }
617
618   // Add the hint
619   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
620
621   unsigned int id = mAuxiliaryHints.size();
622
623   ecore_wl_window_aux_hint_add( mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
624
625   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
626
627   return id;
628 }
629
630 bool WindowBaseEcoreWl::RemoveAuxiliaryHint( unsigned int id )
631 {
632   if( id == 0 || id > mAuxiliaryHints.size() )
633   {
634     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
635     return false;
636   }
637
638   mAuxiliaryHints[id - 1].second = std::string();
639
640   ecore_wl_window_aux_hint_del( mEcoreWindow, static_cast< int >( id ) );
641
642   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
643
644   return true;
645 }
646
647 bool WindowBaseEcoreWl::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
648 {
649   if( id == 0 || id > mAuxiliaryHints.size() )
650   {
651     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
652     return false;
653   }
654
655   mAuxiliaryHints[id - 1].second = value;
656
657   ecore_wl_window_aux_hint_change( mEcoreWindow, static_cast< int >( id ), value.c_str() );
658
659   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
660
661   return true;
662 }
663
664 std::string WindowBaseEcoreWl::GetAuxiliaryHintValue( unsigned int id ) const
665 {
666   if( id == 0 || id > mAuxiliaryHints.size() )
667   {
668     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Concise, "WindowBaseEcoreWl::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
669     return std::string();
670   }
671
672   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
673
674   return mAuxiliaryHints[id - 1].second;
675 }
676
677 unsigned int WindowBaseEcoreWl::GetAuxiliaryHintId( const std::string& hint ) const
678 {
679   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
680   {
681     if( mAuxiliaryHints[i].first == hint )
682     {
683       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
684       return i + 1;
685     }
686   }
687
688   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
689
690   return 0;
691 }
692
693 void WindowBaseEcoreWl::SetInputRegion( const Rect< int >& inputRegion )
694 {
695   ecore_wl_window_input_region_set( mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
696 }
697
698 void WindowBaseEcoreWl::SetType( Dali::Window::Type type )
699 {
700   Ecore_Wl_Window_Type windowType;
701
702   switch( type )
703   {
704     case Dali::Window::NORMAL:
705     {
706       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
707       break;
708     }
709     case Dali::Window::NOTIFICATION:
710     {
711       windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
712       break;
713     }
714     case Dali::Window::UTILITY:
715     {
716       windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
717       break;
718     }
719     case Dali::Window::DIALOG:
720     {
721       windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
722       break;
723     }
724     default:
725     {
726       windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
727       break;
728     }
729   }
730
731   ecore_wl_window_type_set( mEcoreWindow, windowType );
732 }
733
734 bool WindowBaseEcoreWl::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
735 {
736   while( !mTizenPolicy )
737   {
738     wl_display_dispatch_queue( mDisplay, mEventQueue );
739   }
740
741   int notificationLevel;
742
743   switch( level )
744   {
745     case Dali::Window::NotificationLevel::NONE:
746     {
747       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
748       break;
749     }
750     case Dali::Window::NotificationLevel::BASE:
751     {
752       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
753       break;
754     }
755     case Dali::Window::NotificationLevel::MEDIUM:
756     {
757       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
758       break;
759     }
760     case Dali::Window::NotificationLevel::HIGH:
761     {
762       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
763       break;
764     }
765     case Dali::Window::NotificationLevel::TOP:
766     {
767       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
768       break;
769     }
770     default:
771     {
772       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: invalid level [%d]\n", level );
773       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
774       break;
775     }
776   }
777
778   mNotificationLevelChangeDone = false;
779   mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
780
781   tizen_policy_set_notification_level( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), notificationLevel );
782
783   int count = 0;
784
785   while( !mNotificationLevelChangeDone && count < 3 )
786   {
787     ecore_wl_flush();
788     wl_display_dispatch_queue( mDisplay, mEventQueue );
789     count++;
790   }
791
792   if( !mNotificationLevelChangeDone )
793   {
794     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mNotificationChangeState );
795     return false;
796   }
797   else if( mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
798   {
799     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Permission denied! [%d]\n", level );
800     return false;
801   }
802
803   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetNotificationLevel: Level is changed [%d]\n", mNotificationLevel );
804
805   return true;
806 }
807
808 Dali::Window::NotificationLevel::Type WindowBaseEcoreWl::GetNotificationLevel() const
809 {
810   while( !mTizenPolicy )
811   {
812     wl_display_dispatch_queue( mDisplay, mEventQueue );
813   }
814
815   int count = 0;
816
817   while( !mNotificationLevelChangeDone && count < 3 )
818   {
819     ecore_wl_flush();
820     wl_display_dispatch_queue( mDisplay, mEventQueue );
821     count++;
822   }
823
824   if( !mNotificationLevelChangeDone )
825   {
826     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: Error! [%d]\n", mNotificationChangeState );
827     return Dali::Window::NotificationLevel::NONE;
828   }
829
830   Dali::Window::NotificationLevel::Type level;
831
832   switch( mNotificationLevel )
833   {
834     case TIZEN_POLICY_LEVEL_NONE:
835     {
836       level = Dali::Window::NotificationLevel::NONE;
837       break;
838     }
839     case TIZEN_POLICY_LEVEL_DEFAULT:
840     {
841       level = Dali::Window::NotificationLevel::BASE;
842       break;
843     }
844     case TIZEN_POLICY_LEVEL_MEDIUM:
845     {
846       level = Dali::Window::NotificationLevel::MEDIUM;
847       break;
848     }
849     case TIZEN_POLICY_LEVEL_HIGH:
850     {
851       level = Dali::Window::NotificationLevel::HIGH;
852       break;
853     }
854     case TIZEN_POLICY_LEVEL_TOP:
855     {
856       level = Dali::Window::NotificationLevel::TOP;
857       break;
858     }
859     default:
860     {
861       DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: invalid level [%d]\n", mNotificationLevel );
862       level = Dali::Window::NotificationLevel::NONE;
863       break;
864     }
865   }
866
867   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetNotificationLevel: level [%d]\n", mNotificationLevel );
868
869   return level;
870 }
871
872 void WindowBaseEcoreWl::SetOpaqueState( bool opaque )
873 {
874   while( !mTizenPolicy )
875   {
876     wl_display_dispatch_queue( mDisplay, mEventQueue );
877   }
878
879   tizen_policy_set_opaque_state( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), ( opaque ? 1 : 0 ) );
880 }
881
882 bool WindowBaseEcoreWl::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
883 {
884   while( !mTizenPolicy )
885   {
886     wl_display_dispatch_queue( mDisplay, mEventQueue );
887   }
888
889   mScreenOffModeChangeDone = false;
890   mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
891
892   unsigned int mode = 0;
893
894   switch( screenOffMode )
895   {
896     case Dali::Window::ScreenOffMode::TIMEOUT:
897     {
898       mode = 0;
899       break;
900     }
901     case Dali::Window::ScreenOffMode::NEVER:
902     {
903       mode = 1;
904       break;
905     }
906   }
907
908   tizen_policy_set_window_screen_mode( mTizenPolicy, ecore_wl_window_surface_get( mEcoreWindow ), mode );
909
910   int count = 0;
911
912   while( !mScreenOffModeChangeDone && count < 3 )
913   {
914     ecore_wl_flush();
915     wl_display_dispatch_queue( mDisplay, mEventQueue );
916     count++;
917   }
918
919   if( !mScreenOffModeChangeDone )
920   {
921     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mScreenOffModeChangeState );
922     return false;
923   }
924   else if( mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
925   {
926     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
927     return false;
928   }
929
930   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetScreenOffMode: Screen mode is changed [%d]\n", mScreenOffMode );
931
932   return true;
933 }
934
935 Dali::Window::ScreenOffMode::Type WindowBaseEcoreWl::GetScreenOffMode() const
936 {
937   while( !mTizenPolicy )
938   {
939     wl_display_dispatch_queue( mDisplay, mEventQueue );
940   }
941
942   int count = 0;
943
944   while( !mScreenOffModeChangeDone && count < 3 )
945   {
946     ecore_wl_flush();
947     wl_display_dispatch_queue( mDisplay, mEventQueue );
948     count++;
949   }
950
951   if( !mScreenOffModeChangeDone )
952   {
953     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: Error! [%d]\n", mScreenOffModeChangeState );
954     return Dali::Window::ScreenOffMode::TIMEOUT;
955   }
956
957   Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
958
959   switch( mScreenOffMode )
960   {
961     case 0:
962     {
963       screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
964       break;
965     }
966     case 1:
967     {
968       screenMode = Dali::Window::ScreenOffMode::NEVER;
969       break;
970     }
971   }
972
973   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetScreenOffMode: screen mode [%d]\n", mScreenOffMode );
974
975   return screenMode;
976 }
977
978 bool WindowBaseEcoreWl::SetBrightness( int brightness )
979 {
980   while( !mTizenDisplayPolicy )
981   {
982     wl_display_dispatch_queue( mDisplay, mEventQueue );
983   }
984
985   mBrightnessChangeDone = false;
986   mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
987
988   tizen_display_policy_set_window_brightness( mTizenDisplayPolicy, ecore_wl_window_surface_get( mEcoreWindow ), brightness );
989
990   int count = 0;
991
992   while( !mBrightnessChangeDone && count < 3 )
993   {
994     ecore_wl_flush();
995     wl_display_dispatch_queue( mDisplay, mEventQueue );
996     count++;
997   }
998
999   if( !mBrightnessChangeDone )
1000   {
1001     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mBrightnessChangeState );
1002     return false;
1003   }
1004   else if( mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1005   {
1006     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Permission denied! [%d]\n", brightness );
1007     return false;
1008   }
1009
1010   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::SetBrightness: Brightness is changed [%d]\n", mBrightness );
1011
1012   return true;
1013 }
1014
1015 int WindowBaseEcoreWl::GetBrightness() const
1016 {
1017   while( !mTizenDisplayPolicy )
1018   {
1019     wl_display_dispatch_queue( mDisplay, mEventQueue );
1020   }
1021
1022   int count = 0;
1023
1024   while( !mBrightnessChangeDone && count < 3 )
1025   {
1026     ecore_wl_flush();
1027     wl_display_dispatch_queue( mDisplay, mEventQueue );
1028     count++;
1029   }
1030
1031   if( !mBrightnessChangeDone )
1032   {
1033     DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Error! [%d]\n", mBrightnessChangeState );
1034     return 0;
1035   }
1036
1037   DALI_LOG_INFO( gWindowBaseLogFilter, Debug::Verbose, "WindowBaseEcoreWl::GetBrightness: Brightness [%d]\n", mBrightness );
1038
1039   return mBrightness;
1040 }
1041
1042 } // namespace Adaptor
1043
1044 } // namespace Internal
1045
1046 } // namespace Dali
1047
1048 #pragma GCC diagnostic pop