Merge branch 'showwindow'

This commit is contained in:
Camilla Berglund 2012-09-11 20:03:55 +02:00
commit dcc3d67158
9 changed files with 172 additions and 112 deletions

View File

@ -581,7 +581,7 @@ int main(int argc, char** argv)
exit(EXIT_FAILURE);
}
glfwWindowHint(GLFW_WINDOW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

View File

@ -399,18 +399,19 @@ extern "C" {
#define GLFW_ACCUM_ALPHA_BITS 0x0002100A
#define GLFW_AUX_BUFFERS 0x0002100B
#define GLFW_STEREO 0x0002100C
#define GLFW_WINDOW_RESIZABLE 0x0002100D
#define GLFW_FSAA_SAMPLES 0x0002100E
/* The following constants are used with both glfwGetWindowParam
* and glfwWindowHint
*/
#define GLFW_OPENGL_VERSION_MAJOR 0x0002100F
#define GLFW_OPENGL_VERSION_MINOR 0x00021010
#define GLFW_OPENGL_FORWARD_COMPAT 0x00021011
#define GLFW_OPENGL_DEBUG_CONTEXT 0x00021012
#define GLFW_OPENGL_PROFILE 0x00021013
#define GLFW_OPENGL_ROBUSTNESS 0x00021014
#define GLFW_OPENGL_VERSION_MAJOR 0x00022000
#define GLFW_OPENGL_VERSION_MINOR 0x00022001
#define GLFW_OPENGL_FORWARD_COMPAT 0x00022002
#define GLFW_OPENGL_DEBUG_CONTEXT 0x00022003
#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
@ -534,6 +535,8 @@ GLFWAPI void glfwGetWindowPos(GLFWwindow window, int* xpos, int* ypos);
GLFWAPI void glfwSetWindowPos(GLFWwindow window, 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);

View File

@ -283,6 +283,7 @@ version of GLFW.</p>
<li>Added <code>GLFW_OPENGL_ROBUSTNESS</code> window hint and associated strategy tokens for <code>GL_ARB_robustness</code> support</li>
<li>Added <code>GLFW_OPENGL_REVISION</code> window parameter to make up for removal of <code>glfwGetGLVersion</code></li>
<li>Added <code>GLFW_INCLUDE_GL3</code> macro for telling the GLFW header to include <code>gl3.h</code> header 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>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>
@ -297,7 +298,7 @@ version of GLFW.</p>
<li>Renamed <code>glfw.h</code> to <code>glfw3.h</code> to avoid conflicts with 2.x series</li>
<li>Renamed <code>glfwOpenWindowHint</code> to <code>glfwWindowHint</code></li>
<li>Renamed <code>GLFW_WINDOW</code> token to <code>GLFW_WINDOWED</code></li>
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_WINDOW_RESIZABLE</code></li>
<li>Renamed <code>GLFW_WINDOW_NO_RESIZE</code> to <code>GLFW_RESIZABLE</code></li>
<li>Renamed <code>GLFW_BUILD_DLL</code> to <code>_GLFW_BUILD_DLL</code></li>
<li>Renamed <code>version</code> test to <code>glfwinfo</code></li>
<li>Renamed <code>GLFW_NO_GLU</code> to <code>GLFW_INCLUDE_GLU</code> and made it disabled by default</li>
@ -930,8 +931,9 @@ their skills. Special thanks go out to:</p>
<li>Arturo J. Pérez, for a bug fix for cursor tracking on Mac OS X 10.6 Snow
Leopard</li>
<li>Riku Salminen, for making the X11 event processing able to support
multi-threaded rendering</li>
<li>Riku Salminen, for the initial implementation of
<code>glfwShowWindow</code> and <code>glfwHideWindow</code>, and for making
the X11 event processing able to support multi-threaded rendering</li>
<li>Douglas C. Schmidt and Irfan Pyarali, for their excellent article
<a href="http://www.cs.wustl.edu/~schmidt/win32-cv-1.html">Strategies for Implementing POSIX Condition Variables on Win32</a></li>

View File

@ -131,6 +131,25 @@
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)
{
if ([window->NS.object isVisible])
_glfwInputWindowVisibility(window, GL_TRUE);
}
}
@end
@ -898,7 +917,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)
@ -1022,6 +1040,27 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window)
}
//========================================================================
// Show window
//========================================================================
void _glfwPlatformShowWindow(_GLFWwindow* window)
{
[window->NS.object makeKeyAndOrderFront:nil];
_glfwInputWindowVisibility(window, GL_TRUE);
}
//========================================================================
// Hide window
//========================================================================
void _glfwPlatformHideWindow(_GLFWwindow* window)
{
[window->NS.object orderOut:nil];
_glfwInputWindowVisibility(window, GL_FALSE);
}
//========================================================================
// Write back window parameters into GLFW window structure
//========================================================================

View File

@ -98,6 +98,7 @@ struct _GLFWhints
int auxBuffers;
GLboolean stereo;
GLboolean resizable;
GLboolean visible;
int samples;
int glMajor;
int glMinor;
@ -120,6 +121,7 @@ struct _GLFWwndconfig
const char* title;
int refreshRate;
GLboolean resizable;
GLboolean visible;
int glMajor;
int glMinor;
GLboolean glForward;
@ -170,6 +172,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;
@ -287,6 +290,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 processing
void _glfwPlatformPollEvents(void);
@ -315,6 +320,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);

View File

@ -34,95 +34,6 @@
#include <stdlib.h>
#include <malloc.h>
//========================================================================
// 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
//========================================================================
@ -507,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)
@ -836,7 +753,7 @@ static int createWindow(_GLFWwindow* window,
WCHAR* wideTitle;
// Set common window styles
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
dwExStyle = WS_EX_APPWINDOW;
// Set window style, depending on fullscreen mode
@ -1071,9 +988,6 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window,
SWP_NOMOVE | SWP_NOSIZE);
}
setForegroundWindow(window->Win32.handle);
SetFocus(window->Win32.handle);
return GL_TRUE;
}
@ -1193,6 +1107,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
//========================================================================

View File

@ -80,8 +80,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;
// The default is 24 bits of depth, 8 bits of color
_glfwLibrary.hints.depthBits = 24;
@ -180,6 +181,16 @@ void _glfwInputWindowIconify(_GLFWwindow* window, int iconified)
}
//========================================================================
// Register window visibility events
//========================================================================
void _glfwInputWindowVisibility(_GLFWwindow* window, int visible)
{
window->visible = visible;
}
//========================================================================
// Register window damage events
//========================================================================
@ -250,6 +261,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;
@ -354,6 +366,9 @@ GLFWAPI GLFWwindow glfwCreateWindow(int width, int height,
glClear(GL_COLOR_BUFFER_BIT);
_glfwPlatformSwapBuffers(window);
if (wndconfig.visible)
glfwShowWindow(window);
return window;
}
@ -411,9 +426,12 @@ GLFWAPI void glfwWindowHint(int target, int hint)
case GLFW_STEREO:
_glfwLibrary.hints.stereo = hint;
break;
case GLFW_WINDOW_RESIZABLE:
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;
@ -627,6 +645,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
//========================================================================
@ -675,8 +725,10 @@ GLFWAPI int glfwGetWindowParam(GLFWwindow handle, int param)
return window->closeRequested;
case GLFW_REFRESH_RATE:
return window->refreshRate;
case GLFW_WINDOW_RESIZABLE:
case GLFW_RESIZABLE:
return window->resizable;
case GLFW_VISIBLE:
return window->visible;
case GLFW_OPENGL_VERSION_MAJOR:
return window->glMajor;
case GLFW_OPENGL_VERSION_MINOR:

View File

@ -228,10 +228,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;
}
@ -699,6 +695,7 @@ static void processEvent(XEvent *event)
if (window == NULL)
return;
_glfwInputWindowVisibility(window, GL_TRUE);
_glfwInputWindowIconify(window, GL_FALSE);
break;
}
@ -710,6 +707,7 @@ static void processEvent(XEvent *event)
if (window == NULL)
return;
_glfwInputWindowVisibility(window, GL_FALSE);
_glfwInputWindowIconify(window, GL_TRUE);
break;
}
@ -1044,6 +1042,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
//========================================================================

View File

@ -238,6 +238,8 @@ int main(int argc, char** argv)
if (strategy)
glfwWindowHint(GLFW_OPENGL_ROBUSTNESS, strategy);
glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
// We assume here that we stand a better chance of success by leaving all
// possible details of pixel format selection to GLFW