win: workaround Qt bug
This commit is contained in:
parent
77c3eb57e9
commit
12d580cc06
|
@ -110,6 +110,7 @@ struct FramelessDataWin : public FramelessData
|
||||||
// WM_MOUSELEAVE comes or we manually call TrackMouseEvent().
|
// WM_MOUSELEAVE comes or we manually call TrackMouseEvent().
|
||||||
bool mouseLeaveBlocked = false;
|
bool mouseLeaveBlocked = false;
|
||||||
Dpi dpi = {};
|
Dpi dpi = {};
|
||||||
|
HMONITOR monitor = nullptr;
|
||||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
|
#if (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
|
||||||
QRect restoreGeometry = {};
|
QRect restoreGeometry = {};
|
||||||
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
|
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
|
||||||
|
@ -234,6 +235,11 @@ void FramelessHelperWin::addWindow(const QObject *window)
|
||||||
data->frameless = true;
|
data->frameless = true;
|
||||||
data->dpi = Dpi{ Utils::getWindowDpi(data->windowId, true), Utils::getWindowDpi(data->windowId, false) };
|
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;
|
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).
|
// Remove the bad window styles added by Qt (it's not that "bad" though).
|
||||||
std::ignore = Utils::maybeFixupQtInternals(data->windowId);
|
std::ignore = Utils::maybeFixupQtInternals(data->windowId);
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -1138,11 +1144,7 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
#endif // (QT_VERSION <= QT_VERSION_CHECK(6, 4, 2))
|
#endif // (QT_VERSION <= QT_VERSION_CHECK(6, 4, 2))
|
||||||
case WM_DPICHANGED: {
|
case WM_DPICHANGED: {
|
||||||
const Dpi oldDpi = data->dpi;
|
const Dpi oldDpi = data->dpi;
|
||||||
const Dpi newDpi = {UINT(LOWORD(wParam)), UINT(HIWORD(wParam))};
|
const auto newDpi = Dpi{ UINT(LOWORD(wParam)), UINT(HIWORD(wParam)) };
|
||||||
if (Q_UNLIKELY(newDpi == oldDpi)) {
|
|
||||||
WARNING << "Wrong WM_DPICHANGED received: same DPI.";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
DEBUG.noquote() << "New DPI for window" << hwnd2str(hWnd)
|
DEBUG.noquote() << "New DPI for window" << hwnd2str(hWnd)
|
||||||
<< "is" << newDpi << "(was" << oldDpi << ").";
|
<< "is" << newDpi << "(was" << oldDpi << ").";
|
||||||
data->dpi = newDpi;
|
data->dpi = newDpi;
|
||||||
|
@ -1189,6 +1191,19 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 5, 1))
|
#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: {
|
case WM_SYSCOMMAND: {
|
||||||
const WPARAM filteredWParam = (wParam & 0xFFF0);
|
const WPARAM filteredWParam = (wParam & 0xFFF0);
|
||||||
// When the window is fullscreened, don't enter screen saver or power
|
// When the window is fullscreened, don't enter screen saver or power
|
||||||
|
|
|
@ -405,7 +405,7 @@ void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
|
||||||
if (!window) {
|
if (!window) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto update = [window]() -> void {
|
const auto update = [window, q]() -> void {
|
||||||
#ifdef Q_OS_WINDOWS
|
#ifdef Q_OS_WINDOWS
|
||||||
// Sync the internal window frame margins with the latest DPI, otherwise
|
// Sync the internal window frame margins with the latest DPI, otherwise
|
||||||
// we will get wrong window sizes after the DPI change.
|
// we will get wrong window sizes after the DPI change.
|
||||||
|
@ -415,6 +415,13 @@ void FramelessQuickHelperPrivate::repaintAllChildren(const quint32 delay) const
|
||||||
if (!window->isVisible()) {
|
if (!window->isVisible()) {
|
||||||
return;
|
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();
|
window->requestUpdate();
|
||||||
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
|
const QList<QQuickItem *> items = window->findChildren<QQuickItem *>();
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
|
|
Loading…
Reference in New Issue