From 596132c3a1becceb0ba6d10991d52a85ba8f201c Mon Sep 17 00:00:00 2001 From: Riku Salminen Date: Tue, 21 Aug 2012 21:01:57 +0300 Subject: [PATCH] Add glfwShowWindow, glfwHideWindow Add glfwShowWindow and glfwHideWindow functions to allow explicit control over show/hide window. Remove platform specific show window code from _glfwPlatformCreateWindow but call glfwShowWindow from glfwCreateWindow to avoid breaking things (for now). --- include/GL/glfw3.h | 2 + src/cocoa_window.m | 20 +++++++- src/internal.h | 2 + src/win32_window.c | 114 +++++++++------------------------------------ src/window.c | 34 ++++++++++++++ src/x11_window.c | 26 +++++++++-- 6 files changed, 101 insertions(+), 97 deletions(-) diff --git a/include/GL/glfw3.h b/include/GL/glfw3.h index 050f0c30..79b6033a 100644 --- a/include/GL/glfw3.h +++ b/include/GL/glfw3.h @@ -540,6 +540,8 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow, int* xpos, int* ypos); GLFWAPI void glfwSetWindowPos(GLFWwindow, int xpos, int ypos); GLFWAPI void glfwIconifyWindow(GLFWwindow window); GLFWAPI void glfwRestoreWindow(GLFWwindow window); +GLFWAPI void glfwShowWindow(GLFWwindow window); +GLFWAPI void glfwHideWindow(GLFWwindow window); GLFWAPI int glfwGetWindowParam(GLFWwindow window, int param); GLFWAPI void glfwSetWindowUserPointer(GLFWwindow window, void* pointer); GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window); diff --git a/src/cocoa_window.m b/src/cocoa_window.m index d7764f92..db6d07b8 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -906,7 +906,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (!createContext(window, wndconfig, fbconfig)) return GL_FALSE; - [window->NS.object makeKeyAndOrderFront:nil]; [window->NSGL.context setView:[window->NS.object contentView]]; if (wndconfig->mode == GLFW_FULLSCREEN) @@ -1030,6 +1029,25 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + [window->NS.object makeKeyAndOrderFront:nil]; +} + + +//======================================================================== +// Hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + [window->NS.object orderOut:nil]; +} + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/internal.h b/src/internal.h index 89ac48b2..1bad7483 100644 --- a/src/internal.h +++ b/src/internal.h @@ -302,6 +302,8 @@ void _glfwPlatformSetWindowSize(_GLFWwindow* window, int width, int height); void _glfwPlatformSetWindowPos(_GLFWwindow* window, int x, int y); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); +void _glfwPlatformShowWindow(_GLFWwindow* window); +void _glfwPlatformHideWindow(_GLFWwindow* window); // Event management void _glfwPlatformPollEvents(void); diff --git a/src/win32_window.c b/src/win32_window.c index 77b99026..ff6941ab 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -34,95 +34,6 @@ #include #include - -//======================================================================== -// Enable/disable minimize/restore animations -//======================================================================== - -static int setMinMaxAnimations(int enable) -{ - ANIMATIONINFO AI; - int old_enable; - - // Get old animation setting - AI.cbSize = sizeof(ANIMATIONINFO); - SystemParametersInfo(SPI_GETANIMATION, AI.cbSize, &AI, 0); - old_enable = AI.iMinAnimate; - - // If requested, change setting - if (old_enable != enable) - { - AI.iMinAnimate = enable; - SystemParametersInfo(SPI_SETANIMATION, AI.cbSize, &AI, - SPIF_SENDCHANGE); - } - - return old_enable; -} - - -//======================================================================== -// Focus the window and bring it to the top of the stack -// Due to some nastiness with how XP handles SetForegroundWindow we have -// to go through some really bizarre measures to achieve this -//======================================================================== - -static void setForegroundWindow(HWND hWnd) -{ - int try_count = 0; - int old_animate; - - // Try the standard approach first... - BringWindowToTop(hWnd); - SetForegroundWindow(hWnd); - - // If it worked, return now - if (hWnd == GetForegroundWindow()) - { - // Try to modify the system settings (since this is the foreground - // process, we are allowed to do this) - SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, - SPIF_SENDCHANGE); - return; - } - - // For other Windows versions than 95 & NT4.0, the standard approach - // may not work, so if we failed we have to "trick" Windows into - // making our window the foureground window: Iconify and restore - // again. It is ugly, but it seems to work (we turn off those annoying - // zoom animations to make it look a bit better at least). - - // Turn off minimize/restore animations - old_animate = setMinMaxAnimations(0); - - // We try this a few times, just to be on the safe side of things... - do - { - // Iconify & restore - ShowWindow(hWnd, SW_HIDE); - ShowWindow(hWnd, SW_SHOWMINIMIZED); - ShowWindow(hWnd, SW_SHOWNORMAL); - - // Try to get focus - BringWindowToTop(hWnd); - SetForegroundWindow(hWnd); - - // We do not want to keep going on forever, so we keep track of - // how many times we tried - try_count++; - } - while (hWnd != GetForegroundWindow() && try_count <= 3); - - // Restore the system minimize/restore animation setting - setMinMaxAnimations(old_animate); - - // Try to modify the system settings (since this is now hopefully the - // foreground process, we are probably allowed to do this) - SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (LPVOID) 0, - SPIF_SENDCHANGE); -} - - //======================================================================== // Hide mouse cursor //======================================================================== @@ -1071,9 +982,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, SWP_NOMOVE | SWP_NOSIZE); } - setForegroundWindow(window->Win32.handle); - SetFocus(window->Win32.handle); - return GL_TRUE; } @@ -1193,6 +1101,28 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show or hide window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + ShowWindow(window->Win32.handle, SW_SHOWNORMAL); + BringWindowToTop(window->Win32.handle); + SetForegroundWindow(window->Win32.handle); + SetFocus(window->Win32.handle); +} + + +//======================================================================== +// Show or hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + ShowWindow(window->Win32.handle, SW_HIDE); +} + //======================================================================== // Write back window parameters into GLFW window structure //======================================================================== diff --git a/src/window.c b/src/window.c index 4e95129a..efaa1572 100644 --- a/src/window.c +++ b/src/window.c @@ -318,6 +318,8 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height, return GL_FALSE; } + glfwShowWindow(window, 1); // TODO: consider if this is necessary! + // Cache the actual (as opposed to requested) window parameters _glfwPlatformRefreshWindowParams(window); @@ -623,6 +625,38 @@ GLFWAPI void glfwIconifyWindow(GLFWwindow handle) } +//======================================================================== +// Window show +//======================================================================== + +GLFWAPI void glfwShowWindow(GLFWwindow window) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwPlatformShowWindow((_GLFWwindow*)window); +} + + +//======================================================================== +// Window hide +//======================================================================== + +GLFWAPI void glfwHideWindow(GLFWwindow window) +{ + if (!_glfwInitialized) + { + _glfwSetError(GLFW_NOT_INITIALIZED, NULL); + return; + } + + _glfwPlatformHideWindow((_GLFWwindow*)window); +} + + //======================================================================== // Window un-iconification //======================================================================== diff --git a/src/x11_window.c b/src/x11_window.c index 442e76c0..90938ccb 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -230,10 +230,6 @@ static GLboolean createWindow(_GLFWwindow* window, _glfwPlatformSetWindowTitle(window, wndconfig->title); - // Make sure the window is mapped before proceeding - XMapWindow(_glfwLibrary.X11.display, window->X11.handle); - XFlush(_glfwLibrary.X11.display); - return GL_TRUE; } @@ -1099,6 +1095,28 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) } +//======================================================================== +// Show window +//======================================================================== + +void _glfwPlatformShowWindow(_GLFWwindow* window) +{ + XMapRaised(_glfwLibrary.X11.display, window->X11.handle); + XFlush(_glfwLibrary.X11.display); +} + + +//======================================================================== +// Hide window +//======================================================================== + +void _glfwPlatformHideWindow(_GLFWwindow* window) +{ + XUnmapWindow(_glfwLibrary.X11.display, window->X11.handle); + XFlush(_glfwLibrary.X11.display); +} + + //======================================================================== // Read back framebuffer parameters from the context //========================================================================