From 7f3341b2da0e085639752b68e41a4230428ac737 Mon Sep 17 00:00:00 2001 From: Adeel Kazmi Date: Tue, 30 Jun 2015 15:58:36 +0100 Subject: [PATCH] React to window delete events & handle SIGTERM, SIGHUP Change-Id: I9e5084cc359b98a379a1f0b2a2c0cf5c3b0c031e --- adaptors/common/application-impl.cpp | 3 +++ adaptors/common/window-impl.h | 8 ++++++++ adaptors/tizen/framework-tizen.cpp | 2 ++ adaptors/x11/window-impl-x.cpp | 20 +++++++++++++++++++- 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/adaptors/common/application-impl.cpp b/adaptors/common/application-impl.cpp index 0407b78..9e1efdd 100644 --- a/adaptors/common/application-impl.cpp +++ b/adaptors/common/application-impl.cpp @@ -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() diff --git a/adaptors/common/window-impl.h b/adaptors/common/window-impl.h index c4d4cf2..d1403b5 100644 --- a/adaptors/common/window-impl.h +++ b/adaptors/common/window-impl.h @@ -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 DiscardedIndicators; @@ -280,6 +287,7 @@ private: // Signals IndicatorSignalType mIndicatorVisibilityChangedSignal; + SignalType mDeleteRequestSignal; }; } // namespace Adaptor diff --git a/adaptors/tizen/framework-tizen.cpp b/adaptors/tizen/framework-tizen.cpp index 1eef794..18f693d 100644 --- a/adaptors/tizen/framework-tizen.cpp +++ b/adaptors/tizen/framework-tizen.cpp @@ -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; diff --git a/adaptors/x11/window-impl-x.cpp b/adaptors/x11/window-impl-x.cpp index a460d8c..23fae2d 100644 --- a/adaptors/x11/window-impl-x.cpp +++ b/adaptors/x11/window-impl-x.cpp @@ -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; }; -- 2.7.4