diff --git a/include/TGUI/Backend/Window/BackendGui.hpp b/include/TGUI/Backend/Window/BackendGui.hpp index 45e9535f0..9a0e7a96d 100644 --- a/include/TGUI/Backend/Window/BackendGui.hpp +++ b/include/TGUI/Backend/Window/BackendGui.hpp @@ -700,6 +700,11 @@ TGUI_MODULE_EXPORT namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// bool handleTwoFingerScroll(bool wasAlreadyScrolling); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // Updates internal window focus flag and emits signal if flag state was changed. + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void updateWindowFocusState(bool windowFocused); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Updates the view and changes the size of the root container when needed. // Derived classes should update m_framebufferSize in this function and then call this function from the base class. @@ -711,6 +716,8 @@ TGUI_MODULE_EXPORT namespace tgui public: SignalFloatRect onViewChange = {"ViewChanged"}; //!< The view was changed. Optional parameter: new view rectangle + Signal onWindowFocus = {"Focused"}; //!< The window was focused + Signal onWindowUnfocus = {"Unfocused"}; //!< The window was unfocused ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Backend/Window/BackendGui.cpp b/src/Backend/Window/BackendGui.cpp index 657d83cd9..03544cd6f 100644 --- a/src/Backend/Window/BackendGui.cpp +++ b/src/Backend/Window/BackendGui.cpp @@ -186,13 +186,13 @@ namespace tgui } case Event::Type::LostFocus: { - m_windowFocused = false; - break; + updateWindowFocusState(false); + return true; } case Event::Type::GainedFocus: { - m_windowFocused = true; - break; + updateWindowFocusState(true); + return true; } case Event::Type::Resized: { @@ -626,6 +626,20 @@ namespace tgui ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void BackendGui::updateWindowFocusState(bool windowFocused) + { + if(m_windowFocused != windowFocused) { + m_windowFocused = windowFocused; + if(windowFocused) { + onWindowFocus.emit(m_container.get()); + } else { + onWindowUnfocus.emit(m_container.get()); + } + } + } + + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + void BackendGui::updateContainerSize() { m_viewport.updateParentSize({static_cast(m_framebufferSize.x), static_cast(m_framebufferSize.y)});