From 1ef9a85148f0e8be19aaf8999e545bc9e494d94d Mon Sep 17 00:00:00 2001
From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
Date: Fri, 1 Mar 2024 11:44:53 -0500
Subject: [PATCH] QWK: enforce a min Qt version of 6.6.2 on Windows

This will prevent a graphical issue present when disabling QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS to avoid the Windows 10 top border issue for the frameless window option. This allows us to remove the temp workaround that likely introduces side effects.

Gitlab: #1581
Change-Id: I36801064d31e2380312d73f88233e8ed9b757403
---
 CMakeLists.txt                                |  6 +++-
 INSTALL.md                                    |  6 ++--
 .../0002-workaround-right-margin.patch        | 34 -------------------
 extras/scripts/build-windows.py               |  2 +-
 4 files changed, 9 insertions(+), 39 deletions(-)
 delete mode 100644 extras/patches/0002-workaround-right-margin.patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b3f0106d9..b93daeda1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -87,7 +87,6 @@ list(APPEND QWINDOWKIT_OPTIONS
 )
 
 if(WIN32)
-  list(APPEND QWINDOWKIT_PATCHES ${EXTRA_PATCHES_DIR}/0002-workaround-right-margin.patch)
   list(APPEND QWINDOWKIT_OPTIONS QWINDOWKIT_ENABLE_WINDOWS_SYSTEM_BORDERS OFF)
 endif()
 
@@ -140,6 +139,11 @@ else()
   find_package(QT NAMES Qt6 REQUIRED)
 endif()
 if (${QT_VERSION_MINOR} GREATER_EQUAL ${QT6_MINVER_MINOR})
+  # Enforce a minimum Qt version of 6.6.2 for the Windows build
+  # https://github.com/stdware/qwindowkit/issues/23
+  if(MSVC AND ${QT_VERSION_MINOR} EQUAL 6 AND ${QT_VERSION_PATCH} LESS 2)
+    message(FATAL_ERROR "Qt 6.6.2 or higher is required. Found ${QT_VERSION}")
+  endif()
   # Qt version is 6.6 or higher
   message(STATUS "Found a suitable Qt version ${QT_VERSION}")
 else()
diff --git a/INSTALL.md b/INSTALL.md
index a005c2d22..1d20c0cc0 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -212,7 +212,7 @@ Only 64-bit MSVC build can be compiled.
 
   |                      | Qt Version |
   | -------------------- | ---------- |
-  | Minimum requirement: | 6.6.1      |
+  | Minimum requirement: | 6.6.2      |
 
 - Install [Python3](https://www.python.org/downloads/) for Windows
 
@@ -238,7 +238,7 @@ Only 64-bit MSVC build can be compiled.
 - Using a new **Non-Elevated Command Prompt**
 
 ```bash
-    python build.py --install --qt <path-to-qt-bin-folder> (e.g. C:/Qt/6.6.1/msvc2019_64)
+    python build.py --install --qt <path-to-qt-bin-folder> (e.g. C:/Qt/6.6.2/msvc2019_64)
 ```
 
 > **SDK** Note:
@@ -281,7 +281,7 @@ Once the build has finished, you should then be able to use the Visual Studio So
 
 ```
     python extras\scripts\build-windows.py --init
-    python extras\scripts\build-windows.py --qt <path-to-qt-bin-folder> (e.g. C:/Qt/6.6.1/msvc2019_64)
+    python extras\scripts\build-windows.py --qt <path-to-qt-bin-folder> (e.g. C:/Qt/6.6.2/msvc2019_64)
 ```
 
 ## Building On MacOS
diff --git a/extras/patches/0002-workaround-right-margin.patch b/extras/patches/0002-workaround-right-margin.patch
deleted file mode 100644
index 4ebe48372..000000000
--- a/extras/patches/0002-workaround-right-margin.patch
+++ /dev/null
@@ -1,34 +0,0 @@
-From ca2be6466c150d1b82a646d97b27df35b45d90f1 Mon Sep 17 00:00:00 2001
-From: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
-Date: Tue, 9 Jan 2024 15:25:19 -0500
-Subject: [PATCH] workaround right margin
-
----
- src/core/contexts/win32windowcontext.cpp | 11 +++++++++++
- 1 file changed, 11 insertions(+)
-
-diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
-index 3f6623e..9ee7752 100644
---- a/src/core/contexts/win32windowcontext.cpp
-+++ b/src/core/contexts/win32windowcontext.cpp
-@@ -402,6 +402,17 @@ namespace QWK {
-                     return true;
-                 }
-             }
-+
-+#if !QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDERS)
-+            if (msg->message == WM_MOVE || msg->message == WM_SIZE ||
-+                (msg->message == WM_IME_SETCONTEXT && (GetForegroundWindow() == msg->hwnd))) {
-+                static const auto flags = SWP_FRAMECHANGED | SWP_NOMOVE |
-+                                          SWP_NOSIZE | SWP_NOZORDER |
-+                                          SWP_NOOWNERZORDER;
-+                SetWindowPos(msg->hwnd, NULL, 0, 0, 0, 0, flags);
-+            }
-+#endif
-+
-             return false;
-         }
-
---
-2.7.4
-
diff --git a/extras/scripts/build-windows.py b/extras/scripts/build-windows.py
index 03c527d8a..b53f55fd5 100644
--- a/extras/scripts/build-windows.py
+++ b/extras/scripts/build-windows.py
@@ -28,7 +28,7 @@ mutually exclusive required arguments:
   -z, --zip         Build portable archive
 
 examples:
-1.  build.py --qt=C:/Qt/6.6.1/msvc2019_64  # Build the app using a specific Qt
+1.  build.py --qt=C:/Qt/6.6.2/msvc2019_64  # Build the app using a specific Qt
 2.  build.py --init pack --msi             # Build the app and an MSI installer
 3.  build.py --init --tests                # Build the app and run tests
     build.py pack --zip --skip-build       # Generate a 7z archive of the app
-- 
GitLab