mirror of
https://github.com/glfw/glfw.git
synced 2026-09-21 16:44:11 +00:00
Changed state attribs to direct access.
Changed the window states (focused, iconified and visible) to query the system directly. THIS IS A BREAKING CHANGE, although a fairly obscure one. It affects applications that both care about telling actual key events from synthetic ones, and are implemented in a non-self-synchronizing way, and that poll the GLFW_FOCUSED window attribute instead of using the window focus callback. If you maintain one of these, please feel free to drop me an email and I'll help any way I can to transition your application to 3.1. Fixes #189. Fixes #204.
This commit is contained in:
+36
-68
@@ -257,86 +257,33 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_ACTIVATE:
|
||||
case WM_SETFOCUS:
|
||||
{
|
||||
// Window was (de)focused and/or (de)iconified
|
||||
if (window->cursorMode != GLFW_CURSOR_NORMAL)
|
||||
_glfwPlatformApplyCursorMode(window);
|
||||
|
||||
BOOL focused = LOWORD(wParam) != WA_INACTIVE;
|
||||
BOOL iconified = HIWORD(wParam) ? TRUE : FALSE;
|
||||
if (window->monitor && window->autoIconify)
|
||||
enterFullscreenMode(window);
|
||||
|
||||
if (focused && iconified)
|
||||
{
|
||||
if (window->iconified && _glfw.focusedWindow != window)
|
||||
{
|
||||
// This is a workaround for window restoration using the
|
||||
// Win+D hot key leading to windows being told they're
|
||||
// focused and iconified and then never told they're
|
||||
// restored
|
||||
iconified = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is a workaround for window iconification using the
|
||||
// taskbar leading to windows being told they're focused and
|
||||
// iconified and then never told they're defocused
|
||||
focused = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!focused && _glfw.focusedWindow == window)
|
||||
{
|
||||
// The window was defocused (or iconified, see above)
|
||||
|
||||
if (window->cursorMode != GLFW_CURSOR_NORMAL)
|
||||
restoreCursor(window);
|
||||
|
||||
if (window->monitor && window->autoIconify)
|
||||
{
|
||||
if (!iconified)
|
||||
{
|
||||
// Iconify the (on top, borderless, oddly positioned)
|
||||
// window or the user will be annoyed
|
||||
_glfwPlatformIconifyWindow(window);
|
||||
}
|
||||
|
||||
leaveFullscreenMode(window);
|
||||
}
|
||||
}
|
||||
else if (focused && _glfw.focusedWindow != window)
|
||||
{
|
||||
// The window was focused
|
||||
|
||||
if (window->cursorMode != GLFW_CURSOR_NORMAL)
|
||||
_glfwPlatformApplyCursorMode(window);
|
||||
|
||||
if (window->monitor && window->autoIconify)
|
||||
enterFullscreenMode(window);
|
||||
}
|
||||
|
||||
_glfwInputWindowFocus(window, focused);
|
||||
_glfwInputWindowIconify(window, iconified);
|
||||
_glfwInputWindowFocus(window, GL_TRUE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_ACTIVATEAPP:
|
||||
case WM_KILLFOCUS:
|
||||
{
|
||||
if (!wParam && IsIconic(hWnd))
|
||||
if (window->cursorMode != GLFW_CURSOR_NORMAL)
|
||||
restoreCursor(window);
|
||||
|
||||
if (window->monitor && window->autoIconify)
|
||||
{
|
||||
// This is a workaround for full screen windows losing focus
|
||||
// through Alt+Tab leading to windows being told they're
|
||||
// unfocused and restored and then never told they're iconified
|
||||
_glfwInputWindowIconify(window, GL_TRUE);
|
||||
_glfwPlatformIconifyWindow(window);
|
||||
leaveFullscreenMode(window);
|
||||
}
|
||||
|
||||
_glfwInputWindowFocus(window, GL_FALSE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WM_SHOWWINDOW:
|
||||
{
|
||||
_glfwInputWindowVisibility(window, wParam ? GL_TRUE : GL_FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
case WM_SYSCOMMAND:
|
||||
{
|
||||
switch (wParam & 0xfff0)
|
||||
@@ -560,6 +507,11 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
|
||||
|
||||
case WM_SIZE:
|
||||
{
|
||||
if (wParam == SIZE_MINIMIZED)
|
||||
_glfwInputWindowIconify(window, GL_TRUE);
|
||||
else if (wParam == SIZE_RESTORED)
|
||||
_glfwInputWindowIconify(window, GL_FALSE);
|
||||
|
||||
if (_glfw.focusedWindow == window)
|
||||
{
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
@@ -1041,6 +993,21 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
|
||||
ShowWindow(window->win32.handle, SW_HIDE);
|
||||
}
|
||||
|
||||
int _glfwPlatformWindowFocused(_GLFWwindow* window)
|
||||
{
|
||||
return window->win32.handle == GetActiveWindow();
|
||||
}
|
||||
|
||||
int _glfwPlatformWindowIconified(_GLFWwindow* window)
|
||||
{
|
||||
return IsIconic(window->win32.handle);
|
||||
}
|
||||
|
||||
int _glfwPlatformWindowVisible(_GLFWwindow* window)
|
||||
{
|
||||
return IsWindowVisible(window->win32.handle);
|
||||
}
|
||||
|
||||
void _glfwPlatformPollEvents(void)
|
||||
{
|
||||
MSG msg;
|
||||
@@ -1238,7 +1205,8 @@ void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor)
|
||||
// the following condition is not met. That way it should be safe to destroy the
|
||||
// cursor after calling glfwSetCursor(window, NULL) on all windows using the cursor.
|
||||
|
||||
if (window->cursorMode == GLFW_CURSOR_NORMAL && _glfw.focusedWindow == window &&
|
||||
if (_glfw.focusedWindow == window &&
|
||||
window->cursorMode == GLFW_CURSOR_NORMAL &&
|
||||
window->win32.cursorInside)
|
||||
{
|
||||
if (cursor)
|
||||
|
||||
Reference in New Issue
Block a user