From 6f6f96909e7ded6ae3a4e59d9d4b62fa593abb23 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周日, 25 2月 2024 02:33:03 +0800 Subject: [PATCH] Fix quick initialization failure --- src/core/contexts/cocoawindowcontext.mm | 35 ++++++++++++++++++++--------------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/core/contexts/cocoawindowcontext.mm b/src/core/contexts/cocoawindowcontext.mm index cc9bfeb..61ad3b8 100644 --- a/src/core/contexts/cocoawindowcontext.mm +++ b/src/core/contexts/cocoawindowcontext.mm @@ -1,3 +1,7 @@ +// 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" #include <objc/runtime.h> @@ -509,7 +513,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; @@ -657,7 +664,7 @@ } CocoaWindowContext::~CocoaWindowContext() { - releaseWindowProxy(windowId); + releaseWindowProxy(m_windowId); } QString CocoaWindowContext::key() const { @@ -667,7 +674,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; } @@ -679,27 +686,25 @@ 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, @@ -709,7 +714,7 @@ 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; } @@ -736,7 +741,7 @@ } else { return false; } - return ensureWindowProxy(windowId)->setBlurEffect(mode); + return ensureWindowProxy(m_windowId)->setBlurEffect(mode); } return false; -- Gitblit v1.9.1