Skip to content

Commit 0edc5bd

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
Use DPI-aware AdjustWindowRectExForDpi when available
AdjustWindowRectEx does not take DPI into account, leading to dialog windows being cut off. This change adjusts usages of that method to AdjustWindowRectExForDpi, passing the zoom level to retrieve correct coordinates and scaling accordingly.
1 parent 9ee0370 commit 0edc5bd

File tree

9 files changed

+50
-11
lines changed

9 files changed

+50
-11
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -124,6 +124,31 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx)
124124
}
125125
#endif
126126

127+
#ifndef NO_AdjustWindowRectExForDpi
128+
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
129+
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4)
130+
{
131+
RECT _arg0, *lparg0=NULL;
132+
jboolean rc = 0;
133+
134+
OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC);
135+
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
136+
/*
137+
rc = (jboolean)AdjustWindowRectExForDpi(lparg0, arg1, arg2, arg3, arg4);
138+
*/
139+
{
140+
OS_LOAD_FUNCTION(fp, AdjustWindowRectExForDpi)
141+
if (fp) {
142+
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(RECT *, jint, jboolean, jint, jint))fp)(lparg0, arg1, arg2, arg3, arg4);
143+
}
144+
}
145+
fail:
146+
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
147+
OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC);
148+
return rc;
149+
}
150+
#endif
151+
127152
#ifndef NO_AllowSetForegroundWindow
128153
JNIEXPORT jboolean JNICALL OS_NATIVE(AllowSetForegroundWindow)
129154
(JNIEnv *env, jclass that, jint arg0)

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_custom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@
2525
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
2626
#define SetThreadDpiAwarenessContext_LIB "user32.dll"
2727
#define SystemParametersInfoForDpi_LIB "user32.dll"
28+
#define AdjustWindowRectExForDpi_LIB "user32.dll"

bundles/org.eclipse.swt/Eclipse SWT PI/win32/library/os_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2024 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -30,6 +30,7 @@ typedef enum {
3030
ActivateKeyboardLayout_FUNC,
3131
AddFontResourceEx_FUNC,
3232
AdjustWindowRectEx_FUNC,
33+
AdjustWindowRectExForDpi_FUNC,
3334
AllowDarkModeForWindow_FUNC,
3435
AllowSetForegroundWindow_FUNC,
3536
AlphaBlend_FUNC,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,8 @@ public static int HRESULT_FROM_WIN32(int x) {
23462346
*/
23472347
public static final native int AddFontResourceEx(char[] lpszFilename, int fl, long pdv);
23482348
public static final native boolean AdjustWindowRectEx (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle);
2349+
/** @method flags=dynamic */
2350+
public static final native boolean AdjustWindowRectExForDpi (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle, int dpi);
23492351
/** @method flags=no_gen */
23502352
public static final native boolean AllowDarkModeForWindow(long hWnd, boolean allow);
23512353
public static final native boolean AllowSetForegroundWindow (int dwProcessId);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Control computeTabRoot () {
313313
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
314314
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
315315
boolean hasMenu = OS.GetMenu (handle) != 0;
316-
OS.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
316+
adjustWindowRectEx(rect, bits1, hasMenu, bits2);
317317

318318
/* Get the size of the scroll bars */
319319
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
@@ -472,7 +472,7 @@ void fixDecorations (Decorations newDecorations, Control control, Menu [] menus)
472472
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
473473
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
474474
boolean hasMenu = OS.GetMenu (handle) != 0;
475-
OS.AdjustWindowRectEx (rect, bits1, hasMenu, bits2);
475+
adjustWindowRectEx(rect, bits1, hasMenu, bits2);
476476
width = Math.max (0, width - (rect.right - rect.left));
477477
height = Math.max (0, height - (rect.bottom - rect.top));
478478
return new Rectangle (0, 0, width, height);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ Rectangle computeTrimInPixels (int x, int y, int width, int height) {
134134
OS.SetRect (rect, x, y, x + width, y + height);
135135
int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE);
136136
int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE);
137-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
137+
adjustWindowRectEx(rect, bits1, false, bits2);
138138
if (horizontalBar != null) rect.bottom += getSystemMetrics (OS.SM_CYHSCROLL);
139139
if (verticalBar != null) rect.right += getSystemMetrics (OS.SM_CXVSCROLL);
140140
int nWidth = rect.right - rect.left, nHeight = rect.bottom - rect.top;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ Point getMaximumSizeInPixels () {
10681068
RECT rect = new RECT ();
10691069
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
10701070
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1071-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
1071+
adjustWindowRectEx(rect, bits1, false, bits2);
10721072
height = Math.min (height, rect.bottom - rect.top);
10731073
}
10741074
}
@@ -1109,7 +1109,7 @@ Point getMinimumSizeInPixels () {
11091109
RECT rect = new RECT ();
11101110
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
11111111
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1112-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
1112+
adjustWindowRectEx(rect, bits1, false, bits2);
11131113
height = Math.max (height, rect.bottom - rect.top);
11141114
}
11151115
}
@@ -1815,7 +1815,7 @@ void setMaximumSizeInPixels (int width, int height) {
18151815
RECT rect = new RECT ();
18161816
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
18171817
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1818-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
1818+
adjustWindowRectEx(rect, bits1, false, bits2);
18191819
heightLimit = rect.bottom - rect.top;
18201820
}
18211821
}
@@ -1861,7 +1861,7 @@ void setMinimumSizeInPixels (int width, int height) {
18611861
RECT rect = new RECT ();
18621862
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
18631863
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
1864-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
1864+
adjustWindowRectEx(rect, bits1, false, bits2);
18651865
heightLimit = rect.bottom - rect.top;
18661866
}
18671867
}
@@ -2671,7 +2671,7 @@ LRESULT WM_WINDOWPOSCHANGING (long wParam, long lParam) {
26712671
RECT rect = new RECT ();
26722672
int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);
26732673
int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);
2674-
OS.AdjustWindowRectEx (rect, bits1, false, bits2);
2674+
adjustWindowRectEx(rect, bits1, false, bits2);
26752675
lpwp.cy = Math.max (lpwp.cy, rect.bottom - rect.top);
26762676
}
26772677
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void addVerifyListener (VerifyListener listener) {
320320
bits0 &= ~OS.WS_BORDER;
321321
bits1 |= OS.WS_EX_CLIENTEDGE;
322322
}
323-
OS.AdjustWindowRectEx (rect, bits0, false, bits1);
323+
adjustWindowRectEx(rect, bits0, false, bits1);
324324
width = rect.right - rect.left;
325325
height = rect.bottom - rect.top;
326326

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2708,5 +2708,15 @@ int getSystemMetrics(int nIndex) {
27082708
return OS.GetSystemMetrics(nIndex);
27092709
}
27102710

2711+
boolean adjustWindowRectEx(RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle) {
2712+
/*
2713+
* DPI-dependent version of the method was introduced with Windows 10 Version 1607
2714+
*/
2715+
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
2716+
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom));
2717+
}
2718+
return OS.AdjustWindowRectEx(lpRect, dwStyle, bMenu, dwExStyle);
2719+
}
2720+
27112721

27122722
}

0 commit comments

Comments
 (0)