diff --git a/winnativeeventfilter.cpp b/winnativeeventfilter.cpp index 0b58156..e161ce3 100644 --- a/winnativeeventfilter.cpp +++ b/winnativeeventfilter.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -1119,6 +1120,29 @@ bool displaySystemMenu_internal(const HWND handle, const bool isRtl, const LPARA return false; } +QString getCurrentScreenSerialNumber(const HWND handle) +{ + Q_ASSERT(handle); + ResolveWin32APIs(); + if (WNEF_EXECUTE_WINAPI_RETURN(IsWindow, FALSE, handle)) { + QScreen *currentScreen = nullptr; +#ifdef QT_WIDGETS_LIB + const QWidget *widget = QWidget::find(reinterpret_cast(handle)); + if (widget && widget->isTopLevel()) { + currentScreen = widget->screen(); + } +#endif + if (!currentScreen) { + const QWindow *window = findQWindowFromRawHandle(handle); + if (window) { + currentScreen = window->screen(); + } + } + return currentScreen ? currentScreen->serialNumber().toUpper() : QString(); + } + return {}; +} + } // namespace WinNativeEventFilter::WinNativeEventFilter() @@ -1261,6 +1285,8 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, if (!data->initialized) { // Avoid initializing a same window twice. data->initialized = true; + // Record the current screen. + data->currentScreen = getCurrentScreenSerialNumber(msg->hwnd); // Don't restore the window styles to default when you are // developing Qt Quick applications because the QWindow // will disappear once you do it. However, Qt Widgets applications @@ -1307,9 +1333,10 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, 0, LWA_COLORKEY) } - setAcrylicEffectEnabled(msg->hwnd, data->enableBlurBehindWindow); // Bring our frame shadow back through DWM, don't draw it manually. UpdateFrameMarginsForWindow(msg->hwnd); + // Blur effect. + setAcrylicEffectEnabled(msg->hwnd, data->enableBlurBehindWindow); } switch (msg->message) { case WM_NCCALCSIZE: { @@ -1539,8 +1566,9 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, if (!shouldHaveWindowFrame() && !IsFullScreen(msg->hwnd) && !IsMaximized(msg->hwnd) && !IsMinimized(msg->hwnd)) { // Fix the flickering problem when resizing. + // Don't modify the left, right or bottom edge because + // a border line will be seen (at least on Win10). clientRect->top -= 1; - //*result = 0; } return true; } @@ -1965,6 +1993,14 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, break; } } + case WM_MOVE: { + const QString sn = getCurrentScreenSerialNumber(msg->hwnd); + if (data->currentScreen.toUpper() != sn) { + data->currentScreen = sn; + updateWindow(msg->hwnd, true, true); + } + break; + } default: break; } diff --git a/winnativeeventfilter.h b/winnativeeventfilter.h index daf5728..dfebc9d 100644 --- a/winnativeeventfilter.h +++ b/winnativeeventfilter.h @@ -57,6 +57,7 @@ public: QList ignoreAreas = {}, draggableAreas = {}; QList> ignoreObjects = {}, draggableObjects = {}; QSize maximumSize = {}, minimumSize = {}; + QString currentScreen = {}; }; enum class SystemMetric { BorderWidth, BorderHeight, TitleBarHeight }; @@ -137,7 +138,8 @@ public: const int x, const int y); - // a + // Enable or disable the blur effect for a specific window. + // On Win10 it's the Acrylic effect. static bool setAcrylicEffectEnabled(void *handle /* HWND */, const bool enabled = true); ///////////////////////////////////////////////