diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 9c5e18eb..1996832d 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -241,12 +241,6 @@ public: inline double getScaling() const noexcept { return getScaling(); } protected: - /** - A function called when the window is resized. - If there is a top-level widget associated with this window, its size will be set right after this function. - */ - virtual void onReshape(uint width, uint height); - /** A function called when the window is attempted to be closed. Returning true closes the window, which is the default behaviour. @@ -254,6 +248,18 @@ protected: */ virtual bool onClose(); + /** + A function called when the window gains or loses the keyboard focus. + The default implementation does nothing. + */ + virtual void onFocus(bool focus); + + /** + A function called when the window is resized. + If there is a top-level widget associated with this window, its size will be set right after this function. + */ + virtual void onReshape(uint width, uint height); + private: struct PrivateData; PrivateData* const pData; diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 1b77915f..09fd0a6b 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -227,14 +227,18 @@ void Window::setGeometryConstraints(const uint minimumWidth, } } -void Window::onReshape(uint, uint) +bool Window::onClose() { - puglFallbackOnResize(pData->view); + return true; } -bool Window::onClose() +void Window::onFocus(bool) { - return true; +} + +void Window::onReshape(uint, uint) +{ + puglFallbackOnResize(pData->view); } #if 0 diff --git a/dgl/src/WindowPrivateData.cpp b/dgl/src/WindowPrivateData.cpp index 7966222b..cb4a093c 100644 --- a/dgl/src/WindowPrivateData.cpp +++ b/dgl/src/WindowPrivateData.cpp @@ -384,6 +384,18 @@ void Window::PrivateData::onPuglClose() close(); } +void Window::PrivateData::onPuglFocus(const bool focus) +{ + DGL_DBGp("onPuglFocus : %i %u %u\n", focus); + +// if (fModal.childFocus != nullptr) +// return fModal.childFocus->focus(); + +#ifndef DPF_TEST_WINDOW_CPP + self->onFocus(focus); +#endif +} + void Window::PrivateData::onPuglKey(const Events::KeyboardEvent& ev) { DGL_DBGp("onPuglKey : %i %u %u\n", ev.press, ev.key, ev.keycode); @@ -518,10 +530,9 @@ PuglStatus Window::PrivateData::puglEventCallback(PuglView* const view, const Pu ///< Keyboard focus entered view, a #PuglEventFocus case PUGL_FOCUS_IN: - break; - ///< Keyboard focus left view, a #PuglEventFocus case PUGL_FOCUS_OUT: + pData->onPuglFocus(event->type == PUGL_FOCUS_IN); break; ///< Key pressed, a #PuglEventKey diff --git a/dgl/src/WindowPrivateData.hpp b/dgl/src/WindowPrivateData.hpp index 4af83ee0..4a029dc4 100644 --- a/dgl/src/WindowPrivateData.hpp +++ b/dgl/src/WindowPrivateData.hpp @@ -109,6 +109,7 @@ struct Window::PrivateData : IdleCallback { void onPuglConfigure(int width, int height); void onPuglExpose(); void onPuglClose(); + void onPuglFocus(bool focus); void onPuglKey(const Events::KeyboardEvent& ev); void onPuglSpecial(const Events::SpecialEvent& ev); void onPuglText(const Events::CharacterInputEvent& ev);