[libadwaita/wip/exalm/inspector: 5/7] settings: Add API to override system appearance
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libadwaita/wip/exalm/inspector: 5/7] settings: Add API to override system appearance
- Date: Sun, 26 Sep 2021 21:58:25 +0000 (UTC)
commit fa07d6c1f714f59af6cafc252c44058016faf13c
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Sep 27 02:56:10 2021 +0500
settings: Add API to override system appearance
We'll use it for the upcoming inspector page.
src/adw-settings-private.h | 12 +++++
src/adw-settings.c | 115 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 125 insertions(+), 2 deletions(-)
---
diff --git a/src/adw-settings-private.h b/src/adw-settings-private.h
index 892995f2..8aee890f 100644
--- a/src/adw-settings-private.h
+++ b/src/adw-settings-private.h
@@ -35,4 +35,16 @@ AdwSystemColorScheme adw_settings_get_color_scheme (AdwSettings *self);
gboolean adw_settings_get_high_contrast (AdwSettings *self);
+void adw_settings_start_override (AdwSettings *self);
+void adw_settings_end_override (AdwSettings *self);
+
+void adw_settings_override_system_supports_color_schemes (AdwSettings *self,
+ gboolean system_supports_color_schemes);
+
+void adw_settings_override_color_scheme (AdwSettings *self,
+ AdwSystemColorScheme color_scheme);
+
+void adw_settings_override_high_contrast (AdwSettings *self,
+ gboolean high_contrast);
+
G_END_DECLS
diff --git a/src/adw-settings.c b/src/adw-settings.c
index 91fea1d9..b1d47e9f 100644
--- a/src/adw-settings.c
+++ b/src/adw-settings.c
@@ -33,6 +33,11 @@ struct _AdwSettings
gboolean has_high_contrast;
gboolean has_color_scheme;
gboolean color_scheme_use_fdo_setting;
+
+ gboolean override;
+ gboolean system_supports_color_schemes_override;
+ AdwSystemColorScheme color_scheme_override;
+ gboolean high_contrast_override;
};
G_DEFINE_TYPE (AdwSettings, adw_settings, G_TYPE_OBJECT);
@@ -58,7 +63,8 @@ set_color_scheme (AdwSettings *self,
self->color_scheme = color_scheme;
- g_object_notify_by_pspec (G_OBJECT (self), props[PROP_COLOR_SCHEME]);
+ if (!self->override)
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_COLOR_SCHEME]);
}
static void
@@ -70,7 +76,8 @@ set_high_contrast (AdwSettings *self,
self->high_contrast = high_contrast;
- g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HIGH_CONTRAST]);
+ if (!self->override)
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HIGH_CONTRAST]);
}
/* Settings portal */
@@ -479,6 +486,9 @@ adw_settings_get_system_supports_color_schemes (AdwSettings *self)
{
g_return_val_if_fail (ADW_IS_SETTINGS (self), FALSE);
+ if (self->override)
+ return self->system_supports_color_schemes_override;
+
return self->has_color_scheme;
}
@@ -487,6 +497,9 @@ adw_settings_get_color_scheme (AdwSettings *self)
{
g_return_val_if_fail (ADW_IS_SETTINGS (self), ADW_SYSTEM_COLOR_SCHEME_DEFAULT);
+ if (self->override)
+ return self->color_scheme_override;
+
return self->color_scheme;
}
@@ -495,5 +508,103 @@ adw_settings_get_high_contrast (AdwSettings *self)
{
g_return_val_if_fail (ADW_IS_SETTINGS (self), FALSE);
+ if (self->override)
+ return self->high_contrast_override;
+
return self->high_contrast;
}
+
+void
+adw_settings_start_override (AdwSettings *self)
+{
+ g_return_if_fail (ADW_IS_SETTINGS (self));
+
+ if (self->override)
+ return;
+
+ self->override = TRUE;
+
+ self->system_supports_color_schemes_override = self->has_color_scheme;
+ self->color_scheme_override = self->color_scheme;
+ self->high_contrast_override = self->high_contrast;
+}
+
+void
+adw_settings_end_override (AdwSettings *self)
+{
+ gboolean notify_system_supports_color_scheme, notify_color_scheme, notify_hc;
+
+ g_return_if_fail (ADW_IS_SETTINGS (self));
+
+ if (!self->override)
+ return;
+
+ notify_system_supports_color_scheme = self->system_supports_color_schemes_override !=
self->has_color_scheme;
+ notify_color_scheme = self->color_scheme_override != self->color_scheme;
+ notify_hc = self->high_contrast_override != self->high_contrast;
+
+ self->override = FALSE;
+ self->system_supports_color_schemes_override = FALSE;
+ self->color_scheme_override = ADW_SYSTEM_COLOR_SCHEME_DEFAULT;
+ self->high_contrast_override = FALSE;
+
+ if (notify_system_supports_color_scheme)
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SYSTEM_SUPPORTS_COLOR_SCHEMES]);
+ if (notify_color_scheme)
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_COLOR_SCHEME]);
+ if (notify_hc)
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HIGH_CONTRAST]);
+}
+
+void
+adw_settings_override_system_supports_color_schemes (AdwSettings *self,
+ gboolean system_supports_color_schemes)
+{
+ g_return_if_fail (ADW_IS_SETTINGS (self));
+ g_return_if_fail (self->override);
+
+ system_supports_color_schemes = !!system_supports_color_schemes;
+
+ if (system_supports_color_schemes == self->system_supports_color_schemes_override)
+ return;
+
+ if (!system_supports_color_schemes)
+ adw_settings_override_color_scheme (self, ADW_SYSTEM_COLOR_SCHEME_DEFAULT);
+
+ self->system_supports_color_schemes_override = system_supports_color_schemes;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_SYSTEM_SUPPORTS_COLOR_SCHEMES]);
+}
+
+void
+adw_settings_override_color_scheme (AdwSettings *self,
+ AdwSystemColorScheme color_scheme)
+{
+ g_return_if_fail (ADW_IS_SETTINGS (self));
+ g_return_if_fail (self->override);
+
+ if (color_scheme == self->color_scheme_override ||
+ !self->system_supports_color_schemes_override)
+ return;
+
+ self->color_scheme_override = color_scheme;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_COLOR_SCHEME]);
+}
+
+void
+adw_settings_override_high_contrast (AdwSettings *self,
+ gboolean high_contrast)
+{
+ g_return_if_fail (ADW_IS_SETTINGS (self));
+ g_return_if_fail (self->override);
+
+ high_contrast = !!high_contrast;
+
+ if (high_contrast == self->high_contrast_override)
+ return;
+
+ self->high_contrast_override = high_contrast;
+
+ g_object_notify_by_pspec (G_OBJECT (self), props[PROP_HIGH_CONTRAST]);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]