Sine Striker
2023-12-11 8c403d5dd03418febd67d50c6d9094a61c036f9b
Add virtual hook
9个文件已修改
2个文件已删除
235 ■■■■ 已修改文件
qmsetup @ c8d69a 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/CMakeLists.txt 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext.cpp 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/abstractwindowcontext_p.h 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/qtwindowcontext.cpp 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/qtwindowcontext_p.h 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/win32windowcontext.cpp 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/contexts/win32windowcontext_p.h 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/kernel/nativeeventfilter.cpp 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/kernel/sharedeventfilter.cpp 90 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/core/kernel/sharedeventfilter.h 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
qmsetup
@@ -1 +1 @@
Subproject commit 35836d6e80f4395f187e58d94e2030b615d757e9
Subproject commit c8d69a4895784220061c3cf8be5f092da2ac013e
src/core/CMakeLists.txt
@@ -14,8 +14,6 @@
    windowitemdelegate.cpp
    kernel/nativeeventfilter.h
    kernel/nativeeventfilter.cpp
    kernel/sharedeventfilter.h
    kernel/sharedeventfilter.cpp
    contexts/abstractwindowcontext_p.h
    contexts/abstractwindowcontext.cpp
)
src/core/contexts/abstractwindowcontext.cpp
@@ -88,7 +88,9 @@
        return true;
    }
    void AbstractWindowContext::showSystemMenu(const QPoint &pos){Q_UNUSED(pos)}
    void AbstractWindowContext::showSystemMenu(const QPoint &pos) {
        virtual_hook(ShowSystemMenuHook, &const_cast<QPoint &>(pos));
    }
    QRegion AbstractWindowContext::hitTestShape() const {
        if (hitTestVisibleShapeDirty) {
@@ -162,8 +164,17 @@
        return true;
    }
    QObject *AbstractWindowContext::target() const {
        return m_host;
    QString AbstractWindowContext::key() const {
        return {};
    }
    void AbstractWindowContext::virtual_hook(int id, void *data) {
        switch (id) {
            case CentralizeHook:
                break;
            default:
                break;
        }
    }
}
src/core/contexts/abstractwindowcontext_p.h
@@ -9,12 +9,11 @@
#include <QtGui/QPolygon>
#include <QWKCore/windowagentbase.h>
#include <QWKCore/sharedeventfilter.h>
#include <QWKCore/private/windowitemdelegate_p.h>
namespace QWK {
    class QWK_CORE_EXPORT AbstractWindowContext : public QObject, public SharedEventDispatcher {
    class QWK_CORE_EXPORT AbstractWindowContext : public QObject {
        Q_OBJECT
    public:
        AbstractWindowContext();
@@ -36,16 +35,22 @@
        inline const QObject *titleBar() const;
        bool setTitleBar(const QObject *obj);
        virtual void showSystemMenu(const QPoint &pos);
        void showSystemMenu(const QPoint &pos);
        QRegion hitTestShape() const;
        bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const;
        bool isInTitleBarDraggableArea(const QPoint &pos) const;
        virtual QString key() const;
        enum WindowContextHook {
            CentralizeHook = 1,
            ShowSystemMenuHook,
        };
        virtual void virtual_hook(int id, void *data);
    protected:
        virtual bool setupHost() = 0;
        QObject *target() const override;
    protected:
        QObject *m_host;
src/core/contexts/qtwindowcontext.cpp
@@ -46,6 +46,13 @@
    QtWindowContext::~QtWindowContext() {
    }
    QString QtWindowContext::key() const {
        return "qt";
    }
    void QtWindowContext::virtual_hook(int id, void *data) {
    }
    bool QtWindowContext::setupHost() {
        return false;
    }
src/core/contexts/qtwindowcontext_p.h
@@ -11,6 +11,9 @@
        QtWindowContext();
        ~QtWindowContext();
        QString key() const override;
        void virtual_hook(int id, void *data) override;
    protected:
        bool setupHost() override;
    };
src/core/contexts/win32windowcontext.cpp
@@ -669,10 +669,24 @@
        }
    }
    void Win32WindowContext::showSystemMenu(const QPoint &pos) {
    QString Win32WindowContext::key() const {
        return "win32";
    }
    void Win32WindowContext::virtual_hook(int id, void *data) {
        switch (id) {
            case ShowSystemMenuHook: {
                const auto &pos = *reinterpret_cast<const QPoint *>(data);
        auto winId = m_windowHandle->winId();
        auto hWnd = reinterpret_cast<HWND>(winId);
        showSystemMenu2(hWnd, {pos.x(), pos.y()}, false, m_delegate->isHostSizeFixed(m_host));
                showSystemMenu2(hWnd, {pos.x(), pos.y()}, false,
                                m_delegate->isHostSizeFixed(m_host));
                return;
            }
            default:
                break;
        }
        AbstractWindowContext::virtual_hook(id, data);
    }
    bool Win32WindowContext::setupHost() {
@@ -742,7 +756,7 @@
        return false; // Not handled
    }
    static constexpr const auto kMessageTag = WPARAM(0x97CCEA99);
    static constexpr const auto kMessageTag = WPARAM(0xF1C9ADD4);
    static inline constexpr bool isTaggedMessage(WPARAM wParam) {
        return (wParam == kMessageTag);
src/core/contexts/win32windowcontext_p.h
@@ -21,7 +21,8 @@
            TitleBar,
        };
        void showSystemMenu(const QPoint &pos) override;
        QString key() const override;
        void virtual_hook(int id, void *data) override;
    protected:
        bool setupHost() override;
src/core/kernel/nativeeventfilter.cpp
@@ -1,7 +1,7 @@
#include "nativeeventfilter.h"
#include <QtCore/QAbstractNativeEventFilter>
#include <QtGui/QGuiApplication>
#include <QtCore/QCoreApplication>
namespace QWK {
@@ -19,7 +19,7 @@
        bool nativeEventFilter(const QByteArray &eventType, void *message,
                               QT_NATIVE_EVENT_RESULT_TYPE *result) override {
            for (const auto &child : qAsConst(m_children)) {
            for (const auto &child : qAsConst(children)) {
                if (child->nativeEventFilter(eventType, message, result)) {
                    return true;
                }
@@ -27,22 +27,9 @@
            return false;
        }
        inline int count() const {
            return m_children.size();
        }
        inline void addChild(NativeEventFilter *child) {
            m_children.append(child);
        }
        inline void removeChild(NativeEventFilter *child) {
            m_children.removeOne(child);
        }
        QVector<NativeEventFilter *> children;
        static MasterNativeEventFilter *instance;
    protected:
        QVector<NativeEventFilter *> m_children;
    };
    MasterNativeEventFilter *MasterNativeEventFilter::instance = nullptr;
@@ -51,12 +38,12 @@
        if (!MasterNativeEventFilter::instance) {
            MasterNativeEventFilter::instance = new MasterNativeEventFilter();
        }
        MasterNativeEventFilter::instance->addChild(this);
        MasterNativeEventFilter::instance->children.append(this);
    }
    NativeEventFilter::~NativeEventFilter() {
        MasterNativeEventFilter::instance->removeChild(this);
        if (MasterNativeEventFilter::instance->count() == 0) {
        MasterNativeEventFilter::instance->children.removeOne(this);
        if (MasterNativeEventFilter::instance->children.isEmpty()) {
            delete MasterNativeEventFilter::instance;
            MasterNativeEventFilter::instance = nullptr;
        }
src/core/kernel/sharedeventfilter.cpp
File was deleted
src/core/kernel/sharedeventfilter.h
File was deleted