SineStriker
2023-12-20 3871bfc5d3aff45e498fa2944c27e6eb5d146c8e
src/core/contexts/qtwindowcontext.cpp
@@ -2,6 +2,9 @@
#include <QtCore/QDebug>
#include "qwkglobal_p.h"
#include "systemwindow_p.h"
namespace QWK {
    static constexpr const quint8 kDefaultResizeBorderThickness = 8;
@@ -109,18 +112,15 @@
        if (type < QEvent::MouseButtonPress || type > QEvent::MouseMove) {
            return false;
        }
        QObject *host = m_context->host();
        QWindow *window = m_context->window();
        WindowItemDelegate *delegate = m_context->delegate();
        bool fixedSize = delegate->isHostSizeFixed(host);
        auto host = m_context->host();
        auto window = m_context->window();
        auto delegate = m_context->delegate();
        auto me = static_cast<const QMouseEvent *>(event);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
        QPoint scenePos = me->scenePosition().toPoint();
        QPoint globalPos = me->globalPosition().toPoint();
#else
        QPoint scenePos = me->windowPos().toPoint();
        QPoint globalPos = me->screenPos().toPoint();
#endif
        bool fixedSize = delegate->isHostSizeFixed(host);
        QPoint scenePos = getMouseEventScenePos(me);
        QPoint globalPos = getMouseEventGlobalPos(me);
        bool inTitleBar = m_context->isInTitleBarDraggableArea(scenePos);
        switch (type) {
            case QEvent::MouseButtonPress: {
@@ -130,7 +130,7 @@
                            Qt::Edges edges = calculateWindowEdges(window, scenePos);
                            if (edges != Qt::Edges()) {
                                m_windowStatus = Resizing;
                                window->startSystemResize(edges);
                                startSystemResize(window, edges);
                                event->accept();
                                return true;
                            }
@@ -143,7 +143,6 @@
                            event->accept();
                            return true;
                        }
                        m_windowStatus = WaitingRelease;
                        break;
                    }
                    case Qt::RightButton: {
@@ -153,6 +152,7 @@
                    default:
                        break;
                }
                m_windowStatus = WaitingRelease;
                break;
            }
@@ -187,7 +187,7 @@
                    }
                    case PreparingMove: {
                        m_windowStatus = Moving;
                        window->startSystemMove();
                        startSystemMove(window);
                        event->accept();
                        return true;
                    }
@@ -244,17 +244,24 @@
    }
    void QtWindowContext::virtual_hook(int id, void *data) {
        switch (id) {
            case ShowSystemMenuHook:
                return;
            default:
                break;
        }
        AbstractWindowContext::virtual_hook(id, data);
    }
    void QtWindowContext::winIdChanged(QWindow *oldWindow) {
        Q_UNUSED(oldWindow)
    void QtWindowContext::winIdChanged(QWindow *oldWindow, bool isDestroyed) {
        Q_UNUSED(isDestroyed)
        // If the original window id is valid, remove all resources related
        if (oldWindow) {
            qtWindowEventFilter.reset();
        }
        if (!m_windowHandle) {
            m_delegate->setWindowFlags(m_host, m_delegate->getWindowFlags(m_host) &
                                                   ~Qt::FramelessWindowHint);
            return;
        }
        // Allocate new resources
        m_delegate->setWindowFlags(m_host,
                                   m_delegate->getWindowFlags(m_host) | Qt::FramelessWindowHint);
        qtWindowEventFilter = std::make_unique<QtWindowEventFilter>(this);