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>
This commit is contained in:
Yuhang Zhao 2021-07-29 14:58:34 +08:00
parent f5f7f78766
commit e75b1dfe38
14 changed files with 109 additions and 383 deletions

View File

@ -72,6 +72,10 @@ qt_internal_add_plugin(QWindowsDirect2DIntegrationPlugin
winmm winmm
winspool winspool
wtsapi32 wtsapi32
shcore
comdlg32
d3d9
runtimeobject
) )
# Resources: # Resources:

View File

@ -59,6 +59,10 @@ qt_internal_add_plugin(QWindowsIntegrationPlugin
winmm winmm
winspool winspool
wtsapi32 wtsapi32
shcore
comdlg32
d3d9
runtimeobject
) )
# Resources: # Resources:

View File

@ -40,8 +40,8 @@
#include "qwin10helpers.h" #include "qwin10helpers.h"
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qoperatingsystemversion.h> #include <winstring.h>
#include <QtCore/private/qsystemlibrary_p.h> #include <roapi.h>
#if defined(Q_CC_MINGW) || defined(Q_CC_CLANG) #if defined(Q_CC_MINGW) || defined(Q_CC_CLANG)
# define HAS_UI_VIEW_SETTINGS_INTEROP # define HAS_UI_VIEW_SETTINGS_INTEROP
@ -96,56 +96,23 @@ public:
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
// Starting from Windows 10
struct QWindowsComBaseDLL
{
bool init();
bool isValid() const
{
return roGetActivationFactory != nullptr && windowsCreateStringReference != nullptr;
}
typedef HRESULT (WINAPI *RoGetActivationFactory)(HSTRING, REFIID, void **);
typedef HRESULT (WINAPI *WindowsCreateStringReference)(PCWSTR, UINT32, HSTRING_HEADER *, HSTRING *);
RoGetActivationFactory roGetActivationFactory = nullptr;
WindowsCreateStringReference windowsCreateStringReference = nullptr;
};
static QWindowsComBaseDLL baseComDll;
bool QWindowsComBaseDLL::init()
{
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10 && !isValid()) {
QSystemLibrary library(QStringLiteral("combase"));
roGetActivationFactory =
reinterpret_cast<RoGetActivationFactory>(library.resolve("RoGetActivationFactory"));
windowsCreateStringReference =
reinterpret_cast<WindowsCreateStringReference>(library.resolve("WindowsCreateStringReference"));
}
return isValid();
}
// Return tablet mode, note: Does not work for GetDesktopWindow(). // Return tablet mode, note: Does not work for GetDesktopWindow().
bool qt_windowsIsTabletMode(HWND hwnd) bool qt_windowsIsTabletMode(HWND hwnd)
{ {
bool result = false; bool result = false;
if (!baseComDll.init())
return false;
const wchar_t uiViewSettingsId[] = L"Windows.UI.ViewManagement.UIViewSettings"; const wchar_t uiViewSettingsId[] = L"Windows.UI.ViewManagement.UIViewSettings";
HSTRING_HEADER uiViewSettingsIdRefHeader; HSTRING_HEADER uiViewSettingsIdRefHeader;
HSTRING uiViewSettingsIdHs = nullptr; HSTRING uiViewSettingsIdHs = nullptr;
const auto uiViewSettingsIdLen = UINT32(sizeof(uiViewSettingsId) / sizeof(uiViewSettingsId[0]) - 1); const auto uiViewSettingsIdLen = UINT32(sizeof(uiViewSettingsId) / sizeof(uiViewSettingsId[0]) - 1);
if (FAILED(baseComDll.windowsCreateStringReference(uiViewSettingsId, uiViewSettingsIdLen, &uiViewSettingsIdRefHeader, &uiViewSettingsIdHs))) if (FAILED(WindowsCreateStringReference(uiViewSettingsId, uiViewSettingsIdLen, &uiViewSettingsIdRefHeader, &uiViewSettingsIdHs)))
return false; return false;
IUIViewSettingsInterop *uiViewSettingsInterop = nullptr; IUIViewSettingsInterop *uiViewSettingsInterop = nullptr;
// __uuidof(IUIViewSettingsInterop); // __uuidof(IUIViewSettingsInterop);
const GUID uiViewSettingsInteropRefId = {0x3694dbf9, 0x8f68, 0x44be,{0x8f, 0xf5, 0x19, 0x5c, 0x98, 0xed, 0xe8, 0xa6}}; const GUID uiViewSettingsInteropRefId = {0x3694dbf9, 0x8f68, 0x44be,{0x8f, 0xf5, 0x19, 0x5c, 0x98, 0xed, 0xe8, 0xa6}};
HRESULT hr = baseComDll.roGetActivationFactory(uiViewSettingsIdHs, uiViewSettingsInteropRefId, HRESULT hr = RoGetActivationFactory(uiViewSettingsIdHs, uiViewSettingsInteropRefId,
reinterpret_cast<void **>(&uiViewSettingsInterop)); reinterpret_cast<void **>(&uiViewSettingsInterop));
if (FAILED(hr)) if (FAILED(hr))
return false; return false;

View File

@ -191,12 +191,9 @@ void QWindowsClipboard::registerViewer()
createDummyWindow(QStringLiteral("ClipboardView"), L"QtClipboardView", createDummyWindow(QStringLiteral("ClipboardView"), L"QtClipboardView",
qClipboardViewerWndProc, WS_OVERLAPPED); qClipboardViewerWndProc, WS_OVERLAPPED);
// Try format listener API (Vista onwards) first. m_formatListenerRegistered = AddClipboardFormatListener(m_clipboardViewer);
if (QWindowsContext::user32dll.addClipboardFormatListener && QWindowsContext::user32dll.removeClipboardFormatListener) { if (!m_formatListenerRegistered)
m_formatListenerRegistered = QWindowsContext::user32dll.addClipboardFormatListener(m_clipboardViewer); qErrnoWarning("AddClipboardFormatListener() failed.");
if (!m_formatListenerRegistered)
qErrnoWarning("AddClipboardFormatListener() failed.");
}
if (!m_formatListenerRegistered) if (!m_formatListenerRegistered)
m_nextClipboardViewer = SetClipboardViewer(m_clipboardViewer); m_nextClipboardViewer = SetClipboardViewer(m_clipboardViewer);
@ -210,7 +207,7 @@ void QWindowsClipboard::unregisterViewer()
{ {
if (m_clipboardViewer) { if (m_clipboardViewer) {
if (m_formatListenerRegistered) { if (m_formatListenerRegistered) {
QWindowsContext::user32dll.removeClipboardFormatListener(m_clipboardViewer); RemoveClipboardFormatListener(m_clipboardViewer);
m_formatListenerRegistered = false; m_formatListenerRegistered = false;
} else { } else {
ChangeClipboardChain(m_clipboardViewer, m_nextClipboardViewer); ChangeClipboardChain(m_clipboardViewer, m_nextClipboardViewer);

View File

@ -77,11 +77,9 @@
#include <QtCore/qlibraryinfo.h> #include <QtCore/qlibraryinfo.h>
#include <QtCore/qstringlist.h> #include <QtCore/qstringlist.h>
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qoperatingsystemversion.h>
#include <QtCore/qsysinfo.h> #include <QtCore/qsysinfo.h>
#include <QtCore/qscopedpointer.h> #include <QtCore/qscopedpointer.h>
#include <QtCore/quuid.h> #include <QtCore/quuid.h>
#include <QtCore/private/qsystemlibrary_p.h>
#include <QtCore/private/qwinregistry_p.h> #include <QtCore/private/qwinregistry_p.h>
#include <QtGui/private/qwindowsguieventdispatcher_p.h> #include <QtGui/private/qwindowsguieventdispatcher_p.h>
@ -92,6 +90,7 @@
#include <comdef.h> #include <comdef.h>
#include <dbt.h> #include <dbt.h>
#include <wtsapi32.h> #include <wtsapi32.h>
#include <shellscalingapi.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -153,17 +152,15 @@ static inline bool sessionManagerInteractionBlocked() { return false; }
static inline int windowDpiAwareness(HWND hwnd) static inline int windowDpiAwareness(HWND hwnd)
{ {
return QWindowsContext::user32dll.getWindowDpiAwarenessContext && QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext return static_cast<int>(GetAwarenessFromDpiAwarenessContext(GetWindowDpiAwarenessContext(hwnd)));
? QWindowsContext::user32dll.getAwarenessFromDpiAwarenessContext(QWindowsContext::user32dll.getWindowDpiAwarenessContext(hwnd))
: -1;
} }
// Note: This only works within WM_NCCREATE // Note: This only works within WM_NCCREATE
static bool enableNonClientDpiScaling(HWND hwnd) static bool enableNonClientDpiScaling(HWND hwnd)
{ {
bool result = false; bool result = false;
if (QWindowsContext::user32dll.enableNonClientDpiScaling && windowDpiAwareness(hwnd) == 2) { if (windowDpiAwareness(hwnd) == 2) {
result = QWindowsContext::user32dll.enableNonClientDpiScaling(hwnd) != FALSE; result = EnableNonClientDpiScaling(hwnd) != FALSE;
if (!result) { if (!result) {
const DWORD errorCode = GetLastError(); const DWORD errorCode = GetLastError();
qErrnoWarning(int(errorCode), "EnableNonClientDpiScaling() failed for HWND %p (%lu)", qErrnoWarning(int(errorCode), "EnableNonClientDpiScaling() failed for HWND %p (%lu)",
@ -173,73 +170,6 @@ static bool enableNonClientDpiScaling(HWND hwnd)
return result; 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; QWindowsContext *QWindowsContext::m_instance = nullptr;
/*! /*!
@ -285,9 +215,6 @@ bool QWindowsContextPrivate::m_v2DpiAware = false;
QWindowsContextPrivate::QWindowsContextPrivate() QWindowsContextPrivate::QWindowsContextPrivate()
: m_oleInitializeResult(OleInitialize(nullptr)) : m_oleInitializeResult(OleInitialize(nullptr))
{ {
QWindowsContext::user32dll.init();
QWindowsContext::shcoredll.init();
if (m_pointerHandler.touchDevice() || m_mouseHandler.touchDevice()) if (m_pointerHandler.touchDevice() || m_mouseHandler.touchDevice())
m_systemInfo |= QWindowsContext::SI_SupportsTouch; m_systemInfo |= QWindowsContext::SI_SupportsTouch;
m_displayContext = GetDC(nullptr); m_displayContext = GetDC(nullptr);
@ -402,9 +329,6 @@ bool QWindowsContext::initPointer(unsigned integrationOptions)
if (integrationOptions & QWindowsIntegration::DontUseWMPointer) if (integrationOptions & QWindowsIntegration::DontUseWMPointer)
return false; return false;
if (!QWindowsContext::user32dll.supportsPointerApi())
return false;
d->m_systemInfo |= QWindowsContext::SI_SupportsPointer; d->m_systemInfo |= QWindowsContext::SI_SupportsPointer;
return true; return true;
} }
@ -474,10 +398,9 @@ void QWindowsContext::setDetectAltGrModifier(bool a)
int QWindowsContext::processDpiAwareness() int QWindowsContext::processDpiAwareness()
{ {
int result; PROCESS_DPI_AWARENESS result;
if (QWindowsContext::shcoredll.getProcessDpiAwareness if (SUCCEEDED(GetProcessDpiAwareness(nullptr, &result))) {
&& SUCCEEDED(QWindowsContext::shcoredll.getProcessDpiAwareness(nullptr, &result))) { return static_cast<int>(result);
return result;
} }
return -1; return -1;
} }
@ -485,27 +408,20 @@ int QWindowsContext::processDpiAwareness()
void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness) void QWindowsContext::setProcessDpiAwareness(QtWindows::ProcessDpiAwareness dpiAwareness)
{ {
qCDebug(lcQpaWindows) << __FUNCTION__ << dpiAwareness; qCDebug(lcQpaWindows) << __FUNCTION__ << dpiAwareness;
if (QWindowsContext::shcoredll.isValid()) { const HRESULT hr = SetProcessDpiAwareness(static_cast<PROCESS_DPI_AWARENESS>(dpiAwareness));
const HRESULT hr = QWindowsContext::shcoredll.setProcessDpiAwareness(dpiAwareness); // E_ACCESSDENIED means set externally (MSVC manifest or external app loading Qt plugin).
// E_ACCESSDENIED means set externally (MSVC manifest or external app loading Qt plugin). // Silence warning in that case unless debug is enabled.
// Silence warning in that case unless debug is enabled. if (FAILED(hr) && (hr != E_ACCESSDENIED || lcQpaWindows().isDebugEnabled())) {
if (FAILED(hr) && (hr != E_ACCESSDENIED || lcQpaWindows().isDebugEnabled())) { qWarning().noquote().nospace() << "SetProcessDpiAwareness("
qWarning().noquote().nospace() << "SetProcessDpiAwareness(" << dpiAwareness << ") failed: " << QWindowsContext::comErrorString(hr)
<< dpiAwareness << ") failed: " << QWindowsContext::comErrorString(hr) << ", using " << QWindowsContext::processDpiAwareness();
<< ", using " << QWindowsContext::processDpiAwareness();
}
} else {
if (dpiAwareness != QtWindows::ProcessDpiUnaware && QWindowsContext::user32dll.setProcessDPIAware) {
if (!QWindowsContext::user32dll.setProcessDPIAware())
qErrnoWarning("SetProcessDPIAware() failed");
}
} }
} }
void QWindowsContext::setProcessDpiV2Awareness() void QWindowsContext::setProcessDpiV2Awareness()
{ {
qCDebug(lcQpaWindows) << __FUNCTION__; 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) { if (ok) {
QWindowsContextPrivate::m_v2DpiAware = true; QWindowsContextPrivate::m_v2DpiAware = true;
} else { } else {
@ -1046,8 +962,8 @@ void QWindowsContext::forceNcCalcSize(HWND hwnd)
bool QWindowsContext::systemParametersInfo(unsigned action, unsigned param, void *out, bool QWindowsContext::systemParametersInfo(unsigned action, unsigned param, void *out,
unsigned dpi) unsigned dpi)
{ {
const BOOL result = QWindowsContext::user32dll.systemParametersInfoForDpi != nullptr && dpi != 0 const BOOL result = dpi != 0
? QWindowsContext::user32dll.systemParametersInfoForDpi(action, param, out, 0, dpi) ? SystemParametersInfoForDpi(action, param, out, 0, dpi)
: SystemParametersInfo(action, param, out, 0); : SystemParametersInfo(action, param, out, 0);
return result == TRUE; return result == TRUE;
} }
@ -1094,8 +1010,7 @@ bool QWindowsContext::shouldHaveNonClientDpiScaling(const QWindow *window)
if (QWindowsContextPrivate::m_v2DpiAware) if (QWindowsContextPrivate::m_v2DpiAware)
return true; return true;
return QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10 return window->isTopLevel()
&& window->isTopLevel()
&& !window->property(QWindowsWindow::embeddedNativeParentHandleProperty).isValid() && !window->property(QWindowsWindow::embeddedNativeParentHandleProperty).isValid()
#if QT_CONFIG(opengl) // /QTBUG-62901, EnableNonClientDpiScaling has problems with GL #if QT_CONFIG(opengl) // /QTBUG-62901, EnableNonClientDpiScaling has problems with GL
&& (window->surfaceType() != QSurface::OpenGLSurface && (window->surfaceType() != QSurface::OpenGLSurface

View File

@ -82,85 +82,6 @@ class QPoint;
class QKeyEvent; class QKeyEvent;
class QPointingDevice; class QPointingDevice;
struct QWindowsUser32DLL
{
inline void init();
inline bool supportsPointerApi();
typedef BOOL (WINAPI *EnableMouseInPointer)(BOOL);
typedef BOOL (WINAPI *GetPointerType)(UINT32, PVOID);
typedef BOOL (WINAPI *GetPointerInfo)(UINT32, PVOID);
typedef BOOL (WINAPI *GetPointerDeviceRects)(HANDLE, RECT *, RECT *);
typedef BOOL (WINAPI *GetPointerTouchInfo)(UINT32, PVOID);
typedef BOOL (WINAPI *GetPointerFrameTouchInfo)(UINT32, UINT32 *, PVOID);
typedef BOOL (WINAPI *GetPointerFrameTouchInfoHistory)(UINT32, UINT32 *, UINT32 *, PVOID);
typedef BOOL (WINAPI *GetPointerPenInfo)(UINT32, PVOID);
typedef BOOL (WINAPI *GetPointerPenInfoHistory)(UINT32, UINT32 *, PVOID);
typedef BOOL (WINAPI *SkipPointerFrameMessages)(UINT32);
typedef BOOL (WINAPI *SetProcessDPIAware)();
typedef BOOL (WINAPI *SetProcessDpiAwarenessContext)(HANDLE);
typedef BOOL (WINAPI *AddClipboardFormatListener)(HWND);
typedef BOOL (WINAPI *RemoveClipboardFormatListener)(HWND);
typedef BOOL (WINAPI *GetDisplayAutoRotationPreferences)(DWORD *);
typedef BOOL (WINAPI *SetDisplayAutoRotationPreferences)(DWORD);
typedef BOOL (WINAPI *AdjustWindowRectExForDpi)(LPRECT,DWORD,BOOL,DWORD,UINT);
typedef BOOL (WINAPI *EnableNonClientDpiScaling)(HWND);
typedef int (WINAPI *GetWindowDpiAwarenessContext)(HWND);
typedef int (WINAPI *GetAwarenessFromDpiAwarenessContext)(int);
typedef BOOL (WINAPI *SystemParametersInfoForDpi)(UINT, UINT, PVOID, UINT, UINT);
typedef int (WINAPI *GetDpiForWindow)(HWND);
// Windows pointer functions (Windows 8 or later).
EnableMouseInPointer enableMouseInPointer = nullptr;
GetPointerType getPointerType = nullptr;
GetPointerInfo getPointerInfo = nullptr;
GetPointerDeviceRects getPointerDeviceRects = nullptr;
GetPointerTouchInfo getPointerTouchInfo = nullptr;
GetPointerFrameTouchInfo getPointerFrameTouchInfo = nullptr;
GetPointerFrameTouchInfoHistory getPointerFrameTouchInfoHistory = nullptr;
GetPointerPenInfo getPointerPenInfo = nullptr;
GetPointerPenInfoHistory getPointerPenInfoHistory = nullptr;
SkipPointerFrameMessages skipPointerFrameMessages = nullptr;
// Windows Vista onwards
SetProcessDPIAware setProcessDPIAware = nullptr;
// Windows 10 version 1607 onwards
GetDpiForWindow getDpiForWindow = nullptr;
// Windows 10 version 1703 onwards
SetProcessDpiAwarenessContext setProcessDpiAwarenessContext = nullptr;
// Clipboard listeners are present on Windows Vista onwards
// but missing in MinGW 4.9 stub libs. Can be removed in MinGW 5.
AddClipboardFormatListener addClipboardFormatListener = nullptr;
RemoveClipboardFormatListener removeClipboardFormatListener = nullptr;
// Rotation API
GetDisplayAutoRotationPreferences getDisplayAutoRotationPreferences = nullptr;
SetDisplayAutoRotationPreferences setDisplayAutoRotationPreferences = nullptr;
AdjustWindowRectExForDpi adjustWindowRectExForDpi = nullptr;
EnableNonClientDpiScaling enableNonClientDpiScaling = nullptr;
GetWindowDpiAwarenessContext getWindowDpiAwarenessContext = nullptr;
GetAwarenessFromDpiAwarenessContext getAwarenessFromDpiAwarenessContext = nullptr;
SystemParametersInfoForDpi systemParametersInfoForDpi = nullptr;
};
// Shell scaling library (Windows 8.1 onwards)
struct QWindowsShcoreDLL {
void init();
inline bool isValid() const { return getProcessDpiAwareness && setProcessDpiAwareness && getDpiForMonitor; }
typedef HRESULT (WINAPI *GetProcessDpiAwareness)(HANDLE,int *);
typedef HRESULT (WINAPI *SetProcessDpiAwareness)(int);
typedef HRESULT (WINAPI *GetDpiForMonitor)(HMONITOR,int,UINT *,UINT *);
GetProcessDpiAwareness getProcessDpiAwareness = nullptr;
SetProcessDpiAwareness setProcessDpiAwareness = nullptr;
GetDpiForMonitor getDpiForMonitor = nullptr;
};
class QWindowsContext class QWindowsContext
{ {
Q_DISABLE_COPY_MOVE(QWindowsContext) Q_DISABLE_COPY_MOVE(QWindowsContext)
@ -253,9 +174,6 @@ public:
QWindowsScreenManager &screenManager(); QWindowsScreenManager &screenManager();
QWindowsTabletSupport *tabletSupport() const; QWindowsTabletSupport *tabletSupport() const;
static QWindowsUser32DLL user32dll;
static QWindowsShcoreDLL shcoredll;
static QByteArray comErrorString(HRESULT hr); static QByteArray comErrorString(HRESULT hr);
bool asyncExpose() const; bool asyncExpose() const;
void setAsyncExpose(bool value); void setAsyncExpose(bool value);

View File

@ -70,7 +70,6 @@
#include <QtCore/qmutex.h> #include <QtCore/qmutex.h>
#include <QtCore/quuid.h> #include <QtCore/quuid.h>
#include <QtCore/qtemporaryfile.h> #include <QtCore/qtemporaryfile.h>
#include <QtCore/private/qsystemlibrary_p.h>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
@ -1707,9 +1706,6 @@ public slots:
void close() override {} void close() override {}
private: private:
typedef BOOL (APIENTRY *PtrGetOpenFileNameW)(LPOPENFILENAMEW);
typedef BOOL (APIENTRY *PtrGetSaveFileNameW)(LPOPENFILENAMEW);
explicit QWindowsXpNativeFileDialog(const OptionsPtr &options, const QWindowsFileDialogSharedData &data); explicit QWindowsXpNativeFileDialog(const OptionsPtr &options, const QWindowsFileDialogSharedData &data);
void populateOpenFileName(OPENFILENAME *ofn, HWND owner) const; void populateOpenFileName(OPENFILENAME *ofn, HWND owner) const;
QList<QUrl> execExistingDir(HWND owner); QList<QUrl> execExistingDir(HWND owner);
@ -1719,27 +1715,11 @@ private:
QString m_title; QString m_title;
QPlatformDialogHelper::DialogCode m_result; QPlatformDialogHelper::DialogCode m_result;
QWindowsFileDialogSharedData m_data; QWindowsFileDialogSharedData m_data;
static PtrGetOpenFileNameW m_getOpenFileNameW;
static PtrGetSaveFileNameW m_getSaveFileNameW;
}; };
QWindowsXpNativeFileDialog::PtrGetOpenFileNameW QWindowsXpNativeFileDialog::m_getOpenFileNameW = nullptr;
QWindowsXpNativeFileDialog::PtrGetSaveFileNameW QWindowsXpNativeFileDialog::m_getSaveFileNameW = nullptr;
QWindowsXpNativeFileDialog *QWindowsXpNativeFileDialog::create(const OptionsPtr &options, const QWindowsFileDialogSharedData &data) QWindowsXpNativeFileDialog *QWindowsXpNativeFileDialog::create(const OptionsPtr &options, const QWindowsFileDialogSharedData &data)
{ {
// GetOpenFileNameW() GetSaveFileName() are resolved return new QWindowsXpNativeFileDialog(options, data);
// dynamically as not to create a dependency on Comdlg32, which
// is used on XP only.
if (!m_getOpenFileNameW) {
QSystemLibrary library(QStringLiteral("Comdlg32"));
m_getOpenFileNameW = (PtrGetOpenFileNameW)(library.resolve("GetOpenFileNameW"));
m_getSaveFileNameW = (PtrGetSaveFileNameW)(library.resolve("GetSaveFileNameW"));
}
if (m_getOpenFileNameW && m_getSaveFileNameW)
return new QWindowsXpNativeFileDialog(options, data);
return nullptr;
} }
QWindowsXpNativeFileDialog::QWindowsXpNativeFileDialog(const OptionsPtr &options, QWindowsXpNativeFileDialog::QWindowsXpNativeFileDialog(const OptionsPtr &options,
@ -1903,7 +1883,7 @@ QList<QUrl> QWindowsXpNativeFileDialog::execFileNames(HWND owner, int *selectedF
populateOpenFileName(&ofn, owner); populateOpenFileName(&ofn, owner);
QList<QUrl> result; QList<QUrl> result;
const bool isSave = m_options->acceptMode() == QFileDialogOptions::AcceptSave; const bool isSave = m_options->acceptMode() == QFileDialogOptions::AcceptSave;
if (isSave ? m_getSaveFileNameW(&ofn) : m_getOpenFileNameW(&ofn)) { if (isSave ? GetSaveFileNameW(&ofn) : GetOpenFileNameW(&ofn)) {
*selectedFilterIndex = ofn.nFilterIndex - 1; *selectedFilterIndex = ofn.nFilterIndex - 1;
const QString dir = QDir::cleanPath(QString::fromWCharArray(ofn.lpstrFile)); const QString dir = QDir::cleanPath(QString::fromWCharArray(ofn.lpstrFile));
result.push_back(QUrl::fromLocalFile(dir)); result.push_back(QUrl::fromLocalFile(dir));
@ -2045,8 +2025,6 @@ QWindowsNativeColorDialog::QWindowsNativeColorDialog(const SharedPointerColor &c
void QWindowsNativeColorDialog::doExec(HWND owner) void QWindowsNativeColorDialog::doExec(HWND owner)
{ {
typedef BOOL (WINAPI *ChooseColorWType)(LPCHOOSECOLORW);
CHOOSECOLOR chooseColor; CHOOSECOLOR chooseColor;
ZeroMemory(&chooseColor, sizeof(chooseColor)); ZeroMemory(&chooseColor, sizeof(chooseColor));
chooseColor.lStructSize = sizeof(chooseColor); chooseColor.lStructSize = sizeof(chooseColor);
@ -2059,18 +2037,9 @@ void QWindowsNativeColorDialog::doExec(HWND owner)
m_customColors[c] = qColorToCOLORREF(QColor(qCustomColors[c])); m_customColors[c] = qColorToCOLORREF(QColor(qCustomColors[c]));
chooseColor.rgbResult = qColorToCOLORREF(*m_color); chooseColor.rgbResult = qColorToCOLORREF(*m_color);
chooseColor.Flags = CC_FULLOPEN | CC_RGBINIT; chooseColor.Flags = CC_FULLOPEN | CC_RGBINIT;
static ChooseColorWType chooseColorW = 0; m_code = ChooseColorW(&chooseColor) ?
if (!chooseColorW) { QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected;
QSystemLibrary library(QStringLiteral("Comdlg32")); QWindowsDialogs::eatMouseMove();
chooseColorW = (ChooseColorWType)library.resolve("ChooseColorW");
}
if (chooseColorW) {
m_code = chooseColorW(&chooseColor) ?
QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected;
QWindowsDialogs::eatMouseMove();
} else {
m_code = QPlatformDialogHelper::Rejected;
}
if (m_code == QPlatformDialogHelper::Accepted) { if (m_code == QPlatformDialogHelper::Accepted) {
*m_color = COLORREFToQColor(chooseColor.rgbResult); *m_color = COLORREFToQColor(chooseColor.rgbResult);
for (int c= 0; c < customColorCount; ++c) for (int c= 0; c < customColorCount; ++c)

View File

@ -47,7 +47,6 @@
#include <QtCore/qobject.h> #include <QtCore/qobject.h>
#include <QtCore/qrect.h> #include <QtCore/qrect.h>
#include <QtCore/qtextboundaryfinder.h> #include <QtCore/qtextboundaryfinder.h>
#include <QtCore/qoperatingsystemversion.h>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
#include <QtGui/qtextformat.h> #include <QtGui/qtextformat.h>
@ -285,9 +284,7 @@ void QWindowsInputContext::showInputPanel()
// Only trigger the native OSK if the Qt OSK is not in use. // Only trigger the native OSK if the Qt OSK is not in use.
static bool imModuleEmpty = qEnvironmentVariableIsEmpty("QT_IM_MODULE"); static bool imModuleEmpty = qEnvironmentVariableIsEmpty("QT_IM_MODULE");
bool nativeVKDisabled = QCoreApplication::testAttribute(Qt::AA_DisableNativeVirtualKeyboard); bool nativeVKDisabled = QCoreApplication::testAttribute(Qt::AA_DisableNativeVirtualKeyboard);
if ((imModuleEmpty && !nativeVKDisabled) if (imModuleEmpty && !nativeVKDisabled) {
&& QOperatingSystemVersion::current()
>= QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 16299)) {
ShowCaret(platformWindow->handle()); ShowCaret(platformWindow->handle());
} else { } else {
HideCaret(platformWindow->handle()); HideCaret(platformWindow->handle());

View File

@ -122,14 +122,6 @@ QT_BEGIN_NAMESPACE
MinGW-w64 provides more complete headers (compared to stock MinGW from mingw.org), MinGW-w64 provides more complete headers (compared to stock MinGW from mingw.org),
including a considerable part of the Windows SDK. including a considerable part of the Windows SDK.
\endlist \endlist
When using a function from the WinAPI, the minimum supported Windows version
and Windows Embedded support should be checked. If the function is not supported
on Windows XP or is not present in the MinGW-headers, it should be dynamically
resolved. For this purpose, QWindowsContext has static structs like
QWindowsUser32DLL and QWindowsShell32DLL. All function pointers should go to
these structs to avoid lookups in several places.
*/ */
struct QWindowsIntegrationPrivate struct QWindowsIntegrationPrivate
@ -245,10 +237,8 @@ void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStr
initOpenGlBlacklistResources(); initOpenGlBlacklistResources();
static bool dpiAwarenessSet = false; static bool dpiAwarenessSet = false;
static bool hasDpiAwarenessContext = QWindowsContext::user32dll.setProcessDpiAwarenessContext != nullptr;
// Default to per-monitor-v2 awareness (if available) // Default to per-monitor-v2 awareness (if available)
QtWindows::ProcessDpiAwareness dpiAwareness = hasDpiAwarenessContext ? QtWindows::ProcessDpiAwareness dpiAwareness = QtWindows::ProcessPerMonitorV2DpiAware;
QtWindows::ProcessPerMonitorV2DpiAware : QtWindows::ProcessPerMonitorDpiAware;
int tabletAbsoluteRange = -1; int tabletAbsoluteRange = -1;
DarkModeHandling darkModeHandling; DarkModeHandling darkModeHandling;
@ -267,7 +257,7 @@ void QWindowsIntegrationPrivate::parseOptions(QWindowsIntegration *q, const QStr
if (!QCoreApplication::testAttribute(Qt::AA_PluginApplication)) { if (!QCoreApplication::testAttribute(Qt::AA_PluginApplication)) {
// DpiAwareV2 requires using new API // DpiAwareV2 requires using new API
if (dpiAwareness == QtWindows::ProcessPerMonitorV2DpiAware && hasDpiAwarenessContext) { if (dpiAwareness == QtWindows::ProcessPerMonitorV2DpiAware) {
m_context.setProcessDpiV2Awareness(); m_context.setProcessDpiV2Awareness();
qCDebug(lcQpaWindows) qCDebug(lcQpaWindows)
<< __FUNCTION__ << "DpiAwareness: DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2"; << __FUNCTION__ << "DpiAwareness: DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2";

View File

@ -55,7 +55,6 @@
#endif #endif
#include <QtCore/qt_windows.h> #include <QtCore/qt_windows.h>
#include <private/qsystemlibrary_p.h>
#include <d3d9.h> #include <d3d9.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -94,19 +93,12 @@ public:
bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const; bool retrieveAdapterIdentifier(UINT n, D3DADAPTER_IDENTIFIER9 *adapterIdentifier) const;
private: private:
QSystemLibrary m_d3d9lib;
IDirect3D9 *m_direct3D9 = nullptr; IDirect3D9 *m_direct3D9 = nullptr;
}; };
QDirect3D9Handle::QDirect3D9Handle() : QDirect3D9Handle::QDirect3D9Handle()
m_d3d9lib(QStringLiteral("d3d9"))
{ {
using PtrDirect3DCreate9 = IDirect3D9 *(WINAPI *)(UINT); m_direct3D9 = Direct3DCreate9(D3D_SDK_VERSION);
if (m_d3d9lib.load()) {
if (auto direct3DCreate9 = (PtrDirect3DCreate9)m_d3d9lib.resolve("Direct3DCreate9"))
m_direct3D9 = direct3DCreate9(D3D_SDK_VERSION);
}
} }
QDirect3D9Handle::~QDirect3D9Handle() QDirect3D9Handle::~QDirect3D9Handle()

View File

@ -59,7 +59,6 @@
#include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qguiapplication_p.h>
#include <QtCore/qvarlengtharray.h> #include <QtCore/qvarlengtharray.h>
#include <QtCore/qloggingcategory.h> #include <QtCore/qloggingcategory.h>
#include <QtCore/qoperatingsystemversion.h>
#include <QtCore/qqueue.h> #include <QtCore/qqueue.h>
#include <algorithm> #include <algorithm>
@ -87,7 +86,7 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
*result = 0; *result = 0;
const quint32 pointerId = GET_POINTERID_WPARAM(msg.wParam); const quint32 pointerId = GET_POINTERID_WPARAM(msg.wParam);
if (!QWindowsContext::user32dll.getPointerType(pointerId, &m_pointerType)) { if (!GetPointerType(pointerId, &m_pointerType)) {
qWarning() << "GetPointerType() failed:" << qt_error_string(); qWarning() << "GetPointerType() failed:" << qt_error_string();
return false; return false;
} }
@ -101,12 +100,12 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
} }
case QT_PT_TOUCH: { case QT_PT_TOUCH: {
quint32 pointerCount = 0; quint32 pointerCount = 0;
if (!QWindowsContext::user32dll.getPointerFrameTouchInfo(pointerId, &pointerCount, nullptr)) { if (!GetPointerFrameTouchInfo(pointerId, &pointerCount, nullptr)) {
qWarning() << "GetPointerFrameTouchInfo() failed:" << qt_error_string(); qWarning() << "GetPointerFrameTouchInfo() failed:" << qt_error_string();
return false; return false;
} }
QVarLengthArray<POINTER_TOUCH_INFO, 10> touchInfo(pointerCount); QVarLengthArray<POINTER_TOUCH_INFO, 10> touchInfo(pointerCount);
if (!QWindowsContext::user32dll.getPointerFrameTouchInfo(pointerId, &pointerCount, touchInfo.data())) { if (!GetPointerFrameTouchInfo(pointerId, &pointerCount, touchInfo.data())) {
qWarning() << "GetPointerFrameTouchInfo() failed:" << qt_error_string(); qWarning() << "GetPointerFrameTouchInfo() failed:" << qt_error_string();
return false; return false;
} }
@ -119,10 +118,10 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
// dispatch any skipped frames if event compression is disabled by the app // dispatch any skipped frames if event compression is disabled by the app
if (historyCount > 1 && !QCoreApplication::testAttribute(Qt::AA_CompressHighFrequencyEvents)) { if (historyCount > 1 && !QCoreApplication::testAttribute(Qt::AA_CompressHighFrequencyEvents)) {
touchInfo.resize(pointerCount * historyCount); touchInfo.resize(pointerCount * historyCount);
if (!QWindowsContext::user32dll.getPointerFrameTouchInfoHistory(pointerId, if (!GetPointerFrameTouchInfoHistory(pointerId,
&historyCount, &historyCount,
&pointerCount, &pointerCount,
touchInfo.data())) { touchInfo.data())) {
qWarning() << "GetPointerFrameTouchInfoHistory() failed:" << qt_error_string(); qWarning() << "GetPointerFrameTouchInfoHistory() failed:" << qt_error_string();
return false; return false;
} }
@ -140,7 +139,7 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
} }
case QT_PT_PEN: { case QT_PT_PEN: {
POINTER_PEN_INFO penInfo; POINTER_PEN_INFO penInfo;
if (!QWindowsContext::user32dll.getPointerPenInfo(pointerId, &penInfo)) { if (!GetPointerPenInfo(pointerId, &penInfo)) {
qWarning() << "GetPointerPenInfo() failed:" << qt_error_string(); qWarning() << "GetPointerPenInfo() failed:" << qt_error_string();
return false; return false;
} }
@ -152,9 +151,7 @@ bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, Q
|| !QCoreApplication::testAttribute(Qt::AA_CompressTabletEvents))) { || !QCoreApplication::testAttribute(Qt::AA_CompressTabletEvents))) {
QVarLengthArray<POINTER_PEN_INFO, 10> penInfoHistory(historyCount); QVarLengthArray<POINTER_PEN_INFO, 10> penInfoHistory(historyCount);
if (!QWindowsContext::user32dll.getPointerPenInfoHistory(pointerId, if (!GetPointerPenInfoHistory(pointerId, &historyCount, penInfoHistory.data())) {
&historyCount,
penInfoHistory.data())) {
qWarning() << "GetPointerPenInfoHistory() failed:" << qt_error_string(); qWarning() << "GetPointerPenInfoHistory() failed:" << qt_error_string();
return false; return false;
} }
@ -558,7 +555,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
inputIds.insert(touchPoint.id); inputIds.insert(touchPoint.id);
// Avoid getting repeated messages for this frame if there are multiple pointerIds // Avoid getting repeated messages for this frame if there are multiple pointerIds
QWindowsContext::user32dll.skipPointerFrameMessages(touchInfo[i].pointerInfo.pointerId); SkipPointerFrameMessages(touchInfo[i].pointerInfo.pointerId);
} }
// Some devices send touches for each finger in a different message/frame, instead of consolidating // Some devices send touches for each finger in a different message/frame, instead of consolidating
@ -604,7 +601,7 @@ bool QWindowsPointerHandler::translatePenEvent(QWindow *window, HWND hwnd, QtWin
auto *penInfo = static_cast<POINTER_PEN_INFO *>(vPenInfo); auto *penInfo = static_cast<POINTER_PEN_INFO *>(vPenInfo);
RECT pRect, dRect; RECT pRect, dRect;
if (!QWindowsContext::user32dll.getPointerDeviceRects(penInfo->pointerInfo.sourceDevice, &pRect, &dRect)) if (!GetPointerDeviceRects(penInfo->pointerInfo.sourceDevice, &pRect, &dRect))
return false; return false;
const auto systemId = (qint64)penInfo->pointerInfo.sourceDevice; const auto systemId = (qint64)penInfo->pointerInfo.sourceDevice;

View File

@ -56,6 +56,8 @@
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <shellscalingapi.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
static inline QDpi deviceDPI(HDC hdc) static inline QDpi deviceDPI(HDC hdc)
@ -65,12 +67,10 @@ static inline QDpi deviceDPI(HDC hdc)
static inline QDpi monitorDPI(HMONITOR hMonitor) static inline QDpi monitorDPI(HMONITOR hMonitor)
{ {
if (QWindowsContext::shcoredll.isValid()) { UINT dpiX;
UINT dpiX; UINT dpiY;
UINT dpiY; if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY)))
if (SUCCEEDED(QWindowsContext::shcoredll.getDpiForMonitor(hMonitor, 0, &dpiX, &dpiY))) return QDpi(dpiX, dpiY);
return QDpi(dpiX, dpiY);
}
return {0, 0}; return {0, 0};
} }
@ -429,62 +429,50 @@ QRect QWindowsScreen::virtualGeometry(const QPlatformScreen *screen) // cf QScre
return result; return result;
} }
enum OrientationPreference : DWORD // matching Win32 API ORIENTATION_PREFERENCE
{
orientationPreferenceNone = 0,
orientationPreferenceLandscape = 0x1,
orientationPreferencePortrait = 0x2,
orientationPreferenceLandscapeFlipped = 0x4,
orientationPreferencePortraitFlipped = 0x8
};
bool QWindowsScreen::setOrientationPreference(Qt::ScreenOrientation o) bool QWindowsScreen::setOrientationPreference(Qt::ScreenOrientation o)
{ {
bool result = false; bool result = false;
if (QWindowsContext::user32dll.setDisplayAutoRotationPreferences) { ORIENTATION_PREFERENCE orientationPreference = ORIENTATION_PREFERENCE_NONE;
DWORD orientationPreference = 0; switch (o) {
switch (o) { case Qt::PrimaryOrientation:
case Qt::PrimaryOrientation: break;
orientationPreference = orientationPreferenceNone; case Qt::PortraitOrientation:
break; orientationPreference = ORIENTATION_PREFERENCE_PORTRAIT;
case Qt::PortraitOrientation: break;
orientationPreference = orientationPreferencePortrait; case Qt::LandscapeOrientation:
break; orientationPreference = ORIENTATION_PREFERENCE_LANDSCAPE;
case Qt::LandscapeOrientation: break;
orientationPreference = orientationPreferenceLandscape; case Qt::InvertedPortraitOrientation:
break; orientationPreference = ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED;
case Qt::InvertedPortraitOrientation: break;
orientationPreference = orientationPreferencePortraitFlipped; case Qt::InvertedLandscapeOrientation:
break; orientationPreference = ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED;
case Qt::InvertedLandscapeOrientation: break;
orientationPreference = orientationPreferenceLandscapeFlipped;
break;
}
result = QWindowsContext::user32dll.setDisplayAutoRotationPreferences(orientationPreference);
} }
result = SetDisplayAutoRotationPreferences(orientationPreference);
return result; return result;
} }
Qt::ScreenOrientation QWindowsScreen::orientationPreference() Qt::ScreenOrientation QWindowsScreen::orientationPreference()
{ {
Qt::ScreenOrientation result = Qt::PrimaryOrientation; Qt::ScreenOrientation result = Qt::PrimaryOrientation;
if (QWindowsContext::user32dll.getDisplayAutoRotationPreferences) { ORIENTATION_PREFERENCE orientationPreference = ORIENTATION_PREFERENCE_NONE;
DWORD orientationPreference = 0; if (GetDisplayAutoRotationPreferences(&orientationPreference)) {
if (QWindowsContext::user32dll.getDisplayAutoRotationPreferences(&orientationPreference)) { switch (orientationPreference) {
switch (orientationPreference) { case ORIENTATION_PREFERENCE_NONE:
case orientationPreferenceLandscape: break;
result = Qt::LandscapeOrientation; case ORIENTATION_PREFERENCE_LANDSCAPE:
break; result = Qt::LandscapeOrientation;
case orientationPreferencePortrait: break;
result = Qt::PortraitOrientation; case ORIENTATION_PREFERENCE_PORTRAIT:
break; result = Qt::PortraitOrientation;
case orientationPreferenceLandscapeFlipped: break;
result = Qt::InvertedLandscapeOrientation; case ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED:
break; result = Qt::InvertedLandscapeOrientation;
case orientationPreferencePortraitFlipped: break;
result = Qt::InvertedPortraitOrientation; case ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED:
break; result = Qt::InvertedPortraitOrientation;
} break;
} }
} }
return result; return result;

View File

@ -63,7 +63,6 @@
#include <QtCore/qcoreapplication.h> #include <QtCore/qcoreapplication.h>
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qtextstream.h> #include <QtCore/qtextstream.h>
#include <QtCore/qoperatingsystemversion.h>
#include <QtCore/qsysinfo.h> #include <QtCore/qsysinfo.h>
#include <QtCore/qcache.h> #include <QtCore/qcache.h>
#include <QtCore/qthread.h> #include <QtCore/qthread.h>
@ -1053,9 +1052,7 @@ bool QWindowsTheme::useNativeMenus()
bool QWindowsTheme::queryDarkMode() bool QWindowsTheme::queryDarkMode()
{ {
if (QOperatingSystemVersion::current() if (queryHighContrast()) {
< QOperatingSystemVersion(QOperatingSystemVersion::Windows, 10, 0, 17763)
|| queryHighContrast()) {
return false; return false;
} }
const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)") const auto setting = QWinRegistryKey(HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Themes\Personalize)")

View File

@ -65,7 +65,6 @@
#include <QtGui/qwindow.h> #include <QtGui/qwindow.h>
#include <QtGui/qregion.h> #include <QtGui/qregion.h>
#include <QtGui/qopenglcontext.h> #include <QtGui/qopenglcontext.h>
#include <private/qsystemlibrary_p.h>
#include <private/qwindow_p.h> // QWINDOWSIZE_MAX #include <private/qwindow_p.h> // QWINDOWSIZE_MAX
#include <private/qguiapplication_p.h> #include <private/qguiapplication_p.h>
#include <private/qhighdpiscaling_p.h> #include <private/qhighdpiscaling_p.h>
@ -73,7 +72,6 @@
#include <QtCore/qdebug.h> #include <QtCore/qdebug.h>
#include <QtCore/qlibraryinfo.h> #include <QtCore/qlibraryinfo.h>
#include <QtCore/qoperatingsystemversion.h>
#include <dwmapi.h> #include <dwmapi.h>
@ -81,6 +79,8 @@
#include "qwindowsvulkaninstance.h" #include "qwindowsvulkaninstance.h"
#endif #endif
#include <shellscalingapi.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
using QWindowCreationContextPtr = QSharedPointer<QWindowCreationContext>; using QWindowCreationContextPtr = QSharedPointer<QWindowCreationContext>;
@ -436,18 +436,14 @@ static inline void updateGLWindowSettings(const QWindow *w, HWND hwnd, Qt::Windo
static QMargins invisibleMargins(QPoint screenPoint) static QMargins invisibleMargins(QPoint screenPoint)
{ {
if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows10) { POINT pt = {screenPoint.x(), screenPoint.y()};
POINT pt = {screenPoint.x(), screenPoint.y()}; if (HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL)) {
if (HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL)) { UINT dpiX;
if (QWindowsContext::shcoredll.isValid()) { UINT dpiY;
UINT dpiX; if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY))) {
UINT dpiY; const qreal sc = (dpiX - 96) / 96.0;
if (SUCCEEDED(QWindowsContext::shcoredll.getDpiForMonitor(hMonitor, 0, &dpiX, &dpiY))) { const int gap = 7 + qRound(5*sc) - int(sc);
const qreal sc = (dpiX - 96) / 96.0; return QMargins(gap, 0, gap, gap);
const int gap = 7 + qRound(5*sc) - int(sc);
return QMargins(gap, 0, gap, gap);
}
}
} }
} }
return QMargins(); return QMargins();
@ -930,12 +926,9 @@ QMargins QWindowsGeometryHint::frameOnPrimaryScreen(HWND hwnd)
QMargins QWindowsGeometryHint::frame(DWORD style, DWORD exStyle, qreal dpi) QMargins QWindowsGeometryHint::frame(DWORD style, DWORD exStyle, qreal dpi)
{ {
if (QWindowsContext::user32dll.adjustWindowRectExForDpi == nullptr)
return frameOnPrimaryScreen(style, exStyle);
RECT rect = {0,0,0,0}; RECT rect = {0,0,0,0};
style &= ~DWORD(WS_OVERLAPPED); // Not permitted, see docs. style &= ~DWORD(WS_OVERLAPPED); // Not permitted, see docs.
if (QWindowsContext::user32dll.adjustWindowRectExForDpi(&rect, style, FALSE, exStyle, if (AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle, unsigned(qRound(dpi))) == FALSE) {
unsigned(qRound(dpi))) == FALSE) {
qErrnoWarning("%s: AdjustWindowRectExForDpi failed", __FUNCTION__); qErrnoWarning("%s: AdjustWindowRectExForDpi failed", __FUNCTION__);
} }
const QMargins result(qAbs(rect.left), qAbs(rect.top), const QMargins result(qAbs(rect.left), qAbs(rect.top),
@ -965,8 +958,7 @@ QMargins QWindowsGeometryHint::frame(const QWindow *w, const QRect &geometry,
{ {
if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint)) if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
return {}; return {};
if (!QWindowsContext::user32dll.adjustWindowRectExForDpi if (QWindowsScreenManager::isSingleScreen()
|| QWindowsScreenManager::isSingleScreen()
|| !QWindowsContext::shouldHaveNonClientDpiScaling(w)) { || !QWindowsContext::shouldHaveNonClientDpiScaling(w)) {
return frameOnPrimaryScreen(style, exStyle); return frameOnPrimaryScreen(style, exStyle);
} }
@ -1417,8 +1409,7 @@ void QWindowsWindow::initialize()
if (obtainedScreen && screen() != obtainedScreen) if (obtainedScreen && screen() != obtainedScreen)
QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(w, obtainedScreen->screen()); QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(w, obtainedScreen->screen());
} }
QWindowsWindow::setSavedDpi(QWindowsContext::user32dll.getDpiForWindow ? QWindowsWindow::setSavedDpi(GetDpiForWindow(handle()));
QWindowsContext::user32dll.getDpiForWindow(handle()) : 96);
} }
QSurfaceFormat QWindowsWindow::format() const QSurfaceFormat QWindowsWindow::format() const