From 0d7e1794a5d099708974c52cad086e13b5fa8b14 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 20 Sep 2010 02:22:35 +0200 Subject: [PATCH] Added window iconification callback. --- include/GL/glfw3.h | 2 ++ readme.html | 1 + src/cocoa/cocoa_window.m | 6 ++++++ src/internal.h | 1 + src/win32/win32_window.c | 9 ++++++++- src/window.c | 16 ++++++++++++++++ src/x11/x11_window.c | 8 ++++++++ tests/events.c | 9 +++++++++ 8 files changed, 51 insertions(+), 1 deletion(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index fd6d43bf..2de5b409 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -386,6 +386,7 @@ typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int); typedef int (* GLFWwindowclosefun)(GLFWwindow); typedef void (* GLFWwindowrefreshfun)(GLFWwindow); typedef void (* GLFWwindowfocusfun)(GLFWwindow,int); +typedef void (* GLFWwindowiconifyfun)(GLFWwindow,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); typedef void (* GLFWmousewheelfun)(GLFWwindow,int); @@ -431,6 +432,7 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfu GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun); GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun); GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun); +GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun); /* Event handling */ GLFWAPI void glfwPollEvents(void); diff --git a/readme.html b/readme.html index 2389d891..41076390 100644 --- a/readme.html +++ b/readme.html @@ -269,6 +269,7 @@ version of GLFW.

  • Added glfwGetVersionString function for determining which code paths were enabled at compile time
  • Added glfwGetWindowPos function for querying the position of the specified window
  • Added glfwSetWindowFocusCallback function and GLFWwindowfocusfun type for receiving window focus events
  • +
  • Added glfwSetWindowIconifyCallback function and GLFWwindowiconifyfun type for receiving window iconification events
  • Added windows simple multi-window test program
  • Added initial window title parameter to glfwOpenWindow
  • Changed buffer bit depth parameters of glfwOpenWindow to window hints
  • diff --git a/src/cocoa/cocoa_window.m b/src/cocoa/cocoa_window.m index e391eba1..6bb55712 100644 --- a/src/cocoa/cocoa_window.m +++ b/src/cocoa/cocoa_window.m @@ -94,11 +94,17 @@ - (void)windowDidMiniaturize:(NSNotification *)notification { window->iconified = GL_TRUE; + + if (window->windowIconifyCallback) + window->windowIconifyCallback(window, window->iconified); } - (void)windowDidDeminiaturize:(NSNotification *)notification { window->iconified = GL_FALSE; + + if (window->windowIconifyCallback) + window->windowIconifyCallback(window, window->iconified); } - (void)windowDidBecomeKey:(NSNotification *)notification diff --git a/src/internal.h b/src/internal.h index d7bb5d05..7c3d0187 100644 --- a/src/internal.h +++ b/src/internal.h @@ -149,6 +149,7 @@ typedef struct _GLFWwindow GLFWwindowclosefun windowCloseCallback; GLFWwindowrefreshfun windowRefreshCallback; GLFWwindowfocusfun windowFocusCallback; + GLFWwindowiconifyfun windowIconifyCallback; GLFWmousebuttonfun mouseButtonCallback; GLFWmouseposfun mousePosCallback; GLFWmousewheelfun mouseWheelCallback; diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index 7ba50a03..c5e3ca54 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -697,7 +697,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, _glfwInputWindowFocus(window, active); - window->iconified = iconified; + if (iconified != window->iconified) + { + window->iconified = iconified; + + if (window->windowIconifyCallback) + window->windowIconifyCallback(window, window->iconified); + } + return 0; } diff --git a/src/window.c b/src/window.c index 12f0b865..62622d80 100644 --- a/src/window.c +++ b/src/window.c @@ -1122,6 +1122,22 @@ GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cb } +//======================================================================== +// Set callback function for window iconification events +//======================================================================== + +GLFWAPI void glfwSetWindowIconifyCallback(GLFWwindow window, GLFWwindowiconifyfun cbfun) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED); + return; + } + + window->windowIconifyCallback = cbfun; +} + + //======================================================================== // Poll for new window and input events and close any flagged windows //======================================================================== diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index c847bf50..22054930 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -1272,6 +1272,10 @@ static void processSingleEvent(void) } window->iconified = GL_FALSE; + + if (window->windowIconifyCallback) + window->windowIconifyCallback(window, window->iconified); + break; } @@ -1286,6 +1290,10 @@ static void processSingleEvent(void) } window->iconified = GL_TRUE; + + if (window->windowIconifyCallback) + window->windowIconifyCallback(window, window->iconified); + break; } diff --git a/tests/events.c b/tests/events.c index e4f56108..26c1dfea 100644 --- a/tests/events.c +++ b/tests/events.c @@ -193,6 +193,14 @@ static void window_focus_callback(GLFWwindow window, int activated) activated ? "activated" : "deactivated"); } +static void window_iconify_callback(GLFWwindow window, int iconified) +{ + printf("%08x at %0.3f: Window was %s\n", + counter++, + glfwGetTime(), + iconified ? "iconified" : "restored"); +} + static void mouse_button_callback(GLFWwindow window, int button, int action) { const char* name = get_button_name(button); @@ -299,6 +307,7 @@ int main(void) glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); glfwSetWindowFocusCallback(window, window_focus_callback); + glfwSetWindowIconifyCallback(window, window_iconify_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetMousePosCallback(window, mouse_position_callback); glfwSetMouseWheelCallback(window, mouse_wheel_callback);