From 0c62962d06319f47e92a5b3320afc30d20beb34b Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Thu, 23 Sep 2021 02:51:46 -0700 Subject: [PATCH] application: Subclass AdwApplication AdwApplication automatically handles styling for us. --- data/gnome_image_viewer.gresource.xml | 2 +- data/{image-viewer.css => style.css} | 0 src/application.rs | 13 ++++++------- 3 files changed, 7 insertions(+), 8 deletions(-) rename data/{image-viewer.css => style.css} (100%) diff --git a/data/gnome_image_viewer.gresource.xml b/data/gnome_image_viewer.gresource.xml index 90e889a..7f49ff2 100644 --- a/data/gnome_image_viewer.gresource.xml +++ b/data/gnome_image_viewer.gresource.xml @@ -4,6 +4,6 @@ gtk/help_overlay.ui gtk/window.ui gtk/image_view.ui - image-viewer.css + style.css diff --git a/data/image-viewer.css b/data/style.css similarity index 100% rename from data/image-viewer.css rename to data/style.css diff --git a/src/application.rs b/src/application.rs index 78f43ea..5dd0ae0 100644 --- a/src/application.rs +++ b/src/application.rs @@ -23,6 +23,7 @@ use glib::subclass::prelude::*; use gtk::prelude::*; use gtk::subclass::prelude::*; use gtk_macros::*; +use libadwaita::subclass::prelude::*; use crate::config; use crate::window::IvWindow; @@ -44,7 +45,7 @@ mod imp { impl ObjectSubclass for IvApplication { const NAME: &'static str = "IvApplication"; type Type = super::IvApplication; - type ParentType = gtk::Application; + type ParentType = libadwaita::Application; // Initialize with default values fn new() -> Self { @@ -60,11 +61,7 @@ mod imp { fn constructed(&self, obj: &Self::Type) { self.parent_constructed(obj); - // Set up the CSS and force dark theme - let display = gdk::Display::default().unwrap(); - let provider = gtk::CssProvider::new(); - provider.load_from_resource("/org/gnome/ImageViewer/image-viewer.css"); - gtk::StyleContext::add_provider_for_display(&display, &provider, 600); + // Force dark theme self.gtk_settings .set_gtk_application_prefer_dark_theme(true); @@ -93,6 +90,7 @@ mod imp { // This is empty, but we still need to provide an // empty implementation for each type we subclass. impl GtkApplicationImpl for IvApplication {} + impl AdwApplicationImpl for IvApplication {} } // Creates a wrapper struct that inherits the functions @@ -101,7 +99,7 @@ mod imp { // IvApplication without casting. glib::wrapper! { pub struct IvApplication(ObjectSubclass) - @extends gio::Application, gtk::Application, + @extends gio::Application, gtk::Application, libadwaita::Application, @implements gio::ActionGroup, gio::ActionMap; } @@ -112,6 +110,7 @@ impl IvApplication { glib::Object::new(&[ ("application-id", &config::APP_ID.to_string()), ("flags", &gio::ApplicationFlags::HANDLES_OPEN), + ("resource-base-path", &"/org/gnome/ImageViewer/".to_string()), ]) .unwrap() }