From c17a7dd46488bdceccf36688fd932111434c96e3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Sun, 25 Nov 2012 14:53:33 +0100 Subject: [PATCH] Made glfwGetWindowSize immediate. Conflicts: src/internal.h --- src/cocoa_window.m | 18 ++++++++++++++++-- src/input.c | 8 +++++--- src/internal.h | 7 ++++++- src/win32_window.c | 32 +++++++++++++++++++++++++------- src/window.c | 20 +++----------------- src/x11_window.c | 43 +++++++++++++++++++++++++++---------------- 6 files changed, 82 insertions(+), 46 deletions(-) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 1ed10a5c..1687aa06 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -690,8 +690,11 @@ static GLboolean createWindow(_GLFWwindow* window, styleMask |= NSResizableWindowMask; } + NSRect contentRect = NSMakeRect(wndconfig->positionX, wndconfig->positionY, + wndconfig->width, wndconfig->height); + window->ns.object = [[NSWindow alloc] - initWithContentRect:NSMakeRect(wndconfig->positionX, wndconfig->positionY, window->width, window->height) + initWithContentRect:contentRect styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; @@ -773,7 +776,7 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, { int bpp = colorBits + fbconfig->alphaBits; - if (!_glfwSetVideoMode(window->monitor, &window->width, &window->height, &bpp)) + if (!_glfwSetVideoMode(window->monitor, &window->videoMode.width, &window->videoMode.height, &bpp)) return GL_FALSE; _glfwPlatformShowWindow(window); @@ -819,6 +822,17 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char *title) [window->ns.object setTitle:[NSString stringWithUTF8String:title]]; } +void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) +{ + NSRect contentRect = + [window->ns.object contentRectForFrameRect:[window->ns.object frame]]; + + if (width) + *width = contentRect.size.width; + if (height) + *height = contentRect.size.height; +} + void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { [window->ns.object setContentSize:NSMakeSize(width, height)]; diff --git a/src/input.c b/src/input.c index 02a974fc..ddd909f6 100644 --- a/src/input.c +++ b/src/input.c @@ -37,7 +37,7 @@ static void setCursorMode(_GLFWwindow* window, int newMode) { - int oldMode, centerPosX, centerPosY; + int width, height, oldMode, centerPosX, centerPosY; if (newMode != GLFW_CURSOR_NORMAL && newMode != GLFW_CURSOR_HIDDEN && @@ -51,8 +51,10 @@ static void setCursorMode(_GLFWwindow* window, int newMode) if (oldMode == newMode) return; - centerPosX = window->width / 2; - centerPosY = window->height / 2; + _glfwPlatformGetWindowSize(window, &width, &height); + + centerPosX = width / 2; + centerPosY = height / 2; if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED) _glfwPlatformSetCursorPos(window, centerPosX, centerPosY); diff --git a/src/internal.h b/src/internal.h index 3556095b..f0e4a783 100644 --- a/src/internal.h +++ b/src/internal.h @@ -157,6 +157,8 @@ struct _GLFWhints */ struct _GLFWwndconfig { + int width; + int height; const char* title; GLboolean resizable; GLboolean visible; @@ -205,7 +207,6 @@ struct _GLFWwindow struct _GLFWwindow* next; // Window settings and state - int width, height; int positionX, positionY; GLboolean iconified; GLboolean resizable; @@ -460,6 +461,10 @@ void _glfwPlatformDestroyWindow(_GLFWwindow* window); */ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title); +/*! @ingroup platform + */ +void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height); + /*! @ingroup platform */ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); diff --git a/src/win32_window.c b/src/win32_window.c index 6a5af33b..27568a8e 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -738,7 +738,9 @@ static int createWindow(_GLFWwindow* window, } // Adjust window size for frame and title bar - getFullWindowSize(window, window->width, window->height, &fullWidth, &fullHeight); + getFullWindowSize(window, + wndconfig->width, wndconfig->height, + &fullWidth, &fullHeight); if (window->monitor) { @@ -915,13 +917,27 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) free(wideTitle); } +void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) +{ + RECT area; + GetClientRect(window->win32.handle, &area); + + if (width) + *width = area.right; + if (height) + *height = area.bottom; +} + void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { GLboolean sizeChanged = GL_FALSE; if (window->monitor) { - if (width > window->width || height > window->height) + GLFWvidmode mode; + _glfwPlatformGetVideoMode(window->monitor, &mode); + + if (width > mode.width || height > mode.height) { // The new video mode is larger than the current one, so we resize // the window before switch modes to avoid exposing whatever is @@ -980,9 +996,11 @@ void _glfwPlatformPollEvents(void) window = _glfw.focusedWindow; if (window) { + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); window->win32.cursorCentered = GL_FALSE; - window->win32.oldCursorX = window->width / 2; - window->win32.oldCursorY = window->height / 2; + window->win32.oldCursorX = width / 2; + window->win32.oldCursorY = height / 2; } else { @@ -1038,9 +1056,9 @@ void _glfwPlatformPollEvents(void) if (window->cursorMode == GLFW_CURSOR_CAPTURED && !window->win32.cursorCentered) { - _glfwPlatformSetCursorPos(window, - window->width / 2, - window->height / 2); + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2, height / 2); window->win32.cursorCentered = GL_TRUE; } } diff --git a/src/window.c b/src/window.c index f32e552b..0780b2cc 100644 --- a/src/window.c +++ b/src/window.c @@ -122,12 +122,6 @@ void _glfwInputWindowPos(_GLFWwindow* window, int x, int y) void _glfwInputWindowSize(_GLFWwindow* window, int width, int height) { - if (window->width == width && window->height == height) - return; - - window->width = width; - window->height = height; - if (window->callbacks.size) window->callbacks.size((GLFWwindow*) window, width, height); } @@ -206,6 +200,8 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, fbconfig.sRGB = _glfw.hints.sRGB ? GL_TRUE : GL_FALSE; // Set up desired window config + wndconfig.width = width; + wndconfig.height = height; wndconfig.title = title; wndconfig.resizable = _glfw.hints.resizable ? GL_TRUE : GL_FALSE; wndconfig.visible = _glfw.hints.visible ? GL_TRUE : GL_FALSE; @@ -247,8 +243,6 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, window->videoMode.blueBits = fbconfig.blueBits; } - window->width = width; - window->height = height; window->monitor = wndconfig.monitor; window->resizable = wndconfig.resizable; window->cursorMode = GLFW_CURSOR_NORMAL; @@ -487,11 +481,7 @@ GLFWAPI void glfwGetWindowSize(GLFWwindow* handle, int* width, int* height) return; } - if (width != NULL) - *width = window->width; - - if (height != NULL) - *height = window->height; + _glfwPlatformGetWindowSize(window, width, height); } GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) @@ -510,10 +500,6 @@ GLFWAPI void glfwSetWindowSize(GLFWwindow* handle, int width, int height) return; } - // Don't do anything if the window size did not change - if (width == window->width && height == window->height) - return; - if (window->monitor) { window->videoMode.width = width; diff --git a/src/x11_window.c b/src/x11_window.c index 65127800..2e40460d 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -121,7 +121,7 @@ static GLboolean createWindow(_GLFWwindow* window, window->x11.handle = XCreateWindow(_glfw.x11.display, _glfw.x11.root, wndconfig->positionX, wndconfig->positionY, - window->width, window->height, + wndconfig->width, wndconfig->height, 0, // Border width visual->depth, // Color depth InputOutput, @@ -227,8 +227,8 @@ static GLboolean createWindow(_GLFWwindow* window, if (!wndconfig->resizable) { hints->flags |= (PMinSize | PMaxSize); - hints->min_width = hints->max_width = window->width; - hints->min_height = hints->max_height = window->height; + hints->min_width = hints->max_width = wndconfig->width; + hints->min_height = hints->max_height = wndconfig->height; } XSetWMNormalHints(_glfw.x11.display, window->x11.handle, hints); @@ -392,12 +392,15 @@ static void enterFullscreenMode(_GLFWwindow* window) // In override-redirect mode we have divorced ourselves from the // window manager, so we need to do everything manually + GLFWvidmode mode; + _glfwPlatformGetVideoMode(window->monitor, &mode); + XRaiseWindow(_glfw.x11.display, window->x11.handle); XSetInputFocus(_glfw.x11.display, window->x11.handle, RevertToParent, CurrentTime); XMoveWindow(_glfw.x11.display, window->x11.handle, 0, 0); XResizeWindow(_glfw.x11.display, window->x11.handle, - window->width, window->height); + mode.width, mode.height); } } @@ -893,10 +896,19 @@ void _glfwPlatformSetWindowTitle(_GLFWwindow* window, const char* title) } } +void _glfwPlatformGetWindowSize(_GLFWwindow* window, int* width, int* height) +{ + XWindowAttributes attribs; + XGetWindowAttributes(_glfw.x11.display, window->x11.handle, &attribs); + + if (width) + *width = attribs.width; + if (height) + *height = attribs.height; +} + void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) { - GLboolean sizeChanged = GL_FALSE; - if (!window->resizable) { // Update window size restrictions to match new window size @@ -913,18 +925,17 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height) if (window->monitor) { - // Change window size before changing fullscreen mode? - if (width > window->width) + if (window->x11.overrideRedirect) { - XResizeWindow(_glfw.x11.display, window->x11.handle, width, height); - sizeChanged = GL_TRUE; + GLFWvidmode mode; + _glfwPlatformGetVideoMode(window->monitor, &mode); + XResizeWindow(_glfw.x11.display, window->x11.handle, + window->videoMode.width, window->videoMode.height); } _glfwSetVideoMode(window->monitor, &window->videoMode); } - - // Set window size (if not already changed) - if (!sizeChanged) + else XResizeWindow(_glfw.x11.display, window->x11.handle, width, height); } @@ -993,9 +1004,9 @@ void _glfwPlatformPollEvents(void) if (window->cursorMode == GLFW_CURSOR_CAPTURED && !window->x11.cursorCentered) { - _glfwPlatformSetCursorPos(window, - window->width / 2, - window->height / 2); + int width, height; + _glfwPlatformGetWindowSize(window, &width, &height); + _glfwPlatformSetCursorPos(window, width / 2, height / 2); window->x11.cursorCentered = GL_TRUE; // NOTE: This is a temporary fix. It works as long as you use