[*] Harden against bad Windows emulators
Change-Id: Ic09b4cb807e7eba1eeaf12fe7642e9a3213b8f3b
This commit is contained in:
parent
d4827ef266
commit
04403770e6
@ -72,6 +72,10 @@ public:
|
|||||||
|
|
||||||
QPlatformIntegration *QWindowsIntegrationPlugin::create(const QString& system, const QStringList& paramList, int &, char **)
|
QPlatformIntegration *QWindowsIntegrationPlugin::create(const QString& system, const QStringList& paramList, int &, char **)
|
||||||
{
|
{
|
||||||
|
if (!GetProcAddress(LoadLibraryW(L"USER32.dll"), "GetProcessDpiAwareness"))) {
|
||||||
|
SetProcessDPIAware();
|
||||||
|
}
|
||||||
|
|
||||||
if (system.compare(system, "windows"_L1, Qt::CaseInsensitive) == 0)
|
if (system.compare(system, "windows"_L1, Qt::CaseInsensitive) == 0)
|
||||||
return new QWindowsGdiIntegration(paramList);
|
return new QWindowsGdiIntegration(paramList);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -498,7 +498,7 @@ QtWindows::DpiAwareness QWindowsContext::processDpiAwareness()
|
|||||||
|
|
||||||
static auto pGetDPIAwareness = reinterpret_cast<GetProcessDpiAwareness_f>(GetProcAddress(LoadLibraryW(L"USER32.dll"), "GetProcessDpiAwareness"));
|
static auto pGetDPIAwareness = reinterpret_cast<GetProcessDpiAwareness_f>(GetProcAddress(LoadLibraryW(L"USER32.dll"), "GetProcessDpiAwareness"));
|
||||||
if (!pGetDPIAwareness) {
|
if (!pGetDPIAwareness) {
|
||||||
return (QtWindows::DpiAwareness)0;
|
return QtWindows::DpiAwareness::System;
|
||||||
}
|
}
|
||||||
|
|
||||||
static auto pGetThreadDpiAwarenessContext = reinterpret_cast<GetThreadDpiAwarenessContext_f>(GetProcAddress(LoadLibraryW(L"USER32.dll"), "GetThreadDpiAwarenessContext"));
|
static auto pGetThreadDpiAwarenessContext = reinterpret_cast<GetThreadDpiAwarenessContext_f>(GetProcAddress(LoadLibraryW(L"USER32.dll"), "GetThreadDpiAwarenessContext"));
|
||||||
@ -1014,6 +1014,12 @@ bool QWindowsContext::shouldHaveNonClientDpiScaling(const QWindow *window)
|
|||||||
if (QWindowsContextPrivate::m_v2DpiAware)
|
if (QWindowsContextPrivate::m_v2DpiAware)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
static auto pSystemParametersInfoForDpi = reinterpret_cast<SystemParametersInfoForDpi_f>(
|
||||||
|
GetProcAddress(LoadLibraryW(L"USER32.dll"), "SystemParametersInfoForDpi"));
|
||||||
|
if (!pSystemParametersInfoForDpi) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return window->isTopLevel()
|
return 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
|
||||||
|
@ -69,14 +69,35 @@ int GetSystemMetricsForDpi2(int a, UINT dpi)
|
|||||||
return pGetSystemMetricsForDpi ? pGetSystemMetricsForDpi(a, dpi) : GetSystemMetrics(a);
|
return pGetSystemMetricsForDpi ? pGetSystemMetricsForDpi(a, dpi) : GetSystemMetrics(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
HRESULT GetDpiForMonitor2(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *pDpiX, UINT *pDpiY)
|
HRESULT GetDpiForMonitor2(HMONITOR hMonitor, MONITOR_DPI_TYPE dpiType, UINT *pDpiX, UINT *pDpiY)
|
||||||
{
|
{
|
||||||
|
MONITORINFOEX mi { };
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
|
||||||
auto pGetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_f>(GetProcAddress(
|
auto pGetDpiForMonitor = reinterpret_cast<GetDpiForMonitor_f>(GetProcAddress(
|
||||||
LoadLibraryW(L"USER32.dll"), "GetDpiForMonitor"));
|
LoadLibraryW(L"USER32.dll"), "GetDpiForMonitor"));
|
||||||
|
|
||||||
if (pGetDpiForMonitor) {
|
if (pGetDpiForMonitor) {
|
||||||
return pGetDpiForMonitor(hmonitor, dpiType, pDpiX, pDpiY);
|
return pGetDpiForMonitor(hMonitor, dpiType, pDpiX, pDpiY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (GetMonitorInfo(hMonitor, &mi))
|
||||||
|
{
|
||||||
|
// Note: Windows 7 is effectively stuck in System-level of awareness
|
||||||
|
// If these values return anything other than identical values, we're under a really shite Windows emulator providing broken DPI scaling under legacy systems.
|
||||||
|
// We should only be dependent on system upscaling/downscaling based on the primary monitors DPI at time of session startup
|
||||||
|
if (auto hDC = CreateDC(NULL, mi.szDevice, NULL, NULL))
|
||||||
|
{
|
||||||
|
auto dpiX = GetDeviceCaps(hDC, LOGPIXELSX);
|
||||||
|
auto dpiY = GetDeviceCaps(hDC, LOGPIXELSY);
|
||||||
|
*pDpiX = dpiX;
|
||||||
|
*pDpiY = dpiY;
|
||||||
|
ReleaseDC(NULL, hDC);
|
||||||
|
return S_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
auto hwnd = GetActiveWindow();
|
auto hwnd = GetActiveWindow();
|
||||||
if (HDC hDC = GetDC(hwnd)) {
|
if (HDC hDC = GetDC(hwnd)) {
|
||||||
auto dpiX = GetDeviceCaps(hDC, LOGPIXELSX);
|
auto dpiX = GetDeviceCaps(hDC, LOGPIXELSX);
|
||||||
@ -90,6 +111,7 @@ HRESULT GetDpiForMonitor2(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT *pDp
|
|||||||
*pDpiY = 96;
|
*pDpiY = 96;
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT GetDpiForWindow2(HWND hwnd)
|
UINT GetDpiForWindow2(HWND hwnd)
|
||||||
|
Loading…
Reference in New Issue
Block a user