From 8bb5c59d2d01ccc6e1247b5680e7d962fb81de80 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 21 Aug 2012 21:18:09 +0200 Subject: [PATCH] Added GLFW_VISIBLE window hint and parameter. --- include/GL/glfw3.h | 1 + readme.html | 1 + src/cocoa_window.m | 16 ++++++++++++++++ src/internal.h | 4 ++++ src/win32_window.c | 6 ++++++ src/window.c | 22 +++++++++++++++++++--- src/x11_window.c | 2 ++ 7 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 5472f8b1..6f535408 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -417,6 +417,7 @@ extern "C" { #define GLFW_OPENGL_PROFILE 0x00022004 #define GLFW_OPENGL_ROBUSTNESS 0x00022005 #define GLFW_RESIZABLE 0x00022006 +#define GLFW_VISIBLE 0x00022007 /* GLFW_OPENGL_ROBUSTNESS mode tokens */ #define GLFW_OPENGL_NO_ROBUSTNESS 0x00000000 diff --git a/readme.html b/readme.html index 580e21cd..c6eedbf3 100644 --- a/readme.html +++ b/readme.html @@ -283,6 +283,7 @@ version of GLFW.

  • Added GLFW_OPENGL_ROBUSTNESS window hint and associated strategy tokens for GL_ARB_robustness support
  • Added GLFW_OPENGL_REVISION window parameter to make up for removal of glfwGetGLVersion
  • Added GLFW_INCLUDE_GL3 macro for telling the GLFW header to include gl3.h header instead of gl.h
  • +
  • Added GLFW_VISIBLE window hint and parameter for controlling and polling window visibility
  • Added windows simple multi-window test program
  • Added sharing simple OpenGL object sharing test program
  • Added modes video mode enumeration and setting test program
  • diff --git a/src/cocoa_window.m b/src/cocoa_window.m index db6d07b8..0d62b0fa 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -131,6 +131,22 @@ return NSTerminateCancel; } +- (void)applicationDidHide:(NSNotification *)notification +{ + _GLFWwindow* window; + + for (window = _glfwLibrary.windowListHead; window; window = window->next) + _glfwInputWindowVisibility(window, GL_FALSE); +} + +- (void)applicationDidUnhide:(NSNotification *)notification +{ + _GLFWwindow* window; + + for (window = _glfwLibrary.windowListHead; window; window = window->next) + _glfwInputWindowVisibility(window, GL_TRUE); +} + @end diff --git a/src/internal.h b/src/internal.h index 1bad7483..8e923d50 100644 --- a/src/internal.h +++ b/src/internal.h @@ -109,6 +109,7 @@ struct _GLFWhints int auxBuffers; GLboolean stereo; GLboolean resizable; + GLboolean visible; int samples; int glMajor; int glMinor; @@ -131,6 +132,7 @@ struct _GLFWwndconfig const char* title; int refreshRate; GLboolean resizable; + GLboolean visible; int glMajor; int glMinor; GLboolean glForward; @@ -181,6 +183,7 @@ struct _GLFWwindow int positionX, positionY; int mode; // GLFW_WINDOW or GLFW_FULLSCREEN GLboolean resizable; // GL_TRUE if user may resize this window + GLboolean visible; // GL_TRUE if this window is visible int refreshRate; // monitor refresh rate void* userPointer; @@ -338,6 +341,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated); void _glfwInputWindowPos(_GLFWwindow* window, int x, int y); void _glfwInputWindowSize(_GLFWwindow* window, int width, int height); void _glfwInputWindowIconify(_GLFWwindow* window, int iconified); +void _glfwInputWindowVisibility(_GLFWwindow* window, int visible); void _glfwInputWindowDamage(_GLFWwindow* window); void _glfwInputWindowCloseRequest(_GLFWwindow* window); diff --git a/src/win32_window.c b/src/win32_window.c index ff6941ab..b83d504a 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -418,6 +418,12 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, return 0; } + case WM_SHOWWINDOW: + { + _glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE); + break; + } + case WM_SYSCOMMAND: { switch (wParam & 0xfff0) diff --git a/src/window.c b/src/window.c index 4f8a96e6..7e928cf2 100644 --- a/src/window.c +++ b/src/window.c @@ -82,8 +82,9 @@ void _glfwSetDefaultWindowHints(void) _glfwLibrary.hints.glMajor = 1; _glfwLibrary.hints.glMinor = 0; - // The default is to allow window resizing + // The default is to show the window and allow window resizing _glfwLibrary.hints.resizable = GL_TRUE; + _glfwLibrary.hints.visible = GL_TRUE; } @@ -176,6 +177,16 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified) } +//======================================================================== +// Register window visibility events +//======================================================================== + +void _glfwInputWindowVisibility(_GLFWwindow* window, int visible) +{ + window->visible = visible; +} + + //======================================================================== // Register window damage events //======================================================================== @@ -246,6 +257,7 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, wndconfig.title = title; wndconfig.refreshRate = Max(_glfwLibrary.hints.refreshRate, 0); wndconfig.resizable = _glfwLibrary.hints.resizable ? GL_TRUE : GL_FALSE; + wndconfig.visible = _glfwLibrary.hints.visible ? GL_TRUE : GL_FALSE; wndconfig.glMajor = _glfwLibrary.hints.glMajor; wndconfig.glMinor = _glfwLibrary.hints.glMinor; wndconfig.glForward = _glfwLibrary.hints.glForward ? GL_TRUE : GL_FALSE; @@ -318,8 +330,6 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } - glfwShowWindow(window); - // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); @@ -353,6 +363,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, glClear(GL_COLOR_BUFFER_BIT); _glfwPlatformSwapBuffers(window); + if (wndconfig.visible) + glfwShowWindow(window); + return window; } @@ -413,6 +426,9 @@ GLFWAPI void glfwWindowHint(int target, int hint) case GLFW_RESIZABLE: _glfwLibrary.hints.resizable = hint; break; + case GLFW_VISIBLE: + _glfwLibrary.hints.visible = hint; + break; case GLFW_FSAA_SAMPLES: _glfwLibrary.hints.samples = hint; break; diff --git a/src/x11_window.c b/src/x11_window.c index 90938ccb..b4d62605 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -736,6 +736,7 @@ static void processSingleEvent(void) return; } + _glfwInputWindowVisibility(window, GL_TRUE); _glfwInputWindowIconify(window, GL_FALSE); break; } @@ -750,6 +751,7 @@ static void processSingleEvent(void) return; } + _glfwInputWindowVisibility(window, GL_FALSE); _glfwInputWindowIconify(window, GL_TRUE); break; }