Skip to content

Commit d7d0074

Browse files
committed
[Win32] Explicitly set minimum supported OS version to 14393
Currently, there is no explicit minimum version required for executing SWT applications. However, some versions are implicitly not supported anymore as library methods are linked that are not present in older OS versions. In addition, we still have some methods dynamically linked and their execution guarded by a version constraint for version that are out of support. In particular, this holds for every Windows version older than build 14393, which is the 1607 update for Windows 10 and the release of Windows Server 2016, the latter being the latest still supported server version of Windows. This change cleans up Windows version support: - It adds an explicit version check at initialization to avoid that applications fail to start with incomprehensible linkage errors but a proper error message - It removes version guards for methods that are present since Windows build 14393 (update 1607) or older - It removes unnecessary dynamic linking for methods that are present in Windows build 14393 (update 1607) or older Fixes eclipse-platform/eclipse.platform.ui#2852 Probably fixes #2011
1 parent f468eca commit d7d0074

File tree

7 files changed

+24
-112
lines changed

7 files changed

+24
-112
lines changed

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

+1-57
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
132132
jboolean rc = 0;
133133
OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC);
134134
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
135-
/*
136135
rc = (jboolean)AdjustWindowRectExForDpi(lparg0, arg1, arg2, arg3, arg4);
137-
*/
138-
{
139-
OS_LOAD_FUNCTION(fp, AdjustWindowRectExForDpi)
140-
if (fp) {
141-
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(RECT *, jint, jboolean, jint, jint))fp)(lparg0, arg1, arg2, arg3, arg4);
142-
}
143-
}
144136
fail:
145137
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
146138
OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC);
@@ -2493,15 +2485,7 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetDpiForMonitor)
24932485
OS_NATIVE_ENTER(env, that, GetDpiForMonitor_FUNC);
24942486
if (arg2) if ((lparg2 = (*env)->GetIntArrayElements(env, arg2, NULL)) == NULL) goto fail;
24952487
if (arg3) if ((lparg3 = (*env)->GetIntArrayElements(env, arg3, NULL)) == NULL) goto fail;
2496-
/*
24972488
rc = (jint)GetDpiForMonitor(arg0, arg1, lparg2, lparg3);
2498-
*/
2499-
{
2500-
OS_LOAD_FUNCTION(fp, GetDpiForMonitor)
2501-
if (fp) {
2502-
rc = (jint)((jint (CALLING_CONVENTION*)(jlong, jint, jint *, jint *))fp)(arg0, arg1, lparg2, lparg3);
2503-
}
2504-
}
25052489
fail:
25062490
if (arg3 && lparg3) (*env)->ReleaseIntArrayElements(env, arg3, lparg3, 0);
25072491
if (arg2 && lparg2) (*env)->ReleaseIntArrayElements(env, arg2, lparg2, 0);
@@ -2516,15 +2500,7 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetDpiForWindow)
25162500
{
25172501
jint rc = 0;
25182502
OS_NATIVE_ENTER(env, that, GetDpiForWindow_FUNC);
2519-
/*
2520-
rc = (jint)GetDpiForWindow(arg0);
2521-
*/
2522-
{
2523-
OS_LOAD_FUNCTION(fp, GetDpiForWindow)
2524-
if (fp) {
2525-
rc = (jint)((jint (CALLING_CONVENTION*)(jlong))fp)(arg0);
2526-
}
2527-
}
2503+
rc = (jint)GetDpiForWindow((HWND)arg0);
25282504
OS_NATIVE_EXIT(env, that, GetDpiForWindow_FUNC);
25292505
return rc;
25302506
}
@@ -3320,15 +3296,7 @@ JNIEXPORT jint JNICALL OS_NATIVE(GetSystemMetricsForDpi)
33203296
{
33213297
jint rc = 0;
33223298
OS_NATIVE_ENTER(env, that, GetSystemMetricsForDpi_FUNC);
3323-
/*
33243299
rc = (jint)GetSystemMetricsForDpi(arg0, arg1);
3325-
*/
3326-
{
3327-
OS_LOAD_FUNCTION(fp, GetSystemMetricsForDpi)
3328-
if (fp) {
3329-
rc = (jint)((jint (CALLING_CONVENTION*)(jint, jint))fp)(arg0, arg1);
3330-
}
3331-
}
33323300
OS_NATIVE_EXIT(env, that, GetSystemMetricsForDpi_FUNC);
33333301
return rc;
33343302
}
@@ -3426,15 +3394,7 @@ JNIEXPORT jlong JNICALL OS_NATIVE(GetThreadDpiAwarenessContext)
34263394
{
34273395
jlong rc = 0;
34283396
OS_NATIVE_ENTER(env, that, GetThreadDpiAwarenessContext_FUNC);
3429-
/*
34303397
rc = (jlong)GetThreadDpiAwarenessContext();
3431-
*/
3432-
{
3433-
OS_LOAD_FUNCTION(fp, GetThreadDpiAwarenessContext)
3434-
if (fp) {
3435-
rc = (jlong)((jlong (CALLING_CONVENTION*)())fp)();
3436-
}
3437-
}
34383398
OS_NATIVE_EXIT(env, that, GetThreadDpiAwarenessContext_FUNC);
34393399
return rc;
34403400
}
@@ -8971,15 +8931,7 @@ JNIEXPORT jlong JNICALL OS_NATIVE(SetThreadDpiAwarenessContext)
89718931
{
89728932
jlong rc = 0;
89738933
OS_NATIVE_ENTER(env, that, SetThreadDpiAwarenessContext_FUNC);
8974-
/*
89758934
rc = (jlong)SetThreadDpiAwarenessContext((DPI_AWARENESS_CONTEXT)arg0);
8976-
*/
8977-
{
8978-
OS_LOAD_FUNCTION(fp, SetThreadDpiAwarenessContext)
8979-
if (fp) {
8980-
rc = (jlong)((jlong (CALLING_CONVENTION*)(DPI_AWARENESS_CONTEXT))fp)((DPI_AWARENESS_CONTEXT)arg0);
8981-
}
8982-
}
89838935
OS_NATIVE_EXIT(env, that, SetThreadDpiAwarenessContext_FUNC);
89848936
return rc;
89858937
}
@@ -9329,15 +9281,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(SystemParametersInfoForDpi)
93299281
jboolean rc = 0;
93309282
OS_NATIVE_ENTER(env, that, SystemParametersInfoForDpi_FUNC);
93319283
if (arg2) if ((lparg2 = getNONCLIENTMETRICSFields(env, arg2, &_arg2)) == NULL) goto fail;
9332-
/*
93339284
rc = (jboolean)SystemParametersInfoForDpi(arg0, arg1, lparg2, arg3, arg4);
9334-
*/
9335-
{
9336-
OS_LOAD_FUNCTION(fp, SystemParametersInfoForDpi)
9337-
if (fp) {
9338-
rc = (jboolean)((jboolean (CALLING_CONVENTION*)(jint, jint, NONCLIENTMETRICS *, jint, jint))fp)(arg0, arg1, lparg2, arg3, arg4);
9339-
}
9340-
}
93419285
fail:
93429286
if (arg2 && lparg2) setNONCLIENTMETRICSFields(env, arg2, lparg2);
93439287
OS_NATIVE_EXIT(env, that, SystemParametersInfoForDpi_FUNC);

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

-7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,5 @@
1818
#define LOGPEN_sizeof() sizeof(LOGPEN)
1919

2020
/* Libraries for dynamic loaded functions */
21-
#define GetDpiForMonitor_LIB "shcore.dll"
22-
#define GetDpiForWindow_LIB "user32.dll"
2321
#define RtlGetVersion_LIB "ntdll.dll"
2422
#define OpenThemeDataForDpi_LIB "uxtheme.dll"
25-
#define GetSystemMetricsForDpi_LIB "user32.dll"
26-
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
27-
#define SetThreadDpiAwarenessContext_LIB "user32.dll"
28-
#define SystemParametersInfoForDpi_LIB "user32.dll"
29-
#define AdjustWindowRectExForDpi_LIB "user32.dll"

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

+13-11
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ public class OS extends C {
3939
/**
4040
* Values taken from https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions
4141
*/
42-
public static final int WIN32_BUILD_WIN8_1 = 9600; // "Windows 8.1"
4342
public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update"
4443
public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update"
4544
public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update"
4645
public static final int WIN32_BUILD_WIN11_21H2 = 22000; // Initial Windows 11 release
46+
public static final int MINIMUM_COMPATIBLE_OS_VERSION = WIN32_BUILD_WIN10_1607;
4747

4848
public static final String NO_MANIFEST = "org.eclipse.swt.internal.win32.OS.NO_MANIFEST";
4949

@@ -69,6 +69,8 @@ public class OS extends C {
6969
WIN32_BUILD = 0;
7070
}
7171

72+
checkCompatibleWindowsVersion(WIN32_BUILD);
73+
7274
/* Load the manifest to force the XP Theme */
7375
if (System.getProperty (NO_MANIFEST) == null) {
7476
ACTCTX pActCtx = new ACTCTX ();
@@ -93,6 +95,14 @@ public class OS extends C {
9395
IsDBLocale = OS.GetSystemMetrics (SM_IMMENABLED) != 0;
9496
}
9597

98+
private static void checkCompatibleWindowsVersion(int current) {
99+
if (OS.WIN32_BUILD < OS.MINIMUM_COMPATIBLE_OS_VERSION) {
100+
System.err.println(String.format("Incompatible OS: Minimum Windows build version is %s but current is %s",
101+
OS.MINIMUM_COMPATIBLE_OS_VERSION, current));
102+
System.exit(0);
103+
}
104+
}
105+
96106
/* Constants */
97107
public static final int ABS_DOWNDISABLED = 8;
98108
public static final int ABS_DOWNHOT = 6;
@@ -2354,7 +2364,6 @@ public static int HRESULT_FROM_WIN32(int x) {
23542364
*/
23552365
public static final native int AddFontResourceEx(char[] lpszFilename, int fl, long pdv);
23562366
public static final native boolean AdjustWindowRectEx (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle);
2357-
/** @method flags=dynamic */
23582367
public static final native boolean AdjustWindowRectExForDpi (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle, int dpi);
23592368
/** @method flags=no_gen */
23602369
public static final native boolean AllowDarkModeForWindow(long hWnd, boolean allow);
@@ -2818,9 +2827,8 @@ public static int HRESULT_FROM_WIN32(int x) {
28182827
/** @param hDlg cast=(HWND) */
28192828
public static final native long GetDlgItem (long hDlg, int nIDDlgItem);
28202829
public static final native int GetDoubleClickTime ();
2821-
/** @method flags=dynamic */
28222830
public static final native int GetDpiForMonitor (long hmonitor, int dpiType, int [] dpiX, int [] dpiY);
2823-
/** @method flags=dynamic */
2831+
/** @param hWnd cast=(HWND) */
28242832
public static final native int GetDpiForWindow (long hWnd);
28252833
public static final native long GetFocus ();
28262834
/** @param hdc cast=(HDC) */
@@ -3006,7 +3014,6 @@ public static int HRESULT_FROM_WIN32(int x) {
30063014
/** @param hWnd cast=(HWND) */
30073015
public static final native long GetSystemMenu (long hWnd, boolean bRevert);
30083016
public static final native int GetSystemMetrics (int nIndex);
3009-
/** @method flags=dynamic */
30103017
public static final native int GetSystemMetricsForDpi (int nIndex, int dpi);
30113018
/** @param hDC cast=(HDC) */
30123019
public static final native int GetTextColor (long hDC);
@@ -4378,12 +4385,8 @@ public static int HRESULT_FROM_WIN32(int x) {
43784385
/** @param hdc cast=(HDC) */
43794386
public static final native int SetPolyFillMode (long hdc, int iPolyFillMode);
43804387
public static final native boolean SetProcessDPIAware ();
4381-
/**
4382-
* @method flags=dynamic
4383-
* @param dpiContext cast=(DPI_AWARENESS_CONTEXT)
4384-
*/
4388+
/** @param dpiContext cast=(DPI_AWARENESS_CONTEXT) */
43854389
public static final native long SetThreadDpiAwarenessContext (long dpiContext);
4386-
/** @method flags=dynamic */
43874390
public static final native long GetThreadDpiAwarenessContext ();
43884391
/** @method flags=no_gen */
43894392
public static final native int SetPreferredAppMode(int mode);
@@ -4496,7 +4499,6 @@ public static int HRESULT_FROM_WIN32(int x) {
44964499
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, RECT pvParam, int fWinIni);
44974500
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni);
44984501
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, int [] pvParam, int fWinIni);
4499-
/** @method flags=dynamic */
45004502
public static final native boolean SystemParametersInfoForDpi (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni, int dpi);
45014503
/**
45024504
* @param lpKeyState cast=(PBYTE)

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ private long createSystemFontHandle(int zoom) {
9696
}
9797

9898
private static boolean fetchSystemParametersInfo(NONCLIENTMETRICS info, int targetZoom) {
99-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
100-
return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0,
101-
DPIUtil.mapZoomToDPI(targetZoom));
102-
} else {
103-
return OS.SystemParametersInfo(OS.SPI_GETNONCLIENTMETRICS, 0, info, 0);
104-
}
99+
return OS.SystemParametersInfoForDpi(OS.SPI_GETNONCLIENTMETRICS, NONCLIENTMETRICS.sizeof, info, 0,
100+
DPIUtil.mapZoomToDPI(targetZoom));
105101
}
106102

107103
@Override

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -2224,14 +2224,11 @@ public boolean print (GC gc) {
22242224
}
22252225
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22262226
OS.RedrawWindow (topHandle, null, 0, flags);
2227-
int printWindowFlags = 0;
2228-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) {
2229-
/*
2230-
* Undocumented flag in windows, which also allows the capturing
2231-
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2232-
*/
2233-
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
2234-
}
2227+
/*
2228+
* Undocumented flag in windows, which also allows the capturing
2229+
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2230+
*/
2231+
int printWindowFlags = OS.PW_RENDERFULLCONTENT;
22352232
printWidget (topHandle, hdc, gc, printWindowFlags);
22362233
if (gdipGraphics != 0) {
22372234
OS.RestoreDC(hdc, state);

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

+1-9
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,7 @@ public class Display extends Device implements Executor {
533533
private static int ICON_SIZE_AT_100 = retrieveDefaultIconSize();
534534

535535
private static int retrieveDefaultIconSize() {
536-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
537-
return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100));
538-
} else {
539-
return 32;
540-
}
536+
return OS.GetSystemMetricsForDpi(OS.SM_CXICON, DPIUtil.mapZoomToDPI(100));
541537
}
542538

543539
/* Skinning support */
@@ -5396,10 +5392,6 @@ private boolean setMonitorSpecificScaling(boolean activate) {
53965392
}
53975393

53985394
private boolean setDPIAwareness(int desiredDpiAwareness) {
5399-
if (OS.WIN32_BUILD < OS.WIN32_BUILD_WIN10_1607) {
5400-
System.err.println("***WARNING: the OS version does not support setting DPI awareness.");
5401-
return false;
5402-
}
54035395
if (desiredDpiAwareness == OS.GetThreadDpiAwarenessContext()) {
54045396
return true;
54055397
}

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

+2-14
Original file line numberDiff line numberDiff line change
@@ -2699,23 +2699,11 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
26992699
}
27002700

27012701
int getSystemMetrics(int nIndex) {
2702-
/*
2703-
* DPI dependent metrics were introduced after 2016 version of windows 10
2704-
*/
2705-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN10_1607) {
2706-
return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom));
2707-
}
2708-
return OS.GetSystemMetrics(nIndex);
2702+
return OS.GetSystemMetricsForDpi(nIndex, DPIUtil.mapZoomToDPI(nativeZoom));
27092703
}
27102704

27112705
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);
2706+
return OS.AdjustWindowRectExForDpi (lpRect, dwStyle, bMenu, dwExStyle, DPIUtil.mapZoomToDPI(nativeZoom));
27192707
}
27202708

27212709

0 commit comments

Comments
 (0)