From 318f731e3ecc910605053054e4d24958402c3199 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 14 Sep 2010 03:53:22 +0200 Subject: [PATCH] Added glfwGetWindowPos. --- include/GL/glfw3.h | 1 + readme.html | 1 + src/internal.h | 1 + src/win32/win32_window.c | 3 +++ src/window.c | 20 ++++++++++++++++++++ src/x11/x11_window.c | 8 ++++++++ 6 files changed, 34 insertions(+) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 2fffa1d9..a1e53499 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -418,6 +418,7 @@ GLFWAPI void glfwCloseWindow(GLFWwindow window); GLFWAPI void glfwSetWindowTitle(GLFWwindow, const char* title); GLFWAPI void glfwGetWindowSize(GLFWwindow, int* width, int* height); GLFWAPI void glfwSetWindowSize(GLFWwindow, int width, int height); +GLFWAPI void glfwGetWindowPos(GLFWwindow, int* x, int* y); GLFWAPI void glfwSetWindowPos(GLFWwindow, int x, int y); GLFWAPI void glfwIconifyWindow(GLFWwindow window); GLFWAPI void glfwRestoreWindow(GLFWwindow window); diff --git a/readme.html b/readme.html index 04c2b8a2..6bde1f76 100644 --- a/readme.html +++ b/readme.html @@ -267,6 +267,7 @@ version of GLFW.

  • Added glfwGetError and glfwErrorString error reporting functions and a number of error tokens
  • Added glfwSetWindowUserPointer and glfwGetWindowUserPointer functions for per-window user pointers
  • 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 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/internal.h b/src/internal.h index 93499b19..cb19d5e2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -157,6 +157,7 @@ typedef struct _GLFWwindow GLboolean iconified; // GL_TRUE if this window is iconified GLboolean closed; // GL_TRUE if this window should be closed int width, height; + int positionX, positionY; int mode; // GLFW_WINDOW or GLFW_FULLSCREEN GLboolean sysKeysDisabled; // system keys disabled flag GLboolean windowNoResize; // resize- and maximize gadgets disabled flag diff --git a/src/win32/win32_window.c b/src/win32/win32_window.c index 30ba8145..3e158e6f 100644 --- a/src/win32/win32_window.c +++ b/src/win32/win32_window.c @@ -906,6 +906,9 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, case WM_MOVE: { + window->positionX = LOWORD(lParam); + window->positionY = HIWORD(lParam); + // If the mouse is locked, update the clipping rect if (window == _glfwLibrary.cursorLockWindow) { diff --git a/src/window.c b/src/window.c index 3c89abd6..3d044c6a 100644 --- a/src/window.c +++ b/src/window.c @@ -807,6 +807,26 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow window, int width, int height) } +//======================================================================== +// Get the window position +//======================================================================== + +GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* x, int* y) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED); + return; + } + + if (x != NULL) + *x = window->positionX; + + if (y != NULL) + *y = window->positionY; +} + + //======================================================================== // Set the window position //======================================================================== diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 906f1ffc..2825d853 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -1215,6 +1215,14 @@ static void processSingleEvent(void) window->height); } } + + if (event.xconfigure.x != window->positionX || + event.xconfigure.y != window->positionY) + { + window->positionX = event.xconfigure.x; + window->positionY = event.xconfigure.y; + } + break; }