This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Implement settings channel for the Linux shell #22486
Merged
robert-ancell
merged 12 commits into
flutter:master
from
robert-ancell:linux-shell-fl-settings-plugin
Jan 4, 2021
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
dbc9275
Implement settings channel for the Linux shell
robert-ancell 4ccdd03
Merge branch 'master' into linux-shell-fl-settings-plugin
robert-ancell 072cb22
Fill documentation for fl_settings_plugin_new
robert-ancell bd7abc5
Merge branch 'master' into linux-shell-fl-settings-plugin
robert-ancell 7dfb876
Complete docstring
robert-ancell 2292b15
Merge branch 'master' into linux-shell-fl-settings-plugin
robert-ancell 6a60cf6
Add engine tests for Linux shell
robert-ancell 37f0306
Move settings plugin to FlEngine
robert-ancell f76a521
Merge branch 'master' into linux-shell-fl-settings-plugin
robert-ancell c0f3667
Add settings plugin tests
robert-ancell 70f8b03
Merge branch 'master' into linux-shell-fl-settings-plugin
robert-ancell 84f371c
Fix test change not merged in correctly
robert-ancell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "flutter/shell/platform/linux/fl_settings_plugin.h" | ||
|
|
||
| #include <cstring> | ||
|
|
||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" | ||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_json_message_codec.h" | ||
|
|
||
| static constexpr char kChannelName[] = "flutter/settings"; | ||
| static constexpr char kTextScaleFactorKey[] = "textScaleFactor"; | ||
| static constexpr char kAlwaysUse24HourFormatKey[] = "alwaysUse24HourFormat"; | ||
| static constexpr char kPlatformBrightnessKey[] = "platformBrightness"; | ||
| static constexpr char kPlatformBrightnessLight[] = "light"; | ||
| static constexpr char kPlatformBrightnessDark[] = "dark"; | ||
|
|
||
| static constexpr char kDesktopInterfaceSchema[] = "org.gnome.desktop.interface"; | ||
| static constexpr char kDesktopGtkThemeKey[] = "gtk-theme"; | ||
| static constexpr char kDesktopTextScalingFactorKey[] = "text-scaling-factor"; | ||
| static constexpr char kDesktopClockFormatKey[] = "clock-format"; | ||
| static constexpr char kClockFormat24Hour[] = "24h"; | ||
|
|
||
| struct _FlSettingsPlugin { | ||
| GObject parent_instance; | ||
|
|
||
| FlBasicMessageChannel* channel; | ||
|
|
||
| GSettings* interface_settings; | ||
| }; | ||
|
|
||
| G_DEFINE_TYPE(FlSettingsPlugin, fl_settings_plugin, G_TYPE_OBJECT) | ||
|
|
||
| // Sends the current settings to the Flutter engine. | ||
| static void update_settings(FlSettingsPlugin* self) { | ||
| gdouble scaling_factor = 1.0; | ||
| gboolean always_use_24hr = FALSE; | ||
| const gchar* platform_brightness = kPlatformBrightnessLight; | ||
|
|
||
| if (self->interface_settings != nullptr) { | ||
| scaling_factor = g_settings_get_double(self->interface_settings, | ||
| kDesktopTextScalingFactorKey); | ||
| g_autofree gchar* clock_format = | ||
| g_settings_get_string(self->interface_settings, kDesktopClockFormatKey); | ||
| always_use_24hr = g_strcmp0(clock_format, kClockFormat24Hour) == 0; | ||
|
|
||
| // GTK doesn't have a specific flag for dark themes, so we have some | ||
| // hard-coded themes for Ubuntu (Yaru) and GNOME (Adwaita). | ||
| g_autofree gchar* gtk_theme = | ||
| g_settings_get_string(self->interface_settings, kDesktopGtkThemeKey); | ||
| if (g_strcmp0(gtk_theme, "Yaru-dark") == 0 || | ||
| g_strcmp0(gtk_theme, "Adwaita-dark") == 0) { | ||
| platform_brightness = kPlatformBrightnessDark; | ||
| } | ||
| } | ||
|
|
||
| g_autoptr(FlValue) message = fl_value_new_map(); | ||
| fl_value_set_string_take(message, kTextScaleFactorKey, | ||
| fl_value_new_float(scaling_factor)); | ||
| fl_value_set_string_take(message, kAlwaysUse24HourFormatKey, | ||
| fl_value_new_bool(always_use_24hr)); | ||
| fl_value_set_string_take(message, kPlatformBrightnessKey, | ||
| fl_value_new_string(platform_brightness)); | ||
| fl_basic_message_channel_send(self->channel, message, nullptr, nullptr, | ||
| nullptr); | ||
| } | ||
|
|
||
| static void fl_settings_plugin_dispose(GObject* object) { | ||
| FlSettingsPlugin* self = FL_SETTINGS_PLUGIN(object); | ||
|
|
||
| g_clear_object(&self->channel); | ||
| g_clear_object(&self->interface_settings); | ||
|
|
||
| G_OBJECT_CLASS(fl_settings_plugin_parent_class)->dispose(object); | ||
| } | ||
|
|
||
| static void fl_settings_plugin_class_init(FlSettingsPluginClass* klass) { | ||
| G_OBJECT_CLASS(klass)->dispose = fl_settings_plugin_dispose; | ||
| } | ||
|
|
||
| static void fl_settings_plugin_init(FlSettingsPlugin* self) {} | ||
|
|
||
| FlSettingsPlugin* fl_settings_plugin_new(FlBinaryMessenger* messenger) { | ||
| g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr); | ||
|
|
||
| FlSettingsPlugin* self = | ||
| FL_SETTINGS_PLUGIN(g_object_new(fl_settings_plugin_get_type(), nullptr)); | ||
|
|
||
| g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new(); | ||
| self->channel = fl_basic_message_channel_new(messenger, kChannelName, | ||
| FL_MESSAGE_CODEC(codec)); | ||
|
|
||
| return self; | ||
| } | ||
|
|
||
| void fl_settings_plugin_start(FlSettingsPlugin* self) { | ||
| g_return_if_fail(FL_IS_SETTINGS_PLUGIN(self)); | ||
|
|
||
| // If we are on GNOME, get settings from GSettings. | ||
| GSettingsSchemaSource* source = g_settings_schema_source_get_default(); | ||
| if (source != nullptr) { | ||
| g_autoptr(GSettingsSchema) schema = | ||
| g_settings_schema_source_lookup(source, kDesktopInterfaceSchema, FALSE); | ||
| if (schema != nullptr) { | ||
| self->interface_settings = g_settings_new_full(schema, nullptr, nullptr); | ||
| g_signal_connect_object( | ||
| self->interface_settings, "changed::text-scaling-factor", | ||
| G_CALLBACK(update_settings), self, G_CONNECT_SWAPPED); | ||
| g_signal_connect_object(self->interface_settings, "changed::clock-format", | ||
| G_CALLBACK(update_settings), self, | ||
| G_CONNECT_SWAPPED); | ||
| g_signal_connect_object(self->interface_settings, "changed::gtk-theme", | ||
| G_CALLBACK(update_settings), self, | ||
| G_CONNECT_SWAPPED); | ||
| } | ||
| } | ||
|
|
||
| update_settings(self); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_SETTINGS_PLUGIN_H_ | ||
| #define FLUTTER_SHELL_PLATFORM_LINUX_FL_SETTINGS_PLUGIN_H_ | ||
|
|
||
| #include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h" | ||
|
|
||
| G_BEGIN_DECLS | ||
|
|
||
| G_DECLARE_FINAL_TYPE(FlSettingsPlugin, | ||
| fl_settings_plugin, | ||
| FL, | ||
| SETTINGS_PLUGIN, | ||
| GObject); | ||
|
|
||
| /** | ||
| * FlSettingsPlugin: | ||
| * | ||
| * #FlSettingsPlugin is a plugin that implements FIXME. | ||
| */ | ||
|
|
||
| /** | ||
| * fl_settings_plugin_new: | ||
| * @messenger: an #FlBinaryMessenger | ||
| * | ||
| * Creates a new plugin that implements FIXME. | ||
| * | ||
| * Returns: a new #FlSettingsPlugin | ||
| */ | ||
| FlSettingsPlugin* fl_settings_plugin_new(FlBinaryMessenger* messenger); | ||
|
|
||
| /** | ||
| * fl_settings_plugin_start: | ||
| * @self: an #FlSettingsPlugin. | ||
| * | ||
| * Sends the current settings to the engine and updates when they change. | ||
| */ | ||
| void fl_settings_plugin_start(FlSettingsPlugin* plugin); | ||
|
|
||
| G_END_DECLS | ||
|
|
||
| #endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_SETTINGS_PLUGIN_H_ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.