Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
win: workaround Qt bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wangwenx190 committed Oct 12, 2023
1 parent 77c3eb5 commit 12d580c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/core/framelesshelper_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ struct FramelessDataWin : public FramelessData
// WM_MOUSELEAVE comes or we manually call TrackMouseEvent().
bool mouseLeaveBlocked = false;
Dpi dpi = {};
HMONITOR monitor = nullptr;
#if (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
QRect restoreGeometry = {};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
Expand Down Expand Up @@ -234,6 +235,11 @@ void FramelessHelperWin::addWindow(const QObject *window)
data->frameless = true;
data->dpi = Dpi{ Utils::getWindowDpi(data->windowId, true), Utils::getWindowDpi(data->windowId, false) };
DEBUG.noquote() << "The DPI of window" << hwnd2str(data->windowId) << "is" << data->dpi;
data->monitor = ::MonitorFromWindow(reinterpret_cast<HWND>(data->windowId), MONITOR_DEFAULTTONEAREST);
Q_ASSERT(data->monitor);
if (!data->monitor) {
WARNING << Utils::getSystemErrorMessage(kMonitorFromWindow);
}
// Remove the bad window styles added by Qt (it's not that "bad" though).
std::ignore = Utils::maybeFixupQtInternals(data->windowId);
#if 0
Expand Down Expand Up @@ -1138,11 +1144,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
#endif // (QT_VERSION <= QT_VERSION_CHECK(6, 4, 2))
case WM_DPICHANGED: {
const Dpi oldDpi = data->dpi;
const Dpi newDpi = {UINT(LOWORD(wParam)), UINT(HIWORD(wParam))};
if (Q_UNLIKELY(newDpi == oldDpi)) {
WARNING << "Wrong WM_DPICHANGED received: same DPI.";
break;
}
const auto newDpi = Dpi{ UINT(LOWORD(wParam)), UINT(HIWORD(wParam)) };
DEBUG.noquote() << "New DPI for window" << hwnd2str(hWnd)
<< "is" << newDpi << "(was" << oldDpi << ").";
data->dpi = newDpi;
Expand Down Expand Up @@ -1189,6 +1191,19 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
}
} break;
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
case WM_MOVE: {
const HMONITOR currentMonitor = ::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
Q_ASSERT(currentMonitor);
if (!currentMonitor) {
WARNING << Utils::getSystemErrorMessage(kMonitorFromWindow);
break;
}
if (currentMonitor == data->monitor) {
break;
}
data->monitor = currentMonitor;
data->callbacks->forceChildrenRepaint(500);
} break;
case WM_SYSCOMMAND: {
const WPARAM filteredWParam = (wParam & 0xFFF0);
// When the window is fullscreened, don't enter screen saver or power
Expand Down
9 changes: 8 additions & 1 deletion src/quick/framelessquickhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
if (!window) {
return;
}
const auto update = [window]() -> void {
const auto update = [window, q]() -> void {
#ifdef Q_OS_WINDOWS
// Sync the internal window frame margins with the latest DPI, otherwise
// we will get wrong window sizes after the DPI change.
Expand All @@ -415,6 +415,13 @@ void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
if (!window->isVisible()) {
return;
}
if (!((window->windowState() & (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen)) || q->isWindowFixedSize())) {
const QSize originalSize = window->size();
static constexpr const auto margins = QMargins{ 10, 10, 10, 10 };
window->resize(originalSize.shrunkBy(margins));
window->resize(originalSize.grownBy(margins));
window->resize(originalSize);
}
window->requestUpdate();
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
if (items.isEmpty()) {
Expand Down

0 comments on commit 12d580c

Please sign in to comment.