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

Commit 6136f8a

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 6136f8a

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

shell/platform/linux/fl_settings_plugin.cc

Lines changed: 19 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 kPreferLightKey[] = "prefer-light";
21+
static constexpr char kPreferDarkKey[] = "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,27 @@ 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+
g_autofree gchar* color_scheme =
105+
g_settings_get_string(self->interface_settings, kDesktopColorSchemeKey);
106+
if (g_strcmp0(color_scheme, kPreferLightKey) == 0) {
107+
platform_brightness = kPlatformBrightnessLight;
108+
} else if (g_strcmp0(color_scheme, kPreferDarkKey) == 0) {
109+
platform_brightness = kPlatformBrightnessDark;
110+
}
100111
}
101112

102-
if (is_dark_theme()) {
103-
platform_brightness = kPlatformBrightnessDark;
113+
if (platform_brightness == nullptr) {
114+
platform_brightness =
115+
is_dark_theme() ? kPlatformBrightnessDark : kPlatformBrightnessLight;
104116
}
105117

106118
g_autoptr(FlValue) message = fl_value_new_map();
@@ -155,7 +167,7 @@ void fl_settings_plugin_start(FlSettingsPlugin* self) {
155167
GSettingsSchemaSource* source = g_settings_schema_source_get_default();
156168
if (source != nullptr) {
157169
g_autoptr(GSettingsSchema) schema =
158-
g_settings_schema_source_lookup(source, kDesktopInterfaceSchema, FALSE);
170+
g_settings_schema_source_lookup(source, kDesktopInterfaceSchema, TRUE);
159171
if (schema != nullptr) {
160172
self->interface_settings = g_settings_new_full(schema, nullptr, nullptr);
161173
gulong new_connections[] = {
@@ -168,6 +180,9 @@ void fl_settings_plugin_start(FlSettingsPlugin* self) {
168180
g_signal_connect_object(
169181
self->interface_settings, "changed::gtk-theme",
170182
G_CALLBACK(update_settings), self, G_CONNECT_SWAPPED),
183+
g_signal_connect_object(
184+
self->interface_settings, "changed::color-scheme",
185+
G_CALLBACK(update_settings), self, G_CONNECT_SWAPPED),
171186
};
172187
g_array_append_vals(self->connections, new_connections,
173188
sizeof(new_connections) / sizeof(gulong));

0 commit comments

Comments
 (0)