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
+61 -24
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
//========================================================================
@@ -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
// 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
//========================================================================