Sine Striker
2023-12-23 f3721da17996168489778327459084dd227690d6
src/widgets/widgetwindowagent_win.cpp
@@ -3,9 +3,14 @@
#include <QtGui/QPainter>
#include <QWKCore/qwindowkit_windows.h>
#include <QWKCore/qwkconfig.h>
#include <QWKCore/private/nativeeventfilter_p.h>
namespace QWK {
#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
    class WidgetBorderHandler;
    class WidgetBorderHandler : public QObject, public NativeEventFilter {
    public:
@@ -64,11 +69,23 @@
        }
        bool eventFilter(QObject *obj, QEvent *event) override {
            Q_UNUSED(obj)
            switch (event->type()) {
                case QEvent::Paint: {
                    if (widget->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen))
                    if (widget->windowState() &
                        (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen))
                        break;
                    // Friend class helping to call `event`
                    class HackedWidget : public QWidget {
                    public:
                        friend class WidgetBorderHandler;
                    };
                    // Let the widget paint first
                    static_cast<HackedWidget *>(widget)->event(event);
                    // Draw border
                    auto paintEvent = static_cast<QPaintEvent *>(event);
                    auto rect = paintEvent->rect();
                    auto region = paintEvent->region();
@@ -80,7 +97,7 @@
                        &region,
                    };
                    ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook, args);
                    break;
                    return true;
                }
                case QEvent::WindowStateChange: {
@@ -103,13 +120,16 @@
        QWidget *widget;
        AbstractWindowContext *ctx;
    };
#endif
    void WidgetWindowAgentPrivate::setupWindows10BorderWorkaround() {
#if QWINDOWKIT_CONFIG(ENABLE_WINDOWS_SYSTEM_BORDER)
        // Install painting hook
        auto ctx = context.get();
        if (ctx->property("needBorderPainter").toBool()) {
            std::ignore = new WidgetBorderHandler(hostWidget, ctx);
        }
#endif
    }
}