diff --git a/src/private/FloatingWindow.cpp b/src/private/FloatingWindow.cpp index 87238761..ad29ca92 100644 --- a/src/private/FloatingWindow.cpp +++ b/src/private/FloatingWindow.cpp @@ -102,7 +102,7 @@ FloatingWindow::FloatingWindow(MainWindowBase *parent) { if (kddwUsesQtWidgets()) { // For QtQuick we do it a bit later, once we have the QQuickWindow - WidgetResizeHandler::setupWindow(windowHandle()); + setupWindow(); } DockRegistry::self()->registerFloatingWindow(this); @@ -145,6 +145,35 @@ FloatingWindow::~FloatingWindow() DockRegistry::self()->unregisterFloatingWindow(this); } +void FloatingWindow::setupWindow() +{ + // Does some minor setup on our QWindow. + // Like adding the drop shadow on Windows and two other workarounds. + +#if defined(Q_OS_WIN) + // On Windows with Qt 5.9 (and maybe earlier), the WM_NCALCSIZE isn't being processed unless we explicitly create the window. + // So create it now, otherwise floating dock widgets will show a native title bar until resized. + create(); + + if (KDDockWidgets::usesAeroSnapWithCustomDecos()) { +# ifdef KDDOCKWIDGETS_QTWIDGETS + m_nchittestFilter = new NCHITTESTEventFilter(this); + qApp->installNativeEventFilter(m_nchittestFilter); +#endif + connect(windowHandle(), &QWindow::screenChanged, this, [this] { + // Qt honors our frame hijacking usually... but when screen changes we must give it a nudge. + // Otherwise what Qt thinks is the client area is not what Windows knows it is. + // SetWindowPos() will trigger an NCCALCSIZE message, which Qt will intercept and take note of the margins we're using. + SetWindowPos(HWND(winId()), 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); + }); + + // Show drop-shadow: + MARGINS margins = {0, 0, 0, 1}; // arbitrary, just needs to be > 0 it seems + DwmExtendFrameIntoClientArea(HWND(winId()), &margins); + } +#endif // Q_OS_WIN +} + #if defined(Q_OS_WIN) && defined(KDDOCKWIDGETS_QTWIDGETS) bool FloatingWindow::nativeEvent(const QByteArray &eventType, void *message, Qt5Qt6Compat::qintptr *result) { diff --git a/src/private/FloatingWindow_p.h b/src/private/FloatingWindow_p.h index bfd92942..c26d42e6 100644 --- a/src/private/FloatingWindow_p.h +++ b/src/private/FloatingWindow_p.h @@ -168,6 +168,7 @@ Q_SIGNALS: void numFramesChanged(); void windowStateChanged(QWindowStateChangeEvent *); protected: + void setupWindow(); void maybeCreateResizeHandler(); #if defined(Q_OS_WIN) && defined(KDDOCKWIDGETS_QTWIDGETS) diff --git a/src/private/WidgetResizeHandler.cpp b/src/private/WidgetResizeHandler.cpp index f5ae2223..2bc0343f 100644 --- a/src/private/WidgetResizeHandler.cpp +++ b/src/private/WidgetResizeHandler.cpp @@ -488,37 +488,6 @@ CursorPosition WidgetResizeHandler::cursorPosition(QPoint globalPos) const return static_cast(result); } -/** static */ -void WidgetResizeHandler::setupWindow(QWindow *window) -{ - // Does some minor setup on our QWindow. - // Like adding the drop shadow on Windows and two other workarounds. - -#if defined(Q_OS_WIN) - if (KDDockWidgets::usesAeroSnapWithCustomDecos()) { -#ifdef KDDOCKWIDGETS_QTWIDGETS - m_nchittestFilter = new NCHITTESTEventFilter(this); - qApp->installNativeEventFilter(m_nchittestFilter); -#endif - const auto wid = HWND(window->winId()); - connect(window, &QWindow::screenChanged, this, [this] { - // Qt honors our frame hijacking usually... but when screen changes we must give it a - // nudge. Otherwise what Qt thinks is the client area is not what Windows knows it is. - // SetWindowPos() will trigger an NCCALCSIZE message, which Qt will intercept and take - // note of the margins we're using. - SetWindowPos(wid, 0, 0, 0, 0, 0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - }); - - // Show drop-shadow: - MARGINS margins = { 0, 0, 0, 1 }; // arbitrary, just needs to be > 0 it seems - DwmExtendFrameIntoClientArea(wid, &margins); - } -#else - Q_UNUSED(window); -#endif // Q_OS_WIN -} - #if defined(Q_OS_WIN) && defined(KDDOCKWIDGETS_QTWIDGETS) bool NCHITTESTEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, Qt5Qt6Compat::qintptr *result) diff --git a/src/private/WidgetResizeHandler_p.h b/src/private/WidgetResizeHandler_p.h index abd1d6d1..92c1ac80 100644 --- a/src/private/WidgetResizeHandler_p.h +++ b/src/private/WidgetResizeHandler_p.h @@ -69,8 +69,6 @@ public: static int widgetResizeHandlerMargin(); - static void setupWindow(QWindow *window); - #ifdef Q_OS_WIN static bool handleWindowsNativeEvent(FloatingWindow *w, const QByteArray &eventType, void *message, Qt5Qt6Compat::qintptr *result); #endif diff --git a/src/private/quick/FloatingWindowQuick.cpp b/src/private/quick/FloatingWindowQuick.cpp index 86f0d40d..5af27feb 100644 --- a/src/private/quick/FloatingWindowQuick.cpp +++ b/src/private/quick/FloatingWindowQuick.cpp @@ -187,7 +187,7 @@ void FloatingWindowQuick::init() } QWidgetAdapter::setParent(m_quickWindow->contentItem()); - WidgetResizeHandler::setupWindow(m_quickWindow); + setupWindow(); m_quickWindow->installEventFilter(this); // for window resizing maybeCreateResizeHandler(); diff --git a/src/private/quick/FrameQuick.cpp b/src/private/quick/FrameQuick.cpp index 4decc2e6..a9023529 100644 --- a/src/private/quick/FrameQuick.cpp +++ b/src/private/quick/FrameQuick.cpp @@ -21,7 +21,7 @@ #include "Config.h" #include "FrameworkWidgetFactory.h" #include "TabWidgetQuick_p.h" -#include "WidgetResizeHandler_p.h" + #include using namespace KDDockWidgets;