Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mstr2 committed Oct 5, 2024
1 parent 55cca80 commit d39172c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ protected boolean _supportsInputMethods() {
public Map<String, PreferenceMapping<?>> getPlatformKeyMappings() {
return Map.of(
"GTK.theme_fg_color", new PreferenceMapping<>("foregroundColor", Color.class),
"GTK.theme_bg_color", new PreferenceMapping<>("backgroundColor", Color.class)
"GTK.theme_bg_color", new PreferenceMapping<>("backgroundColor", Color.class),
"GTK.theme_selected_bg_color", new PreferenceMapping<>("accentColor", Color.class),
"GTK.enable_animations", new PreferenceMapping<>("reducedMotion", Boolean.class, b -> !b)
);
}

Expand All @@ -502,7 +504,8 @@ public Map<String, Class<?>> getPlatformKeys() {
Map.entry("GTK.unfocused_borders", Color.class),
Map.entry("GTK.warning_color", Color.class),
Map.entry("GTK.error_color", Color.class),
Map.entry("GTK.success_color", Color.class)
Map.entry("GTK.success_color", Color.class),
Map.entry("GTK.enable_animations", Boolean.class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ public static Preferences getPreferences() {
* <tr><td>{@code GTK.warning_color}</td><td>{@link Color}</td></tr>
* <tr><td>{@code GTK.error_color}</td><td>{@link Color}</td></tr>
* <tr><td>{@code GTK.success_color}</td><td>{@link Color}</td></tr>
* <tr><td>{@code GTK.enable_animations}</td><td>{@link Boolean}</td></tr>
* <tr></tr>
* </tbody>
* </table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -200,8 +200,10 @@ JNIEXPORT void JNICALL Java_com_sun_glass_ui_gtk_GtkApplication__1init

GtkSettings* settings = gtk_settings_get_default();
if (settings != NULL) {
g_signal_connect(G_OBJECT(settings), "notify::gtk-theme-name",
G_CALLBACK(call_update_preferences), NULL);
for (const auto& setting : PlatformSupport::observedSettings) {
g_signal_connect_after(G_OBJECT(settings), setting,
G_CALLBACK(call_update_preferences), NULL);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -60,6 +60,17 @@ namespace
env->CallObjectMethod(preferences, jMapPut, prefKey, prefValue);
CHECK_JNI_EXCEPTION(env);
}

void putBoolean(JNIEnv* env, jobject preferences, const char* name, bool value) {
jobject prefKey = env->NewStringUTF(name);
if (EXCEPTION_OCCURED(env) || prefKey == NULL) return;

jobject prefValue = env->GetStaticObjectField(jBooleanCls, value ? jBooleanTRUE : jBooleanFALSE);
if (EXCEPTION_OCCURED(env) || prefValue == NULL) return;

env->CallObjectMethod(preferences, jMapPut, prefKey, prefValue);
CHECK_JNI_EXCEPTION(env);
}
}

PlatformSupport::PlatformSupport(JNIEnv* env, jobject application)
Expand Down Expand Up @@ -98,13 +109,21 @@ jobject PlatformSupport::collectPreferences() const {
putColor(env, prefs, style, "warning_color", "GTK.warning_color");
putColor(env, prefs, style, "error_color", "GTK.error_color");
putColor(env, prefs, style, "success_color", "GTK.success_color");
putColor(env, prefs, style, "accent_color", "GTK.accent_color");
putColor(env, prefs, style, "theme_accent_color", "GTK.theme_accent_color");
putColor(env, prefs, style, "accent_bg_color", "GTK.accent_bg_color");
g_object_unref(style);

GtkSettings* settings = gtk_settings_get_default();
if (settings != NULL) {
gchar* themeName;
g_object_get(settings, "gtk-theme-name", &themeName, NULL);
putString(env, prefs, "GTK.theme_name", themeName);
g_free(themeName);

gboolean enableAnimations = true;
g_object_get(settings, "gtk-enable-animations", &enableAnimations, NULL);
putBoolean(env, prefs, "GTK.enable_animations", enableAnimations);
}

return prefs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
class PlatformSupport final
{
public:
static constexpr const char* observedSettings[] = {
"notify::gtk-theme-name",
"notify::gtk-enable-animations"
};

PlatformSupport(JNIEnv*, jobject);
~PlatformSupport();
PlatformSupport(PlatformSupport const&) = delete;
Expand Down

0 comments on commit d39172c

Please sign in to comment.