| Flutter Linux Embedder |

fl_settings_handler.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "flutter/shell/platform/linux/fl_settings_handler.h"
6
7 #include <gmodule.h>
8
9 #include "flutter/shell/platform/embedder/embedder.h"
10 #include "flutter/shell/platform/linux/fl_engine_private.h"
11 #include "flutter/shell/platform/linux/fl_settings_channel.h"
12
13 struct _FlSettingsHandler {
14 GObject parent_instance;
15
16 FlSettingsChannel* channel;
17 GWeakRef engine;
18 FlSettings* settings;
19 };
20
21 G_DEFINE_TYPE(FlSettingsHandler, fl_settings_handler, G_TYPE_OBJECT)
22
23 static FlSettingsChannelPlatformBrightness to_platform_brightness(
24 FlColorScheme color_scheme) {
25 switch (color_scheme) {
26 case FL_COLOR_SCHEME_LIGHT:
27 return FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT;
28 case FL_COLOR_SCHEME_DARK:
29 return FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK;
30 default:
31 g_assert_not_reached();
32 }
33 }
34
35 // Sends the current settings to the Flutter engine.
36 static void update_settings(FlSettingsHandler* self) {
37 FlClockFormat clock_format = fl_settings_get_clock_format(self->settings);
38 FlColorScheme color_scheme = fl_settings_get_color_scheme(self->settings);
39 gdouble scaling_factor = fl_settings_get_text_scaling_factor(self->settings);
40
41 fl_settings_channel_send(self->channel, scaling_factor,
42 clock_format == FL_CLOCK_FORMAT_24H,
43 to_platform_brightness(color_scheme));
44
45 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
46 if (engine != nullptr) {
47 int32_t flags = 0;
48 if (!fl_settings_get_enable_animations(self->settings)) {
49 flags |= kFlutterAccessibilityFeatureDisableAnimations;
50 }
51 if (fl_settings_get_high_contrast(self->settings)) {
52 flags |= kFlutterAccessibilityFeatureHighContrast;
53 }
54 fl_engine_update_accessibility_features(engine, flags);
55 }
56 }
57
58 static void fl_settings_handler_dispose(GObject* object) {
59 FlSettingsHandler* self = FL_SETTINGS_HANDLER(object);
60
61 g_clear_object(&self->channel);
62 g_clear_object(&self->settings);
63 g_weak_ref_clear(&self->engine);
64
65 G_OBJECT_CLASS(fl_settings_handler_parent_class)->dispose(object);
66 }
67
68 static void fl_settings_handler_class_init(FlSettingsHandlerClass* klass) {
69 G_OBJECT_CLASS(klass)->dispose = fl_settings_handler_dispose;
70 }
71
72 static void fl_settings_handler_init(FlSettingsHandler* self) {}
73
74 FlSettingsHandler* fl_settings_handler_new(FlEngine* engine) {
75 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
76
77 FlSettingsHandler* self = FL_SETTINGS_HANDLER(
78 g_object_new(fl_settings_handler_get_type(), nullptr));
79
80 g_weak_ref_init(&self->engine, engine);
81
82 FlBinaryMessenger* messenger = fl_engine_get_binary_messenger(engine);
83 self->channel = fl_settings_channel_new(messenger);
84
85 return self;
86 }
87
88 void fl_settings_handler_start(FlSettingsHandler* self, FlSettings* settings) {
89 g_return_if_fail(FL_IS_SETTINGS_HANDLER(self));
90 g_return_if_fail(FL_IS_SETTINGS(settings));
91
92 self->settings = FL_SETTINGS(g_object_ref(settings));
93 g_signal_connect_object(settings, "changed", G_CALLBACK(update_settings),
94 self, G_CONNECT_SWAPPED);
95
96 update_settings(self);
97 }
g_autoptr
g_autoptr(FlEngine) engine
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
fl_engine_get_binary_messenger
G_MODULE_EXPORT FlBinaryMessenger * fl_engine_get_binary_messenger(FlEngine *self)
Definition: fl_engine.cc:1451
fl_engine_update_accessibility_features
void fl_engine_update_accessibility_features(FlEngine *self, int32_t flags)
Definition: fl_engine.cc:1475
fl_engine_private.h
fl_settings_get_high_contrast
gboolean fl_settings_get_high_contrast(FlSettings *self)
Definition: fl_settings.cc:42
fl_settings_get_text_scaling_factor
gdouble fl_settings_get_text_scaling_factor(FlSettings *self)
Definition: fl_settings.cc:46
fl_settings_get_enable_animations
gboolean fl_settings_get_enable_animations(FlSettings *self)
Definition: fl_settings.cc:38
fl_settings_get_color_scheme
FlColorScheme fl_settings_get_color_scheme(FlSettings *self)
Definition: fl_settings.cc:34
fl_settings_get_clock_format
FlClockFormat fl_settings_get_clock_format(FlSettings *self)
Definition: fl_settings.cc:30
FlColorScheme
FlColorScheme
Definition: fl_settings.h:33
FL_COLOR_SCHEME_DARK
@ FL_COLOR_SCHEME_DARK
Definition: fl_settings.h:35
FL_COLOR_SCHEME_LIGHT
@ FL_COLOR_SCHEME_LIGHT
Definition: fl_settings.h:34
FlClockFormat
FlClockFormat
Definition: fl_settings.h:21
FL_CLOCK_FORMAT_24H
@ FL_CLOCK_FORMAT_24H
Definition: fl_settings.h:23
fl_settings_channel_send
void fl_settings_channel_send(FlSettingsChannel *self, double text_scale_factor, gboolean always_use_24_hour_format, FlSettingsChannelPlatformBrightness platform_brightness)
Definition: fl_settings_channel.cc:50
fl_settings_channel_new
FlSettingsChannel * fl_settings_channel_new(FlBinaryMessenger *messenger)
Definition: fl_settings_channel.cc:39
fl_settings_channel.h
FlSettingsChannelPlatformBrightness
FlSettingsChannelPlatformBrightness
Definition: fl_settings_channel.h:12
FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK
@ FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_DARK
Definition: fl_settings_channel.h:14
FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT
@ FL_SETTINGS_CHANNEL_PLATFORM_BRIGHTNESS_LIGHT
Definition: fl_settings_channel.h:13
to_platform_brightness
static FlSettingsChannelPlatformBrightness to_platform_brightness(FlColorScheme color_scheme)
Definition: fl_settings_handler.cc:23
update_settings
static void update_settings(FlSettingsHandler *self)
Definition: fl_settings_handler.cc:36
fl_settings_handler_dispose
static void fl_settings_handler_dispose(GObject *object)
Definition: fl_settings_handler.cc:58
fl_settings_handler_start
void fl_settings_handler_start(FlSettingsHandler *self, FlSettings *settings)
Definition: fl_settings_handler.cc:88
fl_settings_handler_new
FlSettingsHandler * fl_settings_handler_new(FlEngine *engine)
Definition: fl_settings_handler.cc:74
fl_settings_handler_class_init
static void fl_settings_handler_class_init(FlSettingsHandlerClass *klass)
Definition: fl_settings_handler.cc:68
fl_settings_handler_init
static void fl_settings_handler_init(FlSettingsHandler *self)
Definition: fl_settings_handler.cc:72
fl_settings_handler.h
_FlSettingsHandler
Definition: fl_settings_handler.cc:13
_FlSettingsHandler::settings
FlSettings * settings
Definition: fl_settings_handler.cc:18
_FlSettingsHandler::engine
GWeakRef engine
Definition: fl_settings_handler.cc:17
_FlSettingsHandler::parent_instance
GObject parent_instance
Definition: fl_settings_handler.cc:14
_FlSettingsHandler::channel
FlSettingsChannel * channel
Definition: fl_settings_handler.cc:16