From fa7e9f9636b1c8c25b2c5dfbaad3260d7c947f48 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Wed, 13 Nov 2024 12:46:33 +0100 Subject: [PATCH] Scaling of Color/Font Dialog not working properly after DPI change Creating a separate UI thread to set the DPI Awareness context to use UNAWARE GDI scale before opening the either dialogs since windows has issues with dialog scaling in AWARE context --- .../win32/org/eclipse/swt/internal/win32/OS.java | 1 + .../Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java | 3 +++ .../Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java | 3 +++ 3 files changed, 7 insertions(+) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java index 6d085694b3a..eaf47b08d18 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java @@ -370,6 +370,7 @@ public class OS extends C { public static final short DMDUP_VERTICAL = 2; public static final short DMDUP_HORIZONTAL = 3; public static final int DPI_AWARENESS_CONTEXT_UNAWARE = 24592; + public static final int DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = 1073766416; public static final int DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 24593; public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 18; public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 34; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java index 77f74229040..0ded998ec4b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java @@ -184,6 +184,9 @@ public RGB open () { /* Allocate the Custom Colors and initialize to white */ Display display = parent.display; + if(display.isRescalingAtRuntime()) { + OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + } if (display.lpCustColors == 0) { long hHeap = OS.GetProcessHeap (); display.lpCustColors = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, CUSTOM_COLOR_COUNT * 4); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java index 10598c0a1b5..771078115dc 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java @@ -219,6 +219,9 @@ public FontData open () { /* Make the parent shell be temporary modal */ Dialog oldModal = null; Display display = parent.getDisplay (); + if(display.isRescalingAtRuntime()) { + OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED); + } if ((style & (SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) { oldModal = display.getModalDialog (); display.setModalDialog (this);