From 5ee113e2c4f916b1078ace782bb130f5edf64bcf Mon Sep 17 00:00:00 2001
From: Zhao Yuhang <2546789017@qq.com>
Date: 摹曛, 14 12月 2023 20:28:02 +0800
Subject: [PATCH] minor tweaks

---
 src/widgets/widgetwindowagent_win.cpp    |    6 +++---
 src/core/contexts/cocoawindowcontext.mm  |    9 ++++-----
 src/quick/quickwindowagent_win.cpp       |    9 ++++-----
 src/core/qwindowkit_windows.h            |    4 ++--
 examples/mainwindow/mainwindow.cpp       |    2 +-
 src/core/contexts/win32windowcontext.cpp |   11 +++++++----
 6 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp
index 47c7791..da44b23 100644
--- a/examples/mainwindow/mainwindow.cpp
+++ b/examples/mainwindow/mainwindow.cpp
@@ -176,7 +176,7 @@
         QTimer::singleShot(75, [iconButton, agent]() {
             if (iconButton->property("double-click-close").toBool())
                 return;
-            agent->showSystemMenu(iconButton->mapToGlobal({0, iconButton->height()}));
+            agent->showSystemMenu(iconButton->mapToGlobal(QPoint{0, iconButton->height()}));
         });
     });
     connect(iconButton, &QWK::WindowButton::doubleClicked, this, [iconButton, this]() {
diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm
index 482f958..fc91cad 100644
--- a/src/core/contexts/cocoawindowcontext.mm
+++ b/src/core/contexts/cocoawindowcontext.mm
@@ -15,10 +15,7 @@
     } g_hook{};
 #endif
 
-    class NSWindowProxy {
-        Q_DISABLE_COPY(NSWindowProxy)
-
-    public:
+    struct NSWindowProxy {
         NSWindowProxy(NSWindow *macWindow) {
             if (instances.contains(macWindow)) {
                 return;
@@ -31,7 +28,7 @@
             }
         }
 
-        ~NSWindowProxy() override {
+        ~NSWindowProxy() {
             instances.remove(nswindow);
             if (instances.count() <= 0) {
                 restoreImplementations();
@@ -184,6 +181,8 @@
         }
 
     private:
+        Q_DISABLE_COPY(NSWindowProxy)
+
         NSWindow *nswindow = nil;
         // NSEvent *lastMouseDownEvent = nil;
 
diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index a2340ac..161903e 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -428,8 +428,8 @@
         const auto monitorInfo = getMonitorForWindow(hwnd);
         RECT windowRect{};
         ::GetWindowRect(hwnd, &windowRect);
-        const auto newX = (RECT_WIDTH(monitorInfo.rcMonitor) - RECT_WIDTH(windowRect)) / 2;
-        const auto newY = (RECT_HEIGHT(monitorInfo.rcMonitor) - RECT_HEIGHT(windowRect)) / 2;
+        const auto newX = monitorInfo.rcMonitor.left + (RECT_WIDTH(monitorInfo.rcMonitor) - RECT_WIDTH(windowRect)) / 2;
+        const auto newY = monitorInfo.rcMonitor.top + (RECT_HEIGHT(monitorInfo.rcMonitor) - RECT_HEIGHT(windowRect)) / 2;
         ::SetWindowPos(hwnd, nullptr, newX, newY, 0, 0,
                        SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
     }
@@ -448,6 +448,9 @@
         ::GetWindowPlacement(hwnd, &wp);
         return ((wp.showCmd == SW_NORMAL) || (wp.showCmd == SW_RESTORE));
 #else
+        if (isFullScreen(hwnd)) {
+            return false;
+        }
         const auto style = static_cast<DWORD>(::GetWindowLongPtrW(hwnd, GWL_STYLE));
         return (!(style & (WS_MINIMIZE | WS_MAXIMIZE)));
 #endif
@@ -840,7 +843,7 @@
                 }
                 painter.save();
 
-                // ### TODO: do we need to enable or disable it?
+                // We needs anti-aliasing to give us better result.
                 painter.setRenderHint(QPainter::Antialiasing);
 
                 painter.setPen(pen);
@@ -1236,7 +1239,7 @@
                     // If wParam is TRUE, the window is being shown.
                     // If lParam is zero, the message was sent because of a call to the ShowWindow
                     // function.
-                    if (wParam && lParam == 0) {
+                    if (wParam && !lParam) {
                         centered = true;
                         moveToDesktopCenter(hWnd);
                     }
diff --git a/src/core/qwindowkit_windows.h b/src/core/qwindowkit_windows.h
index f5f5daf..17e2387 100644
--- a/src/core/qwindowkit_windows.h
+++ b/src/core/qwindowkit_windows.h
@@ -15,11 +15,11 @@
 #endif
 
 #ifndef IsMinimized
-#  define IsMinimized(hwnd) (::IsIconic(hwnd) != FALSE)
+#  define IsMinimized(hwnd) (::IsIconic(hwnd))
 #endif
 
 #ifndef IsMaximized
-#  define IsMaximized(hwnd) (::IsZoomed(hwnd) != FALSE)
+#  define IsMaximized(hwnd) (::IsZoomed(hwnd))
 #endif
 
 #ifndef RECT_WIDTH
diff --git a/src/quick/quickwindowagent_win.cpp b/src/quick/quickwindowagent_win.cpp
index 15418e2..cfc3eb1 100644
--- a/src/quick/quickwindowagent_win.cpp
+++ b/src/quick/quickwindowagent_win.cpp
@@ -31,8 +31,7 @@
 
     BorderItem::BorderItem(QQuickItem *parent, AbstractWindowContext *context)
         : QQuickPaintedItem(parent), context(context) {
-        setAntialiasing(true);   // ### FIXME: do we need to enable or disable this?
-        setMipmap(true);         // ### FIXME: do we need to enable or disable this?
+        setAntialiasing(true);   // We needs anti-aliasing to give us better result.
         setFillColor({});        // Will improve the performance a little bit.
         setOpaquePainting(true); // Will also improve the performance, we don't draw
                                  // semi-transparent borders of course.
@@ -43,7 +42,7 @@
         anchors->setLeft(parentPri->left());
         anchors->setRight(parentPri->right());
 
-        setZ(10);
+        setZ(9999); // Make sure our fake border always above everything in the window.
 
         context->installNativeEventFilter(this);
         connect(window(), &QQuickWindow::activeChanged, this,
@@ -84,7 +83,7 @@
     bool BorderItem::nativeEventFilter(const QByteArray &eventType, void *message,
                                        QT_NATIVE_EVENT_RESULT_TYPE *result) {
         Q_UNUSED(eventType)
-        auto msg = reinterpret_cast<const MSG *>(message);
+        const auto msg = static_cast<const MSG *>(message);
         switch (msg->message) {
             case WM_THEMECHANGED:
             case WM_SYSCOLORCHANGE:
@@ -122,4 +121,4 @@
 
 }
 
-#include "quickwindowagent_win.moc"
\ No newline at end of file
+#include "quickwindowagent_win.moc"
diff --git a/src/widgets/widgetwindowagent_win.cpp b/src/widgets/widgetwindowagent_win.cpp
index ccac368..aa7e9c0 100644
--- a/src/widgets/widgetwindowagent_win.cpp
+++ b/src/widgets/widgetwindowagent_win.cpp
@@ -35,7 +35,7 @@
         bool nativeEventFilter(const QByteArray &eventType, void *message,
                                QT_NATIVE_EVENT_RESULT_TYPE *result) override {
             Q_UNUSED(eventType)
-            auto msg = reinterpret_cast<const MSG *>(message);
+            const auto msg = static_cast<const MSG *>(message);
             switch (msg->message) {
                 case WM_DPICHANGED: {
                     updateGeometry();
@@ -67,7 +67,7 @@
         bool eventFilter(QObject *obj, QEvent *event) override {
             switch (event->type()) {
                 case QEvent::Paint: {
-                    if (widget->windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen))
+                    if (widget->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen))
                         break;
 
                     auto paintEvent = static_cast<QPaintEvent *>(event);
@@ -115,4 +115,4 @@
 
 }
 
-#include "widgetwindowagent_win.moc"
\ No newline at end of file
+#include "widgetwindowagent_win.moc"

--
Gitblit v1.9.1