Revert "[3.0] Implement wayland specfic indicator, window appId, ..."
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / window-impl-ecore-wl.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 "window-impl.h"
20
21 // EXTERNAL HEADERS
22 #include <Ecore.h>
23 #include <Ecore_Wayland.h>
24
25 #include <dali/integration-api/core.h>
26 #include <dali/integration-api/system-overlay.h>
27 #include <dali/public-api/render-tasks/render-task.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <orientation.h>
30
31 // INTERNAL HEADERS
32 #include <window-render-surface.h>
33 #include <drag-and-drop-detector-impl.h>
34 #include <ecore-indicator-impl.h>
35 #include <window-visibility-observer.h>
36 #include <orientation-impl.h>
37
38 namespace
39 {
40 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
41 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
42 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
43 }
44
45 namespace Dali
46 {
47 namespace Internal
48 {
49 namespace Adaptor
50 {
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
53 #endif
54
55 /**
56  * TODO: Abstract Window class out and move this into a window implementation for Ecore
57  */
58 struct Window::EventHandler
59 {
60   /**
61    * Constructor
62    * @param[in]  window  A pointer to the window class.
63    */
64   EventHandler( Window* window )
65   : mWindow( window ),
66     mWindowPropertyHandler( NULL ),
67     mClientMessageHandler( NULL ),
68     mEcoreWindow( 0 )
69   {
70     // store ecore window handle
71     ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
72     if( wlWindow )
73     {
74       mEcoreWindow = wlWindow->GetWlWindow();
75     }
76     DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
77   }
78
79   /**
80    * Destructor
81    */
82   ~EventHandler()
83   {
84     if ( mWindowPropertyHandler )
85     {
86       ecore_event_handler_del( mWindowPropertyHandler );
87     }
88     if ( mClientMessageHandler )
89     {
90       ecore_event_handler_del( mClientMessageHandler );
91     }
92   }
93
94   // Static methods
95
96   /// Called when the window properties are changed.
97   static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
98   {
99     return EINA_FALSE;
100   }
101
102   /// Called when the window properties are changed.
103   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
104   {
105     return EINA_FALSE;
106   }
107
108   // Data
109   Window* mWindow;
110   Ecore_Event_Handler* mWindowPropertyHandler;
111   Ecore_Event_Handler* mClientMessageHandler;
112   Ecore_Wl_Window* mEcoreWindow;
113 };
114
115
116 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
117 {
118   Window* window = new Window();
119   window->mIsTransparent = isTransparent;
120   window->Initialize(posSize, name, className);
121   return window;
122 }
123
124 void Window::SetAdaptor(Dali::Adaptor& adaptor)
125 {
126   DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
127   mStarted = true;
128
129   // Only create one overlay per window
130   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
131   Integration::Core& core = adaptorImpl.GetCore();
132   mOverlay = &core.GetSystemOverlay();
133
134   Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
135   taskList.CreateTask();
136
137   mAdaptor = &adaptorImpl;
138   mAdaptor->AddObserver( *this );
139
140   // Can only create the detector when we know the Core has been instantiated.
141   mDragAndDropDetector = DragAndDropDetector::New();
142   mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
143
144   if( mOrientation )
145   {
146     mOrientation->SetAdaptor(adaptor);
147   }
148
149   if( mIndicator != NULL )
150   {
151     mIndicator->SetAdaptor(mAdaptor);
152   }
153 }
154
155 RenderSurface* Window::GetSurface()
156 {
157   return mSurface;
158 }
159
160 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
161 {
162   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
163   DALI_ASSERT_DEBUG(mOverlay);
164
165   DoShowIndicator( mIndicatorOrientation );
166 }
167
168 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
169 {
170   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
171
172   DoRotateIndicator( orientation );
173 }
174
175 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
176 {
177   mIndicatorOpacityMode = opacityMode;
178
179   if( mIndicator != NULL )
180   {
181     mIndicator->SetOpacityMode( opacityMode );
182   }
183 }
184
185 void Window::SetClass(std::string name, std::string klass)
186 {
187 }
188
189 Window::Window()
190 : mSurface(NULL),
191   mIndicatorVisible(Dali::Window::VISIBLE),
192   mIndicatorIsShown(false),
193   mShowRotatedIndicatorOnClose(false),
194   mStarted(false),
195   mIsTransparent(false),
196   mWMRotationAppSet(false),
197   mIndicator(NULL),
198   mIndicatorOrientation(Dali::Window::PORTRAIT),
199   mNextIndicatorOrientation(Dali::Window::PORTRAIT),
200   mIndicatorOpacityMode(Dali::Window::OPAQUE),
201   mOverlay(NULL),
202   mAdaptor(NULL),
203   mEventHandler(NULL),
204   mPreferredOrientation(Dali::Window::PORTRAIT)
205 {
206 }
207
208 Window::~Window()
209 {
210   delete mEventHandler;
211
212   if( mIndicator )
213   {
214     mIndicator->Close();
215     delete mIndicator;
216   }
217
218   if ( mAdaptor )
219   {
220     mAdaptor->RemoveObserver( *this );
221     mAdaptor->SetDragAndDropDetector( NULL );
222     mAdaptor = NULL;
223   }
224
225   delete mSurface;
226 }
227
228 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
229 {
230   // create an Wayland window by default
231   Any surface;
232   ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
233   SetClass( name, className );
234   windowSurface->Map();
235
236   mSurface = windowSurface;
237
238   mOrientation = Orientation::New(this);
239
240   // create event handler for Wayland window
241   mEventHandler = new EventHandler( this );
242 }
243
244 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
245 {
246   if( mIndicator == NULL )
247   {
248     if( mIndicatorVisible != Dali::Window::INVISIBLE )
249     {
250       mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
251       mIndicator->SetOpacityMode( mIndicatorOpacityMode );
252       Dali::Actor actor = mIndicator->GetActor();
253       SetIndicatorActorRotation();
254       mOverlay->Add(actor);
255     }
256     // else don't create a hidden indicator
257   }
258   else // Already have indicator
259   {
260     if( mIndicatorVisible == Dali::Window::VISIBLE )
261     {
262       // If we are resuming, and rotation has changed,
263       if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
264       {
265         // then close current indicator and open new one
266         mShowRotatedIndicatorOnClose = true;
267         mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
268         // Don't show actor - will contain indicator for old orientation.
269       }
270     }
271   }
272
273   // set indicator visible mode
274   if( mIndicator != NULL )
275   {
276     mIndicator->SetVisible( mIndicatorVisible );
277   }
278
279   bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
280   SetIndicatorProperties( show, lastOrientation );
281   mIndicatorIsShown = show;
282 }
283
284 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
285 {
286   if( mIndicatorIsShown )
287   {
288     mShowRotatedIndicatorOnClose = true;
289     mNextIndicatorOrientation = orientation;
290     mIndicator->Close(); // May synchronously call IndicatorClosed() callback
291   }
292   else
293   {
294     // Save orientation for when the indicator is next shown
295     mShowRotatedIndicatorOnClose = false;
296     mNextIndicatorOrientation = orientation;
297   }
298 }
299
300 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
301 {
302 }
303
304 void Window::IndicatorTypeChanged(Indicator::Type type)
305 {
306 }
307
308 void Window::IndicatorClosed( IndicatorInterface* indicator )
309 {
310   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
311
312   if( mShowRotatedIndicatorOnClose )
313   {
314     Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
315     mIndicator->Open(mNextIndicatorOrientation);
316     mIndicatorOrientation = mNextIndicatorOrientation;
317     SetIndicatorActorRotation();
318     DoShowIndicator(currentOrientation);
319   }
320 }
321
322 void Window::IndicatorVisibilityChanged(bool isVisible)
323 {
324   mIndicatorVisibilityChangedSignal.Emit(isVisible);
325 }
326
327 void Window::SetIndicatorActorRotation()
328 {
329   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
330   DALI_ASSERT_DEBUG( mIndicator != NULL );
331
332   Dali::Actor actor = mIndicator->GetActor();
333   switch( mIndicatorOrientation )
334   {
335     case Dali::Window::PORTRAIT:
336       actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
337       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
338       actor.SetOrientation( Degree(0), Vector3::ZAXIS );
339       break;
340     case Dali::Window::PORTRAIT_INVERSE:
341       actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
342       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
343       actor.SetOrientation( Degree(180), Vector3::ZAXIS );
344       break;
345     case Dali::Window::LANDSCAPE:
346       actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
347       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
348       actor.SetOrientation( Degree(270), Vector3::ZAXIS );
349       break;
350     case Dali::Window::LANDSCAPE_INVERSE:
351       actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
352       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
353       actor.SetOrientation( Degree(90), Vector3::ZAXIS );
354       break;
355   }
356 }
357
358 void Window::Raise()
359 {
360 }
361
362 void Window::Lower()
363 {
364 }
365
366 void Window::Activate()
367 {
368 }
369
370 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
371 {
372   return mDragAndDropDetector;
373 }
374
375 Dali::Any Window::GetNativeHandle() const
376 {
377   if(mEventHandler)
378   {
379     return mEventHandler->mEcoreWindow;
380   }
381   else
382   {
383     return Dali::Any();
384   }
385 }
386
387 void Window::OnStart()
388 {
389   DoShowIndicator( mIndicatorOrientation );
390 }
391
392 void Window::OnPause()
393 {
394 }
395
396 void Window::OnResume()
397 {
398   // resume indicator status
399   if( mIndicator != NULL )
400   {
401     // Restore own indicator opacity
402     // Send opacity mode to indicator service when app resumed
403     mIndicator->SetOpacityMode( mIndicatorOpacityMode );
404   }
405 }
406
407 void Window::OnStop()
408 {
409   if( mIndicator )
410   {
411     mIndicator->Close();
412   }
413
414   delete mIndicator;
415   mIndicator = NULL;
416 }
417
418 void Window::OnDestroy()
419 {
420   mAdaptor = NULL;
421 }
422
423 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
424 {
425   bool found = false;
426
427   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
428   {
429     if(mAvailableOrientations[i] == orientation)
430     {
431       found = true;
432       break;
433     }
434   }
435
436   if( ! found )
437   {
438     mAvailableOrientations.push_back(orientation);
439     SetAvailableOrientations( mAvailableOrientations );
440   }
441 }
442
443 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
444 {
445   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
446        iter != mAvailableOrientations.end(); ++iter )
447   {
448     if( *iter == orientation )
449     {
450       mAvailableOrientations.erase( iter );
451       break;
452     }
453   }
454   SetAvailableOrientations( mAvailableOrientations );
455 }
456
457 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
458 {
459   DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
460 }
461
462 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
463 {
464   return mAvailableOrientations;
465 }
466
467 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
468 {
469   mPreferredOrientation = orientation;
470 }
471
472 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
473 {
474   return mPreferredOrientation;
475 }
476
477 void Window::RotationDone( int orientation, int width, int height )
478 {
479 }
480
481
482 } // Adaptor
483 } // Internal
484 } // Dali