Added window position callback.
diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 8759ea7..e9cea00 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h
@@ -706,6 +706,16 @@ */ typedef void (* GLFWerrorfun)(int,const char*); +/*! @brief The function signature for window position callbacks. + * @param[in] window The window that the user moved. + * @param[in] x The new x-coordinate, in pixels, of the upper-left corner of + * the client area of the window. + * @param[in] y The new y-coordinate, in pixels, of the upper-left corner of + * the client area of the window. + * @ingroup window + */ +typedef void (* GLFWwindowposfun)(GLFWwindow,int,int); + /*! @brief The function signature for window resize callbacks. * @param[in] window The window that the user resized. * @param[in] width The new width, in pixels, of the window. @@ -1274,6 +1284,14 @@ */ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window); +/*! @brief Sets the position callback for the specified window. + * @param[in] window The window whose callback to set. + * @param[in] cbfun The new callback, or @c NULL to remove the currently set + * callback. + * @ingroup window + */ +GLFWAPI void glfwSetWindowPosCallback(GLFWwindow window, GLFWwindowposfun cbfun); + /*! @brief Sets the size callback for the specified window. * @param[in] window The window whose callback to set. * @param[in] cbfun The new callback, or @c NULL to remove the currently set
diff --git a/readme.html b/readme.html index 81100df..1e62945 100644 --- a/readme.html +++ b/readme.html
@@ -274,7 +274,7 @@ <li>Added <code>glfwSetErrorCallback</code> function and <code>GLFWerrorfun</code> type for receiving more specific and/or nested errors</li> <li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li> <li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li> - <li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li> + <li>Added <code>glfwSetWindowPosCallback</code> function and <code>GLFWwindowposfun</code> type for reciving window position events</li> <li>Added <code>glfwSetWindowFocusCallback</code> function and <code>GLFWwindowfocusfun</code> type for receiving window focus events</li> <li>Added <code>glfwSetWindowIconifyCallback</code> function and <code>GLFWwindowiconifyfun</code> type for receiving window iconification events</li> <li>Added <code>glfwGetClipboardString</code> and <code>glfwSetClipboardString</code> functions for interacting with the system clipboard</li> @@ -284,6 +284,7 @@ <li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li> <li>Added <code>GLFW_INCLUDE_GLCOREARB</code> macro for including <code>glcorearb.h</code> instead of <code>gl.h</code></li> <li>Added <code>GLFW_VISIBLE</code> window hint and parameter for controlling and polling window visibility</li> + <li>Added <code>GLFW_POSITION_X</code> and <code>GLFW_POSITION_Y</code> window hints and parameter for controlling and polling window position</li> <li>Added <code>windows</code> simple multi-window test program</li> <li>Added <code>sharing</code> simple OpenGL object sharing test program</li> <li>Added <code>modes</code> video mode enumeration and setting test program</li>
diff --git a/src/internal.h b/src/internal.h index c5a40af..2ef8f10 100644 --- a/src/internal.h +++ b/src/internal.h
@@ -199,6 +199,7 @@ int glRobustness; PFNGLGETSTRINGIPROC GetStringi; + GLFWwindowposfun windowPosCallback; GLFWwindowsizefun windowSizeCallback; GLFWwindowclosefun windowCloseCallback; GLFWwindowrefreshfun windowRefreshCallback;
diff --git a/src/window.c b/src/window.c index 908a2a7..ac0fd02 100644 --- a/src/window.c +++ b/src/window.c
@@ -119,8 +119,14 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) { + if (window->positionX == x && window->positionY == y) + return; + window->positionX = x; window->positionY = y; + + if (window->windowPosCallback) + window->windowPosCallback(window, x, y); } @@ -765,6 +771,24 @@ //======================================================================== +// Set callback function for window position changes +//======================================================================== + +GLFWAPI void glfwSetWindowPosCallback(GLFWwindow handle, GLFWwindowposfun cbfun) +{ + _GLFWwindow* window = (_GLFWwindow*) handle; + + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + window->windowPosCallback = cbfun; +} + + +//======================================================================== // Set callback function for window size changes //========================================================================
diff --git a/tests/events.c b/tests/events.c index 3150a82..46bde2a 100644 --- a/tests/events.c +++ b/tests/events.c
@@ -218,6 +218,15 @@ return result; } +static void window_pos_callback(GLFWwindow window, int x, int y) +{ + printf("%08x at %0.3f: Window position: %i %i\n", + counter++, + glfwGetTime(), + x, + y); +} + static void window_size_callback(GLFWwindow window, int width, int height) { printf("%08x at %0.3f: Window size: %i %i\n", @@ -354,6 +363,7 @@ printf("Window opened\n"); + glfwSetWindowPosCallback(window, window_pos_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetWindowCloseCallback(window, window_close_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback);