Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-11 18:43:21 +08:00
parent bda22fcd9c
commit bb3aeb7f4c
2 changed files with 29 additions and 16 deletions

View File

@ -294,7 +294,9 @@ void WinNativeEventFilter::setFramelessWindows(QVector<HWND> windows) {
void WinNativeEventFilter::addFramelessWindow(HWND window, void WinNativeEventFilter::addFramelessWindow(HWND window,
const WINDOWDATA *data) { const WINDOWDATA *data) {
if (window && !m_framelessWindows.contains(window)) { initWin32Api();
if (window && m_lpIsWindow(window) &&
!m_framelessWindows.contains(window)) {
m_framelessWindows.append(window); m_framelessWindows.append(window);
if (data) { if (data) {
createUserData(window, data); createUserData(window, data);
@ -317,7 +319,7 @@ void WinNativeEventFilter::clearFramelessWindows() {
int WinNativeEventFilter::borderWidth(HWND handle) { int WinNativeEventFilter::borderWidth(HWND handle) {
initWin32Api(); initWin32Api();
if (handle) { if (handle && m_lpIsWindow(handle)) {
createUserData(handle); createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>( const auto userData = reinterpret_cast<WINDOW *>(
__GetWindowLongPtrW(handle, GWLP_USERDATA)); __GetWindowLongPtrW(handle, GWLP_USERDATA));
@ -335,7 +337,7 @@ int WinNativeEventFilter::borderWidth(HWND handle) {
int WinNativeEventFilter::borderHeight(HWND handle) { int WinNativeEventFilter::borderHeight(HWND handle) {
initWin32Api(); initWin32Api();
if (handle) { if (handle && m_lpIsWindow(handle)) {
createUserData(handle); createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>( const auto userData = reinterpret_cast<WINDOW *>(
__GetWindowLongPtrW(handle, GWLP_USERDATA)); __GetWindowLongPtrW(handle, GWLP_USERDATA));
@ -354,7 +356,7 @@ int WinNativeEventFilter::borderHeight(HWND handle) {
int WinNativeEventFilter::titlebarHeight(HWND handle) { int WinNativeEventFilter::titlebarHeight(HWND handle) {
initWin32Api(); initWin32Api();
if (handle) { if (handle && m_lpIsWindow(handle)) {
createUserData(handle); createUserData(handle);
const auto userData = reinterpret_cast<WINDOW *>( const auto userData = reinterpret_cast<WINDOW *>(
__GetWindowLongPtrW(handle, GWLP_USERDATA)); __GetWindowLongPtrW(handle, GWLP_USERDATA));
@ -723,6 +725,10 @@ bool WinNativeEventFilter::nativeEventFilter(const QByteArray &eventType,
*result = 1; *result = 1;
return true; return true;
} }
case WM_WINDOWPOSCHANGED: {
updateWindow(msg->hwnd);
break;
}
default: { default: {
break; break;
} }
@ -747,16 +753,7 @@ void WinNativeEventFilter::updateGlass(HWND handle) {
margins = {-1, -1, -1, -1}; margins = {-1, -1, -1, -1};
} }
m_lpDwmExtendFrameIntoClientArea(handle, &margins); m_lpDwmExtendFrameIntoClientArea(handle, &margins);
// Trigger a frame change event to kick in the change. updateWindow(handle);
// You may find that remove this line doesn't seem to have any side-effects,
// well, you are right in most cases, but don't remove it because it insures
// our code still work well in some rare cases.
m_lpSetWindowPos(handle, nullptr, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE |
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
// Redraw the window.
m_lpRedrawWindow(handle, nullptr, nullptr,
RDW_INVALIDATE | RDW_ERASE | RDW_FRAME | RDW_ALLCHILDREN);
} }
UINT WinNativeEventFilter::getDotsPerInchForWindow(HWND handle) { UINT WinNativeEventFilter::getDotsPerInchForWindow(HWND handle) {
@ -830,7 +827,7 @@ int WinNativeEventFilter::getSystemMetricsForWindow(HWND handle, int index) {
void WinNativeEventFilter::setWindowData(HWND window, const WINDOWDATA *data) { void WinNativeEventFilter::setWindowData(HWND window, const WINDOWDATA *data) {
initWin32Api(); initWin32Api();
if (window && data) { if (window && m_lpIsWindow(window) && data) {
createUserData(window, data); createUserData(window, data);
} }
} }
@ -838,7 +835,7 @@ void WinNativeEventFilter::setWindowData(HWND window, const WINDOWDATA *data) {
WinNativeEventFilter::WINDOWDATA * WinNativeEventFilter::WINDOWDATA *
WinNativeEventFilter::windowData(HWND window) { WinNativeEventFilter::windowData(HWND window) {
initWin32Api(); initWin32Api();
if (window) { if (window && m_lpIsWindow(window)) {
createUserData(window); createUserData(window);
return &reinterpret_cast<WINDOW *>( return &reinterpret_cast<WINDOW *>(
__GetWindowLongPtrW(window, GWLP_USERDATA)) __GetWindowLongPtrW(window, GWLP_USERDATA))
@ -1008,3 +1005,17 @@ qreal WinNativeEventFilter::getPreferedNumber(qreal num) {
#endif #endif
return result; return result;
} }
void WinNativeEventFilter::updateWindow(HWND handle) {
initWin32Api();
if (handle && m_lpIsWindow(handle)) {
m_lpSetWindowPos(handle, nullptr, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOSIZE |
SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
m_lpInvalidateRect(handle, nullptr, TRUE);
m_lpRedrawWindow(handle, nullptr, nullptr,
RDW_INVALIDATE | RDW_ERASE | RDW_FRAME |
RDW_ALLCHILDREN);
m_lpUpdateWindow(handle);
}
}

View File

@ -94,6 +94,8 @@ public:
// window (if the pointer is null, return the system's standard value). // window (if the pointer is null, return the system's standard value).
static int titlebarHeight(HWND handle); static int titlebarHeight(HWND handle);
static void updateWindow(HWND handle);
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
bool nativeEventFilter(const QByteArray &eventType, void *message, bool nativeEventFilter(const QByteArray &eventType, void *message,
qintptr *result) override; qintptr *result) override;