From 47ee9eaf5404162e517f37d096f16eee077c7d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacy=20Kuchci=C5=84ski?= Date: Sat, 20 Aug 2022 14:38:02 +0200 Subject: [PATCH] application: Adopt AdwApplication Doing this allows us to automatically load stylesheets located in the resource base path, so move contents of both Adwaita.css and nautilus.css to style.css in the root of the resource directory, which will be always automatically loaded. Additionally, create a style-hc.css which will be used when the system high contrast preference is enabled, and adjust it to fix issues with NautilusPathBar. Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/2166 --- src/nautilus-application.c | 42 +------------------- src/nautilus-application.h | 8 ++-- src/resources/css/nautilus.css | 7 ---- src/resources/nautilus.gresource.xml | 4 +- src/resources/style-hc.css | 3 ++ src/resources/{css/Adwaita.css => style.css} | 8 ++++ 6 files changed, 18 insertions(+), 54 deletions(-) delete mode 100644 src/resources/css/nautilus.css create mode 100644 src/resources/style-hc.css rename src/resources/{css/Adwaita.css => style.css} (96%) diff --git a/src/nautilus-application.c b/src/nautilus-application.c index 41fb539d2c..eb7b6e32ec 100644 --- a/src/nautilus-application.c +++ b/src/nautilus-application.c @@ -91,7 +91,7 @@ typedef struct guint previewer_selection_id; } NautilusApplicationPrivate; -G_DEFINE_TYPE_WITH_PRIVATE (NautilusApplication, nautilus_application, GTK_TYPE_APPLICATION); +G_DEFINE_TYPE_WITH_PRIVATE (NautilusApplication, nautilus_application, ADW_TYPE_APPLICATION); void nautilus_application_set_accelerator (GApplication *app, @@ -791,7 +791,7 @@ action_kill (GSimpleAction *action, GVariant *parameter, gpointer user_data) { - GtkApplication *application = user_data; + AdwApplication *application = user_data; /* we have been asked to force quit */ g_application_quit (G_APPLICATION (application)); @@ -1054,40 +1054,6 @@ nautilus_application_init (NautilusApplication *self) nautilus_clipboard_register (); } -static void -setup_theme_extensions (void) -{ - static GtkCssProvider *provider = NULL; - static GtkCssProvider *permanent_provider = NULL; - GdkDisplay *display; - - display = gdk_display_get_default (); - - /* CSS that themes can override */ - if (provider == NULL) - { - provider = gtk_css_provider_new (); - gtk_css_provider_load_from_resource (provider, "/org/gnome/nautilus/css/Adwaita.css"); - gtk_style_context_add_provider_for_display (display, - GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - } - - /* CSS we want to always load for any theme */ - if (permanent_provider == NULL) - { - permanent_provider = gtk_css_provider_new (); - gtk_css_provider_load_from_resource (permanent_provider, "/org/gnome/nautilus/css/nautilus.css"); - /* The behavior of two style providers with the same priority is - * undefined and gtk happens to prefer the provider that got added last. - * Use a higher priority here to avoid this problem. - */ - gtk_style_context_add_provider_for_display (display, - GTK_STYLE_PROVIDER (permanent_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1); - } -} - NautilusApplication * nautilus_application_get_default (void) { @@ -1180,12 +1146,8 @@ nautilus_application_startup_common (NautilusApplication *self) */ G_APPLICATION_CLASS (nautilus_application_parent_class)->startup (G_APPLICATION (self)); - adw_init (); - gtk_window_set_default_icon_name (APPLICATION_ID); - setup_theme_extensions (); - /* initialize preferences and create the global GSettings objects */ nautilus_global_preferences_init (); diff --git a/src/nautilus-application.h b/src/nautilus-application.h index 83cc01252f..50bcf4d1c1 100644 --- a/src/nautilus-application.h +++ b/src/nautilus-application.h @@ -20,18 +20,16 @@ #pragma once -#include -#include -#include +#include #include "nautilus-types.h" G_BEGIN_DECLS #define NAUTILUS_TYPE_APPLICATION (nautilus_application_get_type()) -G_DECLARE_DERIVABLE_TYPE (NautilusApplication, nautilus_application, NAUTILUS, APPLICATION, GtkApplication) +G_DECLARE_DERIVABLE_TYPE (NautilusApplication, nautilus_application, NAUTILUS, APPLICATION, AdwApplication) struct _NautilusApplicationClass { - GtkApplicationClass parent_class; + AdwApplicationClass parent_class; void (*open_location_full) (NautilusApplication *application, GFile *location, diff --git a/src/resources/css/nautilus.css b/src/resources/css/nautilus.css deleted file mode 100644 index fd47a9c817..0000000000 --- a/src/resources/css/nautilus.css +++ /dev/null @@ -1,7 +0,0 @@ -label.encrypted_zip { - background-image: -gtk-icontheme('system-lock-screen-symbolic'); - background-position: right center; - background-repeat: no-repeat; - background-size: 16px 16px; - padding-right: 22px; -} diff --git a/src/resources/nautilus.gresource.xml b/src/resources/nautilus.gresource.xml index 6057d7eac6..bfe8b2bd34 100644 --- a/src/resources/nautilus.gresource.xml +++ b/src/resources/nautilus.gresource.xml @@ -32,8 +32,8 @@ ../gtk/nautilusgtkplacesview.ui ../gtk/nautilusgtkplacesviewrow.ui ../../icons/filmholes.png - css/Adwaita.css - css/nautilus.css + style.css + style-hc.css text-x-preview.png Checkerboard.png diff --git a/src/resources/style-hc.css b/src/resources/style-hc.css new file mode 100644 index 0000000000..c5a1d0c729 --- /dev/null +++ b/src/resources/style-hc.css @@ -0,0 +1,3 @@ +#NautilusPathBar { + box-shadow: 0 0 0 1px @borders; +} diff --git a/src/resources/css/Adwaita.css b/src/resources/style.css similarity index 96% rename from src/resources/css/Adwaita.css rename to src/resources/style.css index 88afd0a269..205811c538 100644 --- a/src/resources/css/Adwaita.css +++ b/src/resources/style.css @@ -291,3 +291,11 @@ min-height: 36px; -gtk-icon-size: 32px; } + +label.encrypted_zip { + background-image: -gtk-icontheme('system-lock-screen-symbolic'); + background-position: right center; + background-repeat: no-repeat; + background-size: 16px 16px; + padding-right: 22px; +} -- GitLab