#include "flutter/shell/platform/linux/fl_settings_portal.h"
#include <gio/gio.h>
#include <glib.h>
Go to the source code of this file.
|
static void | fl_settings_portal_iface_init (FlSettingsInterface *iface) |
|
| G_DEFINE_TYPE_WITH_CODE (FlSettingsPortal, fl_settings_portal, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE(fl_settings_get_type(), fl_settings_portal_iface_init)) static gchar *format_key(const FlSetting *setting) |
|
static gboolean | get_value (FlSettingsPortal *portal, const FlSetting *setting, GVariant **value) |
|
static void | set_value (FlSettingsPortal *portal, const FlSetting *setting, GVariant *value) |
|
static gboolean | settings_portal_read (GDBusProxy *proxy, const gchar *ns, const gchar *key, GVariant **out) |
|
static void | settings_portal_changed_cb (GDBusProxy *proxy, const char *sender_name, const char *signal_name, GVariant *parameters, gpointer user_data) |
|
static FlClockFormat | fl_settings_portal_get_clock_format (FlSettings *settings) |
|
static FlColorScheme | fl_settings_portal_get_color_scheme (FlSettings *settings) |
|
static gboolean | fl_settings_portal_get_enable_animations (FlSettings *settings) |
|
static gboolean | fl_settings_portal_get_high_contrast (FlSettings *settings) |
|
static gdouble | fl_settings_portal_get_text_scaling_factor (FlSettings *settings) |
|
static void | fl_settings_portal_dispose (GObject *object) |
|
static void | fl_settings_portal_class_init (FlSettingsPortalClass *klass) |
|
static void | fl_settings_portal_init (FlSettingsPortal *self) |
|
FlSettingsPortal * | fl_settings_portal_new () |
|
FlSettingsPortal * | fl_settings_portal_new_with_values (GVariantDict *values) |
|
gboolean | fl_settings_portal_start (FlSettingsPortal *self, GError **error) |
|
◆ ColorScheme
◆ fl_settings_portal_class_init()
static void fl_settings_portal_class_init |
( |
FlSettingsPortalClass * |
klass | ) |
|
|
static |
Definition at line 248 of file fl_settings_portal.cc.
248 {
249 GObjectClass* object_class = G_OBJECT_CLASS(klass);
251}
static void fl_settings_portal_dispose(GObject *object)
◆ fl_settings_portal_dispose()
static void fl_settings_portal_dispose |
( |
GObject * |
object | ) |
|
|
static |
Definition at line 239 of file fl_settings_portal.cc.
239 {
240 FlSettingsPortal*
self = FL_SETTINGS_PORTAL(
object);
241
242 g_clear_object(&
self->dbus_proxy);
243 g_clear_pointer(&
self->values, g_variant_dict_unref);
244
245 G_OBJECT_CLASS(fl_settings_portal_parent_class)->dispose(object);
246}
◆ fl_settings_portal_get_clock_format()
static FlClockFormat fl_settings_portal_get_clock_format |
( |
FlSettings * |
settings | ) |
|
|
static |
Definition at line 163 of file fl_settings_portal.cc.
163 {
165
167
168 g_autoptr(GVariant)
value =
nullptr;
170 const gchar* clock_format_str = g_variant_get_string(
value,
nullptr);
173 }
174 }
175
176 return clock_format;
177}
static gboolean get_value(FlSettingsPortal *portal, const FlSetting *setting, GVariant **value)
static const FlSetting kClockFormat
static constexpr char kClockFormat12Hour[]
◆ fl_settings_portal_get_color_scheme()
static FlColorScheme fl_settings_portal_get_color_scheme |
( |
FlSettings * |
settings | ) |
|
|
static |
Definition at line 179 of file fl_settings_portal.cc.
179 {
181
183
184 g_autoptr(GVariant)
value =
nullptr;
188 }
190 const gchar* gtk_theme_str = g_variant_get_string(
value,
nullptr);
193 }
194 }
195
196 return color_scheme;
197}
static const FlSetting kColorScheme
static const FlSetting kGtkTheme
static constexpr char kGtkThemeDarkSuffix[]
◆ fl_settings_portal_get_enable_animations()
static gboolean fl_settings_portal_get_enable_animations |
( |
FlSettings * |
settings | ) |
|
|
static |
Definition at line 199 of file fl_settings_portal.cc.
199 {
201
202 gboolean enable_animations = true;
203
204 g_autoptr(GVariant)
value =
nullptr;
206 enable_animations = g_variant_get_boolean(
value);
207 }
208
209 return enable_animations;
210}
static const FlSetting kEnableAnimations
◆ fl_settings_portal_get_high_contrast()
static gboolean fl_settings_portal_get_high_contrast |
( |
FlSettings * |
settings | ) |
|
|
static |
Definition at line 212 of file fl_settings_portal.cc.
212 {
214
215 gboolean high_contrast = false;
216
217 g_autoptr(GVariant)
value =
nullptr;
219 high_contrast = g_variant_get_boolean(
value);
220 }
221
222 return high_contrast;
223}
static const FlSetting kHighContrast
◆ fl_settings_portal_get_text_scaling_factor()
static gdouble fl_settings_portal_get_text_scaling_factor |
( |
FlSettings * |
settings | ) |
|
|
static |
Definition at line 225 of file fl_settings_portal.cc.
226 {
228
229 gdouble scaling_factor = 1.0;
230
231 g_autoptr(GVariant)
value =
nullptr;
233 scaling_factor = g_variant_get_double(
value);
234 }
235
236 return scaling_factor;
237}
static const FlSetting kTextScalingFactor
◆ fl_settings_portal_iface_init()
static void fl_settings_portal_iface_init |
( |
FlSettingsInterface * |
iface | ) |
|
|
static |
Definition at line 253 of file fl_settings_portal.cc.
253 {
259}
static gdouble fl_settings_portal_get_text_scaling_factor(FlSettings *settings)
static FlColorScheme fl_settings_portal_get_color_scheme(FlSettings *settings)
static gboolean fl_settings_portal_get_high_contrast(FlSettings *settings)
static FlClockFormat fl_settings_portal_get_clock_format(FlSettings *settings)
static gboolean fl_settings_portal_get_enable_animations(FlSettings *settings)
◆ fl_settings_portal_init()
static void fl_settings_portal_init |
( |
FlSettingsPortal * |
self | ) |
|
|
static |
◆ fl_settings_portal_new()
FlSettingsPortal * fl_settings_portal_new |
( |
| ) |
|
FlSettingsPortal: #FlSettingsPortal reads settings from the XDG desktop portal. fl_settings_portal_new:
Creates a new settings portal instance.
Returns: a new #FlSettingsPortal.
Definition at line 263 of file fl_settings_portal.cc.
263 {
264 g_autoptr(GVariantDict)
values = g_variant_dict_new(
nullptr);
266}
FlSettingsPortal * fl_settings_portal_new_with_values(GVariantDict *values)
◆ fl_settings_portal_new_with_values()
FlSettingsPortal * fl_settings_portal_new_with_values |
( |
GVariantDict * |
values | ) |
|
fl_settings_portal_new_with_values: @values: (nullable): a #GVariantDict.
Creates a new settings portal instance with initial values for testing.
Returns: a new #FlSettingsPortal.
Definition at line 268 of file fl_settings_portal.cc.
268 {
269 g_return_val_if_fail(
values !=
nullptr,
nullptr);
270 FlSettingsPortal* portal =
271 FL_SETTINGS_PORTAL(g_object_new(fl_settings_portal_get_type(), nullptr));
272 portal->values = g_variant_dict_ref(
values);
273 return portal;
274}
◆ fl_settings_portal_start()
gboolean fl_settings_portal_start |
( |
FlSettingsPortal * |
portal, |
|
|
GError ** |
error |
|
) |
| |
fl_settings_portal_start: @portal: an #FlSettingsPortal. @error: (allow-none): #GError location to store the error occurring, or NULL
Reads the current settings and starts monitoring for changes in the desktop portal settings.
Returns: TRUE on success, or FALSE if the portal is not available.
Definition at line 276 of file fl_settings_portal.cc.
276 {
277 g_return_val_if_fail(FL_IS_SETTINGS_PORTAL(
self),
false);
278 g_return_val_if_fail(
self->dbus_proxy ==
nullptr,
false);
279
280 self->dbus_proxy = g_dbus_proxy_new_for_bus_sync(
281 G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE,
nullptr,
kPortalName,
283
284 if (
self->dbus_proxy ==
nullptr) {
285 return false;
286 }
287
289 g_autoptr(GVariant)
value =
nullptr;
293 }
294 }
295
296 g_signal_connect_object(
self->dbus_proxy,
"g-signal",
298 static_cast<GConnectFlags>(0));
299
300 return true;
301}
const uint8_t uint32_t uint32_t GError ** error
static gboolean settings_portal_read(GDBusProxy *proxy, const gchar *ns, const gchar *key, GVariant **out)
static void set_value(FlSettingsPortal *portal, const FlSetting *setting, GVariant *value)
static void settings_portal_changed_cb(GDBusProxy *proxy, const char *sender_name, const char *signal_name, GVariant *parameters, gpointer user_data)
static const FlSetting kAllSettings[]
static constexpr char kPortalPath[]
static constexpr char kPortalName[]
static constexpr char kPortalSettings[]
◆ G_DEFINE_TYPE_WITH_CODE()
G_DEFINE_TYPE_WITH_CODE |
( |
FlSettingsPortal |
, |
|
|
fl_settings_portal |
, |
|
|
G_TYPE_OBJECT |
, |
|
|
G_IMPLEMENT_INTERFACE(fl_settings_get_type(), fl_settings_portal_iface_init) |
|
|
) |
| const |
Definition at line 76 of file fl_settings_portal.cc.
82 {
83 return g_strconcat(setting->ns, "::", setting->key, nullptr);
84}
◆ get_value()
static gboolean get_value |
( |
FlSettingsPortal * |
portal, |
|
|
const FlSetting * |
setting, |
|
|
GVariant ** |
value |
|
) |
| |
|
static |
Definition at line 86 of file fl_settings_portal.cc.
88 {
89 g_autofree
const gchar*
key = format_key(setting);
90 *
value = g_variant_dict_lookup_value(portal->values,
key, setting->
type);
91 return *
value !=
nullptr;
92}
const GVariantType * type
◆ set_value()
static void set_value |
( |
FlSettingsPortal * |
portal, |
|
|
const FlSetting * |
setting, |
|
|
GVariant * |
value |
|
) |
| |
|
static |
Definition at line 94 of file fl_settings_portal.cc.
96 {
97 g_autofree
const gchar*
key = format_key(setting);
98
99
100 g_autoptr(GVariant) old_value =
101 g_variant_dict_lookup_value(portal->values,
key,
nullptr);
102 if (old_value !=
nullptr &&
value !=
nullptr &&
103 g_variant_equal(old_value,
value)) {
104 return;
105 }
106
107 g_variant_dict_insert_value(portal->values,
key,
value);
109}
void fl_settings_emit_changed(FlSettings *self)
◆ settings_portal_changed_cb()
static void settings_portal_changed_cb |
( |
GDBusProxy * |
proxy, |
|
|
const char * |
sender_name, |
|
|
const char * |
signal_name, |
|
|
GVariant * |
parameters, |
|
|
gpointer |
user_data |
|
) |
| |
|
static |
Definition at line 147 of file fl_settings_portal.cc.
151 {
152 FlSettingsPortal* portal = FL_SETTINGS_PORTAL(
user_data);
153 if (g_strcmp0(signal_name, "SettingChanged")) {
154 return;
155 }
156
158 g_autoptr(GVariant)
value =
nullptr;
159 g_variant_get(parameters,
"(&s&sv)", &setting.
ns, &setting.
key, &
value);
161}
◆ settings_portal_read()
static gboolean settings_portal_read |
( |
GDBusProxy * |
proxy, |
|
|
const gchar * |
ns, |
|
|
const gchar * |
key, |
|
|
GVariant ** |
out |
|
) |
| |
|
static |
Definition at line 113 of file fl_settings_portal.cc.
116 {
117 g_autoptr(GError)
error =
nullptr;
118 g_autoptr(GVariant)
value =
119 g_dbus_proxy_call_sync(proxy,
"Read", g_variant_new(
"(ss)", ns,
key),
120 G_DBUS_CALL_FLAGS_NONE, G_MAXINT,
nullptr, &
error);
121
123 if (
error->domain == G_DBUS_ERROR &&
124 error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) {
125 g_debug(
"XDG desktop portal unavailable: %s",
error->message);
126 return false;
127 }
128
129 if (
error->domain == G_DBUS_ERROR &&
130 error->code == G_DBUS_ERROR_UNKNOWN_METHOD) {
131 g_debug(
"XDG desktop portal settings unavailable: %s",
error->message);
132 return false;
133 }
134
135 g_critical("Failed to read XDG desktop portal settings: %s",
137 return false;
138 }
139
140 g_autoptr(GVariant) child = nullptr;
141 g_variant_get(
value,
"(v)", &child);
142 g_variant_get(child,
"v",
out);
143
144 return true;
145}
◆ kAllSettings
◆ kClockFormat
Initial value:= {
"clock-format",
G_VARIANT_TYPE_STRING,
}
static constexpr char kGnomeDesktopInterface[]
Definition at line 36 of file fl_settings_portal.cc.
◆ kClockFormat12Hour
constexpr char kClockFormat12Hour[] = "12h" |
|
staticconstexpr |
◆ kColorScheme
Initial value:= {
"color-scheme",
G_VARIANT_TYPE_UINT32,
}
static constexpr char kXdgAppearance[]
Definition at line 21 of file fl_settings_portal.cc.
◆ kEnableAnimations
Initial value:= {
"enable-animations",
G_VARIANT_TYPE_BOOLEAN,
}
Definition at line 41 of file fl_settings_portal.cc.
◆ kGnomeA11yInterface
constexpr char kGnomeA11yInterface[] |
|
staticconstexpr |
◆ kGnomeDesktopInterface
constexpr char kGnomeDesktopInterface[] = "org.gnome.desktop.interface" |
|
staticconstexpr |
◆ kGtkTheme
◆ kGtkThemeDarkSuffix
constexpr char kGtkThemeDarkSuffix[] = "-dark" |
|
staticconstexpr |
◆ kHighContrast
Initial value:= {
"high-contrast",
G_VARIANT_TYPE_BOOLEAN,
}
static constexpr char kGnomeA11yInterface[]
Definition at line 29 of file fl_settings_portal.cc.
◆ kPortalName
constexpr char kPortalName[] = "org.freedesktop.portal.Desktop" |
|
staticconstexpr |
◆ kPortalPath
constexpr char kPortalPath[] = "/org/freedesktop/portal/desktop" |
|
staticconstexpr |
◆ kPortalSettings
constexpr char kPortalSettings[] = "org.freedesktop.portal.Settings" |
|
staticconstexpr |
◆ kTextScalingFactor
Initial value:= {
"text-scaling-factor",
G_VARIANT_TYPE_DOUBLE,
}
Definition at line 51 of file fl_settings_portal.cc.
◆ kXdgAppearance
constexpr char kXdgAppearance[] = "org.freedesktop.appearance" |
|
staticconstexpr |