Skip to content

Commit b6b7f9b

Browse files
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
1 parent e6588c2 commit b6b7f9b

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ public class OS extends C {
370370
public static final short DMDUP_VERTICAL = 2;
371371
public static final short DMDUP_HORIZONTAL = 3;
372372
public static final int DPI_AWARENESS_CONTEXT_UNAWARE = 24592;
373+
public static final int DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED = 1073766416;
373374
public static final int DPI_AWARENESS_CONTEXT_SYSTEM_AWARE = 24593;
374375
public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE = 18;
375376
public static final int DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 = 34;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ColorDialog.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ public RGB open () {
233233

234234
display.externalEventLoop = true;
235235
display.sendPreExternalEventDispatchEvent ();
236+
237+
/* Temporarily setting the thread dpi awareness to gdi scaling because window dialog has weird resize handling */
238+
long currentDpiAwarenessContext = OS.GetThreadDpiAwarenessContext();
239+
if(display.isRescalingAtRuntime()) {
240+
currentDpiAwarenessContext = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
241+
}
242+
236243
/* Open the dialog */
237244
boolean success = OS.ChooseColor (lpcc);
238245
display.externalEventLoop = false;
@@ -270,6 +277,11 @@ public RGB open () {
270277
rgb = new RGB (red, green, blue);
271278
}
272279

280+
/* Reset the dpi awareness context */
281+
if(display.isRescalingAtRuntime()) {
282+
OS.SetThreadDpiAwarenessContext(currentDpiAwarenessContext);
283+
}
284+
273285
/* Free the CCHookProc */
274286
callback.dispose ();
275287

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ public FontData open () {
226226

227227
display.externalEventLoop = true;
228228
display.sendPreExternalEventDispatchEvent ();
229+
230+
/* Temporarily setting the thread dpi awareness to gdi scaling because window dialog has weird resize handling */
231+
long currentDpiAwarenessContext = OS.GetThreadDpiAwarenessContext();
232+
if(display.isRescalingAtRuntime()) {
233+
currentDpiAwarenessContext = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
234+
}
235+
229236
/* Open the dialog */
230237
boolean success = OS.ChooseFont (lpcf);
231238
display.externalEventLoop = false;
@@ -279,6 +286,11 @@ public FontData open () {
279286
}
280287
}
281288

289+
/* Reset the dpi awareness context */
290+
if(display.isRescalingAtRuntime()) {
291+
OS.SetThreadDpiAwarenessContext(currentDpiAwarenessContext);
292+
}
293+
282294
/* Free the OS memory */
283295
if (lpLogFont != 0) OS.HeapFree (hHeap, 0, lpLogFont);
284296

0 commit comments

Comments
 (0)