SineStriker
2025-03-11 921dbf5719c9b734fbd26d7b6300e29c943093f3
update
3个文件已修改
81 ■■■■ 已修改文件
src/core/contexts/abstractwindowcontext.cpp 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext_p.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/win32windowcontext.cpp 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext.cpp
@@ -32,21 +32,16 @@
            return false;
        }
        auto it = m_hitTestVisibleItems.find(obj);
        if (visible) {
            if (it != m_hitTestVisibleItems.end()) {
                return true;
            }
            connect(obj, &QObject::destroyed, this,
                    &AbstractWindowContext::_q_hitTestVisibleItemDestroyed);
            m_hitTestVisibleItems.insert(obj);
            m_hitTestVisibleItems.removeAll(nullptr);
            m_hitTestVisibleItems.removeAll(obj);
            m_hitTestVisibleItems.append(obj);
        } else {
            if (it == m_hitTestVisibleItems.end()) {
                return false;
            for (auto &item : m_hitTestVisibleItems) {
                if (item == obj) {
                    item = nullptr;
            }
            disconnect(obj, &QObject::destroyed, this,
                       &AbstractWindowContext::_q_hitTestVisibleItemDestroyed);
            m_hitTestVisibleItems.erase(it);
            }
        }
        return true;
    }
@@ -60,16 +55,7 @@
        auto org = m_systemButtons[button];
        if (org == obj) {
            return true;
        }
        if (org) {
            disconnect(org, &QObject::destroyed, this,
                       &AbstractWindowContext::_q_systemButtonDestroyed);
        }
        if (obj) {
            connect(obj, &QObject::destroyed, this,
                    &AbstractWindowContext::_q_systemButtonDestroyed);
            return false;
        }
        m_systemButtons[button] = obj;
        return true;
@@ -85,11 +71,6 @@
        if (org) {
            // Since the title bar is changed, all items inside it should be dereferenced right away
            removeSystemButtonsAndHitTestItems();
            disconnect(org, &QObject::destroyed, this,
                       &AbstractWindowContext::_q_titleBarDistroyed);
        }
        if (item) {
            connect(item, &QObject::destroyed, this, &AbstractWindowContext::_q_titleBarDistroyed);
        }
        m_titleBar = item;
        return true;
@@ -150,13 +131,12 @@
            }
        }
        for (auto widget : m_hitTestVisibleItems) {
            if (widget && m_delegate->isVisible(widget) && m_delegate->isEnabled(widget) &&
                m_delegate->mapGeometryToScene(widget).contains(pos)) {
        for (auto item : m_hitTestVisibleItems) {
            if (item && m_delegate->isVisible(item) && m_delegate->isEnabled(item) &&
                m_delegate->mapGeometryToScene(item).contains(pos)) {
                return false;
            }
        }
        return true;
    }
@@ -315,33 +295,9 @@
            if (!button) {
                continue;
            }
            disconnect(button, &QObject::destroyed, this,
                       &AbstractWindowContext::_q_systemButtonDestroyed);
            button = nullptr;
        }
        for (auto &item : m_hitTestVisibleItems) {
            disconnect(item, &QObject::destroyed, this,
                       &AbstractWindowContext::_q_hitTestVisibleItemDestroyed);
        }
        m_hitTestVisibleItems.clear();
    }
    void AbstractWindowContext::_q_titleBarDistroyed(QObject *obj) {
        Q_UNUSED(obj)
        removeSystemButtonsAndHitTestItems();
        m_titleBar = nullptr;
    }
    void AbstractWindowContext::_q_hitTestVisibleItemDestroyed(QObject *obj) {
        m_hitTestVisibleItems.remove(obj);
    }
    void AbstractWindowContext::_q_systemButtonDestroyed(QObject *obj) {
        for (auto &item : m_systemButtons) {
            if (item == obj) {
                item = nullptr;
            }
        }
    }
}
src/core/contexts/abstractwindowcontext_p.h
@@ -116,13 +116,13 @@
        QPointer<QWindow> m_windowHandle;
        WId m_windowId{};
        QSet<const QObject *> m_hitTestVisibleItems;
        QVector<QPointer<QObject>> m_hitTestVisibleItems;
#ifdef Q_OS_MAC
        ScreenRectCallback m_systemButtonAreaCallback;
#endif
        QObject *m_titleBar{};
        std::array<QObject *, WindowAgentBase::Close + 1> m_systemButtons{};
        QPointer<QObject> m_titleBar{};
        std::array<QPointer<QObject>, WindowAgentBase::Close + 1> m_systemButtons{};
        std::list<std::pair<QString, QVariant>> m_windowAttributesOrder;
        QHash<QString, decltype(m_windowAttributesOrder)::iterator> m_windowAttributes;
@@ -130,11 +130,6 @@
        std::unique_ptr<WinIdChangeEventFilter> m_winIdChangeEventFilter;
        void removeSystemButtonsAndHitTestItems();
    private:
        void _q_titleBarDistroyed(QObject *obj);
        void _q_hitTestVisibleItemDestroyed(QObject *obj);
        void _q_systemButtonDestroyed(QObject *obj);
    };
    inline QObject *AbstractWindowContext::host() const {
@@ -154,7 +149,7 @@
    }
    inline bool AbstractWindowContext::isHitTestVisible(const QObject *obj) const {
        return m_hitTestVisibleItems.contains(obj);
        return m_hitTestVisibleItems.contains(const_cast<QObject *>(obj));
    }
    inline QObject *
src/core/contexts/win32windowcontext.cpp
@@ -2329,7 +2329,7 @@
                if (!mouseHook) {
                    mouseHook = ::SetWindowsHookExW(
                        WH_MOUSE,
                        [](int nCode, WPARAM wParam, LPARAM lParam) {
                        [](int nCode, WPARAM wParam, LPARAM lParam) -> LRESULT WINAPI {
                            if (nCode >= 0) {
                                switch (wParam) {
                                    case WM_LBUTTONDBLCLK: