[gnome-builder/wip/gtk4-port: 284/736] libide/gui: recolor UI based on selected style scheme
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 284/736] libide/gui: recolor UI based on selected style scheme
- Date: Tue, 26 Apr 2022 01:46:22 +0000 (UTC)
commit 21a959d9956554333e9e733ceb602f276ff90209
Author: Christian Hergert <chergert redhat com>
Date: Thu Mar 31 04:14:14 2022 -0700
libide/gui: recolor UI based on selected style scheme
src/libide/gui/ide-application-color.c | 44 ++++++++++++++++++++++++++++++++
src/libide/gui/ide-application-private.h | 4 +++
src/libide/gui/ide-application.c | 4 +++
3 files changed, 52 insertions(+)
---
diff --git a/src/libide/gui/ide-application-color.c b/src/libide/gui/ide-application-color.c
index 0f42e698a..94161065e 100644
--- a/src/libide/gui/ide-application-color.c
+++ b/src/libide/gui/ide-application-color.c
@@ -26,6 +26,7 @@
#include "ide-application.h"
#include "ide-application-private.h"
+#include "ide-recoloring-private.h"
static void
add_style_name (GPtrArray *ar,
@@ -130,6 +131,8 @@ _ide_application_update_style_scheme (IdeApplication *self)
g_autofree gchar *old_name = NULL;
g_autofree gchar *new_name = NULL;
+ g_assert (IDE_IS_APPLICATION (self));
+
manager = adw_style_manager_get_default ();
/*
@@ -150,9 +153,38 @@ _ide_application_update_style_scheme (IdeApplication *self)
g_settings_set_string (editor_settings, "style-scheme-name", new_name);
}
+static void
+ide_application_color_style_scheme_changed_cb (IdeApplication *self,
+ const char *key,
+ GSettings *editor_settings)
+{
+ GtkSourceStyleSchemeManager *manager;
+ GtkSourceStyleScheme *scheme;
+ g_autofree char *style_scheme_name = NULL;
+ g_autofree char *css = NULL;
+
+ g_assert (IDE_IS_APPLICATION (self));
+ g_assert (g_strcmp0 (key, "style-scheme-name") == 0);
+ g_assert (G_IS_SETTINGS (editor_settings));
+
+ style_scheme_name = g_settings_get_string (editor_settings, key);
+ g_debug ("Style scheme changed to %s", style_scheme_name);
+
+ manager = gtk_source_style_scheme_manager_get_default ();
+ scheme = gtk_source_style_scheme_manager_get_scheme (manager, style_scheme_name);
+
+ if (scheme == NULL)
+ return;
+
+ if ((css = _ide_recoloring_generate_css (scheme)))
+ gtk_css_provider_load_from_data (self->recoloring, css, -1);
+}
+
void
_ide_application_init_color (IdeApplication *self)
{
+ g_autofree char *style_scheme_name = NULL;
+
g_return_if_fail (IDE_IS_APPLICATION (self));
g_return_if_fail (G_IS_SETTINGS (self->settings));
@@ -176,6 +208,18 @@ _ide_application_init_color (IdeApplication *self)
G_CONNECT_SWAPPED);
}
+ style_scheme_name = g_settings_get_string (self->editor_settings, "style-scheme-name");
+ g_debug ("Initialized with style scheme %s", style_scheme_name);
+ g_signal_connect_object (self->editor_settings,
+ "changed::style-scheme-name",
+ G_CALLBACK (ide_application_color_style_scheme_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+ gtk_style_context_add_provider_for_display (gdk_display_get_default (),
+ GTK_STYLE_PROVIDER (self->recoloring),
+ GTK_STYLE_PROVIDER_PRIORITY_THEME+1);
+
_ide_application_update_color (self);
_ide_application_update_style_scheme (self);
+ ide_application_color_style_scheme_changed_cb (self, "style-scheme-name", self->editor_settings);
}
diff --git a/src/libide/gui/ide-application-private.h b/src/libide/gui/ide-application-private.h
index 94f478254..eca37f886 100644
--- a/src/libide/gui/ide-application-private.h
+++ b/src/libide/gui/ide-application-private.h
@@ -59,6 +59,7 @@ struct _IdeApplication
* for various keys.
*/
GSettings *settings;
+ GSettings *editor_settings;
/* We need to track the GResource files that were manually loaded for
* plugins on disk (generally Python plugins that need resources). That
@@ -71,6 +72,9 @@ struct _IdeApplication
*/
GHashTable *css_providers;
+ /* The CSS provider to recolor all of the widgetry based on style schemes */
+ GtkCssProvider *recoloring;
+
/* We need to stash the unmodified argv for the application somewhere
* so that we can pass it to a remote instance. Otherwise we lose
* the ability by cmdline-addins to determine if any options were
diff --git a/src/libide/gui/ide-application.c b/src/libide/gui/ide-application.c
index 407a5d288..77631e0d3 100644
--- a/src/libide/gui/ide-application.c
+++ b/src/libide/gui/ide-application.c
@@ -339,7 +339,9 @@ ide_application_dispose (GObject *object)
g_clear_pointer (&self->css_providers, g_hash_table_unref);
g_clear_pointer (&self->argv, g_strfreev);
g_clear_pointer (&self->menu_merge_ids, g_hash_table_unref);
+ g_clear_object (&self->recoloring);
g_clear_object (&self->addins);
+ g_clear_object (&self->editor_settings);
g_clear_object (&self->settings);
g_clear_object (&self->network_monitor);
g_clear_object (&self->menu_manager);
@@ -373,9 +375,11 @@ ide_application_init (IdeApplication *self)
self->workspace_type = IDE_TYPE_PRIMARY_WORKSPACE;
self->workbenches = g_ptr_array_new_with_free_func (g_object_unref);
self->settings = g_settings_new ("org.gnome.builder");
+ self->editor_settings = g_settings_new ("org.gnome.builder.editor");
self->plugin_gresources = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify)g_resource_unref);
self->css_providers = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref );
+ self->recoloring = gtk_css_provider_new ();
g_application_set_default (G_APPLICATION (self));
gtk_window_set_default_icon_name (ide_get_application_id ());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]