Browse Source

Windows: Set correct value for isWindows11 in SystemInfo through native code

Currently, the JDK doesn't correctly report the current operating system.
For now, we query the value ourselves using native code. This will be updated
once the JDK backport is available:
https://bugs.openjdk.java.net/browse/JDK-8274840
spotless
Jannis Weis 3 years ago
parent
commit
df03d31e43
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 2
      core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java
  2. 18
      utils/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java
  3. 28
      windows/src/main/cpp/Decorations.cpp
  4. 2
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java
  5. 2
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java
  6. 1
      windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java

2
core/src/main/java/com/github/weisj/darklaf/task/ThemeDefaultsInitTask.java

@ -160,7 +160,7 @@ public class ThemeDefaultsInitTask implements DefaultsInitTask {
PropertyLoader.loadProperties(DarkLaf.class, osName, "platform/"), PropertyLoader.loadProperties(DarkLaf.class, osName, "platform/"),
uiProps, defaults, iconResolver); uiProps, defaults, iconResolver);
osPlatformLoader.accept(getOsName()); osPlatformLoader.accept(getOsName());
if (SystemInfo.isWindows11OrGreater) { if (SystemInfo.isWindows11()) {
osPlatformLoader.accept("windows11"); osPlatformLoader.accept("windows11");
} }
currentTheme.customizePlatformProperties(uiProps, defaults, iconResolver); currentTheme.customizePlatformProperties(uiProps, defaults, iconResolver);

18
utils/src/main/java/com/github/weisj/darklaf/util/SystemInfo.java

@ -69,7 +69,7 @@ public final class SystemInfo {
public static final boolean isMacOSMojave; public static final boolean isMacOSMojave;
public static final boolean isMacOSCatalina; public static final boolean isMacOSCatalina;
public static final boolean isMacOSYosemite; public static final boolean isMacOSYosemite;
public static final boolean isWindows11OrGreater; private static boolean isWindows11;
public static final boolean isWindows10OrGreater; public static final boolean isWindows10OrGreater;
public static final boolean isWindows7; public static final boolean isWindows7;
public static final boolean isWindowsVista; public static final boolean isWindowsVista;
@ -97,7 +97,7 @@ public final class SystemInfo {
isMacOSYosemite = isMacOSCatalina || (isMac && isOsVersionAtLeast("10.10")); isMacOSYosemite = isMacOSCatalina || (isMac && isOsVersionAtLeast("10.10"));
isWindows10OrGreater = isWindows && isOsVersionAtLeast("10.0"); isWindows10OrGreater = isWindows && isOsVersionAtLeast("10.0");
isWindows11OrGreater = isWindows && _OS_NAME.contains("windows 11"); isWindows11 = isWindows && _OS_NAME.contains("windows 11");
isWindows7 = isWindows10OrGreater || (isWindows && isOsVersionAtLeast("6.1")); isWindows7 = isWindows10OrGreater || (isWindows && isOsVersionAtLeast("6.1"));
isWindowsVista = isWindows7 || (isWindows && isOsVersionAtLeast("6.0")); isWindowsVista = isWindows7 || (isWindows && isOsVersionAtLeast("6.0"));
@ -148,6 +148,20 @@ public final class SystemInfo {
} }
} }
public static boolean isWindows11() {
return isWindows11;
}
/**
* This function is temporary for the time being as the JDK doesn't report whether we are running on
* Windows 11. Don't call this method if you aren't sure that you are passing the correct value.
*
* @param isWindows11 Whether the OS is Windows 11
*/
public static void setWindows11State(final boolean isWindows11) {
SystemInfo.isWindows11 = isWindows11;
}
public static boolean isJavaVersionAtLeast(final String v) { public static boolean isJavaVersionAtLeast(final String v) {
return compareVersionNumbers(JAVA_RUNTIME_VERSION, v) >= 0; return compareVersionNumbers(JAVA_RUNTIME_VERSION, v) >= 0;
} }

28
windows/src/main/cpp/Decorations.cpp

@ -558,14 +558,28 @@ Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_restore(JNI
ShowWindow(handle, SW_RESTORE); ShowWindow(handle, SW_RESTORE);
} }
JNIEXPORT void JNICALL static bool checkIsWindows11() {
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_init(JNIEnv*, jclass) { static bool local_is_windows_11 = []() {
try { try {
auto buildVersion = RegGetString( auto buildVersion = RegGetString(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
HKEY_LOCAL_MACHINE,
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",
"CurrentBuild"); "CurrentBuild");
auto buildInt = std::stoi(buildVersion); auto buildInt = std::stoi(buildVersion);
is_windows_11 = buildInt >= 22000; return buildInt >= 22000;
} catch (LONG) {} } catch (LONG) {
return false;
}
}();
return local_is_windows_11;
}
JNIEXPORT void JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_init(JNIEnv*, jclass) {
// We setup this global value here once to avoid the lock associated with querying the local static
// in checkIsWindows11().
is_windows_11 = checkIsWindows11();
}
JNIEXPORT jboolean JNICALL
Java_com_github_weisj_darklaf_platform_windows_JNIDecorationsWindows_isWindows11(JNIEnv*, jclass) {
return checkIsWindows11();
} }

2
windows/src/main/java/com/github/weisj/darklaf/platform/windows/JNIDecorationsWindows.java

@ -52,4 +52,6 @@ public final class JNIDecorationsWindows {
public static native boolean installPopupMenuDecorations(final long hwnd); public static native boolean installPopupMenuDecorations(final long hwnd);
public static native void init(); public static native void init();
public static native boolean isWindows11();
} }

2
windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsDecorationsProvider.java

@ -107,7 +107,7 @@ public class WindowsDecorationsProvider implements DecorationsProvider {
properties, currentDefaults, iconLoader); properties, currentDefaults, iconLoader);
loadProps.accept("windows_icons"); loadProps.accept("windows_icons");
loadProps.accept("windows_decorations"); loadProps.accept("windows_decorations");
if (SystemInfo.isWindows11OrGreater) { if (SystemInfo.isWindows11()) {
loadProps.accept("windows_11_decorations"); loadProps.accept("windows_11_decorations");
} }
} }

1
windows/src/main/java/com/github/weisj/darklaf/platform/windows/WindowsLibrary.java

@ -43,6 +43,7 @@ public class WindowsLibrary extends AbstractLibrary {
@Override @Override
protected void afterLoad() { protected void afterLoad() {
JNIDecorationsWindows.init(); JNIDecorationsWindows.init();
SystemInfo.setWindows11State(JNIDecorationsWindows.isWindows11());
} }
@Override @Override

Loading…
Cancel
Save