diff options
author | Yuhang Zhao <2546789017@qq.com> | 2021-07-29 14:58:34 +0800 |
---|---|---|
committer | Yuhang Zhao <2546789017@qq.com> | 2021-11-24 09:16:38 +0800 |
commit | e75b1dfe380e854ed5ceaf5933740e3759a22aaf (patch) | |
tree | 85f20bfeab34768a1eca2675312aa909e44dc14a /src/plugins/platforms/windows/qwindowscontext.cpp | |
parent | f5f7f78766d62b7192b98b96bbd68dab1961e54e (diff) |
Windows QPA: Further cleanup of pre-Win10 code
Mostly a removal of dynamically loaded Win32 APIs.
Since Qt 6's minimum supported platform is Win10 1809
(10.0.17763, code name RS5), all these functions will
be available and no need to resolve them at run-time.
Things not remove:
WinTab functions in "qwindowstabletsupport.cpp".
Not my familiar area, so not touch it.
Pick-to: 6.2
Task-number: QTBUG-84432
Change-Id: I7ad6c3bc8376f6c0e3ac90f34e22f7628efeb694
Reviewed-by: André de la Rocha <andre.rocha@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp')
-rw-r--r-- | src/plugins/platforms/windows/qwindowscontext.cpp | 121 |
1 files changed, 18 insertions, 103 deletions
diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 1c75f7f7d2..0538f42bec 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -77,11 +77,9 @@ #include <QtCore/qlibraryinfo.h> #include <QtCore/qstringlist.h> #include <QtCore/qdebug.h> -#include <QtCore/qoperatingsystemversion.h> #include <QtCore/qsysinfo.h> #include <QtCore/qscopedpointer.h> #include <QtCore/quuid.h> -#include <QtCore/private/qsystemlibrary_p.h> #include <QtCore/private/qwinregistry_p.h> #include <QtGui/private/qwindowsguieventdispatcher_p.h> @@ -92,6 +90,7 @@ #include <comdef.h> #include <dbt.h> #include <wtsapi32.h> +#include <shellscalingapi.h> QT_BEGIN_NAMESPACE @@ -153,17 +152,15 @@ static inline bool sessionManagerInteractionBlocked() { return false; } static inline int windowDpiAwareness(HWND hwnd) { - return QWindowsContext::user32dll.getWindowDpiAwarenessContext && QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext - ? QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext(QWindowsContext::user32dll.getWindowDpiAwarenessContext(hwnd)) - : -1; + return static_cast<int>(GetAwarenessFromDpiAwarenessContext(GetWindowDpiAwarenessContext(hwnd))); } // Note: This only works within WM_NCCREATE static bool enableNonClientDpiScaling(HWND hwnd) { bool result = false; - if (QWindowsContext::user32dll.enableNonClientDpiScaling && windowDpiAwareness(hwnd) == 2) { - result = QWindowsContext::user32dll.enableNonClientDpiScaling(hwnd) != FALSE; + if (windowDpiAwareness(hwnd) == 2) { + result = EnableNonClientDpiScaling(hwnd) != FALSE; if (!result) { const DWORD errorCode = GetLastError(); qErrnoWarning(int(errorCode), "EnableNonClientDpiScaling() failed for HWND %p (%lu)", @@ -173,73 +170,6 @@ static bool enableNonClientDpiScaling(HWND hwnd) return result; } -/*! - \class QWindowsUser32DLL - \brief Struct that contains dynamically resolved symbols of User32.dll. - - The stub libraries shipped with the MinGW compiler miss some of the - functions. They need to be retrieved dynamically. - - In addition, touch-related functions are available only from Windows onwards. - These need to resolved dynamically for Q_CC_MSVC as well. - - \sa QWindowsShell32DLL - - \internal -*/ - -void QWindowsUser32DLL::init() -{ - QSystemLibrary library(QStringLiteral("user32")); - setProcessDPIAware = (SetProcessDPIAware)library.resolve("SetProcessDPIAware"); - setProcessDpiAwarenessContext = (SetProcessDpiAwarenessContext)library.resolve("SetProcessDpiAwarenessContext"); - - addClipboardFormatListener = (AddClipboardFormatListener)library.resolve("AddClipboardFormatListener"); - removeClipboardFormatListener = (RemoveClipboardFormatListener)library.resolve("RemoveClipboardFormatListener"); - - getDisplayAutoRotationPreferences = (GetDisplayAutoRotationPreferences)library.resolve("GetDisplayAutoRotationPreferences"); - setDisplayAutoRotationPreferences = (SetDisplayAutoRotationPreferences)library.resolve("SetDisplayAutoRotationPreferences"); - - enableMouseInPointer = (EnableMouseInPointer)library.resolve("EnableMouseInPointer"); - getPointerType = (GetPointerType)library.resolve("GetPointerType"); - getPointerInfo = (GetPointerInfo)library.resolve("GetPointerInfo"); - getPointerDeviceRects = (GetPointerDeviceRects)library.resolve("GetPointerDeviceRects"); - getPointerTouchInfo = (GetPointerTouchInfo)library.resolve("GetPointerTouchInfo"); - getPointerFrameTouchInfo = (GetPointerFrameTouchInfo)library.resolve("GetPointerFrameTouchInfo"); - getPointerFrameTouchInfoHistory = (GetPointerFrameTouchInfoHistory)library.resolve("GetPointerFrameTouchInfoHistory"); - getPointerPenInfo = (GetPointerPenInfo)library.resolve("GetPointerPenInfo"); - getPointerPenInfoHistory = (GetPointerPenInfoHistory)library.resolve("GetPointerPenInfoHistory"); - skipPointerFrameMessages = (SkipPointerFrameMessages)library.resolve("SkipPointerFrameMessages"); - - if (QOperatingSystemVersion::current() - >= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 14393)) { - adjustWindowRectExForDpi = (AdjustWindowRectExForDpi)library.resolve("AdjustWindowRectExForDpi"); - enableNonClientDpiScaling = (EnableNonClientDpiScaling)library.resolve("EnableNonClientDpiScaling"); - getWindowDpiAwarenessContext = (GetWindowDpiAwarenessContext)library.resolve("GetWindowDpiAwarenessContext"); - getAwarenessFromDpiAwarenessContext = (GetAwarenessFromDpiAwarenessContext)library.resolve("GetAwarenessFromDpiAwarenessContext"); - systemParametersInfoForDpi = (SystemParametersInfoForDpi)library.resolve("SystemParametersInfoForDpi"); - getDpiForWindow = (GetDpiForWindow)library.resolve("GetDpiForWindow"); - } -} - -bool QWindowsUser32DLL::supportsPointerApi() -{ - return enableMouseInPointer && getPointerType && getPointerInfo && getPointerDeviceRects - && getPointerTouchInfo && getPointerFrameTouchInfo && getPointerFrameTouchInfoHistory - && getPointerPenInfo && getPointerPenInfoHistory && skipPointerFrameMessages; -} - -void QWindowsShcoreDLL::init() -{ - QSystemLibrary library(QStringLiteral("SHCore")); - getProcessDpiAwareness = (GetProcessDpiAwareness)library.resolve("GetProcessDpiAwareness"); - setProcessDpiAwareness = (SetProcessDpiAwareness)library.resolve("SetProcessDpiAwareness"); - getDpiForMonitor = (GetDpiForMonitor)library.resolve("GetDpiForMonitor"); -} - -QWindowsUser32DLL QWindowsContext::user32dll; -QWindowsShcoreDLL QWindowsContext::shcoredll; - QWindowsContext *QWindowsContext::m_instance = nullptr; /*! @@ -285,9 +215,6 @@ bool QWindowsContextPrivate::m_v2DpiAware = false; QWindowsContextPrivate::QWindowsContextPrivate() : m_oleInitializeResult(OleInitialize(nullptr)) { - QWindowsContext::user32dll.init(); - QWindowsContext::shcoredll.init(); - if (m_pointerHandler.touchDevice() || m_mouseHandler.touchDevice()) m_systemInfo |= QWindowsContext::SI_SupportsTouch; m_displayContext = GetDC(nullptr); @@ -402,9 +329,6 @@ bool QWindowsContext::initPointer(unsigned integrationOptions) if (integrationOptions & QWindowsIntegration::DontUseWMPointer) return false; - if (!QWindowsContext::user32dll.supportsPointerApi()) - return false; - d->m_systemInfo |= QWindowsContext::SI_SupportsPointer; return true; } @@ -474,10 +398,9 @@ void QWindowsContext::setDetectAltGrModifier(bool a) int QWindowsContext::processDpiAwareness() { - int result; - if (QWindowsContext::shcoredll.getProcessDpiAwareness - && SUCCEEDED(QWindowsContext::shcoredll.getProcessDpiAwareness(nullptr, &result))) { - return result; + PROCESS_DPI_AWARENESS result; + if (SUCCEEDED(GetProcessDpiAwareness(nullptr, &result))) { + return static_cast<int>(result); } return -1; } @@ -485,27 +408,20 @@ int QWindowsContext::processDpiAwareness() void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness) { qCDebug(lcQpaWindows) << __FUNCTION__ << dpiAwareness; - if (QWindowsContext::shcoredll.isValid()) { - const HRESULT hr = QWindowsContext::shcoredll.setProcessDpiAwareness(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 || lcQpaWindows().isDebugEnabled())) { - qWarning().noquote().nospace() << "SetProcessDpiAwareness(" - << dpiAwareness << ") failed: " << QWindowsContext::comErrorString(hr) - << ", using " << QWindowsContext::processDpiAwareness(); - } - } else { - if (dpiAwareness != QtWindows::ProcessDpiUnaware && QWindowsContext::user32dll.setProcessDPIAware) { - if (!QWindowsContext::user32dll.setProcessDPIAware()) - qErrnoWarning("SetProcessDPIAware() failed"); - } + 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 || lcQpaWindows().isDebugEnabled())) { + qWarning().noquote().nospace() << "SetProcessDpiAwareness(" + << dpiAwareness << ") failed: " << QWindowsContext::comErrorString(hr) + << ", using " << QWindowsContext::processDpiAwareness(); } } void QWindowsContext::setProcessDpiV2Awareness() { qCDebug(lcQpaWindows) << __FUNCTION__; - const BOOL ok = QWindowsContext::user32dll.setProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + const BOOL ok = SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); if (ok) { QWindowsContextPrivate::m_v2DpiAware = true; } else { @@ -1046,8 +962,8 @@ void QWindowsContext::forceNcCalcSize(HWND hwnd) bool QWindowsContext::systemParametersInfo(unsigned action, unsigned param, void *out, unsigned dpi) { - const BOOL result = QWindowsContext::user32dll.systemParametersInfoForDpi != nullptr && dpi != 0 - ? QWindowsContext::user32dll.systemParametersInfoForDpi(action, param, out, 0, dpi) + const BOOL result = dpi != 0 + ? SystemParametersInfoForDpi(action, param, out, 0, dpi) : SystemParametersInfo(action, param, out, 0); return result == TRUE; } @@ -1094,8 +1010,7 @@ bool QWindowsContext::shouldHaveNonClientDpiScaling(const QWindow *window) if (QWindowsContextPrivate::m_v2DpiAware) return true; - return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10 - && window->isTopLevel() + return window->isTopLevel() && !window->property(QWindowsWindow::embeddedNativeParentHandleProperty).isValid() #if QT_CONFIG(opengl) // /QTBUG-62901, EnableNonClientDpiScaling has problems with GL && (window->surfaceType() != QSurface::OpenGLSurface |