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 13, 2024
1 parent d9d9bf0 commit db2b493
Show file tree
Hide file tree
Showing 3 changed files with 7 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 @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit db2b493

Please sign in to comment.