React to window delete events & handle SIGTERM, SIGHUP 16/42616/4
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 30 Jun 2015 14:58:36 +0000 (15:58 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 16 Jul 2015 08:17:51 +0000 (09:17 +0100)
Change-Id: I9e5084cc359b98a379a1f0b2a2c0cf5c3b0c031e

adaptors/common/application-impl.cpp
adaptors/common/window-impl.h
adaptors/tizen/framework-tizen.cpp
adaptors/x11/window-impl-x.cpp

index 0407b78..9e1efdd 100644 (file)
@@ -123,6 +123,9 @@ void Application::CreateWindow()
 
   const std::string& windowClassName = mEnvironmentOptions.GetWindowClassName();
   mWindow = Dali::Window::New( windowPosition, mName, windowClassName, mWindowMode == Dali::Application::TRANSPARENT );
+
+  // Quit the application when the window is closed
+  GetImplementation( mWindow ).DeleteRequestSignal().Connect( mSlotDelegate, &Application::Quit );
 }
 
 void Application::CreateAdaptor()
index c4d4cf2..d1403b5 100644 (file)
@@ -59,6 +59,7 @@ class Window : public Dali::BaseObject, public Indicator::Observer, public LifeC
 {
 public:
   typedef Dali::Window::IndicatorSignalType IndicatorSignalType;
+  typedef Signal< void () > SignalType;
 
   /**
    * Create a new Window. This should only be called once by the Application class
@@ -246,11 +247,17 @@ private: // Adaptor::Observer interface
   virtual void OnDestroy();
 
 public: // Signals
+
   /**
    * The user should connect to this signal to get a timing when indicator was shown / hidden.
    */
   IndicatorSignalType& IndicatorVisibilityChangedSignal() { return mIndicatorVisibilityChangedSignal; }
 
+  /**
+   * This signal is emitted when the window is requesting to be deleted
+   */
+  SignalType& DeleteRequestSignal() { return mDeleteRequestSignal; }
+
 private:
 
   typedef std::vector<Indicator*> DiscardedIndicators;
@@ -280,6 +287,7 @@ private:
 
   // Signals
   IndicatorSignalType mIndicatorVisibilityChangedSignal;
+  SignalType          mDeleteRequestSignal;
 };
 
 } // namespace Adaptor
index 1eef794..18f693d 100644 (file)
@@ -374,6 +374,8 @@ bool Framework::AppStatusHandler(int type, void *bundleData)
       mAbortHandler.AbortOnSignal( SIGINT );
       mAbortHandler.AbortOnSignal( SIGQUIT );
       mAbortHandler.AbortOnSignal( SIGKILL );
+      mAbortHandler.AbortOnSignal( SIGTERM );
+      mAbortHandler.AbortOnSignal( SIGHUP );
 
       mObserver.OnInit();
       break;
index a460d8c..23fae2d 100644 (file)
@@ -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,10 +205,19 @@ 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;
 };