Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / tizen-wayland / ecore-wl2 / window-system-ecore-wl2.cpp
1 /*
2  * Copyright (c) 2023 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 // EXTERNAL_HEADERS
19 #include <Ecore_Wl2.h>
20 #include <dali/integration-api/adaptor-framework/adaptor.h>
21 #include <dali/integration-api/adaptor-framework/scene-holder.h>
22 #include <dali/integration-api/debug.h>
23
24 // INTERNAL HEADERS
25 #include <dali/devel-api/adaptor-framework/keyboard.h>
26 #include <dali/internal/adaptor/common/framework-factory.h>
27 #include <dali/internal/system/common/time-service.h>
28 #include <dali/internal/window-system/common/window-system.h>
29
30 #define START_DURATION_CHECK()                               \
31   uint32_t durationMilliSeconds = static_cast<uint32_t>(-1); \
32   uint32_t startTime, endTime;                               \
33   startTime = TimeService::GetMilliSeconds();
34
35 #define FINISH_DURATION_CHECK(functionName)                                             \
36   endTime              = TimeService::GetMilliSeconds();                                \
37   durationMilliSeconds = endTime - startTime;                                           \
38   if(durationMilliSeconds > 0)                                                          \
39   {                                                                                     \
40     DALI_LOG_DEBUG_INFO("%s : duration [%u ms]\n", functionName, durationMilliSeconds); \
41   }
42
43 namespace Dali
44 {
45 namespace Internal
46 {
47 namespace Adaptor
48 {
49 namespace WindowSystem
50 {
51 namespace
52 {
53 static int32_t gScreenWidth     = 0;
54 static int32_t gScreenHeight    = 0;
55 static bool    gGeometryHittest = false;
56 } // unnamed namespace
57
58 void Initialize()
59 {
60   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
61   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
62   {
63     ecore_wl2_init();
64   }
65 }
66
67 void Shutdown()
68 {
69   auto backend = Dali::Internal::Adaptor::GetFrameworkFactory()->GetFrameworkBackend();
70   if(backend == FrameworkBackend::DEFAULT)
71   {
72     ecore_wl2_shutdown();
73   }
74 }
75
76 void GetScreenSize(int32_t& width, int32_t& height)
77 {
78   auto backend = Dali::Internal::Adaptor::GetFrameworkFactory()->GetFrameworkBackend();
79   if(backend == FrameworkBackend::DEFAULT)
80   {
81     if(gScreenWidth == 0 || gScreenHeight == 0)
82     {
83       Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
84       if(display)
85       {
86         START_DURATION_CHECK();
87         ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight);
88         FINISH_DURATION_CHECK("ecore_wl2_display_screen_size_get");
89
90         DALI_ASSERT_ALWAYS((gScreenWidth > 0) && "screen width is 0");
91         DALI_ASSERT_ALWAYS((gScreenHeight > 0) && "screen height is 0");
92       }
93     }
94   }
95   width  = gScreenWidth;
96   height = gScreenHeight;
97 }
98
99 void UpdateScreenSize()
100 {
101   auto backend = Dali::Internal::Adaptor::GetFrameworkFactory()->GetFrameworkBackend();
102   if(backend == FrameworkBackend::DEFAULT)
103   {
104     Ecore_Wl2_Display* display = ecore_wl2_display_connect(NULL);
105     if(display)
106     {
107       START_DURATION_CHECK();
108       ecore_wl2_display_screen_size_get(display, &gScreenWidth, &gScreenHeight);
109       FINISH_DURATION_CHECK("ecore_wl2_display_screen_size_get");
110     }
111   }
112 }
113
114 bool SetKeyboardRepeatInfo(float rate, float delay)
115 {
116   auto backend = Dali::Internal::Adaptor::GetFrameworkFactory()->GetFrameworkBackend();
117   if(backend == FrameworkBackend::DEFAULT)
118   {
119     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
120     return ecore_wl2_input_keyboard_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
121   }
122   return false;
123 }
124
125 bool GetKeyboardRepeatInfo(float& rate, float& delay)
126 {
127   auto backend = Dali::Internal::Adaptor::GetFrameworkFactory()->GetFrameworkBackend();
128   if(backend == FrameworkBackend::DEFAULT)
129   {
130     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
131     double           rateVal, delayVal;
132     bool             ret = ecore_wl2_input_keyboard_repeat_get(input, &rateVal, &delayVal);
133     rate                 = static_cast<float>(rateVal);
134     delay                = static_cast<float>(delayVal);
135
136     return ret;
137   }
138   return false;
139 }
140
141 bool SetKeyboardHorizontalRepeatInfo(float rate, float delay)
142 {
143 #ifdef OVER_TIZEN_VERSION_8
144   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
145   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
146   {
147     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
148     return ecore_wl2_input_keyboard_horizontal_way_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
149   }
150   return false;
151 #else
152   return SetKeyboardRepeatInfo(rate, delay);
153 #endif
154 }
155
156 bool GetKeyboardHorizontalRepeatInfo(float& rate, float& delay)
157 {
158 #ifdef OVER_TIZEN_VERSION_8
159   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
160   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
161   {
162     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
163     double           rateVal, delayVal;
164     bool             ret = ecore_wl2_input_keyboard_horizontal_way_repeat_get(input, &rateVal, &delayVal);
165     rate                 = static_cast<float>(rateVal);
166     delay                = static_cast<float>(delayVal);
167
168     return ret;
169   }
170   return false;
171 #else
172   return GetKeyboardRepeatInfo(rate, delay);
173 #endif
174 }
175
176 bool SetKeyboardVerticalRepeatInfo(float rate, float delay)
177 {
178 #ifdef OVER_TIZEN_VERSION_8
179   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
180   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
181   {
182     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
183     return ecore_wl2_input_keyboard_vertical_way_repeat_set(input, static_cast<double>(rate), static_cast<double>(delay));
184   }
185   return false;
186 #else
187   return SetKeyboardRepeatInfo(rate, delay);
188 #endif
189 }
190
191 bool GetKeyboardVerticalRepeatInfo(float& rate, float& delay)
192 {
193 #ifdef OVER_TIZEN_VERSION_8
194   auto frameworkFactory = Dali::Internal::Adaptor::GetFrameworkFactory();
195   if(frameworkFactory == nullptr || (frameworkFactory && frameworkFactory->GetFrameworkBackend() == FrameworkBackend::DEFAULT))
196   {
197     Ecore_Wl2_Input* input = ecore_wl2_input_default_input_get(ecore_wl2_connected_display_get(NULL));
198     double           rateVal, delayVal;
199     bool             ret = ecore_wl2_input_keyboard_vertical_way_repeat_get(input, &rateVal, &delayVal);
200     rate                 = static_cast<float>(rateVal);
201     delay                = static_cast<float>(delayVal);
202
203     return ret;
204   }
205   return false;
206 #else
207   return GetKeyboardRepeatInfo(rate, delay);
208 #endif
209 }
210
211 void SetGeometryHittestEnabled(bool enable)
212 {
213   DALI_LOG_RELEASE_INFO("GeometryHittest : %d \n", enable);
214   gGeometryHittest = enable;
215   if(gGeometryHittest)
216   {
217     Dali::SceneHolderList sceneHolders = Dali::Adaptor::Get().GetSceneHolders();
218     for(auto iter = sceneHolders.begin(); iter != sceneHolders.end(); ++iter)
219     {
220       if(*iter)
221       {
222         (*iter).SetGeometryHittestEnabled(enable);
223       }
224     }
225   }
226 }
227
228 bool IsGeometryHittestEnabled()
229 {
230   return gGeometryHittest;
231 }
232
233 } // namespace WindowSystem
234
235 } // namespace Adaptor
236
237 } // namespace Internal
238
239 } // namespace Dali
240
241 #pragma GCC diagnostic pop