Merge "Move key grab implementation to window" into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / internal / window-system / ubuntu-x11 / window-base-ecore-x.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/ubuntu-x11/window-base-ecore-x.h>
24
25 // INTERNAL HEADERS
26 #include <dali/internal/window-system/common/window-impl.h>
27 #include <dali/internal/window-system/ubuntu-x11/window-render-surface-ecore-x.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 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
50 {
51   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
52   if( windowBase )
53   {
54     return windowBase->OnWindowPropertyChanged( data, type, event );
55   }
56
57   return ECORE_CALLBACK_PASS_ON;
58 }
59
60 /// Called when the window receives a delete request
61 static Eina_Bool EcoreEventWindowDeleteRequest( void* data, int type, void* event )
62 {
63   WindowBaseEcoreX* windowBase = static_cast< WindowBaseEcoreX* >( data );
64   if( windowBase )
65   {
66     windowBase->OnDeleteRequest();
67   }
68   return ECORE_CALLBACK_DONE;
69 }
70
71 } // unnamed namespace
72
73 WindowBaseEcoreX::WindowBaseEcoreX( Window* window, WindowRenderSurface* windowRenderSurface )
74 : mEcoreEventHandler(),
75   mWindow( window ),
76   mWindowSurface( NULL ),
77   mEcoreWindow( 0 ),
78   mRotationAppSet( false )
79 {
80   mWindowSurface = dynamic_cast< WindowRenderSurfaceEcoreX* >( windowRenderSurface );
81 }
82
83 WindowBaseEcoreX::~WindowBaseEcoreX()
84 {
85   for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
86   {
87     ecore_event_handler_del( *iter );
88   }
89   mEcoreEventHandler.Clear();
90 }
91
92 void WindowBaseEcoreX::Initialize()
93 {
94   if( !mWindowSurface )
95   {
96     DALI_ASSERT_ALWAYS( "Invalid window surface" );
97   }
98
99   mEcoreWindow = mWindowSurface->GetXWindow();
100   DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no EcoreX window" );
101
102   ecore_x_input_multi_select( mEcoreWindow );
103
104   // This ensures that we catch the window close (or delete) request
105   ecore_x_icccm_protocol_set( mEcoreWindow, ECORE_X_WM_PROTOCOL_DELETE_REQUEST, EINA_TRUE );
106
107   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_PROPERTY, EcoreEventWindowPropertyChanged, this ) );
108   mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DELETE_REQUEST, EcoreEventWindowDeleteRequest, this ) );
109 }
110
111 Eina_Bool WindowBaseEcoreX::OnWindowPropertyChanged( void* data, int type, void* event )
112 {
113   Ecore_X_Event_Window_Property* propertyChangedEvent = static_cast< Ecore_X_Event_Window_Property* >( event );
114   Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
115
116   if( propertyChangedEvent->win == mEcoreWindow )
117   {
118     Ecore_X_Window_State_Hint state( ecore_x_icccm_state_get( propertyChangedEvent->win ) );
119
120     switch( state )
121     {
122       case ECORE_X_WINDOW_STATE_HINT_WITHDRAWN:
123       {
124         // Window was hidden.
125         mWindow->OnIconifyChanged( true );
126         DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%d) Withdrawn\n", mWindow );
127         handled = ECORE_CALLBACK_DONE;
128         break;
129       }
130       case ECORE_X_WINDOW_STATE_HINT_ICONIC:
131       {
132         // Window was iconified (minimised).
133         mWindow->OnIconifyChanged( true );
134         DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%d) Iconfied\n", mWindow );
135         handled = ECORE_CALLBACK_DONE;
136         break;
137       }
138       case ECORE_X_WINDOW_STATE_HINT_NORMAL:
139       {
140         // Window was shown.
141         mWindow->OnIconifyChanged( false );
142         DALI_LOG_INFO( gWindowBaseLogFilter, Debug::General, "Window (%d) Shown\n", mWindow );
143         handled = ECORE_CALLBACK_DONE;
144         break;
145       }
146       default:
147       {
148         // Ignore
149         break;
150       }
151     }
152   }
153
154   return handled;
155 }
156
157 void WindowBaseEcoreX::OnDeleteRequest()
158 {
159   mWindow->OnDeleteRequest();
160 }
161
162 void WindowBaseEcoreX::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode, Dali::Window::IndicatorBgOpacity opacityMode )
163 {
164   DALI_LOG_TRACE_METHOD_FMT( gWindowBaseLogFilter, "visible : %d\n", visibleMode );
165
166   if( visibleMode == Dali::Window::VISIBLE )
167   {
168     // when the indicator is visible, set proper mode for indicator server according to bg mode
169     if( opacityMode == Dali::Window::OPAQUE )
170     {
171       ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_OPAQUE );
172     }
173     else if( opacityMode == Dali::Window::TRANSLUCENT )
174     {
175       ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT );
176     }
177 #if defined (DALI_PROFILE_MOBILE)
178     else if( opacityMode == Dali::Window::TRANSPARENT )
179     {
180       ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_OPAQUE );
181     }
182 #endif
183   }
184   else
185   {
186     // when the indicator is not visible, set TRANSPARENT mode for indicator server
187     ecore_x_e_illume_indicator_opacity_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_TRANSPARENT ); // it means hidden indicator
188   }
189 }
190
191 void WindowBaseEcoreX::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
192 {
193   int show_state = static_cast< int >( isShow );
194   ecore_x_window_prop_property_set( mEcoreWindow, ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE,
195                                     ECORE_X_ATOM_CARDINAL, 32, &show_state, 1 );
196
197   if( isShow )
198   {
199     ecore_x_e_illume_indicator_state_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_STATE_ON );
200   }
201   else
202   {
203     ecore_x_e_illume_indicator_state_set( mEcoreWindow, ECORE_X_ILLUME_INDICATOR_STATE_OFF );
204   }
205 }
206
207 void WindowBaseEcoreX::IndicatorTypeChanged( IndicatorInterface::Type type )
208 {
209 }
210
211 void WindowBaseEcoreX::SetClass( std::string name, std::string className )
212 {
213   ecore_x_icccm_name_class_set( mEcoreWindow, name.c_str(), className.c_str() );
214 }
215
216 void WindowBaseEcoreX::Raise()
217 {
218   ecore_x_window_raise( mEcoreWindow );
219 }
220
221 void WindowBaseEcoreX::Lower()
222 {
223   ecore_x_window_lower( mEcoreWindow );
224 }
225
226 void WindowBaseEcoreX::Activate()
227 {
228   ecore_x_netwm_client_active_request( ecore_x_window_root_get( mEcoreWindow ), mEcoreWindow, 1 /* request type, 1:application, 2:pager */, 0 );
229 }
230
231 void WindowBaseEcoreX::SetAvailableOrientations( const std::vector< Dali::Window::WindowOrientation >& orientations )
232 {
233 }
234
235 void WindowBaseEcoreX::SetPreferredOrientation( Dali::Window::WindowOrientation orientation )
236 {
237 }
238
239 void WindowBaseEcoreX::SetAcceptFocus( bool accept )
240 {
241 }
242
243 void WindowBaseEcoreX::Show()
244 {
245   ecore_x_window_show( mEcoreWindow );
246 }
247
248 void WindowBaseEcoreX::Hide()
249 {
250   ecore_x_window_hide( mEcoreWindow );
251 }
252
253 unsigned int WindowBaseEcoreX::GetSupportedAuxiliaryHintCount() const
254 {
255   return 0;
256 }
257
258 std::string WindowBaseEcoreX::GetSupportedAuxiliaryHint( unsigned int index ) const
259 {
260   return std::string();
261 }
262
263 unsigned int WindowBaseEcoreX::AddAuxiliaryHint( const std::string& hint, const std::string& value )
264 {
265   return 0;
266 }
267
268 bool WindowBaseEcoreX::RemoveAuxiliaryHint( unsigned int id )
269 {
270   return false;
271 }
272
273 bool WindowBaseEcoreX::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
274 {
275   return false;
276 }
277
278 std::string WindowBaseEcoreX::GetAuxiliaryHintValue( unsigned int id ) const
279 {
280   return std::string();
281 }
282
283 unsigned int WindowBaseEcoreX::GetAuxiliaryHintId( const std::string& hint ) const
284 {
285   return 0;
286 }
287
288 void WindowBaseEcoreX::SetInputRegion( const Rect< int >& inputRegion )
289 {
290 }
291
292 void WindowBaseEcoreX::SetType( Dali::Window::Type type )
293 {
294 }
295
296 bool WindowBaseEcoreX::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
297 {
298   return false;
299 }
300
301 Dali::Window::NotificationLevel::Type WindowBaseEcoreX::GetNotificationLevel() const
302 {
303   return Dali::Window::NotificationLevel::NONE;
304 }
305
306 void WindowBaseEcoreX::SetOpaqueState( bool opaque )
307 {
308 }
309
310 bool WindowBaseEcoreX::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
311 {
312   return false;
313 }
314
315 Dali::Window::ScreenOffMode::Type WindowBaseEcoreX::GetScreenOffMode() const
316 {
317   return Dali::Window::ScreenOffMode::TIMEOUT;
318 }
319
320 bool WindowBaseEcoreX::SetBrightness( int brightness )
321 {
322   return false;
323 }
324
325 int WindowBaseEcoreX::GetBrightness() const
326 {
327   return 0;
328 }
329
330 bool WindowBaseEcoreX::GrabKey( Dali::KEY key, KeyGrab::KeyGrabMode grabMode )
331 {
332   return false;
333 }
334
335 bool WindowBaseEcoreX::UngrabKey( Dali::KEY key )
336 {
337   return false;
338 }
339
340 bool WindowBaseEcoreX::GrabKeyList( const Dali::Vector< Dali::KEY >& key, const Dali::Vector< KeyGrab::KeyGrabMode >& grabMode, Dali::Vector< bool >& result )
341 {
342   return false;
343 }
344
345 bool WindowBaseEcoreX::UngrabKeyList( const Dali::Vector< Dali::KEY >& key, Dali::Vector< bool >& result )
346 {
347   return false;
348 }
349
350 } // namespace Adaptor
351
352 } // namespace Internal
353
354 } // namespace Dali
355
356 #pragma GCC diagnostic pop