diff --git a/macos/src/main/objcpp/ThemeInfo.mm b/macos/src/main/objcpp/ThemeInfo.mm index 6f2a6c04..b69d0400 100644 --- a/macos/src/main/objcpp/ThemeInfo.mm +++ b/macos/src/main/objcpp/ThemeInfo.mm @@ -191,7 +191,7 @@ JNIEXPORT jlong JNICALL Java_com_github_weisj_darklaf_platform_macos_JNIThemeInfoMacOS_createPreferenceChangeListener(JNIEnv *env, jclass obj, jobject callback) { JNF_COCOA_DURING(env); // We dont want an auto release pool. JavaVM *jvm; - if (env->GetJavaVM(&jvm) == 0) { + if (env->GetJavaVM(&jvm) == JNI_OK) { jobject callbackRef = env->NewGlobalRef(callback); PreferenceChangeListener *listener = [[PreferenceChangeListener alloc] initWithJVM:jvm andCallBack: callbackRef]; [listener retain]; diff --git a/windows/src/main/cpp/ThemeInfo.cpp b/windows/src/main/cpp/ThemeInfo.cpp index 9e9e50d7..e914602e 100644 --- a/windows/src/main/cpp/ThemeInfo.cpp +++ b/windows/src/main/cpp/ThemeInfo.cpp @@ -32,23 +32,23 @@ #include #include -#define DARK_MODE_PATH ("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize") -#define DARK_MODE_KEY ("AppsUseLightTheme") +constexpr auto DARK_MODE_PATH = "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"; +constexpr auto DARK_MODE_KEY = "AppsUseLightTheme"; -#define FONT_SCALE_PATH ("Software\\Microsoft\\Accessibility") -#define FONT_SCALE_KEY ("TextScaleFactor") +constexpr auto FONT_SCALE_PATH = "Software\\Microsoft\\Accessibility"; +constexpr auto FONT_SCALE_KEY = "TextScaleFactor"; -#define HIGH_CONTRAST_PATH ("Control Panel\\Accessibility\\HighContrast") -#define HIGH_CONTRAST_THEME_KEY ("High Contrast Scheme") -#define HIGH_CONTRAST_LIGHT_THEME ("High Contrast White") +constexpr auto HIGH_CONTRAST_PATH = "Control Panel\\Accessibility\\HighContrast"; +constexpr auto HIGH_CONTRAST_THEME_KEY = "High Contrast Scheme"; +constexpr auto HIGH_CONTRAST_LIGHT_THEME = "High Contrast White"; -#define ACCENT_COLOR_PATH "SOFTWARE\\Microsoft\\Windows\\DWM" -#define ACCENT_COLOR_KEY "ColorizationColor" +constexpr auto ACCENT_COLOR_PATH = "SOFTWARE\\Microsoft\\Windows\\DWM"; +constexpr auto ACCENT_COLOR_KEY = "ColorizationColor"; -#define DARK_MODE_DEFAULT_VALUE false -#define HIGH_CONTRAST_DEFAULT_VALUE false -#define FONT_SCALE_DEFAULT_VALUE 100 -#define ACCENT_COLOR_DEFAULT_VALUE 0 +constexpr auto DARK_MODE_DEFAULT_VALUE = false; +constexpr auto HIGH_CONTRAST_DEFAULT_VALUE = false; +constexpr auto FONT_SCALE_DEFAULT_VALUE = 100; +constexpr auto ACCENT_COLOR_DEFAULT_VALUE = 0; void ModifyFlags(DWORD &flags) { #ifdef _WIN64 @@ -97,13 +97,11 @@ bool IsHighContrastMode() { bool IsDarkMode() { try { - bool appsUseDark = (0 == RegGetDword(HKEY_CURRENT_USER, DARK_MODE_PATH, - DARK_MODE_KEY)); + bool appsUseDark = (0 == RegGetDword(HKEY_CURRENT_USER, DARK_MODE_PATH, DARK_MODE_KEY)); bool isHighContrast = IsHighContrastMode(); if (!isHighContrast) return appsUseDark; - std::string themeValue = RegGetString(HKEY_CURRENT_USER, - HIGH_CONTRAST_PATH, HIGH_CONTRAST_THEME_KEY); + std::string themeValue = RegGetString(HKEY_CURRENT_USER, HIGH_CONTRAST_PATH, HIGH_CONTRAST_THEME_KEY); return (strcmp(themeValue.c_str(), HIGH_CONTRAST_LIGHT_THEME) != 0); } catch (LONG e) { return DARK_MODE_DEFAULT_VALUE; @@ -133,35 +131,30 @@ bool RegisterRegistryEvent(const LPCSTR subKey, HANDLE event) { int GetAccentColor() { try { - return RegGetDword(HKEY_CURRENT_USER, ACCENT_COLOR_PATH, - ACCENT_COLOR_KEY); + return RegGetDword(HKEY_CURRENT_USER, ACCENT_COLOR_PATH, ACCENT_COLOR_KEY); } catch (LONG e) { return ACCENT_COLOR_DEFAULT_VALUE; } } JNIEXPORT jboolean JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_isDarkThemeEnabled(JNIEnv *env, jclass obj) -{ - return (jboolean) IsDarkMode(); +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_isDarkThemeEnabled(JNIEnv *env, jclass obj) { + return static_cast(IsDarkMode()); } JNIEXPORT jboolean JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_isHighContrastEnabled(JNIEnv *env, jclass obj) -{ - return (jboolean) IsHighContrastMode(); +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_isHighContrastEnabled(JNIEnv *env, jclass obj) { + return static_cast(IsHighContrastMode()); } JNIEXPORT jlong JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_getFontScaleFactor(JNIEnv *env, jclass obj) -{ - return (jlong) GetTextScaleFactor(); +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_getFontScaleFactor(JNIEnv *env, jclass obj) { + return static_cast(GetTextScaleFactor()); } JNIEXPORT jint JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_getAccentColor(JNIEnv *env, jclass obj) -{ - return (jint) GetAccentColor(); +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_getAccentColor(JNIEnv *env, jclass obj) { + return static_cast(GetAccentColor()); } struct EventHandler { @@ -223,25 +216,21 @@ struct EventHandler { }; JNIEXPORT jlong JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_createEventHandler(JNIEnv *env, jclass obj, jobject callback) -{ +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_createEventHandler(JNIEnv *env, jclass obj, jobject callback) { JavaVM *jvm; - if (env->GetJavaVM(&jvm) == 0) - { + if (env->GetJavaVM(&jvm) == JNI_OK) { jobject callbackRef = env->NewGlobalRef(callback); HANDLE event = CreateEvent(NULL, FALSE, FALSE, NULL); EventHandler* eventHandler = new EventHandler(jvm, callbackRef, event); return reinterpret_cast(eventHandler); } - return (jlong) 0; + return static_cast(0); } JNIEXPORT void JNICALL -Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_deleteEventHandler(JNIEnv *env, jclass obj, jlong eventHandler) -{ +Java_com_github_weisj_darklaf_platform_windows_JNIThemeInfoWindows_deleteEventHandler(JNIEnv *env, jclass obj, jlong eventHandler) { EventHandler *handler = reinterpret_cast(eventHandler); - if (handler) - { + if (handler) { env->DeleteGlobalRef(handler->callback); handler->stop(); delete handler;