[Tizen] Support Ecore-Wayland2
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen / adaptor-impl-tizen.cpp
1 /*
2  * Copyright (c) 2014 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 // CLASS HEADER
19 #include <dali/internal/adaptor/common/adaptor-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <app_common.h>
23 #include <system_settings.h>
24
25 #ifdef APPCORE_WATCH_AVAILABLE
26 #include <screen_connector_provider.h>
27 #endif
28
29 #ifdef ECORE_WAYLAND2
30 #include <Ecore_Wl2.h>
31 #else
32 #include <Ecore_Wayland.h>
33 #endif
34
35
36 namespace Dali
37 {
38
39 namespace Internal
40 {
41
42 namespace Adaptor
43 {
44
45 namespace
46 {
47
48 static void OnSystemLanguageChanged( system_settings_key_e key, void* data )
49 {
50   char* locale = NULL;
51   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
52       locale == NULL )
53   {
54     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
55     return;
56   }
57
58   Adaptor* adaptor = static_cast< Adaptor* >( data );
59   if( adaptor != NULL )
60   {
61     adaptor->SetRootLayoutDirection( locale );
62   }
63
64   free( locale );
65 }
66
67 } // namesapce
68
69 void Adaptor::GetDataStoragePath( std::string& path)
70 {
71 #ifdef USE_APPFW
72   char *pathInt = app_get_data_path();
73   if ( pathInt )
74   {
75     path = pathInt;
76     free( pathInt );
77   }
78   else
79   {
80     path = "";
81   }
82 #endif
83
84 }
85
86 void Adaptor::GetAppId( std::string& appId )
87 {
88 #ifdef USE_APPFW
89   char *id;
90   app_get_id(&id);
91   if ( id )
92   {
93     appId = id;
94   }
95   else
96   {
97     appId = "";
98   }
99 #endif
100 }
101
102 void Adaptor::SurfaceInitialized()
103 {
104 #ifdef APPCORE_WATCH_AVAILABLE
105   if ( !mUseRemoteSurface )
106   {
107     return;
108   }
109   char *appId;
110   app_get_id(&appId);
111
112   // Use strdup() in app_get_id(), so need to free memory
113   if( appId )
114   {
115 #ifdef ECORE_WAYLAND2
116     Ecore_Wl2_Window* ecoreWlWindow = AnyCast<Ecore_Wl2_Window*>( mNativeWindow );
117     screen_connector_provider_remote_enable( appId, ecore_wl2_window_surface_get( ecoreWlWindow ) );
118 #else
119     Ecore_Wl_Window* ecoreWlWindow = AnyCast<Ecore_Wl_Window*>( mNativeWindow );
120     screen_connector_provider_remote_enable( appId, ecore_wl_window_surface_get( ecoreWlWindow ) );
121 #endif
122     free( appId );
123   }
124 #endif
125 }
126
127 void Adaptor::SetupSystemInformation()
128 {
129   if( system_settings_set_changed_cb( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this ) != SYSTEM_SETTINGS_ERROR_NONE )
130   {
131     DALI_LOG_ERROR( "DALI system_settings_set_changed_cb failed.\n" );
132     return;
133   }
134
135   char* locale = NULL;
136   if( system_settings_get_value_string( SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale ) != SYSTEM_SETTINGS_ERROR_NONE ||
137       locale == NULL )
138   {
139     DALI_LOG_ERROR( "DALI OnSystemLanguageChanged failed " );
140     return;
141   }
142
143   SetRootLayoutDirection( locale );
144
145   free( locale );
146
147 }
148
149 } // namespace Adaptor
150
151 } // namespace Internal
152
153 } // namespace Dali