diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2022-10-31 10:01:14 +0100 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2022-12-23 20:34:19 +0800 |
commit | c3f8198d07c04cd8962637f134a9c78fbb5760c2 (patch) | |
tree | 987f3a7c64ef4f382ce8f331a27acd55e8889c68 /src/plugins/platforms/windows/qwindowscontext.cpp | |
parent | 585614ec220057077a9f036871f2f0e229859620 (diff) |
QWindowsContext::setProcessDpi[V2]Awareness check current value before setting it
Our previous assumption was that the right value was used if we ran into
an "access denied" error. That error only states that the function has
been called before though. The warning should be omitted if the right
value has been set before.
Pick-to: 6.5
Change-Id: I1379242f68e2f09bc6a25dd322fe3634622d8e8e
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 3e2cb79def..e8914fb6a2 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -378,30 +378,35 @@ int QWindowsContext::processDpiAwareness() void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness) { qCDebug(lcQpaWindow) << __FUNCTION__ << dpiAwareness; + if (processDpiAwareness() == int(dpiAwareness)) + return; + const HRESULT hr = SetProcessDpiAwareness(static_cast<PROCESS_DPI_AWARENESS>(dpiAwareness)); - // E_ACCESSDENIED means set externally (MSVC manifest or external app loading Qt plugin). - // Silence warning in that case unless debug is enabled. - if (FAILED(hr) && hr != E_ACCESSDENIED) { + if (FAILED(hr)) { qCWarning(lcQpaWindow).noquote().nospace() << "SetProcessDpiAwareness(" - << dpiAwareness << ") failed: " << QSystemError::windowsComString(hr) - << ", using " << QWindowsContext::processDpiAwareness(); + << dpiAwareness << ") failed: " << QSystemError::windowsComString(hr) << ", using " + << QWindowsContext::processDpiAwareness() << "\nQt's fallback DPI awareness is " + << "PROCESS_DPI_AWARENESS. If you know what you are doing consider an override in qt.conf"; } } bool QWindowsContext::setProcessDpiV2Awareness() { qCDebug(lcQpaWindow) << __FUNCTION__; + auto dpiContext = GetThreadDpiAwarenessContext(); + if (AreDpiAwarenessContextsEqual(dpiContext, DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)) + return true; + const BOOL ok = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); if (!ok) { const DWORD dwError = GetLastError(); - // ERROR_ACCESS_DENIED means set externally (MSVC manifest or external app loading Qt plugin). - // Silence warning in that case unless debug is enabled. - if (dwError != ERROR_ACCESS_DENIED) { - qCWarning(lcQpaWindow).noquote().nospace() - << "SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) failed: " - << QSystemError::windowsComString(HRESULT(dwError)); - return false; - } + qCWarning(lcQpaWindow).noquote().nospace() + << "SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) failed: " + << QSystemError::windowsComString(HRESULT(dwError)) << "\nQt's default DPI awareness " + << "context is DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2. If you know what you " + << "are doing you can overwrite this default using qt.conf " + << "(https://doc.qt.io/qt-6/highdpi.html#configuring-windows)"; + return false; } QWindowsContextPrivate::m_v2DpiAware = true; return true; |