From e9f790d3533ebaee1f782e91b6e13b2c6375c86a Mon Sep 17 00:00:00 2001
From: SineStriker <55847490+SineStriker@users.noreply.github.com>
Date: 周二, 11 2月 2025 23:06:01 +0800
Subject: [PATCH] AWC: fix window attribute handler

---
 src/core/contexts/cocoawindowcontext.mm |   54 +++++++++++++++++++++++++++---------------------------
 1 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm
index ca49d2f..c26152f 100644
--- a/src/core/contexts/cocoawindowcontext.mm
+++ b/src/core/contexts/cocoawindowcontext.mm
@@ -1,4 +1,5 @@
-// Copyright (C) 2023-2024 Stdware Collections
+// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
+// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
 // SPDX-License-Identifier: Apache-2.0
 
 #include "cocoawindowcontext_p.h"
@@ -329,13 +330,9 @@
             nswindow.movableByWindowBackground = NO;
             nswindow.movable = NO; // This line causes the window in the wrong position when
                                    // become fullscreen.
-            //  For some unknown reason, we don't need the following hack in Qt versions below or
-            //  equal to 6.2.4.
-#if (QT_VERSION > QT_VERSION_CHECK(6, 2, 4))
-            [nswindow standardWindowButton:NSWindowCloseButton].hidden = (visible ? NO : YES);
-            [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = (visible ? NO : YES);
-            [nswindow standardWindowButton:NSWindowZoomButton].hidden = (visible ? NO : YES);
-#endif
+            [nswindow standardWindowButton:NSWindowCloseButton].hidden = NO;
+            [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = NO;
+            [nswindow standardWindowButton:NSWindowZoomButton].hidden = NO;
         }
 
         static void replaceImplementations() {
@@ -512,7 +509,10 @@
 
     static inline void releaseWindowProxy(const WId windowId) {
         if (auto proxy = g_proxyList->take(windowId)) {
-            proxy->setSystemTitleBarVisible(true);
+            // TODO: Determine if the window is valid
+
+            // The window has been destroyed
+            // proxy->setSystemTitleBarVisible(true);
             delete proxy;
         } else {
             return;
@@ -633,10 +633,11 @@
             }
 
             case QEvent::MouseButtonDblClick: {
-                if (me->button() == Qt::LeftButton && inTitleBar &&
-                    !delegate->isHostSizeFixed(host)) {
+                if (me->button() == Qt::LeftButton && inTitleBar && !m_context->isHostSizeFixed()) {
+                    Qt::WindowFlags windowFlags = delegate->getWindowFlags(host);
                     Qt::WindowStates windowState = delegate->getWindowState(host);
-                    if (!(windowState & Qt::WindowFullScreen)) {
+                    if ((windowFlags & Qt::WindowMaximizeButtonHint) &&
+                        !(windowState & Qt::WindowFullScreen)) {
                         if (windowState & Qt::WindowMaximized) {
                             delegate->setWindowState(host, windowState & ~Qt::WindowMaximized);
                         } else {
@@ -660,7 +661,7 @@
     }
 
     CocoaWindowContext::~CocoaWindowContext() {
-        releaseWindowProxy(windowId);
+        releaseWindowProxy(m_windowId);
     }
 
     QString CocoaWindowContext::key() const {
@@ -670,7 +671,7 @@
     void CocoaWindowContext::virtual_hook(int id, void *data) {
         switch (id) {
             case SystemButtonAreaChangedHook: {
-                ensureWindowProxy(windowId)->setScreenRectCallback(m_systemButtonAreaCallback);
+                ensureWindowProxy(m_windowId)->setScreenRectCallback(m_systemButtonAreaCallback);
                 return;
             }
 
@@ -682,37 +683,37 @@
 
     QVariant CocoaWindowContext::windowAttribute(const QString &key) const {
         if (key == QStringLiteral("title-bar-height")) {
-            if (!m_windowHandle)
-                return 0;
-            return ensureWindowProxy(windowId)->titleBarHeight();
+            if (!m_windowId)
+                return {};
+            return ensureWindowProxy(m_windowId)->titleBarHeight();
         }
         return AbstractWindowContext::windowAttribute(key);
     }
 
-    void CocoaWindowContext::winIdChanged() {
+    void CocoaWindowContext::winIdChanged(WId winId, WId oldWinId) {
         // If the original window id is valid, remove all resources related
-        if (windowId) {
-            releaseWindowProxy(windowId);
-            windowId = 0;
+        if (oldWinId) {
+            releaseWindowProxy(oldWinId);
         }
 
-        if (!m_windowHandle) {
+        if (!winId) {
             return;
         }
 
         // Allocate new resources
-        windowId = m_windowHandle->winId();
-        ensureWindowProxy(windowId)->setSystemTitleBarVisible(false);
+        ensureWindowProxy(winId)->setSystemTitleBarVisible(false);
     }
 
     bool CocoaWindowContext::windowAttributeChanged(const QString &key, const QVariant &attribute,
                                                     const QVariant &oldAttribute) {
         Q_UNUSED(oldAttribute)
 
+        Q_ASSERT(m_windowId);
+
         if (key == QStringLiteral("no-system-buttons")) {
             if (attribute.type() != QVariant::Bool)
                 return false;
-            ensureWindowProxy(windowId)->setSystemButtonVisible(!attribute.toBool());
+            ensureWindowProxy(m_windowId)->setSystemButtonVisible(!attribute.toBool());
             return true;
         }
 
@@ -739,9 +740,8 @@
             } else {
                 return false;
             }
-            return ensureWindowProxy(windowId)->setBlurEffect(mode);
+            return ensureWindowProxy(m_windowId)->setBlurEffect(mode);
         }
-
         return false;
     }
 

--
Gitblit v1.9.1