Add handling for context loss and regain behaviour
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / window-impl-x.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_X.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 <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( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_PROPERTY,  EcoreEventWindowPropertyChanged, this ) ),
67     mClientMessagehandler( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE,  EcoreEventClientMessage, this ) ),
68     mEcoreWindow( 0 )
69   {
70     // store ecore window handle
71     ECore::WindowRenderSurface* x11Window( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
72     if( x11Window )
73     {
74       mEcoreWindow = x11Window->GetXWindow();
75     }
76     DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore x window");
77
78 #ifndef DALI_PROFILE_UBUNTU
79     // set property on window to get deiconify approve client message
80     unsigned int tmp = 1;
81     ecore_x_window_prop_card32_set(mEcoreWindow,
82                              ECORE_X_ATOM_E_DEICONIFY_APPROVE,
83                              &tmp, 1);
84 #endif // DALI_PROFILE_UBUNTU
85   }
86
87   /**
88    * Destructor
89    */
90   ~EventHandler()
91   {
92     if ( mWindowPropertyHandler )
93     {
94       ecore_event_handler_del( mWindowPropertyHandler );
95     }
96     if ( mClientMessagehandler )
97     {
98       ecore_event_handler_del( mClientMessagehandler );
99     }
100   }
101
102   // Static methods
103
104   /// Called when the window properties are changed.
105   static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
106   {
107     Ecore_X_Event_Window_Property* propertyChangedEvent( (Ecore_X_Event_Window_Property*)event );
108     EventHandler* handler( (EventHandler*)data );
109     Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
110
111     if ( handler && handler->mWindow )
112     {
113       WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
114       if ( observer && ( propertyChangedEvent->win == handler->mEcoreWindow ) )
115       {
116         Ecore_X_Window_State_Hint state( ecore_x_icccm_state_get( propertyChangedEvent->win ) );
117
118         switch ( state )
119         {
120           case ECORE_X_WINDOW_STATE_HINT_WITHDRAWN:
121           {
122             // Window was hidden.
123             observer->OnWindowHidden();
124             DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Withdrawn\n", handler->mEcoreWindow );
125             handled = ECORE_CALLBACK_DONE;
126           }
127           break;
128
129           case ECORE_X_WINDOW_STATE_HINT_ICONIC:
130           {
131             // Window was iconified (minimised).
132             observer->OnWindowHidden();
133             DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
134             handled = ECORE_CALLBACK_DONE;
135           }
136           break;
137
138           case ECORE_X_WINDOW_STATE_HINT_NORMAL:
139           {
140             // Window was shown.
141             observer->OnWindowShown();
142             DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
143             handled = ECORE_CALLBACK_DONE;
144           }
145           break;
146
147           default:
148             // Ignore
149             break;
150         }
151       }
152     }
153
154     return handled;
155   }
156
157   /// Called when the window properties are changed.
158   static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
159   {
160     Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
161 #ifndef DALI_PROFILE_UBUNTU
162     Ecore_X_Event_Client_Message* clientMessageEvent( (Ecore_X_Event_Client_Message*)event );
163     EventHandler* handler( (EventHandler*)data );
164
165     if (clientMessageEvent->message_type == ECORE_X_ATOM_E_DEICONIFY_APPROVE)
166     {
167       ECore::WindowRenderSurface* x11Window( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
168       WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
169
170       if ( observer && ( (unsigned int)clientMessageEvent->data.l[0] == handler->mEcoreWindow ) )
171       {
172         if (clientMessageEvent->data.l[1] == 0) //wm sends request message using value 0
173         {
174           observer->OnWindowShown();
175
176           // request to approve the deiconify. render-surface should send proper event after real rendering
177           if(x11Window)
178           {
179             x11Window->RequestToApproveDeiconify();
180           }
181
182           handled = ECORE_CALLBACK_DONE;
183         }
184       }
185     }
186 #endif // DALI_PROFILE_UBUNTU
187
188     return handled;
189   }
190
191   // Data
192   Window* mWindow;
193   Ecore_Event_Handler* mWindowPropertyHandler;
194   Ecore_Event_Handler* mClientMessagehandler;
195   Ecore_X_Window mEcoreWindow;
196 };
197
198
199 Window* Window::New(const PositionSize& posSize, const std::string& name, bool isTransparent)
200 {
201   Window* window = new Window();
202   window->mIsTransparent = isTransparent;
203   window->Initialize(posSize, name);
204   return window;
205 }
206
207 void Window::SetAdaptor(Dali::Adaptor& adaptor)
208 {
209   DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
210   mStarted = true;
211
212   // Only create one overlay per window
213   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
214   Integration::Core& core = adaptorImpl.GetCore();
215   mOverlay = &core.GetSystemOverlay();
216
217   Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
218   taskList.CreateTask();
219
220   mAdaptor = &adaptorImpl;
221   mAdaptor->AddObserver( *this );
222
223   // Can only create the detector when we know the Core has been instantiated.
224   mDragAndDropDetector = DragAndDropDetector::New();
225   mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
226
227   if( mOrientation )
228   {
229     mOrientation->SetAdaptor(adaptor);
230   }
231
232   if( mIndicator != NULL )
233   {
234     mIndicator->SetAdaptor(mAdaptor);
235   }
236 }
237
238 RenderSurface* Window::GetSurface()
239 {
240   return mSurface;
241 }
242
243 void Window::SetIndicatorStyle( Dali::Window::IndicatorStyle style )
244 {
245   mIndicatorStyle = style;
246 }
247
248 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
249 {
250   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
251   DALI_ASSERT_DEBUG(mOverlay);
252
253   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
254   DALI_ASSERT_DEBUG(x11Window);
255   Ecore_X_Window xWinId = x11Window->GetXWindow();
256
257   mIndicatorVisible = visibleMode;
258
259   if ( mIndicatorVisible == Dali::Window::VISIBLE )
260   {
261     // when the indicator is visible, set proper mode for indicator server according to bg mode
262     if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
263     {
264       ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_OPAQUE);
265     }
266     else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
267     {
268       ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_TRANSLUCENT);
269     }
270 #if defined(DALI_PROFILE_MOBILE)
271     else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
272     {
273       ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_BG_TRANSPARENT);
274     }
275 #endif
276   }
277   else
278   {
279     // when the indicator is not visible, set TRANSPARENT mode for indicator server
280     ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_TRANSPARENT); // it means hidden indicator
281   }
282
283   DoShowIndicator( mIndicatorOrientation );
284 }
285
286 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
287 {
288   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
289
290   DoRotateIndicator( orientation );
291 }
292
293 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
294 {
295   mIndicatorOpacityMode = opacityMode;
296
297   if( mIndicator != NULL )
298   {
299     mIndicator->SetOpacityMode( opacityMode );
300   }
301 }
302
303 void Window::SetClass(std::string name, std::string klass)
304 {
305   // Get render surface's x11 window
306   if( mSurface )
307   {
308     ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
309     if( x11Window )
310     {
311       ecore_x_icccm_name_class_set( x11Window->GetXWindow(), name.c_str(), klass.c_str() );
312     }
313   }
314 }
315
316 Window::Window()
317 : mSurface(NULL),
318   mIndicatorStyle(Dali::Window::CHANGEABLE_COLOR),
319   mIndicatorVisible(Dali::Window::VISIBLE),
320   mIndicatorIsShown(false),
321   mShowRotatedIndicatorOnClose(false),
322   mStarted(false),
323   mIsTransparent(false),
324   mWMRotationAppSet(false),
325   mIndicator(NULL),
326   mIndicatorOrientation(Dali::Window::PORTRAIT),
327   mNextIndicatorOrientation(Dali::Window::PORTRAIT),
328   mIndicatorOpacityMode(Dali::Window::OPAQUE),
329   mOverlay(NULL),
330   mAdaptor(NULL)
331 {
332 }
333
334 Window::~Window()
335 {
336   delete mEventHandler;
337
338   if( mIndicator )
339   {
340     mOverlay->Remove( mIndicator->GetActor() );
341     Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
342     Dali::RenderTask indicatorTask = taskList.GetTask(0);
343     mOverlay->GetOverlayRenderTasks().RemoveTask(indicatorTask);
344     mIndicator->Close();
345     delete mIndicator;
346   }
347
348   if( mAdaptor )
349   {
350     mAdaptor->RemoveObserver( *this );
351     mAdaptor->SetDragAndDropDetector( NULL );
352     mAdaptor = NULL;
353   }
354
355   delete mSurface;
356 }
357
358 void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
359 {
360   // create an X11 window by default
361   Any surface;
362   Any display;
363   mSurface = new ECore::WindowRenderSurface( windowPosition, surface, display, name, mIsTransparent );
364   mOrientation = Orientation::New(this);
365
366   // create event handler for X11 window
367   mEventHandler = new EventHandler( this );
368 }
369
370 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
371 {
372   if( mIndicator == NULL )
373   {
374     if( mIndicatorVisible != Dali::Window::INVISIBLE )
375     {
376       mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, mIndicatorStyle, this );
377       mIndicator->SetOpacityMode( mIndicatorOpacityMode );
378       Dali::Actor actor = mIndicator->GetActor();
379       SetIndicatorActorRotation();
380       mOverlay->Add(actor);
381     }
382     // else don't create a hidden indicator
383   }
384   else // Already have indicator
385   {
386     if( mIndicatorVisible == Dali::Window::VISIBLE )
387     {
388       // If we are resuming, and rotation has changed,
389       if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
390       {
391         // then close current indicator and open new one
392         mShowRotatedIndicatorOnClose = true;
393         mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
394         // Don't show actor - will contain indicator for old orientation.
395       }
396     }
397   }
398
399   // set indicator visible mode
400   if( mIndicator != NULL )
401   {
402     mIndicator->SetVisible( mIndicatorVisible );
403   }
404
405   bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
406   SetIndicatorProperties( show, lastOrientation );
407   mIndicatorIsShown = show;
408 }
409
410 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
411 {
412   if( mIndicatorIsShown )
413   {
414     mShowRotatedIndicatorOnClose = true;
415     mNextIndicatorOrientation = orientation;
416     mIndicator->Close(); // May synchronously call IndicatorClosed() callback
417   }
418   else
419   {
420     // Save orientation for when the indicator is next shown
421     mShowRotatedIndicatorOnClose = false;
422     mNextIndicatorOrientation = orientation;
423   }
424 }
425
426 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
427 {
428   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
429   if( x11Window )
430   {
431     Ecore_X_Window win = x11Window->GetXWindow();
432
433     int show_state = static_cast<int>( isShow );
434     ecore_x_window_prop_property_set( win,
435                                       ECORE_X_ATOM_E_ILLUME_INDICATOR_STATE,
436                                       ECORE_X_ATOM_CARDINAL, 32, &show_state, 1);
437
438     if ( isShow )
439     {
440       ecore_x_e_illume_indicator_state_set(win, ECORE_X_ILLUME_INDICATOR_STATE_ON);
441     }
442     else
443     {
444       ecore_x_e_illume_indicator_state_set(win, ECORE_X_ILLUME_INDICATOR_STATE_OFF);
445     }
446   }
447 }
448
449 void Window::IndicatorTypeChanged(Indicator::Type type)
450 {
451   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
452   if( x11Window )
453   {
454 #ifndef DALI_PROFILE_UBUNTU
455     Ecore_X_Window win = x11Window->GetXWindow();
456     switch(type)
457     {
458       case Indicator::INDICATOR_TYPE_1:
459         ecore_x_e_illume_indicator_type_set( win, ECORE_X_ILLUME_INDICATOR_TYPE_1 );
460         break;
461
462       case Indicator::INDICATOR_TYPE_2:
463         ecore_x_e_illume_indicator_type_set( win, ECORE_X_ILLUME_INDICATOR_TYPE_2 );
464         break;
465
466       case Indicator::INDICATOR_TYPE_UNKNOWN:
467       default:
468         break;
469     }
470 #endif // DALI_PROFILE_UBUNTU
471   }
472 }
473
474 void Window::IndicatorClosed( Indicator* indicator )
475 {
476   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
477
478   if( mShowRotatedIndicatorOnClose )
479   {
480     Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
481     mIndicator->Open(mNextIndicatorOrientation);
482     mIndicatorOrientation = mNextIndicatorOrientation;
483     SetIndicatorActorRotation();
484     DoShowIndicator(currentOrientation);
485   }
486 }
487
488 void Window::SetIndicatorActorRotation()
489 {
490   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
491   DALI_ASSERT_DEBUG( mIndicator != NULL );
492
493   Dali::Actor actor = mIndicator->GetActor();
494   switch( mIndicatorOrientation )
495   {
496     case Dali::Window::PORTRAIT:
497       actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
498       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
499       actor.SetRotation( Degree(0), Vector3::ZAXIS );
500       break;
501     case Dali::Window::PORTRAIT_INVERSE:
502       actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
503       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
504       actor.SetRotation( Degree(180), Vector3::ZAXIS );
505       break;
506     case Dali::Window::LANDSCAPE:
507       actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
508       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
509       actor.SetRotation( Degree(270), Vector3::ZAXIS );
510       break;
511     case Dali::Window::LANDSCAPE_INVERSE:
512       actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
513       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
514       actor.SetRotation( Degree(90), Vector3::ZAXIS );
515       break;
516   }
517 }
518
519 void Window::Raise()
520 {
521   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
522   if( x11Window )
523   {
524     Ecore_X_Window win = x11Window->GetXWindow();
525     ecore_x_window_raise(win);
526   }
527 }
528
529 void Window::Lower()
530 {
531   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
532   if( x11Window )
533   {
534     Ecore_X_Window win = x11Window->GetXWindow();
535     ecore_x_window_lower(win);
536   }
537 }
538
539 void Window::Activate()
540 {
541   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
542   if( x11Window )
543   {
544     Ecore_X_Window win = x11Window->GetXWindow();
545     ecore_x_netwm_client_active_request(ecore_x_window_root_get(win), win, 1 /* request type, 1:application, 2:pager */, 0);
546   }
547 }
548
549 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
550 {
551   return mDragAndDropDetector;
552 }
553
554 void Window::OnStart()
555 {
556   DoShowIndicator( mIndicatorOrientation );
557 }
558
559 void Window::OnPause()
560 {
561 }
562
563 void Window::OnResume()
564 {
565   // resume indicator status
566   if( mIndicator != NULL )
567   {
568     // Restore own indicator opacity
569     // Send opacity mode to indicator service when app resumed
570     mIndicator->SetOpacityMode( mIndicatorOpacityMode );
571   }
572 }
573
574 void Window::OnStop()
575 {
576   if( mIndicator )
577   {
578     mIndicator->Close();
579   }
580
581   delete mIndicator;
582   mIndicator = NULL;
583 }
584
585 void Window::OnDestroy()
586 {
587   mAdaptor = NULL;
588 }
589
590 OrientationPtr Window::GetOrientation()
591 {
592   return mOrientation;
593 }
594
595 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
596 {
597   bool found = false;
598
599   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
600   {
601     if(mAvailableOrientations[i] == orientation)
602     {
603       found = true;
604       break;
605     }
606   }
607
608   if( ! found )
609   {
610     mAvailableOrientations.push_back(orientation);
611     SetAvailableOrientations( mAvailableOrientations );
612   }
613 }
614
615 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
616 {
617   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
618        iter != mAvailableOrientations.end(); ++iter )
619   {
620     if( *iter == orientation )
621     {
622       mAvailableOrientations.erase( iter );
623       break;
624     }
625   }
626   SetAvailableOrientations( mAvailableOrientations );
627 }
628
629 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
630 {
631   DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
632
633   mAvailableOrientations = orientations;
634   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
635   if( x11Window )
636   {
637 #ifndef DALI_PROFILE_UBUNTU
638     Ecore_X_Window ecoreWindow = x11Window->GetXWindow();
639     if( ! mWMRotationAppSet )
640     {
641       mWMRotationAppSet = true;
642       ecore_x_e_window_rotation_app_set(ecoreWindow, EINA_TRUE);
643     }
644
645     int rotations[4];
646     for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
647     {
648       rotations[i] = static_cast<int>(mAvailableOrientations[i]);
649     }
650     ecore_x_e_window_rotation_available_rotations_set(ecoreWindow, rotations, mAvailableOrientations.size() );
651 #endif // DALI_PROFILE_UBUNTU
652   }
653 }
654
655 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
656 {
657   return mAvailableOrientations;
658 }
659
660 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
661 {
662   mPreferredOrientation = orientation;
663
664   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
665   if( x11Window )
666   {
667 #ifndef DALI_PROFILE_UBUNTU
668     Ecore_X_Window ecoreWindow = x11Window->GetXWindow();
669
670     if( ! mWMRotationAppSet )
671     {
672       mWMRotationAppSet = true;
673       ecore_x_e_window_rotation_app_set(ecoreWindow, EINA_TRUE);
674     }
675
676     ecore_x_e_window_rotation_preferred_rotation_set(ecoreWindow, orientation);
677 #endif // DALI_PROFILE_UBUNTU
678   }
679 }
680
681 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
682 {
683   return mPreferredOrientation;
684 }
685
686 void Window::RotationDone( int orientation, int width, int height )
687 {
688   // Tell window manager we're done
689   ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
690   if( x11Window )
691   {
692 #ifndef DALI_PROFILE_UBUNTU
693     Ecore_X_Window ecoreWindow = x11Window->GetXWindow();
694     Ecore_X_Window root = ecore_x_window_root_get(ecoreWindow);
695
696     /**
697      * send rotation done message to wm, even if window is already rotated.
698      * that's why wm must be wait for comming rotation done message
699      * after sending rotation request.
700      */
701     ecore_x_e_window_rotation_change_done_send(root, ecoreWindow, orientation, width, height);
702
703     /**
704      * set rotate window property
705      */
706     int angles[2] = { orientation, orientation };
707     ecore_x_window_prop_property_set( ecoreWindow,
708                                      ECORE_X_ATOM_E_ILLUME_ROTATE_WINDOW_ANGLE,
709                                      ECORE_X_ATOM_CARDINAL, 32, &angles, 2 );
710 #endif // DALI_PROFILE_UBUNTU
711   }
712 }
713
714
715 } // Adaptor
716 } // Internal
717 } // Dali