[dali_2.3.22] Merge branch 'devel/master'
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor / tizen-wayland / adaptor-impl-tizen.cpp
1 /*
2  * Copyright (c) 2021 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 <dali/internal/adaptor/tizen-wayland/dali-ecore-wl2.h>
31 #else
32 #include <dali/internal/adaptor/tizen-wayland/dali-ecore-wayland.h>
33 #endif
34
35 #include <aul.h>
36 #include <unistd.h>
37
38 // INTERNAL INCLUDES
39 #include <dali/devel-api/text-abstraction/font-client.h>
40
41 namespace Dali
42 {
43 namespace Internal
44 {
45 namespace Adaptor
46 {
47 namespace
48 {
49 static void OnSystemLanguageChanged(system_settings_key_e key, void* data)
50 {
51   char* locale = NULL;
52   if(system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale) != SYSTEM_SETTINGS_ERROR_NONE ||
53      locale == NULL)
54   {
55     DALI_LOG_ERROR("DALI OnSystemLanguageChanged failed ");
56     return;
57   }
58
59   Adaptor* adaptor = static_cast<Adaptor*>(data);
60   if(adaptor != NULL)
61   {
62     TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
63     fontClient.ClearCacheOnLocaleChanged();
64     fontClient.InitDefaultFontDescription();
65
66     adaptor->SetRootLayoutDirection(locale);
67     adaptor->LocaleChangedSignal().Emit(locale);
68   }
69
70   free(locale);
71 }
72
73 } // namespace
74
75 std::string Adaptor::GetApplicationPackageName()
76 {
77   char appname[4096] = {0};
78   int  pid           = getpid();
79   aul_app_get_pkgname_bypid(pid, appname, sizeof(appname));
80   return appname;
81 }
82
83 void Adaptor::GetResourceStoragePath(std::string& path)
84 {
85 #ifdef USE_APPFW
86   char* pathInt = app_get_resource_path();
87   if(pathInt)
88   {
89     path = pathInt;
90     free(pathInt);
91   }
92   else
93   {
94     path = "";
95   }
96 #endif
97 }
98
99 void Adaptor::GetDataStoragePath(std::string& path)
100 {
101 #ifdef USE_APPFW
102   char* pathInt = app_get_data_path();
103   if(pathInt)
104   {
105     path = pathInt;
106     free(pathInt);
107   }
108   else
109   {
110     path = "";
111   }
112 #endif
113 }
114
115 void Adaptor::GetAppId(std::string& appId)
116 {
117 #ifdef USE_APPFW
118   char* id;
119   app_get_id(&id);
120   if(id)
121   {
122     appId = id;
123     free(id);
124   }
125   else
126   {
127     appId = "";
128   }
129 #endif
130 }
131
132 void Adaptor::SurfaceInitialized()
133 {
134 #ifdef APPCORE_WATCH_AVAILABLE
135   if(!mUseRemoteSurface)
136   {
137     return;
138   }
139   char* appId;
140   app_get_id(&appId);
141
142   // Use strdup() in app_get_id(), so need to free memory
143   if(appId)
144   {
145 #ifdef ECORE_WAYLAND2
146     Ecore_Wl2_Window* ecoreWlWindow = AnyCast<Ecore_Wl2_Window*>(mWindows.front()->GetNativeHandle());
147     screen_connector_provider_remote_enable(appId, ecore_wl2_window_surface_get(ecoreWlWindow));
148 #else
149     Ecore_Wl_Window* ecoreWlWindow = AnyCast<Ecore_Wl_Window*>(mWindows.front()->GetNativeHandle());
150     screen_connector_provider_remote_enable(appId, ecore_wl_window_surface_get(ecoreWlWindow));
151 #endif
152     free(appId);
153   }
154 #endif
155 }
156
157 void Adaptor::SetupSystemInformation()
158 {
159   if(system_settings_add_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged, this) != SYSTEM_SETTINGS_ERROR_NONE)
160   {
161     DALI_LOG_ERROR("DALI system_settings_add_changed_cb failed.\n");
162     return;
163   }
164
165   char* locale = NULL;
166   if(system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale) != SYSTEM_SETTINGS_ERROR_NONE ||
167      locale == NULL)
168   {
169     DALI_LOG_ERROR("DALI OnSystemLanguageChanged failed ");
170     return;
171   }
172
173   SetRootLayoutDirection(locale);
174
175   free(locale);
176 }
177
178 void Adaptor::RemoveSystemInformation()
179 {
180   if(system_settings_remove_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, OnSystemLanguageChanged) != SYSTEM_SETTINGS_ERROR_NONE)
181   {
182     DALI_LOG_ERROR("DALI system_settings_remove_changed_cb failed.\n");
183     return;
184   }
185 }
186
187 } // namespace Adaptor
188
189 } // namespace Internal
190
191 } // namespace Dali