From 5e1c012c539e74804454d45a1b945093afdb8f4f Mon Sep 17 00:00:00 2001
From: Zhao Yuhang <2546789017@qq.com>
Date: 周日, 09 2月 2025 11:15:59 +0800
Subject: [PATCH] apply some fixes and workarounds

---
 examples/qml/main.qml                    |    3 ++-
 src/widgets/widgetwindowagent_win.cpp    |   12 ++++++++++--
 examples/qml/QWKButton.qml               |    2 +-
 README.md                                |   14 --------------
 src/core/contexts/win32windowcontext.cpp |   18 +++++++++++++++++-
 5 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/README.md b/README.md
index a90b231..c2e1f9d 100644
--- a/README.md
+++ b/README.md
@@ -45,20 +45,6 @@
 |:-------------------------------:|:---------------------------------:|
 | ![image](./docs/images/mac.png) | ![image](./docs/images/linux.png) |
 
-## Products who use QWK
-
-### Jami
-
-![jami](https://jami.net/content/images/2024/02/Screenshot-2024-01-22-160459-1.jpg)
-
-[Jami](https://jami.net/) is a free/libre, end-to-end encrypted, and private communication software.
-
-### Tietie
-
-![tietie](https://tietieapp.com/tietie.png)
-
-[Tietie](https://tietieapp.com) is a simple and easy to use clipboard management software. Multi-format support, powerful search ability.
-
 ## Requirements
 
 | Component | Requirement |          Details          |
diff --git a/examples/qml/QWKButton.qml b/examples/qml/QWKButton.qml
index e781d69..8bf58a2 100644
--- a/examples/qml/QWKButton.qml
+++ b/examples/qml/QWKButton.qml
@@ -1,5 +1,5 @@
 import QtQuick 2.15
-import QtQuick.Controls 2.15
+import QtQuick.Controls.Basic 2.15
 
 Button {
     id: root
diff --git a/examples/qml/main.qml b/examples/qml/main.qml
index ff034e9..315064d 100644
--- a/examples/qml/main.qml
+++ b/examples/qml/main.qml
@@ -1,6 +1,6 @@
 import QtQuick 2.15
 import QtQuick.Window 2.15
-import QtQuick.Controls 2.15
+import QtQuick.Controls.Basic 2.15
 import Qt.labs.platform 1.1
 import QWindowKit 1.0
 
@@ -144,6 +144,7 @@
         color: "#FEFEFE"
         Component.onCompleted: {
             if ($curveRenderingAvailable) {
+                console.log("Curve rendering for text is available.")
                 timeLabel.renderType = Text.CurveRendering
             }
         }
diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index ce1037a..204b4b0 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -33,6 +33,10 @@
 #include "qwkglobal_p.h"
 #include "qwkwindowsextra_p.h"
 
+#if (QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)) && (QT_VERSION <= QT_VERSION_CHECK(6, 6, 1))
+#  error Current Qt version has a critical bug which will break QWK functionality. Please upgrade to > 6.6.1 or downgrade to < 6.6.0
+#endif
+
 namespace QWK {
 
     enum IconButtonClickLevelFlag {
@@ -922,7 +926,8 @@
             // from the top side. In the end I found that we only need to extend from the left
             // side if we extend long enough. In this way we can see the special material even
             // when the host object is a QWidget and the title bar still remain hidden. But even
-            // though this solution seems perfect, I really don't know why it works.
+            // though this solution seems perfect, I really don't know why it works. The following
+            // hack is totally based on experiments.
             static constexpr const MARGINS margins = {65536, 0, 0, 0};
             apis.pDwmExtendFrameIntoClientArea(hwnd, &margins);
         };
@@ -2016,6 +2021,17 @@
         // and align it with the upper-left corner of our new client area".
         const auto clientRect = wParam ? &(reinterpret_cast<LPNCCALCSIZE_PARAMS>(lParam))->rgrc[0]
                                        : reinterpret_cast<LPRECT>(lParam);
+        [[maybe_unused]] const auto& d3dFlickerReducer = qScopeGuard([this]() {
+            // When we receive this message, it means the window size has changed
+            // already, and it seems this message always come before any client
+            // area size notifications (eg. WM_WINDOWPOSCHANGED and WM_SIZE). Let
+            // D3D paint immediately to let user see the latest result as soon as
+            // possible.
+            if (m_windowHandle && m_windowHandle->surfaceType() == QSurface::Direct3DSurface
+                && isDwmCompositionEnabled() && DynamicApis::instance().pDwmFlush) {
+                DynamicApis::instance().pDwmFlush();
+            }
+        });
         if (isSystemBorderEnabled()) {
             // Store the original top margin before the default window procedure applies the
             // default frame.
diff --git a/src/widgets/widgetwindowagent_win.cpp b/src/widgets/widgetwindowagent_win.cpp
index 2e08d04..1522cab 100644
--- a/src/widgets/widgetwindowagent_win.cpp
+++ b/src/widgets/widgetwindowagent_win.cpp
@@ -55,8 +55,16 @@
         }
 
         void updateGeometry() override {
-            widget->setContentsMargins(isNormalWindow() ? QMargins(0, borderThickness(), 0, 0)
-                                                        : QMargins());
+            // The window top border is manually painted by QWK so we want to give
+            // some margins to avoid it covering real window contents, however, we
+            // found that there are some rounding issues for the thin border and
+            // thus this small trick doesn't work very well when the DPR is not
+            // integer. So far we haven't found a perfect solution, so just don't
+            // set any margins. In theory the window content will only be covered
+            // by 1px or so, it should not be a serious issue in the real world.
+            //
+            // widget->setContentsMargins(isNormalWindow() ? QMargins(0, borderThickness(), 0, 0)
+            //                                             : QMargins());
         }
 
         bool isWindowActive() const override {

--
Gitblit v1.9.1