Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 3f707bf

Browse files
committed
[linux] fix theme updates on gnome 42
Read `org.gnome.desktop.interface.color-scheme` if available. The old brightness detection algorithm is kept as a fallback for older gnome and other platforms. Fixes: flutter/flutter#101438
1 parent 5f2b566 commit 3f707bf

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

shell/platform/linux/fl_settings_plugin.cc

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ static constexpr char kAlwaysUse24HourFormatKey[] = "alwaysUse24HourFormat";
1717
static constexpr char kPlatformBrightnessKey[] = "platformBrightness";
1818
static constexpr char kPlatformBrightnessLight[] = "light";
1919
static constexpr char kPlatformBrightnessDark[] = "dark";
20+
static constexpr char kPreferLight[] = "prefer-light";
21+
static constexpr char kPreferDark[] = "prefer-dark";
2022

2123
static constexpr char kDesktopInterfaceSchema[] = "org.gnome.desktop.interface";
2224
static constexpr char kDesktopTextScalingFactorKey[] = "text-scaling-factor";
2325
static constexpr char kDesktopClockFormatKey[] = "clock-format";
26+
static constexpr char kDesktopColorSchemeKey[] = "color-scheme";
2427
static constexpr char kClockFormat24Hour[] = "24h";
2528

2629
enum class Brightness { Light, Dark };
@@ -89,18 +92,31 @@ static bool is_dark_theme() {
8992
static void update_settings(FlSettingsPlugin* self) {
9093
gdouble scaling_factor = 1.0;
9194
gboolean always_use_24hr = FALSE;
92-
const gchar* platform_brightness = kPlatformBrightnessLight;
95+
const gchar* platform_brightness = nullptr;
9396

9497
if (self->interface_settings != nullptr) {
9598
scaling_factor = g_settings_get_double(self->interface_settings,
9699
kDesktopTextScalingFactorKey);
97100
g_autofree gchar* clock_format =
98101
g_settings_get_string(self->interface_settings, kDesktopClockFormatKey);
99102
always_use_24hr = g_strcmp0(clock_format, kClockFormat24Hour) == 0;
103+
104+
GSettingsSchema* schema = nullptr;
105+
g_object_get(self->interface_settings, "settings-schema", &schema, nullptr);
106+
if (g_settings_schema_has_key(schema, kDesktopColorSchemeKey)) {
107+
g_autofree gchar* color_scheme = g_settings_get_string(
108+
self->interface_settings, kDesktopColorSchemeKey);
109+
if (g_strcmp0(color_scheme, kPreferLight) == 0) {
110+
platform_brightness = kPlatformBrightnessLight;
111+
} else if (g_strcmp0(color_scheme, kPreferDark) == 0) {
112+
platform_brightness = kPlatformBrightnessDark;
113+
}
114+
}
100115
}
101116

102-
if (is_dark_theme()) {
103-
platform_brightness = kPlatformBrightnessDark;
117+
if (platform_brightness == nullptr) {
118+
platform_brightness =
119+
is_dark_theme() ? kPlatformBrightnessDark : kPlatformBrightnessLight;
104120
}
105121

106122
g_autoptr(FlValue) message = fl_value_new_map();
@@ -155,7 +171,7 @@ void fl_settings_plugin_start(FlSettingsPlugin* self) {
155171
GSettingsSchemaSource* source = g_settings_schema_source_get_default();
156172
if (source != nullptr) {
157173
g_autoptr(GSettingsSchema) schema =
158-
g_settings_schema_source_lookup(source, kDesktopInterfaceSchema, FALSE);
174+
g_settings_schema_source_lookup(source, kDesktopInterfaceSchema, TRUE);
159175
if (schema != nullptr) {
160176
self->interface_settings = g_settings_new_full(schema, nullptr, nullptr);
161177
gulong new_connections[] = {
@@ -168,6 +184,9 @@ void fl_settings_plugin_start(FlSettingsPlugin* self) {
168184
g_signal_connect_object(
169185
self->interface_settings, "changed::gtk-theme",
170186
G_CALLBACK(update_settings), self, G_CONNECT_SWAPPED),
187+
g_signal_connect_object(
188+
self->interface_settings, "changed::color-scheme",
189+
G_CALLBACK(update_settings), self, G_CONNECT_SWAPPED),
171190
};
172191
g_array_append_vals(self->connections, new_connections,
173192
sizeof(new_connections) / sizeof(gulong));

0 commit comments

Comments
 (0)