From 9cd2e9ec8fc0127393dfce9c0359d500c8c238be Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Tue, 09 Apr 2019 02:22:50 +0000
Subject: [PATCH] updae source to 2.0.9 source

---
 source/src/video/windows/SDL_windowsevents.c |   52 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 42 insertions(+), 10 deletions(-)

diff --git a/source/src/video/windows/SDL_windowsevents.c b/source/src/video/windows/SDL_windowsevents.c
index a5fd006..e961cf5 100644
--- a/source/src/video/windows/SDL_windowsevents.c
+++ b/source/src/video/windows/SDL_windowsevents.c
@@ -228,9 +228,7 @@
         /* Ignore the button click for activation */
         if (!bwParamMousePressed) {
             data->focus_click_pending &= ~SDL_BUTTON(button);
-            if (!data->focus_click_pending) {
-                WIN_UpdateClipCursor(data->window);
-            }
+            WIN_UpdateClipCursor(data->window);
         }
         if (WIN_ShouldIgnoreFocusClick()) {
             return;
@@ -416,10 +414,22 @@
         }
         break;
 
+    case WM_NCACTIVATE:
+        {
+            /* Don't immediately clip the cursor in case we're clicking minimize/maximize buttons */
+            data->skip_update_clipcursor = SDL_TRUE;
+        }
+        break;
+
     case WM_ACTIVATE:
         {
             POINT cursorPos;
             BOOL minimized;
+
+            /* Don't mark the window as shown if it's activated before being shown */
+            if (!IsWindowVisible(hwnd)) {
+                break;
+            }
 
             minimized = HIWORD(wParam);
             if (!minimized && (LOWORD(wParam) != WA_INACTIVE)) {
@@ -460,6 +470,8 @@
                 SDL_ToggleModState(KMOD_CAPS, (GetKeyState(VK_CAPITAL) & 0x0001) != 0);
                 SDL_ToggleModState(KMOD_NUM, (GetKeyState(VK_NUMLOCK) & 0x0001) != 0);
             } else {
+                RECT rect;
+
                 data->in_window_deactivation = SDL_TRUE;
 
                 if (SDL_GetKeyboardFocus() == data->window) {
@@ -467,7 +479,10 @@
                     WIN_ResetDeadKeys();
                 }
 
-                ClipCursor(NULL);
+                if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect) == 0)) {
+                    ClipCursor(NULL);
+                    SDL_zero(data->cursor_clipped_rect);
+                }
 
                 data->in_window_deactivation = SDL_FALSE;
             }
@@ -648,7 +663,7 @@
         break;
 
     case WM_UNICHAR:
-        if ( wParam == UNICODE_NOCHAR ) {
+        if (wParam == UNICODE_NOCHAR) {
             returnCode = 1;
             break;
         }
@@ -656,8 +671,8 @@
     case WM_CHAR:
         {
             char text[5];
-            if ( WIN_ConvertUTF32toUTF8( (UINT32)wParam, text ) ) {
-                SDL_SendKeyboardText( text );
+            if (WIN_ConvertUTF32toUTF8((UINT32)wParam, text)) {
+                SDL_SendKeyboardText(text);
             }
         }
         returnCode = 0;
@@ -1022,6 +1037,20 @@
     }
 }
 
+static void WIN_UpdateClipCursorForWindows()
+{
+    SDL_VideoDevice *_this = SDL_GetVideoDevice();
+    SDL_Window *window;
+
+    if (_this) {
+        for (window = _this->windows; window; window = window->next) {
+            if (window->driverdata) {
+                WIN_UpdateClipCursor(window);
+            }
+        }
+    }
+}
+
 /* A message hook called before TranslateMessage() */
 static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
 static void *g_WindowsMessageHookData = NULL;
@@ -1067,6 +1096,9 @@
     if ((keystate[SDL_SCANCODE_RSHIFT] == SDL_PRESSED) && !(GetKeyState(VK_RSHIFT) & 0x8000)) {
         SDL_SendKeyboardKey(SDL_RELEASED, SDL_SCANCODE_RSHIFT);
     }
+
+    /* Update the clipping rect in case someone else has stolen it */
+    WIN_UpdateClipCursorForWindows();
 }
 
 /* to work around #3931, a bug introduced in Win10 Fall Creators Update (build nr. 16299)
@@ -1094,9 +1126,9 @@
             SDL_zero(info);
             info.dwOSVersionInfoSize = sizeof(info);
             if (getVersionPtr(&info) == 0) { /* STATUS_SUCCESS == 0 */
-                if (   (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299)
-                    || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0)
-                    || (info.dwMajorVersion > 10) )
+                if ((info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && info.dwBuildNumber >= 16299) ||
+                    (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) ||
+                    (info.dwMajorVersion > 10))
                 {
                     return SDL_TRUE;
                 }

--
Gitblit v1.9.3