1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-11-23 02:38:52 -05:00

Added window focus callback (Cocoa implementation missing).

This commit is contained in:
Camilla Berglund 2010-09-19 02:49:42 +02:00
parent 7ebe76289d
commit bc7a8d48da
6 changed files with 81 additions and 42 deletions

View File

@ -385,6 +385,7 @@ typedef struct
typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int); typedef void (* GLFWwindowsizefun)(GLFWwindow,int,int);
typedef int (* GLFWwindowclosefun)(GLFWwindow); typedef int (* GLFWwindowclosefun)(GLFWwindow);
typedef void (* GLFWwindowrefreshfun)(GLFWwindow); typedef void (* GLFWwindowrefreshfun)(GLFWwindow);
typedef void (* GLFWwindowfocusfun)(GLFWwindow,int);
typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int); typedef void (* GLFWmousebuttonfun)(GLFWwindow,int,int);
typedef void (* GLFWmouseposfun)(GLFWwindow,int,int); typedef void (* GLFWmouseposfun)(GLFWwindow,int,int);
typedef void (* GLFWmousewheelfun)(GLFWwindow,int); typedef void (* GLFWmousewheelfun)(GLFWwindow,int);
@ -429,6 +430,7 @@ GLFWAPI void* glfwGetWindowUserPointer(GLFWwindow window);
GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun); GLFWAPI void glfwSetWindowSizeCallback(GLFWwindow window, GLFWwindowsizefun cbfun);
GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun); GLFWAPI void glfwSetWindowCloseCallback(GLFWwindow window, GLFWwindowclosefun cbfun);
GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun); GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfun cbfun);
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun);
/* Event handling */ /* Event handling */
GLFWAPI void glfwPollEvents(void); GLFWAPI void glfwPollEvents(void);

View File

@ -268,6 +268,7 @@ version of GLFW.</p>
<li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li> <li>Added <code>glfwSetWindowUserPointer</code> and <code>glfwGetWindowUserPointer</code> functions for per-window user pointers</li>
<li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li> <li>Added <code>glfwGetVersionString</code> function for determining which code paths were enabled at compile time</li>
<li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li> <li>Added <code>glfwGetWindowPos</code> function for querying the position of the specified window</li>
<li>Added <code>glfwSetWindowFocusCallback</code> function and GLFWwindowfocusfun type for receiving window focus events</li>
<li>Added <code>windows</code> simple multi-window test program</li> <li>Added <code>windows</code> simple multi-window test program</li>
<li>Added initial window title parameter to <code>glfwOpenWindow</code></li> <li>Added initial window title parameter to <code>glfwOpenWindow</code></li>
<li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li> <li>Changed buffer bit depth parameters of <code>glfwOpenWindow</code> to window hints</li>

View File

@ -148,6 +148,7 @@ typedef struct _GLFWwindow
GLFWwindowsizefun windowSizeCallback; GLFWwindowsizefun windowSizeCallback;
GLFWwindowclosefun windowCloseCallback; GLFWwindowclosefun windowCloseCallback;
GLFWwindowrefreshfun windowRefreshCallback; GLFWwindowrefreshfun windowRefreshCallback;
GLFWwindowfocusfun windowFocusCallback;
GLFWmousebuttonfun mouseButtonCallback; GLFWmousebuttonfun mouseButtonCallback;
GLFWmouseposfun mousePosCallback; GLFWmouseposfun mousePosCallback;
GLFWmousewheelfun mouseWheelCallback; GLFWmousewheelfun mouseWheelCallback;
@ -295,10 +296,10 @@ void _glfwSetError(int error);
void _glfwClearWindowHints(void); void _glfwClearWindowHints(void);
// Input handling (window.c) // Input handling (window.c)
void _glfwInputDeactivation(_GLFWwindow* window);
void _glfwInputKey(_GLFWwindow* window, int key, int action); void _glfwInputKey(_GLFWwindow* window, int key, int action);
void _glfwInputChar(_GLFWwindow* window, int character); void _glfwInputChar(_GLFWwindow* window, int character);
void _glfwInputMouseClick(_GLFWwindow* window, int button, int action); void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated);
// OpenGL extensions (glext.c) // OpenGL extensions (glext.c)
void _glfwParseGLVersion(int* major, int* minor, int* rev); void _glfwParseGLVersion(int* major, int* minor, int* rev);

View File

@ -642,12 +642,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
BOOL active = LOWORD(wParam) != WA_INACTIVE; BOOL active = LOWORD(wParam) != WA_INACTIVE;
BOOL iconified = HIWORD(wParam) ? TRUE : FALSE; BOOL iconified = HIWORD(wParam) ? TRUE : FALSE;
if ((!active && _glfwLibrary.activeWindow == window) || if (active && iconified)
(iconified && !window->iconified))
{ {
// The window was either deactivated, iconified or both // This is a workaround for window iconification using the
// taskbar leading to windows being told they're active and
// iconified and then never told they're deactivated
active = FALSE;
}
_glfwInputDeactivation(window); if (!active && _glfwLibrary.activeWindow == window)
{
// The window was deactivated (or iconified, see above)
if (window == _glfwLibrary.cursorLockWindow) if (window == _glfwLibrary.cursorLockWindow)
_glfwPlatformShowMouseCursor(window); _glfwPlatformShowMouseCursor(window);
@ -668,8 +673,10 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
} }
} }
} }
else if (active && !iconified) else if (active && _glfwLibrary.activeWindow != window)
{ {
// The window was activated
if (window == _glfwLibrary.cursorLockWindow) if (window == _glfwLibrary.cursorLockWindow)
_glfwPlatformHideMouseCursor(window); _glfwPlatformHideMouseCursor(window);
@ -688,13 +695,7 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
} }
} }
if (active) _glfwInputWindowFocus(window, active);
_glfwLibrary.activeWindow = window;
else
{
if (window == _glfwLibrary.activeWindow)
_glfwLibrary.activeWindow = NULL;
}
window->iconified = iconified; window->iconified = iconified;
return 0; return 0;

View File

@ -117,30 +117,6 @@ void _glfwClearWindowHints(void)
} }
//========================================================================
// Handle the input tracking part of window deactivation
//========================================================================
void _glfwInputDeactivation(_GLFWwindow* window)
{
int i;
// Release all keyboard keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_PRESS)
_glfwInputKey(window, i, GLFW_RELEASE);
}
// Release all mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_PRESS)
_glfwInputMouseClick(window, i, GLFW_RELEASE);
}
}
//======================================================================== //========================================================================
// Register keyboard activity // Register keyboard activity
//======================================================================== //========================================================================
@ -207,6 +183,51 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
} }
//========================================================================
// Register window focus events
//========================================================================
void _glfwInputWindowFocus(_GLFWwindow* window, GLboolean activated)
{
if (activated)
{
if (_glfwLibrary.activeWindow != window)
{
_glfwLibrary.activeWindow = window;
if (window->windowFocusCallback)
window->windowFocusCallback(window, activated);
}
}
else
{
if (_glfwLibrary.activeWindow == window)
{
int i;
// Release all pressed keyboard keys
for (i = 0; i <= GLFW_KEY_LAST; i++)
{
if (window->key[i] == GLFW_PRESS)
_glfwInputKey(window, i, GLFW_RELEASE);
}
// Release all pressed mouse buttons
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButton[i] == GLFW_PRESS)
_glfwInputMouseClick(window, i, GLFW_RELEASE);
}
_glfwLibrary.activeWindow = NULL;
if (window->windowFocusCallback)
window->windowFocusCallback(window, activated);
}
}
}
//======================================================================== //========================================================================
// Return the available framebuffer config closest to the desired values // Return the available framebuffer config closest to the desired values
// This is based on the manual GLX Visual selection from 2.6 // This is based on the manual GLX Visual selection from 2.6
@ -1084,6 +1105,22 @@ GLFWAPI void glfwSetWindowRefreshCallback(GLFWwindow window, GLFWwindowrefreshfu
} }
//========================================================================
// Set callback function for window focus events
//========================================================================
GLFWAPI void glfwSetWindowFocusCallback(GLFWwindow window, GLFWwindowfocusfun cbfun)
{
if (!_glfwInitialized)
{
_glfwSetError(GLFW_NOT_INITIALIZED);
return;
}
window->windowFocusCallback = cbfun;
}
//======================================================================== //========================================================================
// Poll for new window and input events and close any flagged windows // Poll for new window and input events and close any flagged windows
//======================================================================== //========================================================================

View File

@ -1299,7 +1299,7 @@ static void processSingleEvent(void)
return; return;
} }
_glfwLibrary.activeWindow = window; _glfwInputWindowFocus(window, GL_TRUE);
if (_glfwLibrary.cursorLockWindow == window) if (_glfwLibrary.cursorLockWindow == window)
_glfwPlatformHideMouseCursor(window); _glfwPlatformHideMouseCursor(window);
@ -1317,10 +1317,7 @@ static void processSingleEvent(void)
return; return;
} }
if (_glfwLibrary.activeWindow == window) _glfwInputWindowFocus(window, GL_FALSE);
_glfwLibrary.activeWindow = NULL;
_glfwInputDeactivation(window);
if (_glfwLibrary.cursorLockWindow == window) if (_glfwLibrary.cursorLockWindow == window)
_glfwPlatformShowMouseCursor(window); _glfwPlatformShowMouseCursor(window);