From adb46e1e151b73e56a7e0066a896b48b92a7230e Mon Sep 17 00:00:00 2001 From: Zhao Yuhang <2546789017@qq.com> Date: 周五, 22 12月 2023 21:44:10 +0800 Subject: [PATCH] win: use modern API --- src/core/contexts/abstractwindowcontext.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-) diff --git a/src/core/contexts/abstractwindowcontext.cpp b/src/core/contexts/abstractwindowcontext.cpp index a568bfd..d2da16f 100644 --- a/src/core/contexts/abstractwindowcontext.cpp +++ b/src/core/contexts/abstractwindowcontext.cpp @@ -48,6 +48,33 @@ } } + bool AbstractWindowContext::setWindowAttribute(const QString &key, const QVariant &attribute) { + auto it = m_windowAttributes.find(key); + if (it == m_windowAttributes.end()) { + if (!attribute.isValid()) { + return true; + } + if (m_windowHandle && !windowAttributeChanged(key, attribute, {})) { + return false; + } + m_windowAttributes.insert(key, attribute); + return true; + } + + if (it.value() == attribute) + return true; + if (m_windowHandle && !windowAttributeChanged(key, attribute, it.value())) { + return false; + } + + if (attribute.isValid()) { + it.value() = attribute; + } else { + m_windowAttributes.erase(it); + } + return true; + } + bool AbstractWindowContext::setHitTestVisible(const QObject *obj, bool visible) { Q_ASSERT(obj); if (!obj) { @@ -81,6 +108,15 @@ if (m_titleBar == item) { return false; } + + if (m_titleBar) { + // Since the title bar is changed, all items inside it should be dereferenced right away + for (auto &button : m_systemButtons) { + button = nullptr; + } + m_hitTestVisibleItems.clear(); + } + m_titleBar = item; return true; } @@ -210,6 +246,24 @@ if (oldWindow == m_windowHandle) return; winIdChanged(); + + if (m_windowHandle) { + // Refresh window attributes + auto attributes = m_windowAttributes; + m_windowAttributes.clear(); + for (auto it = attributes.begin(); it != attributes.end(); ++it) { + if (!windowAttributeChanged(it.key(), it.value(), {})) { + continue; + } + m_windowAttributes.insert(it.key(), it.value()); + } + } + } + + bool AbstractWindowContext::windowAttributeChanged(const QString &key, + const QVariant &attribute, + const QVariant &oldAttribute) { + return false; } } -- Gitblit v1.9.1