From dcc78017b0cf11bfe24876592c97da0a9097939d Mon Sep 17 00:00:00 2001
From: Camilla Berglund <elmindreda@elmindreda.org>
Date: Tue, 6 Jan 2015 15:35:49 +0100
Subject: [PATCH] Fixed iconification event for maximized windows.

---
 src/win32_platform.h |  1 +
 src/win32_window.c   | 11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/win32_platform.h b/src/win32_platform.h
index 1270350f..861d2bc3 100644
--- a/src/win32_platform.h
+++ b/src/win32_platform.h
@@ -159,6 +159,7 @@ typedef struct _GLFWwindowWin32
     DWORD               dwExStyle;
 
     GLboolean           cursorInside;
+    GLboolean           iconified;
 
     // The last received cursor position, regardless of source
     int                 cursorPosX, cursorPosY;
diff --git a/src/win32_window.c b/src/win32_window.c
index e6e94662..176ed596 100644
--- a/src/win32_window.c
+++ b/src/win32_window.c
@@ -489,10 +489,17 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg,
                     updateClipRect(window);
             }
 
-            if (wParam == SIZE_MINIMIZED)
+            if (!window->win32.iconified && wParam == SIZE_MINIMIZED)
+            {
+                window->win32.iconified = GL_TRUE;
                 _glfwInputWindowIconify(window, GL_TRUE);
-            else if (wParam == SIZE_RESTORED)
+            }
+            else if (window->win32.iconified &&
+                     (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED))
+            {
+                window->win32.iconified = GL_FALSE;
                 _glfwInputWindowIconify(window, GL_FALSE);
+            }
 
             _glfwInputFramebufferSize(window, LOWORD(lParam), HIWORD(lParam));
             _glfwInputWindowSize(window, LOWORD(lParam), HIWORD(lParam));