automatically enable UI_MODE_NIGHT when gtk-theme-name contains "dark"

gtk-theme-name is only checked once at start up
This commit is contained in:
Julian Winkler
2024-03-10 12:05:33 +01:00
parent f49922cf1b
commit 005e2299bd
8 changed files with 87 additions and 5 deletions

View File

@@ -376,3 +376,31 @@ JNIEXPORT void JNICALL Java_android_content_res_AssetManager_copyTheme(JNIEnv *e
{
Theme_setTo(_PTR(dest), _PTR(src));
}
JNIEXPORT void JNICALL Java_android_content_res_AssetManager_setConfiguration(
JNIEnv *env, jobject this, jint mcc, jint mnc, jstring locale,
jint orientation, jint touchscreen, jint density, jint keyboard,
jint keyboardHidden, jint navigation, jint screenWidth, jint screenHeight,
jint smallestScreenWidthDp, jint screenWidthDp, jint screenHeightDp,
jint screenLayout, jint uiMode, jint majorVersion)
{
struct AssetManager *asset_manager = _PTR(_GET_LONG_FIELD(this, "mObject"));
const struct ResTable_config config = {
.mcc = mcc,
.mnc = mnc,
.orientation = orientation,
.touchscreen = touchscreen,
.density = density,
.keyboard = keyboard,
.navigation = navigation,
.screenWidth = screenWidth,
.screenHeight = screenHeight,
.smallestScreenWidthDp = smallestScreenWidthDp,
.screenWidthDp = screenWidthDp,
.screenHeightDp = screenHeightDp,
.screenLayout = screenLayout,
.uiMode = uiMode,
.sdkVersion = majorVersion
};
AssetManager_setConfiguration(asset_manager, &config, NULL);
}

View File

@@ -0,0 +1,20 @@
#define _GNU_SOURCE
#include <gtk/gtk.h>
#include <string.h>
#include "../defines.h"
#include "../util.h"
#include "../generated_headers/android_content_Context.h"
JNIEXPORT void JNICALL Java_android_content_Context_native_1updateConfig(JNIEnv *env, jclass class, jobject config)
{
GtkSettings *settings = gtk_settings_get_default();
gchar *theme_name;
g_object_get(settings, "gtk-theme-name", &theme_name, NULL);
bool night_mode = strcasestr(theme_name, "dark") || strcasestr(theme_name, "black");
if (night_mode) {
_SET_INT_FIELD(config, "uiMode", /*UI_MODE_NIGHT_YES*/ 0x20);
}
}

View File

@@ -0,0 +1,23 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_content_Context */
#ifndef _Included_android_content_Context
#define _Included_android_content_Context
#ifdef __cplusplus
extern "C" {
#endif
#undef android_content_Context_MODE_PRIVATE
#define android_content_Context_MODE_PRIVATE 0L
/*
* Class: android_content_Context
* Method: native_updateConfig
* Signature: (Landroid/content/res/Configuration;)V
*/
JNIEXPORT void JNICALL Java_android_content_Context_native_1updateConfig
(JNIEnv *, jclass, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -81,6 +81,14 @@ JNIEXPORT void JNICALL Java_android_content_res_AssetManager_setLocale
JNIEXPORT jobjectArray JNICALL Java_android_content_res_AssetManager_getLocales
(JNIEnv *, jobject);
/*
* Class: android_content_res_AssetManager
* Method: setConfiguration
* Signature: (IILjava/lang/String;IIIIIIIIIIIIII)V
*/
JNIEXPORT void JNICALL Java_android_content_res_AssetManager_setConfiguration
(JNIEnv *, jobject, jint, jint, jstring, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint, jint);
/*
* Class: android_content_res_AssetManager
* Method: getResourceIdentifier