Remove updateRegion function.

It's causing huge problems on Windows 7.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-03 10:46:20 +08:00
parent 6b3f555a95
commit 84d6b03539
2 changed files with 5 additions and 45 deletions

View File

@ -209,43 +209,6 @@ int WinNativeEventFilter::titlebarHeight(HWND handle) {
getSystemMetricsForWindow(handle, SM_CYCAPTION); getSystemMetricsForWindow(handle, SM_CYCAPTION);
} }
void WinNativeEventFilter::updateRegion(LPWINDOW data) {
const RECT null_rect = {0, 0, 0, 0};
RECT rect;
if (IsMaximized(data->hWnd)) {
WINDOWINFO windowInfo;
SecureZeroMemory(&windowInfo, sizeof(windowInfo));
windowInfo.cbSize = sizeof(windowInfo);
GetWindowInfo(data->hWnd, &windowInfo);
// For maximized windows, a region is needed to cut off the
// non-client borders that hang over the edge of the screen.
rect.left = windowInfo.rcClient.left - windowInfo.rcWindow.left;
rect.top = windowInfo.rcClient.top - windowInfo.rcWindow.top;
rect.right = windowInfo.rcClient.right - windowInfo.rcWindow.left;
rect.bottom = windowInfo.rcClient.bottom - windowInfo.rcWindow.top;
} else if (!data->dwmCompositionEnabled) {
// For ordinary themed windows when composition is disabled, a
// region is needed to remove the rounded top corners. Make it
// as large as possible to avoid having to change it when the
// window is resized.
rect.left = 0;
rect.top = 0;
rect.right = 32767;
rect.bottom = 32767;
} else {
// Don't mess with the region when composition is enabled and
// the window is not maximized, otherwise it will lose its
// shadow.
rect = null_rect;
}
// Treat empty regions as NULL regions.
if (EqualRect(&rect, &null_rect)) {
SetWindowRgn(data->hWnd, nullptr, TRUE);
} else {
SetWindowRgn(data->hWnd, CreateRectRgnIndirect(&rect), TRUE);
}
}
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType, bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
void *message, qintptr *result) void *message, qintptr *result)
@ -527,7 +490,6 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
break; break;
} }
case WM_WINDOWPOSCHANGED: { case WM_WINDOWPOSCHANGED: {
updateRegion(data);
// Repaint the non-client area immediately. // Repaint the non-client area immediately.
InvalidateRect(msg->hwnd, nullptr, TRUE); InvalidateRect(msg->hwnd, nullptr, TRUE);
break; break;
@ -540,15 +502,15 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
qDebug().noquote() << "Window DPI changed: new DPI -->" << dpi qDebug().noquote() << "Window DPI changed: new DPI -->" << dpi
<< "new DPR -->" << "new DPR -->"
<< qreal(dpi) / qreal(USER_DEFAULT_SCREEN_DPI); << qreal(dpi) / qreal(USER_DEFAULT_SCREEN_DPI);
// Qt can also do the scaling for us, but here we scale our window #if 0
// ourself to let the window redraw itself.
const auto prcNewWindow = reinterpret_cast<LPRECT const>(msg->lParam); const auto prcNewWindow = reinterpret_cast<LPRECT const>(msg->lParam);
SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top, SetWindowPos(msg->hwnd, nullptr, prcNewWindow->left, prcNewWindow->top,
prcNewWindow->right - prcNewWindow->left, prcNewWindow->right - prcNewWindow->left,
prcNewWindow->bottom - prcNewWindow->top, prcNewWindow->bottom - prcNewWindow->top,
SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE); SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE);
*result = 0; #endif
return true; updateWindow(msg->hwnd);
break;
} }
default: { default: {
break; break;
@ -609,7 +571,6 @@ void WinNativeEventFilter::handleDwmCompositionChanged(LPWINDOW data) {
DwmExtendFrameIntoClientArea(data->hWnd, &margins); DwmExtendFrameIntoClientArea(data->hWnd, &margins);
} }
handleBlurForWindow(data); handleBlurForWindow(data);
updateRegion(data);
updateWindow(data->hWnd); updateWindow(data->hWnd);
} }
@ -824,7 +785,7 @@ void WinNativeEventFilter::updateWindow(HWND handle) {
SetWindowPos(handle, nullptr, 0, 0, 0, 0, SetWindowPos(handle, nullptr, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE |
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER); SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
SendMessageW(handle, WM_SIZE, NULL, NULL); SendMessageW(handle, WM_SIZE, 0, 0);
UpdateWindow(handle); UpdateWindow(handle);
} }
} }

View File

@ -71,7 +71,6 @@ private:
void handleDwmCompositionChanged(LPWINDOW data); void handleDwmCompositionChanged(LPWINDOW data);
void handleThemeChanged(LPWINDOW data); void handleThemeChanged(LPWINDOW data);
void handleBlurForWindow(LPWINDOW data); void handleBlurForWindow(LPWINDOW data);
void updateRegion(LPWINDOW data);
static void updateWindow(HWND handle); static void updateWindow(HWND handle);
static UINT getDpiForWindow(HWND handle); static UINT getDpiForWindow(HWND handle);
static qreal getDprForWindow(HWND handle); static qreal getDprForWindow(HWND handle);