From ccd6a044297708dda3f8aad60effc14ffe5c48c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 24 Sep 2023 20:17:49 -0300 Subject: [PATCH] Fixed a bug introduced when adding a cb to the InputEvent::Quit. --- include/eepp/window/window.hpp | 6 ++++++ src/eepp/window/input.cpp | 2 +- src/eepp/window/window.cpp | 12 ++++++++++-- src/tools/ecode/ecode.cpp | 11 +++++++++-- src/tools/uieditor/uieditor.cpp | 5 +++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/eepp/window/window.hpp b/include/eepp/window/window.hpp index 72449300b..d5429d73f 100644 --- a/include/eepp/window/window.hpp +++ b/include/eepp/window/window.hpp @@ -160,6 +160,7 @@ class EE_API Window { public: typedef std::function WindowResizeCallback; typedef std::function WindowRequestCloseCallback; + typedef std::function WindowQuitCallback; Window( WindowSettings Settings, ContextSettings Context, Clipboard* Clipboard, Input* Input, CursorManager* CursorManager ); @@ -464,6 +465,8 @@ class EE_API Window { void setCloseRequestCallback( const WindowRequestCloseCallback& closeRequestCallback ); + void setQuitCallback( const WindowQuitCallback& quitCallback ); + /** In case of a frame rate limit is set, this will return the time spent sleeping per second. */ const System::Time& getSleepTimePerSecond() const; @@ -500,6 +503,7 @@ class EE_API Window { Uint32 mNumCallBacks; std::map mCallbacks; WindowRequestCloseCallback mCloseRequestCallback; + WindowQuitCallback mQuitCallback; Sizei mLastWindowedSize; class FrameData { @@ -559,6 +563,8 @@ class EE_API Window { void logFailureInit( const std::string& ClassName, const std::string& BackendName ); void onCloseRequest(); + + void onQuit(); }; }} // namespace EE::Window diff --git a/src/eepp/window/input.cpp b/src/eepp/window/input.cpp index 7b0fdf964..20fa30b25 100644 --- a/src/eepp/window/input.cpp +++ b/src/eepp/window/input.cpp @@ -219,7 +219,7 @@ void Input::processEvent( InputEvent* Event ) { break; } case InputEvent::Quit: { - mWindow->onCloseRequest(); + mWindow->onQuit(); break; } } diff --git a/src/eepp/window/window.cpp b/src/eepp/window/window.cpp index 200fd9cc2..130aa4fa7 100644 --- a/src/eepp/window/window.cpp +++ b/src/eepp/window/window.cpp @@ -142,6 +142,10 @@ void Window::setCloseRequestCallback( const WindowRequestCloseCallback& closeReq mCloseRequestCallback = closeRequestCallback; } +void Window::setQuitCallback( const WindowQuitCallback& quitCallback ) { + mQuitCallback = quitCallback; +} + void Window::setViewport( const Int32& x, const Int32& y, const Uint32& Width, const Uint32& Height ) { GLi->viewport( x, getHeight() - ( y + Height ), Width, Height ); @@ -476,13 +480,17 @@ void Window::logFailureInit( const std::string& ClassName, const std::string& Ba } void Window::onCloseRequest() { - if ( mCloseRequestCallback && !mCloseRequestCallback( this ) ) { + if ( mCloseRequestCallback && !mCloseRequestCallback( this ) ) return; - } close(); } +void Window::onQuit() { + if ( mQuitCallback ) + mQuitCallback( this ); +} + std::string Window::getTitle() { return mWindow.WindowConfig.Title; } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index aea670750..cbb6ec99d 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3104,6 +3104,7 @@ void App::loadFolder( const std::string& path ) { mSplitter->getCurWidget()->setFocus(); } +#if EE_PLATFORM == EE_PLATFORM_MACOS static std::string getDefaultShell() { std::string shell = Sys::getEnv( "SHELL" ); if ( !shell.empty() ) @@ -3141,6 +3142,7 @@ static std::string getShellEnv( const std::string& env, const std::string& defSh } return ""; } +#endif FontTrueType* App::loadFont( const std::string& name, std::string fontPath, const std::string& fallback ) { @@ -3297,8 +3299,8 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe } if ( mWindow->isWindowed() && mWindow->getSize() >= currentDisplay->getSize().asInt() ) { - mWindow->setPosition( mWindow->getBorderSize().getWidth(), - mWindow->getBorderSize().getHeight() ); + auto borderSize( mWindow->getBorderSize() ); + mWindow->setPosition( borderSize.getWidth(), borderSize.getHeight() ); } loadKeybindings(); @@ -3318,6 +3320,11 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mWindow->setCloseRequestCallback( [this]( EE::Window::Window* win ) -> bool { return onCloseRequestCallback( win ); } ); + mWindow->setQuitCallback( [this]( EE::Window::Window* win ) { + if ( mWindow->isOpen() ) + onCloseRequestCallback( win ); + } ); + mWindow->getInput()->pushCallback( [this]( InputEvent* event ) { if ( event->Type == InputEvent::FileDropped ) { onFileDropped( event->file.file ); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index d5b2e01f8..768e74580 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -1220,6 +1220,11 @@ void App::init( const Float& pixelDensityConf, const bool& useAppTheme, const st mWindow->setCloseRequestCallback( [this]( auto* window ) -> bool { return onCloseRequestCallback( window ); } ); + mWindow->setQuitCallback( [this]( EE::Window::Window* win ) { + if ( mWindow->isOpen() ) + onCloseRequestCallback( win ); + } ); + mResPath = Sys::getProcessPath(); #if EE_PLATFORM == EE_PLATFORM_MACOS if ( String::contains( mResPath, "eepp-UIEditor.app" ) ) {