From d030b88c8614eba9396b16357782e0daa2fd371d Mon Sep 17 00:00:00 2001 From: Eden Salomon Date: Tue, 20 Oct 2015 20:29:49 +0300 Subject: [PATCH] Fix issue in windows when autoIconify is enabled the window attempts to enter fullscreen mode twice --- src/win32_window.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/win32_window.c b/src/win32_window.c index 2f2db36e2..7f8f380f5 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -871,9 +871,14 @@ int _glfwPlatformCreateWindow(_GLFWwindow* window, if (window->monitor) { + // the following function calls ShowWindow + // which sends WM_SETFOCUS to windowProc() + // Which then enters fullscreen mode if autoIconify is enabled (win32_window.c : line 283) _glfwPlatformShowWindow(window); - if (!enterFullscreenMode(window)) - return GLFW_FALSE; + if (!window->autoIconify) { // add this to prevent entering full screen mode twice when autoIconify == true + if (!enterFullscreenMode(window)) + return GLFW_FALSE; + } } return GLFW_TRUE; @@ -1030,11 +1035,44 @@ void _glfwPlatformRestoreWindow(_GLFWwindow* window) void _glfwPlatformShowWindow(_GLFWwindow* window) { ShowWindow(window->win32.handle, SW_SHOW); + + // Consider separating the following function calls to a different function? + // e.g. RequestFocus(_GLFWwindow* window) (any of these might fail) BringWindowToTop(window->win32.handle); SetForegroundWindow(window->win32.handle); SetFocus(window->win32.handle); } +/* one example of separation */ + +int _glfwPlatformGrabFocus(_GLFWwindow* window) +{ + if (!BringWindowToTop(window->win32.handle)) + return GLFW_FALSE; + if (!SetForegroundWindow(window->win32.handle)) + return GLFW_FALSE; + if (!SetFocus(window->win32.handle)) + return GLFW_FALSE; + return GLFW_FALSE; +} + +void _glfwPlatformRequestFocus(_GLFWwindow* window) +{ + // The following can be used to flash the taskbar icon + // if any of the focus related functions fail + if (!_glfwPlatformGrabFocus(window)) { + // create a taskbar notification ("flash") + FLASHWINFO info; + info.cbSize = sizeof(FLASHWINFO); + info.hwnd = window->win32.handle; + info.dwFlags = FLASHW_TRAY; + info.uCount = 3; + info.dwTimeout = 0; + + FlashWindowEx(&info); + } +} + void _glfwPlatformUnhideWindow(_GLFWwindow* window) { ShowWindow(window->win32.handle, SW_SHOW);