commit 74680dedcf658ac9298afea5a7cc9237e46a283e
parent d7d9d9ea0ddae7175972bdd6f5d6b897870f1c84
Author: falkTX <falktx@falktx.com>
Date: Sun, 16 May 2021 12:18:12 +0100
Add Window::onFocus event
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
4 files changed, 34 insertions(+), 12 deletions(-)
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
@@ -242,18 +242,24 @@ public:
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.
Override this method and return false to prevent the window from being closed by the user.
*/
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
@@ -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
@@ -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
@@ -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);