Skip to content

Commit

Permalink
Scaling of Color/Font Dialog not working properly after DPI change
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ShahzaibIbrahim committed Nov 14, 2024
1 parent e6588c2 commit b6b7f9b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,13 @@ public RGB open () {

display.externalEventLoop = true;
display.sendPreExternalEventDispatchEvent ();

/* Temporarily setting the thread dpi awareness to gdi scaling because window dialog has weird resize handling */
long currentDpiAwarenessContext = OS.GetThreadDpiAwarenessContext();
if(display.isRescalingAtRuntime()) {
currentDpiAwarenessContext = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
}

/* Open the dialog */
boolean success = OS.ChooseColor (lpcc);
display.externalEventLoop = false;
Expand Down Expand Up @@ -270,6 +277,11 @@ public RGB open () {
rgb = new RGB (red, green, blue);
}

/* Reset the dpi awareness context */
if(display.isRescalingAtRuntime()) {
OS.SetThreadDpiAwarenessContext(currentDpiAwarenessContext);
}

/* Free the CCHookProc */
callback.dispose ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ public FontData open () {

display.externalEventLoop = true;
display.sendPreExternalEventDispatchEvent ();

/* Temporarily setting the thread dpi awareness to gdi scaling because window dialog has weird resize handling */
long currentDpiAwarenessContext = OS.GetThreadDpiAwarenessContext();
if(display.isRescalingAtRuntime()) {
currentDpiAwarenessContext = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED);
}

/* Open the dialog */
boolean success = OS.ChooseFont (lpcf);
display.externalEventLoop = false;
Expand Down Expand Up @@ -279,6 +286,11 @@ public FontData open () {
}
}

/* Reset the dpi awareness context */
if(display.isRescalingAtRuntime()) {
OS.SetThreadDpiAwarenessContext(currentDpiAwarenessContext);
}

/* Free the OS memory */
if (lpLogFont != 0) OS.HeapFree (hHeap, 0, lpLogFont);

Expand Down

0 comments on commit b6b7f9b

Please sign in to comment.