[gnome-software/wip/exalm/style-loading: 1/2] application: Use AdwApplication




commit b37b313f9a2a19a346339cd1c51bd7d70cb18bb2
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Nov 10 02:24:17 2021 +0500

    application: Use AdwApplication
    
    Take advantage of automatic initialization and style loading.
    
    Don't load regular style from the HC one, they are already layered on top
    of each other.

 src/gnome-software.gresource.xml       |  4 ++--
 src/gs-application.c                   | 34 ++--------------------------------
 src/gs-application.h                   |  4 ++--
 src/{gtk-style-hc.css => style-hc.css} |  2 --
 src/{gtk-style.css => style.css}       |  0
 5 files changed, 6 insertions(+), 38 deletions(-)
---
diff --git a/src/gnome-software.gresource.xml b/src/gnome-software.gresource.xml
index 7255b5184..5d7163faf 100644
--- a/src/gnome-software.gresource.xml
+++ b/src/gnome-software.gresource.xml
@@ -50,8 +50,8 @@
   <file preprocess="xml-stripblanks">gs-updates-section.ui</file>
   <file preprocess="xml-stripblanks">gs-upgrade-banner.ui</file>
   <file preprocess="xml-stripblanks">org.freedesktop.PackageKit.xml</file>
-  <file>gtk-style.css</file>
-  <file>gtk-style-hc.css</file>
+  <file>style.css</file>
+  <file>style-hc.css</file>
   <file preprocess="xml-stripblanks" alias="up-to-date.svg">../data/assets/up-to-date.svg</file>
   <file preprocess="xml-stripblanks" 
alias="icons/scalable/apps/system-component-addon.svg">../data/icons/system-component-addon.svg</file>
   <file preprocess="xml-stripblanks" 
alias="icons/scalable/apps/system-component-application.svg">../data/icons/system-component-application.svg</file>
diff --git a/src/gs-application.c b/src/gs-application.c
index b62931bc1..f128f9e81 100644
--- a/src/gs-application.c
+++ b/src/gs-application.c
@@ -13,7 +13,6 @@
 #include "gs-application.h"
 
 #include <stdlib.h>
-#include <adwaita.h>
 #include <glib/gi18n.h>
 #include <gio/gio.h>
 #include <gio/gdesktopappinfo.h>
@@ -35,9 +34,8 @@
 #define ENABLE_REPOS_DIALOG_CONF_KEY "enable-repos-dialog"
 
 struct _GsApplication {
-       GtkApplication   parent;
+       AdwApplication   parent;
        GCancellable    *cancellable;
-       GtkCssProvider  *provider;
        GsPluginLoader  *plugin_loader;
        gint             pending_apps;
        GtkWindow       *main_window;
@@ -53,7 +51,7 @@ struct _GsApplication {
        GsDebug         *debug;  /* (owned) (not nullable) */
 };
 
-G_DEFINE_TYPE (GsApplication, gs_application, GTK_TYPE_APPLICATION);
+G_DEFINE_TYPE (GsApplication, gs_application, ADW_TYPE_APPLICATION);
 
 typedef enum {
        PROP_DEBUG = 1,
@@ -236,21 +234,6 @@ gs_application_show_first_run_dialog (GsApplication *app)
        }
 }
 
-static void
-theme_changed (GtkSettings *settings, GParamSpec *pspec, GsApplication *app)
-{
-       g_autoptr(GFile) file = NULL;
-       g_autofree gchar *theme = NULL;
-
-       g_object_get (settings, "gtk-theme-name", &theme, NULL);
-       if (g_strcmp0 (theme, "HighContrast") == 0) {
-               file = g_file_new_for_uri ("resource:///org/gnome/Software/gtk-style-hc.css");
-       } else {
-               file = g_file_new_for_uri ("resource:///org/gnome/Software/gtk-style.css");
-       }
-       gtk_css_provider_load_from_file (app->provider, file);
-}
-
 static void
 gs_application_shell_loaded_cb (GsShell *shell, GsApplication *app)
 {
@@ -268,16 +251,6 @@ gs_application_initialize_ui (GsApplication *app)
 
        initialized = TRUE;
 
-       /* get CSS */
-       app->provider = gtk_css_provider_new ();
-       gtk_style_context_add_provider_for_display (gdk_display_get_default (),
-                                                   GTK_STYLE_PROVIDER (app->provider),
-                                                   GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-
-       g_signal_connect (gtk_settings_get_default (), "notify::gtk-theme-name",
-                         G_CALLBACK (theme_changed), app);
-       theme_changed (gtk_settings_get_default (), NULL, app);
-
        gs_application_initialize_plugins (app);
 
        /* setup UI */
@@ -1002,8 +975,6 @@ gs_application_startup (GApplication *application)
        GsApplication *app = GS_APPLICATION (application);
        G_APPLICATION_CLASS (gs_application_parent_class)->startup (application);
 
-       adw_init ();
-
        gs_application_add_wrapper_actions (application);
 
        g_action_map_add_action_entries (G_ACTION_MAP (application),
@@ -1109,7 +1080,6 @@ gs_application_dispose (GObject *object)
 
        g_clear_object (&app->plugin_loader);
        g_clear_object (&app->shell);
-       g_clear_object (&app->provider);
        g_clear_object (&app->update_monitor);
 #ifdef HAVE_PACKAGEKIT
        g_clear_object (&app->dbus_helper);
diff --git a/src/gs-application.h b/src/gs-application.h
index 04461bd3b..cf8fb7ab1 100644
--- a/src/gs-application.h
+++ b/src/gs-application.h
@@ -8,14 +8,14 @@
 
 #pragma once
 
-#include <gtk/gtk.h>
+#include <adwaita.h>
 
 #include "gnome-software-private.h"
 #include "gs-debug.h"
 
 #define GS_APPLICATION_TYPE (gs_application_get_type ())
 
-G_DECLARE_FINAL_TYPE (GsApplication, gs_application, GS, APPLICATION, GtkApplication)
+G_DECLARE_FINAL_TYPE (GsApplication, gs_application, GS, APPLICATION, AdwApplication)
 
 GsApplication  *gs_application_new                     (GsDebug *debug);
 GsPluginLoader *gs_application_get_plugin_loader       (GsApplication *application);
diff --git a/src/gtk-style-hc.css b/src/style-hc.css
similarity index 95%
rename from src/gtk-style-hc.css
rename to src/style-hc.css
index c01b5b120..0144d4c19 100644
--- a/src/gtk-style-hc.css
+++ b/src/style-hc.css
@@ -1,5 +1,3 @@
-@import url("resource:///org/gnome/Software/gtk-style.css");
-
 .installed-overlay-box {
        text-shadow: none;
 }
diff --git a/src/gtk-style.css b/src/style.css
similarity index 100%
rename from src/gtk-style.css
rename to src/style.css


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