Move FloatingWindow::setupWindow() into a reusable function

So other QWindow can use this
This commit is contained in:
Sergio Martins
2021-02-15 18:29:19 +00:00
parent e3c370eb6b
commit 94ee2e55fd
6 changed files with 36 additions and 33 deletions

View File

@@ -28,6 +28,7 @@
# include <QtGui/private/qhighdpiscaling_p.h>
# include <windowsx.h>
# include <windows.h>
# include <dwmapi.h>
# if defined(Q_CC_MSVC)
# pragma comment(lib,"User32.lib")
# endif
@@ -488,6 +489,33 @@ CursorPosition WidgetResizeHandler::cursorPosition(QPoint globalPos) const
return static_cast<CursorPosition>(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()) {
const auto wid = HWND(window->winId());
connect(window, &QWindow::screenChanged, window, [window, wid] {
// 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)