From 03f8528315fa46c95991a34f3325d7b33ae5538c Mon Sep 17 00:00:00 2001
From: Edward Rudd <urkle@outoforder.cc>
Date: Sat, 02 May 2020 21:48:36 +0000
Subject: [PATCH] Update source to SDL2 2.0.12

---
 source/src/video/windows/SDL_windowswindow.c |   63 +++++++++++++++++++------------
 1 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/source/src/video/windows/SDL_windowswindow.c b/source/src/video/windows/SDL_windowswindow.c
index 45463c4..237d380 100644
--- a/source/src/video/windows/SDL_windowswindow.c
+++ b/source/src/video/windows/SDL_windowswindow.c
@@ -1,6 +1,6 @@
 /*
   Simple DirectMedia Layer
-  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
+  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
 
   This software is provided 'as-is', without any express or implied
   warranty.  In no event will the authors be held liable for any damages
@@ -93,9 +93,14 @@
             style |= STYLE_NORMAL;
         }
 
-        /* You can have a borderless resizable window */
         if (window->flags & SDL_WINDOW_RESIZABLE) {
-            style |= STYLE_RESIZABLE;
+            /* You can have a borderless resizable window, but Windows doesn't always draw it correctly,
+               see https://bugzilla.libsdl.org/show_bug.cgi?id=4466
+             */
+            if (!(window->flags & SDL_WINDOW_BORDERLESS) ||
+                SDL_GetHintBoolean("SDL_BORDERLESS_RESIZABLE_STYLE", SDL_FALSE)) {
+                style |= STYLE_RESIZABLE;
+            }
         }
 
         /* Need to set initialize minimize style, or when we call ShowWindow with WS_MINIMIZE it will activate a random window */
@@ -380,12 +385,13 @@
     HWND hwnd = (HWND) data;
     LPTSTR title;
     int titleLen;
+    SDL_bool isstack;
 
     /* Query the title from the existing window */
     titleLen = GetWindowTextLength(hwnd);
-    title = SDL_stack_alloc(TCHAR, titleLen + 1);
+    title = SDL_small_alloc(TCHAR, titleLen + 1, &isstack);
     if (title) {
-        titleLen = GetWindowText(hwnd, title, titleLen);
+        titleLen = GetWindowText(hwnd, title, titleLen + 1);
     } else {
         titleLen = 0;
     }
@@ -393,7 +399,7 @@
         window->title = WIN_StringToUTF8(title);
     }
     if (title) {
-        SDL_stack_free(title);
+        SDL_small_free(title, isstack);
     }
 
     if (SetupWindowData(_this, window, hwnd, GetParent(hwnd), SDL_FALSE) < 0) {
@@ -443,14 +449,15 @@
     BYTE *icon_bmp;
     int icon_len, mask_len, y;
     SDL_RWops *dst;
+    SDL_bool isstack;
 
     /* Create temporary buffer for ICONIMAGE structure */
     mask_len = (icon->h * (icon->w + 7)/8);
     icon_len = 40 + icon->h * icon->w * sizeof(Uint32) + mask_len;
-    icon_bmp = SDL_stack_alloc(BYTE, icon_len);
+    icon_bmp = SDL_small_alloc(BYTE, icon_len, &isstack);
     dst = SDL_RWFromMem(icon_bmp, icon_len);
     if (!dst) {
-        SDL_stack_free(icon_bmp);
+        SDL_small_free(icon_bmp, isstack);
         return;
     }
 
@@ -481,7 +488,7 @@
     hicon = CreateIconFromResource(icon_bmp, icon_len, TRUE, 0x00030000);
 
     SDL_RWclose(dst);
-    SDL_stack_free(icon_bmp);
+    SDL_small_free(icon_bmp, isstack);
 
     /* Set the icon for the window */
     SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
@@ -902,7 +909,7 @@
 {
     SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     SDL_Mouse *mouse = SDL_GetMouse();
-    RECT rect;
+    RECT rect, clipped_rect;
 
     if (data->in_title_click || data->focus_click_pending) {
         return;
@@ -911,35 +918,43 @@
         data->skip_update_clipcursor = SDL_FALSE;
         return;
     }
+    if (!GetClipCursor(&clipped_rect)) {
+        return;
+    }
 
     if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
         (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
         if (mouse->relative_mode && !mouse->relative_mode_warp) {
-            LONG cx, cy;
-            GetWindowRect(data->hwnd, &rect);
+            if (GetWindowRect(data->hwnd, &rect)) {
+                LONG cx, cy;
 
-            cx = (rect.left + rect.right) / 2;
-            cy = (rect.top + rect.bottom) / 2;
+                cx = (rect.left + rect.right) / 2;
+                cy = (rect.top + rect.bottom) / 2;
 
-            /* Make an absurdly small clip rect */
-            rect.left = cx - 1;
-            rect.right = cx + 1;
-            rect.top = cy - 1;
-            rect.bottom = cy + 1;
+                /* Make an absurdly small clip rect */
+                rect.left = cx - 1;
+                rect.right = cx + 1;
+                rect.top = cy - 1;
+                rect.bottom = cy + 1;
 
-            if (ClipCursor(&rect)) {
-                data->cursor_clipped_rect = rect;
+                if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
+                    if (ClipCursor(&rect)) {
+                        data->cursor_clipped_rect = rect;
+                    }
+                }
             }
         } else {
             if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
                 ClientToScreen(data->hwnd, (LPPOINT) & rect);
                 ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
-                if (ClipCursor(&rect)) {
-                    data->cursor_clipped_rect = rect;
+                if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
+                    if (ClipCursor(&rect)) {
+                        data->cursor_clipped_rect = rect;
+                    }
                 }
             }
         }
-    } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
+    } else if (SDL_memcmp(&clipped_rect, &data->cursor_clipped_rect, sizeof(clipped_rect)) == 0) {
         ClipCursor(NULL);
         SDL_zero(data->cursor_clipped_rect);
     }

--
Gitblit v1.9.3