[gnome-builder] theme: add GbCssProvider



commit 36f32ed6a5008d71344aa47e29112bbdd6fd4489
Author: Christian Hergert <christian hergert me>
Date:   Sat Apr 11 13:52:17 2015 -0700

    theme: add GbCssProvider
    
    This custom theme provider allows us to break things out into light
    and dark variants as well as share common components between the
    themes. It handles changes to light/dark variant modes as well as
    theme changes.
    
    I'm still unsure what we want to do about non-Adwaita themes. That is
    definitely my focus. Not a whole lot is reliably reusable without
    knowing the theme.

 data/css/builder.Adwaita.css              |  192 -----------------------------
 data/theme/Adwaita-dark.css               |   18 +++
 data/theme/Adwaita-shared.css             |  135 ++++++++++++++++++++
 data/theme/Adwaita.css                    |   17 +++
 src/app/gb-application.c                  |   72 ++----------
 src/css/gb-css-provider.c                 |  166 +++++++++++++++++++++++++
 src/css/gb-css-provider.h                 |   34 +++++
 src/gnome-builder.mk                      |    3 +
 src/resources/gnome-builder.gresource.xml |    5 +-
 9 files changed, 385 insertions(+), 257 deletions(-)
---
diff --git a/data/theme/Adwaita-dark.css b/data/theme/Adwaita-dark.css
new file mode 100644
index 0000000..99ffa0b
--- /dev/null
+++ b/data/theme/Adwaita-dark.css
@@ -0,0 +1,18 @@
+ import url("resource:///org/gnome/builder/theme/Adwaita-shared.css");
+
+/*
+ * Project Tree
+ */
+GbProjectTree.view {
+  color: #eeeeec;
+  background-color: #2e3436;
+}
+GbProjectTree.view:backdrop {
+  color: #a1a1a1;
+  background-color: #2e3436;
+}
+GbProjectTree.view.cell:selected {
+  color: #fff;
+  background-color: #4a90d9;
+}
+
diff --git a/data/theme/Adwaita-shared.css b/data/theme/Adwaita-shared.css
new file mode 100644
index 0000000..bbf6639
--- /dev/null
+++ b/data/theme/Adwaita-shared.css
@@ -0,0 +1,135 @@
+.floating-bar {
+  padding: 2px;
+  background-color: @theme_base_color;
+  border-width: 1px;
+  border-style: solid solid none;
+  border-color: @borders;
+  border-radius: 3px 3px 0 0;
+}
+
+.floating-bar.bottom.left { /* axes left border and border radius */
+  border-left-style: none;
+  border-top-left-radius: 0;
+}
+.floating-bar.bottom.right { /* axes right border and border radius */
+  border-right-style: none;
+  border-top-right-radius: 0;
+}
+
+.floating-bar:backdrop {
+  background-color: @theme_unfocused_base_color;
+  border-color: @unfocused_borders;
+}
+
+.floating-bar .button {
+  padding: 4px;
+}
+
+
+/*
+ * Editor Floating Search Entry.
+ */
+GbEditorFrame .gb-search-slider {
+  background-color: @theme_base_color;
+  padding: 6px;
+  border-color: shade (@theme_base_color, 0.60);
+  border-radius: 0 0 5px 5px;
+  border-width: 0 1px 1px 1px;
+  border-style: solid;
+}
+.gb-search-entry-occurrences-tag {
+  color: shade (@theme_unfocused_fg_color, 0.8);
+  margin: 2px;
+  padding: 2px;
+}
+GdTaggedEntry {
+  color: @theme_fg_color;
+}
+
+
+/*
+ * Preferences styling.
+ */
+.preferences.sidebar GtkViewport {
+   border: 0px;
+}
+.preferences.sidebar GtkListBox {
+  background-color: shade(@theme_bg_color, 0.99);
+}
+.preferences.sidebar GtkListBoxRow {
+  padding: 10px;
+}
+GbPreferencesPageLanguage GtkSearchEntry {
+  border-bottom-left-radius: 0;
+  border-bottom-right-radius: 0;
+}
+GbPreferencesPageLanguage GtkScrolledWindow {
+  border-top-width: 0;
+}
+GbPreferencesSwitch:prelight {
+  background-color: shade(@theme_bg_color, 1.01);
+}
+
+
+/*
+ * Command Bar styling.
+ */
+GtkBox.gb-command-bar-box {
+  border: none;
+  background-image: linear-gradient(to bottom, #2e3436, #555753 10%);
+  box-shadow: inset 0px 3px 6px #2e3436;
+}
+GtkBox.gb-command-bar-box GtkLabel {
+  color: #eeeeec;
+}
+GtkEntry.gb-command-bar-entry {
+  font-family: Monospace;
+  background-image: none;
+  padding: 6px 6px 6px 6px;
+  color: #eeeeec;
+}
+
+
+/*
+ * Style selector widget.
+ */
+GbSourceStyleSchemeWidget GtkSourceView {
+  font-family: Monospace;
+}
+
+
+/*
+ * Editor tweak widget.
+ */
+GbEditorTweakWidget GtkScrolledWindow {
+  border-top: none;
+}
+
+
+/*
+ * Disable various animatinos that are enabled by default and really annoying
+ * to the overall flow of Builder.
+ */
+GbSearchDisplayGroup GtkListBox .list-row {
+  transition: none;
+}
+GbDocumentStack .button {
+  transition: none;
+}
+
+
+/*
+ * View stack styling.
+ */
+GbViewStack GtkBox.header.notebook {
+  border-bottom: 1px solid @borders;
+}
+GbViewStack:not(.focused) GtkBox.header.notebook {
+  background-color: shade (@theme_bg_color, 0.95);
+}
+GbEditorWorkspace > GtkPaned > GtkBox > GtkBox.header.notebook {
+  border-bottom: 1px solid @borders;
+}
+GbNewProjectDialog GtkFileChooserButton.linked-on-right .button {
+  border-radius: 3px 0 0 3px;
+}
diff --git a/data/theme/Adwaita.css b/data/theme/Adwaita.css
new file mode 100644
index 0000000..4bb2337
--- /dev/null
+++ b/data/theme/Adwaita.css
@@ -0,0 +1,17 @@
+ import url("resource:///org/gnome/builder/theme/Adwaita-shared.css");
+
+/*
+ * Project Tree
+ */
+GbProjectTree.view {
+  color: #555753;
+  background-color: #eeeeec;
+}
+GbProjectTree.view:backdrop {
+  color: #888a85;
+  background-color: #efefef;
+}
+GbProjectTree.view.cell:selected {
+  color: #fff;
+  background-color: #4a90d9;
+}
diff --git a/src/app/gb-application.c b/src/app/gb-application.c
index bf33d59..a5be57c 100644
--- a/src/app/gb-application.c
+++ b/src/app/gb-application.c
@@ -29,6 +29,7 @@
 #include "gb-application.h"
 #include "gb-application-actions.h"
 #include "gb-application-private.h"
+#include "gb-css-provider.h"
 #include "gb-editor-document.h"
 #include "gb-editor-workspace.h"
 #include "gb-glib.h"
@@ -125,79 +126,22 @@ gb_application_make_skeleton_dirs (GbApplication *self)
   g_free (path);
 }
 
-/**
- * gb_application_on_theme_changed:
- * @self: A #GbApplication.
- *
- * Update the theme overrides when the theme changes. This includes our custom
- * CSS for Adwaita, etc.
- */
-static void
-gb_application_on_theme_changed (GbApplication *self,
-                                 GParamSpec    *pspec,
-                                 GtkSettings   *settings)
-{
-  static GtkCssProvider *provider;
-  GdkScreen *screen;
-  gchar *theme;
-
-  IDE_ENTRY;
-
-  g_assert (GB_IS_APPLICATION (self));
-  g_assert (GTK_IS_SETTINGS (settings));
-
-  g_object_get (settings, "gtk-theme-name", &theme, NULL);
-  screen = gdk_screen_get_default ();
-
-  if (g_str_equal (theme, "Adwaita"))
-    {
-      if (provider == NULL)
-        {
-          GFile *file;
-
-          provider = gtk_css_provider_new ();
-          file = g_file_new_for_uri (ADWAITA_CSS);
-          gtk_css_provider_load_from_file (provider, file, NULL);
-          g_object_unref (file);
-        }
-
-      gtk_style_context_add_provider_for_screen (screen,
-                                                 GTK_STYLE_PROVIDER (provider),
-                                                 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-    }
-  else if (provider != NULL)
-    {
-      gtk_style_context_remove_provider_for_screen (screen,
-                                                    GTK_STYLE_PROVIDER (provider));
-      g_clear_object (&provider);
-    }
-
-  g_free (theme);
-
-  IDE_EXIT;
-}
-
 static void
 gb_application_register_theme_overrides (GbApplication *application)
 {
-  GtkSettings *settings;
+  GtkCssProvider *provider;
+  GdkScreen *screen;
 
   IDE_ENTRY;
 
   gtk_icon_theme_add_resource_path (gtk_icon_theme_get_default (),
                                     "/org/gnome/builder/icons/");
 
-  /* Set up a handler to load our custom css for Adwaita.
-   * See https://bugzilla.gnome.org/show_bug.cgi?id=732959
-   * for a more automatic solution that is still under discussion.
-   */
-  settings = gtk_settings_get_default ();
-  g_signal_connect_object (settings,
-                           "notify::gtk-theme-name",
-                           G_CALLBACK (gb_application_on_theme_changed),
-                           application,
-                           G_CONNECT_SWAPPED);
-  gb_application_on_theme_changed (application, NULL, settings);
+  provider = gb_css_provider_new ();
+  screen = gdk_screen_get_default ();
+  gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER (provider),
+                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+  g_object_unref (provider);
 
   IDE_EXIT;
 }
diff --git a/src/css/gb-css-provider.c b/src/css/gb-css-provider.c
new file mode 100644
index 0000000..b94a516
--- /dev/null
+++ b/src/css/gb-css-provider.c
@@ -0,0 +1,166 @@
+/* gb-css-provider.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <glib/gi18n.h>
+#include <ide.h>
+
+#include "gb-css-provider.h"
+
+struct _GbCssProvider
+{
+  GtkCssProvider parent_instance;
+
+  GtkSettings *settings;
+  gulong       notify_gtk_theme_name_handler;
+};
+
+G_DEFINE_TYPE (GbCssProvider, gb_css_provider, GTK_TYPE_CSS_PROVIDER)
+
+GtkCssProvider *
+gb_css_provider_new (void)
+{
+  return g_object_new (GB_TYPE_CSS_PROVIDER, NULL);
+}
+
+static void
+gb_css_provider_update (GbCssProvider *self)
+{
+  g_autofree gchar *theme_name = NULL;
+  g_autofree gchar *resource_path = NULL;
+  gboolean prefer_dark_theme = FALSE;
+
+  IDE_ENTRY;
+
+  g_assert (GB_IS_CSS_PROVIDER (self));
+  g_assert (GTK_IS_SETTINGS (self->settings));
+
+  g_object_get (self->settings,
+                "gtk-theme-name", &theme_name,
+                "gtk-application-prefer-dark-theme", &prefer_dark_theme,
+                NULL);
+
+  resource_path = g_strdup_printf ("/org/gnome/builder/theme/%s%s.css",
+                                   theme_name,
+                                   prefer_dark_theme ? "-dark" : "");
+
+  gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (self), resource_path);
+
+  IDE_EXIT;
+}
+
+static void
+gb_css_provider__settings_notify_gtk_theme_name (GbCssProvider *self,
+                                                 GParamSpec    *pspec,
+                                                 GtkSettings   *settings)
+{
+  g_assert (GB_IS_CSS_PROVIDER (self));
+
+  gb_css_provider_update (self);
+}
+
+static void
+gb_css_provider__settings_notify_gtk_application_prefer_dark_theme (GbCssProvider *self,
+                                                                    GParamSpec    *pspec,
+                                                                    GtkSettings   *settings)
+{
+  g_assert (GB_IS_CSS_PROVIDER (self));
+
+  gb_css_provider_update (self);
+}
+
+static void
+gb_css_provider_parsing_error (GtkCssProvider *provider,
+                               GtkCssSection  *section,
+                               const GError   *error)
+{
+  g_autofree gchar *uri = NULL;
+  GFile *file;
+  guint line = 0;
+  guint line_offset = 0;
+
+  g_assert (GB_IS_CSS_PROVIDER (provider));
+  g_assert (error != NULL);
+
+  if (section != NULL)
+    {
+      file = gtk_css_section_get_file (section);
+      uri = g_file_get_uri (file);
+      line = gtk_css_section_get_start_line (section);
+      line_offset = gtk_css_section_get_start_position (section);
+      g_warning ("Parsing Error: %s @ %u:%u: %s", uri, line, line_offset, error->message);
+    }
+  else
+    {
+      g_warning ("%s", error->message);
+    }
+}
+
+static void
+gb_css_provider_constructed (GObject *object)
+{
+  GbCssProvider *self = (GbCssProvider *)object;
+
+  G_OBJECT_CLASS (gb_css_provider_parent_class)->constructed (object);
+
+  self->settings = g_object_ref (gtk_settings_get_default ());
+
+  self->notify_gtk_theme_name_handler =
+    g_signal_connect_object (self->settings,
+                             "notify::gtk-theme-name",
+                             G_CALLBACK (gb_css_provider__settings_notify_gtk_theme_name),
+                             self,
+                             G_CONNECT_SWAPPED);
+
+  self->notify_gtk_theme_name_handler =
+    g_signal_connect_object (
+      self->settings,
+      "notify::gtk-application-prefer-dark-theme",
+      G_CALLBACK (gb_css_provider__settings_notify_gtk_application_prefer_dark_theme),
+      self,
+      G_CONNECT_SWAPPED);
+
+  gb_css_provider_update (self);
+}
+
+static void
+gb_css_provider_finalize (GObject *object)
+{
+  GbCssProvider *self = (GbCssProvider *)object;
+
+  ide_clear_signal_handler (self->settings, &self->notify_gtk_theme_name_handler);
+  g_clear_object (&self->settings);
+
+  G_OBJECT_CLASS (gb_css_provider_parent_class)->finalize (object);
+}
+
+static void
+gb_css_provider_class_init (GbCssProviderClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GtkCssProviderClass *provider_class = GTK_CSS_PROVIDER_CLASS (klass);
+
+  object_class->finalize = gb_css_provider_finalize;
+  object_class->constructed = gb_css_provider_constructed;
+
+  provider_class->parsing_error = gb_css_provider_parsing_error;
+}
+
+static void
+gb_css_provider_init (GbCssProvider *self)
+{
+}
diff --git a/src/css/gb-css-provider.h b/src/css/gb-css-provider.h
new file mode 100644
index 0000000..bc2dbe5
--- /dev/null
+++ b/src/css/gb-css-provider.h
@@ -0,0 +1,34 @@
+/* gb-css-provider.h
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GB_CSS_PROVIDER_H
+#define GB_CSS_PROVIDER_H
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_CSS_PROVIDER (gb_css_provider_get_type())
+
+G_DECLARE_FINAL_TYPE (GbCssProvider, gb_css_provider, GB, CSS_PROVIDER, GtkCssProvider)
+
+GtkCssProvider *gb_css_provider_new (void);
+
+G_END_DECLS
+
+#endif /* GB_CSS_PROVIDER_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 22fdefa..d03b82a 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -31,6 +31,8 @@ libgnome_builder_la_SOURCES = \
        src/commands/gb-command-vim.h \
        src/commands/gb-command.c \
        src/commands/gb-command.h \
+        src/css/gb-css-provider.c \
+        src/css/gb-css-provider.h \
        src/devhelp/gb-devhelp-document.c \
        src/devhelp/gb-devhelp-document.h \
        src/devhelp/gb-devhelp-view.c \
@@ -184,6 +186,7 @@ libgnome_builder_la_CFLAGS = \
        -I$(top_srcdir)/libide \
        -I$(top_srcdir)/src/app \
        -I$(top_srcdir)/src/commands \
+       -I$(top_srcdir)/src/css \
        -I$(top_srcdir)/src/devhelp \
        -I$(top_srcdir)/src/dialogs \
        -I$(top_srcdir)/src/documents \
diff --git a/src/resources/gnome-builder.gresource.xml b/src/resources/gnome-builder.gresource.xml
index 9369d00..81147db 100644
--- a/src/resources/gnome-builder.gresource.xml
+++ b/src/resources/gnome-builder.gresource.xml
@@ -1,7 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gresources>
   <gresource prefix="/org/gnome/builder">
-    <file alias="css/builder.Adwaita.css">../../data/css/builder.Adwaita.css</file>
     <file alias="css/markdown.css">../../data/css/markdown.css</file>
 
     <file>editor/uncrustify/uncrustify.c.cfg</file>
@@ -33,6 +32,10 @@
     <file alias="keybindings/emacs.css">../../data/keybindings/emacs.css</file>
     <file alias="keybindings/vim.css">../../data/keybindings/vim.css</file>
 
+    <file alias="theme/Adwaita.css">../../data/theme/Adwaita.css</file>
+    <file alias="theme/Adwaita-dark.css">../../data/theme/Adwaita-dark.css</file>
+    <file alias="theme/Adwaita-shared.css">../../data/theme/Adwaita-shared.css</file>
+
     <file alias="ui/gb-command-bar.ui">../../data/ui/gb-command-bar.ui</file>
     <file alias="ui/gb-devhelp-view.ui">../../data/ui/gb-devhelp-view.ui</file>
     <file alias="ui/gb-editor-frame.ui">../../data/ui/gb-editor-frame.ui</file>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]