Skip to content

Commit f2c022b

Browse files
committed
[Win32] Remove obsolete checks for non-supported Windows versions #2011
With introducing an explicit minimum supported OS version for Windows, all code guards for older than the minimum supported Windows version became obsolete. This change removes those guards and those OS methods that became unused. It also makes those methods, whose calls are not version-guarded anymore, statically instead of dynamically linked. This fixes some issue with wrong values returned by the AdjustWindowRectExForDpi method when used via dynamic linking. Fixes eclipse-platform/eclipse.platform.ui#2852 Fixes #2011
1 parent 1d4db25 commit f2c022b

File tree

12 files changed

+17
-135
lines changed

12 files changed

+17
-135
lines changed

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

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,6 @@ JNIEXPORT jint JNICALL OS_NATIVE(AddFontResourceEx)
108108
}
109109
#endif
110110

111-
#ifndef NO_AdjustWindowRectEx
112-
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectEx)
113-
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3)
114-
{
115-
RECT _arg0, *lparg0=NULL;
116-
jboolean rc = 0;
117-
OS_NATIVE_ENTER(env, that, AdjustWindowRectEx_FUNC);
118-
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
119-
rc = (jboolean)AdjustWindowRectEx(lparg0, arg1, arg2, arg3);
120-
fail:
121-
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
122-
OS_NATIVE_EXIT(env, that, AdjustWindowRectEx_FUNC);
123-
return rc;
124-
}
125-
#endif
126-
127111
#ifndef NO_AdjustWindowRectExForDpi
128112
JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
129113
(JNIEnv *env, jclass that, jobject arg0, jint arg1, jboolean arg2, jint arg3, jint arg4)
@@ -132,15 +116,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(AdjustWindowRectExForDpi)
132116
jboolean rc = 0;
133117
OS_NATIVE_ENTER(env, that, AdjustWindowRectExForDpi_FUNC);
134118
if (arg0) if ((lparg0 = getRECTFields(env, arg0, &_arg0)) == NULL) goto fail;
135-
/*
136119
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-
}
144120
fail:
145121
if (arg0 && lparg0) setRECTFields(env, arg0, lparg0);
146122
OS_NATIVE_EXIT(env, that, AdjustWindowRectExForDpi_FUNC);
@@ -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
}
@@ -9329,15 +9297,7 @@ JNIEXPORT jboolean JNICALL OS_NATIVE(SystemParametersInfoForDpi)
93299297
jboolean rc = 0;
93309298
OS_NATIVE_ENTER(env, that, SystemParametersInfoForDpi_FUNC);
93319299
if (arg2) if ((lparg2 = getNONCLIENTMETRICSFields(env, arg2, &_arg2)) == NULL) goto fail;
9332-
/*
93339300
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-
}
93419301
fail:
93429302
if (arg2 && lparg2) setNONCLIENTMETRICSFields(env, arg2, lparg2);
93439303
OS_NATIVE_EXIT(env, that, SystemParametersInfoForDpi_FUNC);

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,5 @@
2222
#define GetDpiForWindow_LIB "user32.dll"
2323
#define RtlGetVersion_LIB "ntdll.dll"
2424
#define OpenThemeDataForDpi_LIB "uxtheme.dll"
25-
#define GetSystemMetricsForDpi_LIB "user32.dll"
2625
#define GetThreadDpiAwarenessContext_LIB "user32.dll"
2726
#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/library/os_stats.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ typedef enum {
2929
ActivateActCtx_FUNC,
3030
ActivateKeyboardLayout_FUNC,
3131
AddFontResourceEx_FUNC,
32-
AdjustWindowRectEx_FUNC,
3332
AdjustWindowRectExForDpi_FUNC,
3433
AllowDarkModeForWindow_FUNC,
3534
AllowSetForegroundWindow_FUNC,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#define OsVersion_LOAD_FUNCTION LOAD_FUNCTION
3030

31-
#include "osversion_custom.h"
31+
/* Libraries for dynamic loaded functions */
32+
#define RtlGetVersion_LIB "ntdll.dll"
3233

3334
#endif /* INC_osversion_H */

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

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

Lines changed: 0 additions & 16 deletions
This file was deleted.

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ 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"
43-
public static final int WIN32_BUILD_WIN10_1607 = 14393; // "Windows 10 August 2016 Update"
4442
public static final int WIN32_BUILD_WIN10_1809 = 17763; // "Windows 10 October 2018 Update"
4543
public static final int WIN32_BUILD_WIN10_2004 = 19041; // "Windows 10 May 2020 Update"
4644
public static final int WIN32_BUILD_WIN11_21H2 = 22000; // Initial Windows 11 release
@@ -2353,8 +2351,6 @@ public static int HRESULT_FROM_WIN32(int x) {
23532351
* @param pdv cast=(PVOID)
23542352
*/
23552353
public static final native int AddFontResourceEx(char[] lpszFilename, int fl, long pdv);
2356-
public static final native boolean AdjustWindowRectEx (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle);
2357-
/** @method flags=dynamic */
23582354
public static final native boolean AdjustWindowRectExForDpi (RECT lpRect, int dwStyle, boolean bMenu, int dwExStyle, int dpi);
23592355
/** @method flags=no_gen */
23602356
public static final native boolean AllowDarkModeForWindow(long hWnd, boolean allow);
@@ -3006,7 +3002,6 @@ public static int HRESULT_FROM_WIN32(int x) {
30063002
/** @param hWnd cast=(HWND) */
30073003
public static final native long GetSystemMenu (long hWnd, boolean bRevert);
30083004
public static final native int GetSystemMetrics (int nIndex);
3009-
/** @method flags=dynamic */
30103005
public static final native int GetSystemMetricsForDpi (int nIndex, int dpi);
30113006
/** @param hDC cast=(HDC) */
30123007
public static final native int GetTextColor (long hDC);
@@ -4496,7 +4491,6 @@ public static int HRESULT_FROM_WIN32(int x) {
44964491
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, RECT pvParam, int fWinIni);
44974492
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni);
44984493
public static final native boolean SystemParametersInfo (int uiAction, int uiParam, int [] pvParam, int fWinIni);
4499-
/** @method flags=dynamic */
45004494
public static final native boolean SystemParametersInfoForDpi (int uiAction, int uiParam, NONCLIENTMETRICS pvParam, int fWinIni, int dpi);
45014495
/**
45024496
* @param lpKeyState cast=(PBYTE)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ public class OsVersion extends Platform {
4242
*/
4343
public static final int WIN32_MINIMUM_COMPATIBLE_BUILD = WIN32_BUILD_WIN10_1607;
4444

45+
private static final String DISABLE_WINDOWS_VERSION_CHECK_PROPERTY = "swt.disableWindowsVersionCheck";
46+
4547
static {
4648
/*
4749
* Starting with Windows 10, GetVersionEx() lies about version unless
@@ -59,7 +61,9 @@ public class OsVersion extends Platform {
5961
}
6062

6163
public static void checkCompatibleWindowsVersion() {
62-
if (WIN32_BUILD < WIN32_MINIMUM_COMPATIBLE_BUILD) {
64+
String disableVersionCheckPropertyValue = System.getProperty(DISABLE_WINDOWS_VERSION_CHECK_PROPERTY, "false");
65+
boolean versionCheckDisabled = "".equals(disableVersionCheckPropertyValue) || Boolean.TRUE.toString().equalsIgnoreCase(disableVersionCheckPropertyValue);
66+
if (!versionCheckDisabled && WIN32_BUILD < WIN32_MINIMUM_COMPATIBLE_BUILD) {
6367
System.err.println(String.format("Incompatible OS: Minimum Windows build version is %s but current is %s",
6468
WIN32_MINIMUM_COMPATIBLE_BUILD, WIN32_BUILD));
6569
System.exit(1);

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,8 @@ private long createSystemFontHandle(int zoom) {
9797
}
9898

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

108104
@Override

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,13 +2229,11 @@ public boolean print (GC gc) {
22292229
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
22302230
OS.RedrawWindow (topHandle, null, 0, flags);
22312231
int printWindowFlags = 0;
2232-
if (OS.WIN32_BUILD >= OS.WIN32_BUILD_WIN8_1) {
2233-
/*
2234-
* Undocumented flag in windows, which also allows the capturing
2235-
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2236-
*/
2237-
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
2238-
}
2232+
/*
2233+
* Undocumented flag in windows, which also allows the capturing
2234+
* of GPU-drawn areas, e.g. an embedded Edge WebView2.
2235+
*/
2236+
printWindowFlags |= OS.PW_RENDERFULLCONTENT;
22392237
printWidget (topHandle, hdc, gc, printWindowFlags);
22402238
if (gdipGraphics != 0) {
22412239
OS.RestoreDC(hdc, state);

0 commit comments

Comments
 (0)