summaryrefslogtreecommitdiffstats
path: root/widget/windows
diff options
context:
space:
mode:
authorMoonchild <moonchild@palemoon.org>2020-10-06 09:32:46 +0000
committerMoonchild <moonchild@palemoon.org>2020-10-06 09:32:46 +0000
commita98d06380fe706e3b1b602411c597b9882516b3e (patch)
tree60452c5f39b8dc60a8e97454d4103baf2cd194ae /widget/windows
parent63a0006985036b062eed7e9e83324581d8ab247c (diff)
parent1e8d07cac205a5db3d7d416d7f414a213fd892ff (diff)
downloadUXP-a98d06380fe706e3b1b602411c597b9882516b3e.tar
UXP-a98d06380fe706e3b1b602411c597b9882516b3e.tar.gz
UXP-a98d06380fe706e3b1b602411c597b9882516b3e.tar.lz
UXP-a98d06380fe706e3b1b602411c597b9882516b3e.tar.xz
UXP-a98d06380fe706e3b1b602411c597b9882516b3e.zip
Merge branch 'redwood' into release
Diffstat (limited to 'widget/windows')
-rw-r--r--widget/windows/WinUtils.cpp20
-rw-r--r--widget/windows/WinUtils.h21
-rw-r--r--widget/windows/nsWindow.cpp2
3 files changed, 32 insertions, 11 deletions
diff --git a/widget/windows/WinUtils.cpp b/widget/windows/WinUtils.cpp
index 28033193f..a43c92b69 100644
--- a/widget/windows/WinUtils.cpp
+++ b/widget/windows/WinUtils.cpp
@@ -449,10 +449,20 @@ WinUtils::Initialize()
if (IsWin10OrLater()) {
HMODULE user32Dll = ::GetModuleHandleW(L"user32");
if (user32Dll) {
- sEnableNonClientDpiScaling = (EnableNonClientDpiScalingProc)
- ::GetProcAddress(user32Dll, "EnableNonClientDpiScaling");
- sSetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc)
- ::GetProcAddress(user32Dll, "SetThreadDpiAwarenessContext");
+ auto getThreadDpiAwarenessContext = (decltype(GetThreadDpiAwarenessContext)*)
+ ::GetProcAddress(user32Dll, "GetThreadDpiAwarenessContext");
+ auto areDpiAwarenessContextsEqual = (decltype(AreDpiAwarenessContextsEqual)*)
+ ::GetProcAddress(user32Dll, "AreDpiAwarenessContextsEqual");
+ if (getThreadDpiAwarenessContext && areDpiAwarenessContextsEqual &&
+ areDpiAwarenessContextsEqual(getThreadDpiAwarenessContext(),
+ DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE)) {
+ // Only per-monitor DPI awareness v1 requires these workarounds.
+ // Since this was introduced in Win 8.1 we'll need to keep this indefinitely.
+ sEnableNonClientDpiScaling = (EnableNonClientDpiScalingProc)
+ ::GetProcAddress(user32Dll, "EnableNonClientDpiScaling");
+ sSetThreadDpiAwarenessContext = (SetThreadDpiAwarenessContextProc)
+ ::GetProcAddress(user32Dll, "SetThreadDpiAwarenessContext");
+ }
}
}
@@ -468,7 +478,7 @@ LRESULT WINAPI
WinUtils::NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
WPARAM wParam, LPARAM lParam)
{
- if (msg == WM_NCCREATE && sEnableNonClientDpiScaling) {
+ if (msg == WM_NCCREATE) {
sEnableNonClientDpiScaling(hWnd);
}
return ::DefWindowProcW(hWnd, msg, wParam, lParam);
diff --git a/widget/windows/WinUtils.h b/widget/windows/WinUtils.h
index 1281171be..f268f907f 100644
--- a/widget/windows/WinUtils.h
+++ b/widget/windows/WinUtils.h
@@ -96,6 +96,11 @@ typedef enum DPI_AWARENESS {
#define DPI_AWARENESS_CONTEXT_DECLARED
#endif // (DPI_AWARENESS_CONTEXT_DECLARED)
+#if WINVER < 0x0605
+WINUSERAPI DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext();
+WINUSERAPI BOOL WINAPI
+AreDpiAwarenessContextsEqual(DPI_AWARENESS_CONTEXT, DPI_AWARENESS_CONTEXT);
+#endif /* WINVER < 0x0605 */
typedef DPI_AWARENESS_CONTEXT(WINAPI * SetThreadDpiAwarenessContextProc)(DPI_AWARENESS_CONTEXT);
typedef BOOL(WINAPI * EnableNonClientDpiScalingProc)(HWND);
@@ -152,6 +157,12 @@ class WinUtils
static SetThreadDpiAwarenessContextProc sSetThreadDpiAwarenessContext;
static EnableNonClientDpiScalingProc sEnableNonClientDpiScaling;
+ // Wrapper for DefWindowProc that will enable non-client dpi scaling on the
+ // window during creation.
+ static LRESULT WINAPI
+ NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
+ WPARAM wParam, LPARAM lParam);
+
public:
class AutoSystemDpiAware
{
@@ -174,11 +185,11 @@ public:
DPI_AWARENESS_CONTEXT mPrevContext;
};
- // Wrapper for DefWindowProc that will enable non-client dpi scaling on the
- // window during creation.
- static LRESULT WINAPI
- NonClientDpiScalingDefWindowProcW(HWND hWnd, UINT msg,
- WPARAM wParam, LPARAM lParam);
+ static decltype(::DefWindowProcW)* GetDefWindowProc() {
+ return sEnableNonClientDpiScaling ?
+ NonClientDpiScalingDefWindowProcW :
+ ::DefWindowProcW;
+ }
/**
* Get the system's default logical-to-physical DPI scaling factor,
diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp
index 907d8b9a5..b9c3ea154 100644
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -999,7 +999,7 @@ nsWindow::RegisterWindowClass(const wchar_t* aClassName,
}
wc.style = CS_DBLCLKS | aExtraStyle;
- wc.lpfnWndProc = WinUtils::NonClientDpiScalingDefWindowProcW;
+ wc.lpfnWndProc = WinUtils::GetDefWindowProc();
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = nsToolkit::mDllInstance;