Revert "[Tizen] keygrab & ecore-wl-window-handle c# binding"
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / window-impl-x.cpp
index 7165cc2..710d9fb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,9 @@
 #include "window-impl.h"
 
 // EXTERNAL HEADERS
+// Ecore is littered with C style cast
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wold-style-cast"
 #include <Ecore.h>
 #include <Ecore_X.h>
 
 #include <dali/integration-api/system-overlay.h>
 #include <dali/public-api/render-tasks/render-task.h>
 #include <dali/public-api/render-tasks/render-task-list.h>
-#include <orientation.h>
 
 // INTERNAL HEADERS
 #include <window-render-surface.h>
 #include <drag-and-drop-detector-impl.h>
-#include <indicator-impl.h>
+#include <ecore-indicator-impl.h>
 #include <window-visibility-observer.h>
+#include <orientation.h>
 #include <orientation-impl.h>
 
 namespace
@@ -63,8 +66,9 @@ struct Window::EventHandler
    */
   EventHandler( Window* window )
   : mWindow( window ),
-    mWindowPropertyHandler( ecore_event_handler_add( ECORE_X_EVENT_WINDOW_PROPERTY,  EcoreEventWindowPropertyChanged, this ) ),
-    mClientMessagehandler( ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE,  EcoreEventClientMessage, this ) ),
+    mWindowPropertyHandler( NULL ),
+    mClientMessagehandler( NULL ),
+    mWindowDeleteRequestHandler( NULL ),
     mEcoreWindow( 0 )
   {
     // store ecore window handle
@@ -82,6 +86,18 @@ struct Window::EventHandler
                              ECORE_X_ATOM_E_DEICONIFY_APPROVE,
                              &tmp, 1);
 #endif // DALI_PROFILE_UBUNTU
+
+    if( mWindow->mEcoreEventHander )
+    {
+      ecore_x_input_multi_select( mEcoreWindow );
+
+      // This ensures that we catch the window close (or delete) request
+      ecore_x_icccm_protocol_set( mEcoreWindow, ECORE_X_WM_PROTOCOL_DELETE_REQUEST, EINA_TRUE );
+
+      mWindowPropertyHandler=  ecore_event_handler_add( ECORE_X_EVENT_WINDOW_PROPERTY,  EcoreEventWindowPropertyChanged, this );
+      mClientMessagehandler =  ecore_event_handler_add( ECORE_X_EVENT_CLIENT_MESSAGE,  EcoreEventClientMessage, this );
+      mWindowDeleteRequestHandler = ecore_event_handler_add( ECORE_X_EVENT_WINDOW_DELETE_REQUEST, EcoreEventWindowDeleteRequest, this );
+    }
   }
 
   /**
@@ -97,6 +113,10 @@ struct Window::EventHandler
     {
       ecore_event_handler_del( mClientMessagehandler );
     }
+    if ( mWindowDeleteRequestHandler )
+    {
+      ecore_event_handler_del( mWindowDeleteRequestHandler );
+    }
   }
 
   // Static methods
@@ -188,19 +208,28 @@ struct Window::EventHandler
     return handled;
   }
 
+  /// Called when the window receives a delete request
+  static Eina_Bool EcoreEventWindowDeleteRequest( void* data, int type, void* event )
+  {
+    EventHandler* handler( (EventHandler*)data );
+    handler->mWindow->mDeleteRequestSignal.Emit();
+    return ECORE_CALLBACK_DONE;
+  }
+
   // Data
   Window* mWindow;
   Ecore_Event_Handler* mWindowPropertyHandler;
   Ecore_Event_Handler* mClientMessagehandler;
+  Ecore_Event_Handler* mWindowDeleteRequestHandler;
   Ecore_X_Window mEcoreWindow;
 };
 
 
-Window* Window::New(const PositionSize& posSize, const std::string& name, bool isTransparent)
+Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
 {
   Window* window = new Window();
   window->mIsTransparent = isTransparent;
-  window->Initialize(posSize, name);
+  window->Initialize(posSize, name, className);
   return window;
 }
 
@@ -240,11 +269,6 @@ RenderSurface* Window::GetSurface()
   return mSurface;
 }
 
-void Window::SetIndicatorStyle( Dali::Window::IndicatorStyle style )
-{
-  mIndicatorStyle = style;
-}
-
 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
 {
   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
@@ -270,7 +294,7 @@ void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
 #if defined(DALI_PROFILE_MOBILE)
     else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
     {
-      ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_BG_TRANSPARENT);
+      ecore_x_e_illume_indicator_opacity_set(xWinId, ECORE_X_ILLUME_INDICATOR_OPAQUE);
     }
 #endif
   }
@@ -314,21 +338,40 @@ void Window::SetClass(std::string name, std::string klass)
 }
 
 Window::Window()
-: mSurface(NULL),
-  mIndicatorStyle(Dali::Window::CHANGEABLE_COLOR),
-  mIndicatorVisible(Dali::Window::VISIBLE),
-  mIndicatorIsShown(false),
-  mShowRotatedIndicatorOnClose(false),
-  mStarted(false),
-  mIsTransparent(false),
-  mWMRotationAppSet(false),
-  mIndicator(NULL),
-  mIndicatorOrientation(Dali::Window::PORTRAIT),
-  mNextIndicatorOrientation(Dali::Window::PORTRAIT),
-  mIndicatorOpacityMode(Dali::Window::OPAQUE),
-  mOverlay(NULL),
-  mAdaptor(NULL)
-{
+: mSurface( NULL ),
+  mIndicatorVisible( Dali::Window::INVISIBLE ),
+  mIndicatorIsShown( false ),
+  mShowRotatedIndicatorOnClose( false ),
+  mStarted( false ),
+  mIsTransparent( false ),
+  mWMRotationAppSet( false ),
+  mEcoreEventHander( true ),
+  mIsFocusAcceptable( true ),
+  mVisible( true ),
+  mOpaqueState( false ),
+  mIndicator( NULL ),
+  mIndicatorOrientation( Dali::Window::PORTRAIT ),
+  mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
+  mIndicatorOpacityMode( Dali::Window::OPAQUE ),
+  mOverlay( NULL ),
+  mAdaptor( NULL ),
+  mType( Dali::DevelWindow::NORMAL ),
+  mEventHandler( NULL ),
+  mPreferredOrientation( Dali::Window::PORTRAIT ),
+  mSupportedAuxiliaryHints(),
+  mAuxiliaryHints()
+{
+
+  // Detect if we're not running in a ecore main loop (e.g. libuv).
+  // Typically ecore_x_init is called by app_efl_main->elm_init
+  // but if we're not using app_efl_main then we have to call it ourselves
+  // This is a hack until we create a pure X Window class
+  if( ecore_x_display_get() == NULL )
+  {
+    mEcoreEventHander = false;
+    ecore_x_init (NULL); //  internally calls _ecore_x_input_init
+  }
+
 }
 
 Window::~Window()
@@ -355,12 +398,15 @@ Window::~Window()
   delete mSurface;
 }
 
-void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
+void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
 {
   // create an X11 window by default
   Any surface;
-  Any display;
-  mSurface = new ECore::WindowRenderSurface( windowPosition, surface, display, name, mIsTransparent );
+  ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, className, mIsTransparent );
+  windowSurface->Map();
+
+  mSurface = windowSurface;
+
   mOrientation = Orientation::New(this);
 
   // create event handler for X11 window
@@ -373,7 +419,7 @@ void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
   {
     if( mIndicatorVisible != Dali::Window::INVISIBLE )
     {
-      mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, mIndicatorStyle, this );
+      mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
       mIndicator->SetOpacityMode( mIndicatorOpacityMode );
       Dali::Actor actor = mIndicator->GetActor();
       SetIndicatorActorRotation();
@@ -471,7 +517,7 @@ void Window::IndicatorTypeChanged(Indicator::Type type)
   }
 }
 
-void Window::IndicatorClosed( Indicator* indicator )
+void Window::IndicatorClosed( IndicatorInterface* indicator )
 {
   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
 
@@ -485,6 +531,11 @@ void Window::IndicatorClosed( Indicator* indicator )
   }
 }
 
+void Window::IndicatorVisibilityChanged(bool isVisible)
+{
+  mIndicatorVisibilityChangedSignal.Emit(isVisible);
+}
+
 void Window::SetIndicatorActorRotation()
 {
   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
@@ -496,22 +547,22 @@ void Window::SetIndicatorActorRotation()
     case Dali::Window::PORTRAIT:
       actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetRotation( Degree(0), Vector3::ZAXIS );
+      actor.SetOrientation( Degree(0), Vector3::ZAXIS );
       break;
     case Dali::Window::PORTRAIT_INVERSE:
       actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetRotation( Degree(180), Vector3::ZAXIS );
+      actor.SetOrientation( Degree(180), Vector3::ZAXIS );
       break;
     case Dali::Window::LANDSCAPE:
       actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetRotation( Degree(270), Vector3::ZAXIS );
+      actor.SetOrientation( Degree(270), Vector3::ZAXIS );
       break;
     case Dali::Window::LANDSCAPE_INVERSE:
       actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
-      actor.SetRotation( Degree(90), Vector3::ZAXIS );
+      actor.SetOrientation( Degree(90), Vector3::ZAXIS );
       break;
   }
 }
@@ -551,9 +602,21 @@ Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
   return mDragAndDropDetector;
 }
 
+Dali::Any Window::GetNativeHandle() const
+{
+  if(mEventHandler)
+  {
+    return mEventHandler->mEcoreWindow;
+  }
+  else
+  {
+    return Dali::Any();
+  }
+}
+
 void Window::OnStart()
 {
-  DoShowIndicator( mIndicatorOrientation );
+  ShowIndicator( mIndicatorVisible );
 }
 
 void Window::OnPause()
@@ -587,11 +650,6 @@ void Window::OnDestroy()
   mAdaptor = NULL;
 }
 
-OrientationPtr Window::GetOrientation()
-{
-  return mOrientation;
-}
-
 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
 {
   bool found = false;
@@ -683,6 +741,55 @@ Dali::Window::WindowOrientation Window::GetPreferredOrientation()
   return mPreferredOrientation;
 }
 
+void Window::SetAcceptFocus( bool accept )
+{
+  mIsFocusAcceptable = accept;
+}
+
+bool Window::IsFocusAcceptable()
+{
+  return mIsFocusAcceptable;
+}
+
+void Window::Show()
+{
+  ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
+  if( x11Window )
+  {
+    Ecore_X_Window win = x11Window->GetXWindow();
+    ecore_x_window_show( win );
+
+    // Need an update request
+    if( mAdaptor )
+    {
+      mAdaptor->RequestUpdateOnce();
+    }
+  }
+}
+
+void Window::Hide()
+{
+  ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
+  if( x11Window )
+  {
+    Ecore_X_Window win = x11Window->GetXWindow();
+    ecore_x_window_hide( win );
+  }
+}
+
+bool Window::IsVisible() const
+{
+  bool visible = false;
+
+  ECore::WindowRenderSurface* x11Window = dynamic_cast< ECore::WindowRenderSurface * >( mSurface );
+  if( x11Window )
+  {
+    Ecore_X_Window win = x11Window->GetXWindow();
+    visible = static_cast< bool >( ecore_x_window_visible_get( win ) );
+  }
+  return visible;
+}
+
 void Window::RotationDone( int orientation, int width, int height )
 {
   // Tell window manager we're done
@@ -711,7 +818,99 @@ void Window::RotationDone( int orientation, int width, int height )
   }
 }
 
+unsigned int Window::GetSupportedAuxiliaryHintCount()
+{
+  return 0;
+}
+
+std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
+{
+  return std::string();
+}
+
+unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
+{
+  return -1;
+}
+
+bool Window::RemoveAuxiliaryHint( unsigned int id )
+{
+  return false;
+}
+
+bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
+{
+  return false;
+}
+
+std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
+{
+  return std::string();
+}
+
+unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
+{
+  return -1;
+}
+
+void Window::SetInputRegion( const Rect< int >& inputRegion )
+{
+}
+
+void Window::SetType( Dali::DevelWindow::Type type )
+{
+  mType = type;
+}
+
+Dali::DevelWindow::Type Window::GetType() const
+{
+  return mType;
+}
+
+bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
+{
+  return false;
+}
+
+Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
+{
+  return Dali::DevelWindow::NotificationLevel::NONE;
+}
+
+void Window::SetOpaqueState( bool opaque )
+{
+  mOpaqueState = opaque;
+}
+
+bool Window::IsOpaqueState()
+{
+  return mOpaqueState;
+}
+
+bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
+{
+  return false;
+}
+
+Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
+{
+  return Dali::DevelWindow::ScreenMode::DEFAULT;
+}
+
+bool Window::SetBrightness( int brightness )
+{
+  return false;
+}
+
+int Window::GetBrightness()
+{
+  return 0;
+}
 
 } // Adaptor
+
 } // Internal
+
 } // Dali
+
+#pragma GCC diagnostic pop