From 64afb193e8f07e04eaa4439f55b1f2a70b269c01 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Wed, 6 Mar 2013 23:29:37 +0100 Subject: [PATCH] Removed return value of close callback. --- docs/quick.dox | 6 +++--- include/GL/glfw3.h | 25 +++++++++---------------- src/window.c | 6 +++--- tests/events.c | 4 ++-- tests/reopen.c | 3 +-- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/docs/quick.dox b/docs/quick.dox index aa5cb7b5..fc9f104b 100644 --- a/docs/quick.dox +++ b/docs/quick.dox @@ -181,9 +181,9 @@ while (!glfwWindowShouldClose(window)) } @endcode -You can intercept the setting of the close flag by setting a close callback with -@ref glfwSetWindowCloseCallback. The return value of the close callback becomes -the new value of the close flag. +You can be notified when user is attempting to close the window by setting +a close callback with @ref glfwSetWindowCloseCallback. The callback will be +called immediately after the close flag has been set. You can also set it yourself with @ref glfwSetWindowShouldClose. This can be useful if you want to interpret other kinds of input as closing the window, like diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 4ecd62dd..65a13311 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -591,15 +591,11 @@ typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int); /*! @brief The function signature for window close callbacks. * @param[in] window The window that the user attempted to close. - * @return One of @c GL_TRUE or @c GL_FALSE. * @ingroup window * - * The return value of the close callback becomes the new value returned by - * @ref glfwWindowShouldClose. - * * @sa glfwSetWindowCloseCallback */ -typedef int (* GLFWwindowclosefun)(GLFWwindow*); +typedef void (* GLFWwindowclosefun)(GLFWwindow*); /*! @brief The function signature for window content refresh callbacks. * @param[in] window The window whose content needs to be refreshed. @@ -1121,20 +1117,17 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, const char* title, G */ GLFWAPI void glfwDestroyWindow(GLFWwindow* window); -/*! @brief Checks whether the specified window has been requested to close. +/*! @brief Checks the close flag of the specified window. * @param[in] window The window to query. - * @return @c GL_TRUE if the window should close, or @c GL_FALSE otherwise. + * @return The value of the close flag. * @ingroup window */ GLFWAPI int glfwWindowShouldClose(GLFWwindow* window); -/*! @brief Sets whether the specified window should close. - * @param[in] window The window whose value to change. +/*! @brief Sets the close flag of the specified window. + * @param[in] window The window whose flag to change. * @param[in] value The new value. * @ingroup window - * - * @note Calling this from the close callback will have no effect, as whatever - * value you set will be overwritten by the return value of the close callback. */ GLFWAPI void glfwSetWindowShouldClose(GLFWwindow* window, int value); @@ -1367,11 +1360,11 @@ GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbf * @ingroup window * * This callback is called when the user attempts to close the window, i.e. - * clicks the window's close widget. Calling @ref glfwDestroyWindow does not - * cause this callback to be called. + * for example by clicking the window's close widget. It is called immediately + * after the window's close flag has been set. * - * The return value of the close callback becomes the new value returned by - * @ref glfwWindowShouldClose. + * @remarks Calling @ref glfwDestroyWindow does not cause this callback to be + * called. * * @remarks Mac OS X: Selecting Quit from the application menu will * trigger the close callback for all windows. diff --git a/src/window.c b/src/window.c index 4ca174ad..57907eaf 100644 --- a/src/window.c +++ b/src/window.c @@ -126,10 +126,10 @@ void _glfwInputWindowDamage(_GLFWwindow* window) void _glfwInputWindowCloseRequest(_GLFWwindow* window) { + window->closed = GL_TRUE; + if (window->callbacks.close) - window->closed = window->callbacks.close((GLFWwindow*) window); - else - window->closed = GL_TRUE; + window->callbacks.close((GLFWwindow*) window); } diff --git a/tests/events.c b/tests/events.c index a899ef33..96756f88 100644 --- a/tests/events.c +++ b/tests/events.c @@ -244,11 +244,11 @@ static void window_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } -static int window_close_callback(GLFWwindow* window) +static void window_close_callback(GLFWwindow* window) { printf("%08x at %0.3f: Window close\n", counter++, glfwGetTime()); - return closeable; + glfwSetWindowShouldClose(window, closeable); } static void window_refresh_callback(GLFWwindow* window) diff --git a/tests/reopen.c b/tests/reopen.c index 7a2e3814..ea64f2bb 100644 --- a/tests/reopen.c +++ b/tests/reopen.c @@ -48,10 +48,9 @@ static void window_size_callback(GLFWwindow* window, int width, int height) glViewport(0, 0, width, height); } -static int window_close_callback(GLFWwindow* window) +static void window_close_callback(GLFWwindow* window) { printf("Close callback triggered\n"); - return GL_TRUE; } static void key_callback(GLFWwindow* window, int key, int action)