| | |
| | | |
| | | AbstractWindowContext::~AbstractWindowContext() = default; |
| | | |
| | | class EventFilterForwarder : public QObject { |
| | | public: |
| | | using EventProc = bool (*)(QEvent *, void *); |
| | | |
| | | EventFilterForwarder(EventProc proc, void *user, QObject *parent = nullptr) |
| | | : QObject(parent), proc(proc), user(user) { |
| | | } |
| | | |
| | | bool eventFilter(QObject *obj, QEvent *event) override { |
| | | Q_UNUSED(obj) |
| | | return proc(event, user); |
| | | } |
| | | |
| | | protected: |
| | | EventProc proc; |
| | | void *user; |
| | | }; |
| | | |
| | | bool AbstractWindowContext::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | if (!host || !delegate) { |
| | | return false; |
| | |
| | | m_host = host; |
| | | m_delegate.reset(delegate); |
| | | m_windowHandle = windowHandle; |
| | | |
| | | if (!setupHost()) { |
| | | m_host = nullptr; |
| | | m_delegate = nullptr; |
| | | m_windowHandle = nullptr; |
| | | return false; |
| | | } |
| | | |
| | | // Install specific event filter |
| | | host->installEventFilter(new EventFilterForwarder( |
| | | [](QEvent *event, void *user) { |
| | | return reinterpret_cast<AbstractWindowContext *>(user)->hostEventFilter(event); |
| | | }, |
| | | this, this)); |
| | | |
| | | return true; |
| | | } |
| | | |
| | |
| | | return true; |
| | | } |
| | | |
| | | bool AbstractWindowContext::hostEventFilter(QEvent *event) { |
| | | Q_UNUSED(event) |
| | | return false; |
| | | } |
| | | |
| | | } |
| | |
| | | ~AbstractWindowContext() override; |
| | | |
| | | public: |
| | | virtual bool setup(QObject *host, WindowItemDelegate *delegate); |
| | | bool setup(QObject *host, WindowItemDelegate *delegate); |
| | | |
| | | inline QObject *host() const; |
| | | inline QWindow *window() const; |
| | |
| | | bool isInTitleBarDraggableArea(const QPoint &pos) const; |
| | | |
| | | protected: |
| | | virtual bool setupHost() = 0; |
| | | virtual bool hostEventFilter(QEvent *event); |
| | | |
| | | protected: |
| | | QObject *m_host; |
| | | std::unique_ptr<WindowItemDelegate> m_delegate; |
| | | QWindow *m_windowHandle; |
| | |
| | | QtWindowContext::~QtWindowContext() { |
| | | } |
| | | |
| | | bool QtWindowContext::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | if (!AbstractWindowContext::setup(host, delegate)) { |
| | | return false; |
| | | } |
| | | bool QtWindowContext::setupHost() { |
| | | return false; |
| | | } |
| | | |
| | | bool QtWindowContext::eventFilter(QObject *obj, QEvent *event) { |
| | | return AbstractWindowContext::eventFilter(obj, event); |
| | | bool QtWindowContext::hostEventFilter(QEvent *event) { |
| | | return false; |
| | | } |
| | | |
| | | } |
| | |
| | | QtWindowContext(); |
| | | ~QtWindowContext(); |
| | | |
| | | public: |
| | | bool setup(QObject *host, WindowItemDelegate *delegate) override; |
| | | |
| | | protected: |
| | | bool eventFilter(QObject *obj, QEvent *event) override; |
| | | bool setupHost() override; |
| | | bool hostEventFilter(QEvent *event) override; |
| | | }; |
| | | |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | bool Win32WindowContext::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | if (!AbstractWindowContext::setup(host, delegate)) { |
| | | return false; |
| | | } |
| | | |
| | | bool Win32WindowContext::setupHost() { |
| | | // Install window hook |
| | | auto winId = m_windowHandle->winId(); |
| | | auto hWnd = reinterpret_cast<HWND>(winId); |
| | |
| | | TitleBar, |
| | | }; |
| | | |
| | | public: |
| | | bool setup(QObject *host, WindowItemDelegate *delegate) override; |
| | | protected: |
| | | bool setupHost() override; |
| | | |
| | | public: |
| | | bool windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result); |
| | | |
| | | // In order to perfectly apply Windows 11 Snap Layout into the Qt window, we need to |
| | |
| | | quickwindowagent.h |
| | | quickwindowagent_p.h |
| | | quickwindowagent.cpp |
| | | contexts/quickwindowcontext_p.h |
| | | contexts/quickwindowcontext.cpp |
| | | ) |
| | | |
| | | qwk_add_library(${PROJECT_NAME} AUTOGEN |
New file |
| | |
| | | #include "quickwindowcontext_p.h" |
| | | |
| | | namespace QWK { |
| | | |
| | | bool QuickWindowContext::hostEventFilter(QEvent *event) { |
| | | return false; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | #ifndef QUICKWINDOWCONTEXT_P_H |
| | | #define QUICKWINDOWCONTEXT_P_H |
| | | |
| | | #include <QtGlobal> |
| | | |
| | | #ifdef Q_OS_WINDOWS |
| | | # include <QWKCore/private/win32windowcontext_p.h> |
| | | #else |
| | | # include <QWKCore/private/qtwindowcontext_p.h> |
| | | #endif |
| | | |
| | | namespace QWK { |
| | | |
| | | using CoreWindowContext = |
| | | #ifdef Q_OS_WINDOWS |
| | | Win32WindowContext |
| | | #else |
| | | QtWindowContext |
| | | #endif |
| | | ; |
| | | |
| | | class QuickWindowContext : public CoreWindowContext { |
| | | Q_OBJECT |
| | | public: |
| | | QuickWindowContext() = default; |
| | | ~QuickWindowContext() override = default; |
| | | |
| | | protected: |
| | | bool hostEventFilter(QEvent *event) override; |
| | | }; |
| | | |
| | | } |
| | | |
| | | #endif // QUICKWINDOWCONTEXT_P_H |
| | |
| | | widgetwindowagent.h |
| | | widgetwindowagent_p.h |
| | | widgetwindowagent.cpp |
| | | contexts/widgetwindowcontext_p.h |
| | | contexts/widgetwindowcontext.cpp |
| | | ) |
| | | |
| | | qwk_add_library(${PROJECT_NAME} AUTOGEN |
New file |
| | |
| | | #include "widgetwindowcontext_p.h" |
| | | |
| | | namespace QWK { |
| | | |
| | | bool WidgetWindowContext::hostEventFilter(QEvent *event) { |
| | | return false; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | #ifndef WIDGETWINDOWCONTEXT_P_H |
| | | #define WIDGETWINDOWCONTEXT_P_H |
| | | |
| | | #include <QtGlobal> |
| | | |
| | | #ifdef Q_OS_WINDOWS |
| | | # include <QWKCore/private/win32windowcontext_p.h> |
| | | #else |
| | | # include <QWKCore/private/qtwindowcontext_p.h> |
| | | #endif |
| | | |
| | | namespace QWK { |
| | | |
| | | using CoreWindowContext = |
| | | #ifdef Q_OS_WINDOWS |
| | | Win32WindowContext |
| | | #else |
| | | QtWindowContext |
| | | #endif |
| | | ; |
| | | |
| | | class WidgetWindowContext : public CoreWindowContext { |
| | | Q_OBJECT |
| | | public: |
| | | WidgetWindowContext() = default; |
| | | ~WidgetWindowContext() override = default; |
| | | |
| | | protected: |
| | | bool hostEventFilter(QEvent *event) override; |
| | | }; |
| | | |
| | | } |
| | | |
| | | #endif // WIDGETWINDOWCONTEXT_P_H |