Add window focus API and signals
[platform/core/uifw/dali-adaptor.git] / adaptors / x11 / window-impl-x.cpp
index b189872..7f9e909 100644 (file)
@@ -30,7 +30,7 @@
 // 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>
@@ -65,6 +65,7 @@ struct Window::EventHandler
   : mWindow( window ),
     mWindowPropertyHandler( NULL ),
     mClientMessagehandler( NULL ),
+    mWindowDeleteRequestHandler( NULL ),
     mEcoreWindow( 0 )
   {
     // store ecore window handle
@@ -86,10 +87,14 @@ struct Window::EventHandler
     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 );
     }
-
   }
 
   /**
@@ -105,6 +110,10 @@ struct Window::EventHandler
     {
       ecore_event_handler_del( mClientMessagehandler );
     }
+    if ( mWindowDeleteRequestHandler )
+    {
+      ecore_event_handler_del( mWindowDeleteRequestHandler );
+    }
   }
 
   // Static methods
@@ -196,19 +205,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;
 }
 
@@ -317,22 +335,23 @@ void Window::SetClass(std::string name, std::string klass)
 }
 
 Window::Window()
-: mSurface(NULL),
-  mIndicatorVisible(Dali::Window::INVISIBLE),
-  mIndicatorIsShown(false),
-  mShowRotatedIndicatorOnClose(false),
-  mStarted(false),
-  mIsTransparent(false),
-  mWMRotationAppSet(false),
-  mEcoreEventHander(true),
-  mIndicator(NULL),
-  mIndicatorOrientation(Dali::Window::PORTRAIT),
-  mNextIndicatorOrientation(Dali::Window::PORTRAIT),
-  mIndicatorOpacityMode(Dali::Window::OPAQUE),
-  mOverlay(NULL),
-  mAdaptor(NULL),
-  mEventHandler(NULL),
-  mPreferredOrientation(Dali::Window::PORTRAIT)
+: mSurface( NULL ),
+  mIndicatorVisible( Dali::Window::INVISIBLE ),
+  mIndicatorIsShown( false ),
+  mShowRotatedIndicatorOnClose( false ),
+  mStarted( false ),
+  mIsTransparent( false ),
+  mWMRotationAppSet( false ),
+  mEcoreEventHander( true ),
+  mIsFocusAcceptable( true ),
+  mIndicator( NULL ),
+  mIndicatorOrientation( Dali::Window::PORTRAIT ),
+  mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
+  mIndicatorOpacityMode( Dali::Window::OPAQUE ),
+  mOverlay( NULL ),
+  mAdaptor( NULL ),
+  mEventHandler( NULL ),
+  mPreferredOrientation( Dali::Window::PORTRAIT )
 {
 
   // Detect if we're not running in a ecore main loop (e.g. libuv).
@@ -371,11 +390,11 @@ 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;
-  ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
+  ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, className, mIsTransparent );
   windowSurface->Map();
 
   mSurface = windowSurface;
@@ -490,7 +509,7 @@ void Window::IndicatorTypeChanged(Indicator::Type type)
   }
 }
 
-void Window::IndicatorClosed( Indicator* indicator )
+void Window::IndicatorClosed( IndicatorInterface* indicator )
 {
   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
 
@@ -714,6 +733,16 @@ Dali::Window::WindowOrientation Window::GetPreferredOrientation()
   return mPreferredOrientation;
 }
 
+void Window::SetAcceptFocus( bool accept )
+{
+  mIsFocusAcceptable = accept;
+}
+
+bool Window::IsFocusAcceptable()
+{
+  return mIsFocusAcceptable;
+}
+
 void Window::RotationDone( int orientation, int width, int height )
 {
   // Tell window manager we're done