Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
fl_gnome_settings.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_gnome_settings.h"
6
7#include <gio/gio.h>
8#include <glib.h>
9
10static constexpr char kDesktopInterfaceSchema[] = "org.gnome.desktop.interface";
11static constexpr char kDesktopTextScalingFactorKey[] = "text-scaling-factor";
12static constexpr char kDesktopClockFormatKey[] = "clock-format";
13static constexpr char kDesktopGtkThemeKey[] = "gtk-theme";
14
15static constexpr char kClockFormat12Hour[] = "12h";
16static constexpr char kGtkThemeDarkSuffix[] = "-dark";
17static constexpr char kInterfaceSettings[] = "interface-settings";
18
21
23};
24
26
27static void fl_gnome_settings_iface_init(FlSettingsInterface* iface);
28
30 fl_gnome_settings,
31 G_TYPE_OBJECT,
32 G_IMPLEMENT_INTERFACE(fl_settings_get_type(),
34
35static FlClockFormat fl_gnome_settings_get_clock_format(FlSettings* settings) {
36 FlGnomeSettings* self = FL_GNOME_SETTINGS(settings);
37
39
40 if (self->interface_settings != nullptr) {
41 g_autofree gchar* value =
42 g_settings_get_string(self->interface_settings, kDesktopClockFormatKey);
43 if (g_strcmp0(value, kClockFormat12Hour) == 0) {
44 clock_format = FL_CLOCK_FORMAT_12H;
45 }
46 }
47 return clock_format;
48}
49
51 FlGnomeSettings* self = FL_GNOME_SETTINGS(settings);
52
54
55 if (self->interface_settings != nullptr) {
56 // check whether org.gnome.desktop.interface.gtk-theme ends with "-dark"
57 g_autofree gchar* value =
58 g_settings_get_string(self->interface_settings, kDesktopGtkThemeKey);
59 if (g_str_has_suffix(value, kGtkThemeDarkSuffix)) {
60 color_scheme = FL_COLOR_SCHEME_DARK;
61 }
62 }
63 return color_scheme;
64}
65
66static gboolean fl_gnome_settings_get_enable_animations(FlSettings* settings) {
67 return true;
68}
69
70static gboolean fl_gnome_settings_get_high_contrast(FlSettings* settings) {
71 return false;
72}
73
74static gdouble fl_gnome_settings_get_text_scaling_factor(FlSettings* settings) {
75 FlGnomeSettings* self = FL_GNOME_SETTINGS(settings);
76
77 gdouble scaling_factor = 1.0;
78
79 if (self->interface_settings != nullptr) {
80 scaling_factor = g_settings_get_double(self->interface_settings,
82 }
83 return scaling_factor;
84}
85
87 GSettings* settings) {
88 g_return_if_fail(G_IS_SETTINGS(settings));
89
90 g_signal_connect_object(settings, "changed::clock-format",
91 G_CALLBACK(fl_settings_emit_changed), self,
92 G_CONNECT_SWAPPED);
93 g_signal_connect_object(settings, "changed::gtk-theme",
94 G_CALLBACK(fl_settings_emit_changed), self,
95 G_CONNECT_SWAPPED);
96 g_signal_connect_object(settings, "changed::text-scaling-factor",
97 G_CALLBACK(fl_settings_emit_changed), self,
98 G_CONNECT_SWAPPED);
99
100 self->interface_settings = G_SETTINGS(g_object_ref(settings));
101}
102
103static void fl_gnome_settings_set_property(GObject* object,
104 guint prop_id,
105 const GValue* value,
106 GParamSpec* pspec) {
107 FlGnomeSettings* self = FL_GNOME_SETTINGS(object);
108 switch (prop_id) {
111 self, G_SETTINGS(g_value_get_object(value)));
112 break;
113 default:
114 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
115 break;
116 }
117}
118
119static void fl_gnome_settings_dispose(GObject* object) {
120 FlGnomeSettings* self = FL_GNOME_SETTINGS(object);
121
122 g_clear_object(&self->interface_settings);
123
124 G_OBJECT_CLASS(fl_gnome_settings_parent_class)->dispose(object);
125}
126
127static void fl_gnome_settings_class_init(FlGnomeSettingsClass* klass) {
128 GObjectClass* object_class = G_OBJECT_CLASS(klass);
129 object_class->dispose = fl_gnome_settings_dispose;
130 object_class->set_property = fl_gnome_settings_set_property;
131
132 g_object_class_install_property(
133 object_class, kPropInterfaceSettings,
134 g_param_spec_object(
136 g_settings_get_type(),
137 static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
138 G_PARAM_STATIC_STRINGS)));
139}
140
141static void fl_gnome_settings_iface_init(FlSettingsInterface* iface) {
142 iface->get_clock_format = fl_gnome_settings_get_clock_format;
143 iface->get_color_scheme = fl_gnome_settings_get_color_scheme;
144 iface->get_enable_animations = fl_gnome_settings_get_enable_animations;
145 iface->get_high_contrast = fl_gnome_settings_get_high_contrast;
146 iface->get_text_scaling_factor = fl_gnome_settings_get_text_scaling_factor;
147}
148
149static void fl_gnome_settings_init(FlGnomeSettings* self) {}
150
151static GSettings* create_settings(const gchar* schema_id) {
152 GSettings* settings = nullptr;
153 GSettingsSchemaSource* source = g_settings_schema_source_get_default();
154 if (source != nullptr) {
155 g_autoptr(GSettingsSchema) schema =
156 g_settings_schema_source_lookup(source, schema_id, TRUE);
157 if (schema != nullptr) {
158 settings = g_settings_new_full(schema, nullptr, nullptr);
159 }
160 }
161 return settings;
162}
163
165 g_autoptr(GSettings) interface_settings =
167 return FL_SETTINGS(g_object_new(fl_gnome_settings_get_type(),
168 kInterfaceSettings, interface_settings,
169 nullptr));
170}
SkBitmap source
Definition examples.cpp:28
static void fl_gnome_settings_iface_init(FlSettingsInterface *iface)
FlSettings * fl_gnome_settings_new()
static gboolean fl_gnome_settings_get_high_contrast(FlSettings *settings)
static constexpr char kDesktopTextScalingFactorKey[]
static constexpr char kDesktopInterfaceSchema[]
static void fl_gnome_settings_class_init(FlGnomeSettingsClass *klass)
static void fl_gnome_settings_dispose(GObject *object)
@ kPropLast
@ kPropInterfaceSettings
static constexpr char kDesktopGtkThemeKey[]
static void fl_gnome_settings_set_interface_settings(FlGnomeSettings *self, GSettings *settings)
static FlColorScheme fl_gnome_settings_get_color_scheme(FlSettings *settings)
G_DEFINE_TYPE_WITH_CODE(FlGnomeSettings, fl_gnome_settings, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_settings_get_type(), fl_gnome_settings_iface_init)) static FlClockFormat fl_gnome_settings_get_clock_format(FlSettings *settings)
static constexpr char kClockFormat12Hour[]
static void fl_gnome_settings_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
static GSettings * create_settings(const gchar *schema_id)
static void fl_gnome_settings_init(FlGnomeSettings *self)
static constexpr char kInterfaceSettings[]
static gboolean fl_gnome_settings_get_enable_animations(FlSettings *settings)
static constexpr char kDesktopClockFormatKey[]
static constexpr char kGtkThemeDarkSuffix[]
static gdouble fl_gnome_settings_get_text_scaling_factor(FlSettings *settings)
void fl_settings_emit_changed(FlSettings *self)
FlColorScheme
Definition fl_settings.h:35
@ FL_COLOR_SCHEME_DARK
Definition fl_settings.h:38
@ FL_COLOR_SCHEME_LIGHT
Definition fl_settings.h:37
FlClockFormat
Definition fl_settings.h:21
@ FL_CLOCK_FORMAT_12H
Definition fl_settings.h:23
@ FL_CLOCK_FORMAT_24H
Definition fl_settings.h:24
uint8_t value
guint const GValue GParamSpec * pspec
GSettings * interface_settings